-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathWedgeCalibration.py
More file actions
138 lines (78 loc) · 3.51 KB
/
WedgeCalibration.py
File metadata and controls
138 lines (78 loc) · 3.51 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
import FMC as f
import numpy as np
import _pickle as pickle
from scipy.signal import hilbert
import itertools
import matplotlib.pylab as plt
from imp import reload
reload(f)
def MeasureThickness(AScans,fs,N,p,h,angle,cw,cl,Th):
h = h + 0.5*p*(N-1)*np.sin(angle)
T = int(np.round(fs*2*(h/cw + Th/cl)))
W = int(np.round(fs*0.25*Th/cl))
b = np.argmax(np.abs(hilbert(np.real(AScans[0,0,T-W:T+W])))) + T - W
t1 = b/fs
T = int(np.round(fs*2*(h/cw + 2*Th/cl)))
b = np.argmax(np.abs(hilbert(np.real(AScans[0,0,T-W:T+W])))) + T - W
t2 = b/fs
return 0.5*cl*(t2-t1)
# return 0.5*cl*(b/fs - 2*(h/cw))
def MeasureProbeOffset(AScans,SweepAngle,fs,N,p,h,angle,cw,cs,Th):
phiw = angle
a = SweepAngle
phir = np.arcsin((cs/cw)*np.sin(phiw+a))
T = int(np.round(2*fs*(Th/cs*np.cos(phir) + (h + 0.5*p*(N-1)*np.sin(phiw))/(cw*np.cos(phiw+a)))))
W = int(np.round(0.15*T))
s = np.abs(hilbert(np.real(AScans[T-W:T+W])))
b = np.argmax(s) + T - W
L = cs*np.sin(phir)*(0.5*b/fs - (h + 0.5*p*(N-1)*np.sin(phiw))/(cw*np.cos(phiw+a)))
offset = L + np.tan(phiw+a)*(h + 0.5*p*(N-1)*np.sin(phiw)) + np.cos(phiw)*(0.5*p*(N-1))
return (np.max(s),offset)
def KeepDiagonalElements(AScans):
return np.array([AScans[n,n,:] for n in range(AScans.shape[0])])
def EstimateWedgeParameters(AScans,fs,h,cw,angle,p):
from scipy.signal import hilbert
A = KeepDiagonalElements(AScans)
B = np.zeros(A.shape[0])
for i in range(A.shape[0]):
eh = h + i*p*np.sin(angle*np.pi/180)
t = int(np.round(fs*2*eh/cw))
w = int(np.round(fs*0.25*eh/cw))
b = np.argmax(np.abs(hilbert(np.real(A[i,t-w:t+w])))) + t - w
B[i] = (0.5*cw*b)/fs
plt.plot(B)
plt.show()
# NN=A.shape[0]-1
Co = np.polyfit(np.array(range(A.shape[0])),B,1)
return {'Height':Co[1], 'Angle':np.arcsin(Co[0]/p)*180/np.pi}
# fs, cw, Th, cs, cl, p, h, angle, N = 25., 2.33, 10, 3.24, 5.9, 0.6, 6.7, 31.9, 32
fs, cw, T, cs, cl, p, h, angle, N = 25., 1.48, 25, 3.24, 5.9, 0.6, 32, 13, 32
WedgeParameter = {'Height':h,'Velocity': cw, 'Angle':angle}
# Scans = pickle.load(open('/mnt/c/Users/mmarvasti/Desktop/MoScans/CheckBackWallDelays/BackwallTest.p','rb'))
Scans = pickle.load(open('/mnt/c/Users/mmarvasti/Desktop/MoScans/LReference.p','rb'))
# Scans = pickle.load(open('/mnt/c/Users/mmarvasti/Desktop/MoScans/Sample11.p','rb'))
# F = f.LinearCapture(fs,[Scans['AScans'][1]],p,32,WedgeParameters=WedgeParameter)
F = f.LinearCapture(fs,[Scans['AScans'][0]],p,64,WedgeParameters=WedgeParameter)
F.ProcessScans(100,100)
F.KeepElements(range(N))
# F.KeepElements(range(32,64))
WP = EstimateWedgeParameters(F.AScans[0],fs,h,cw,angle,p)
WedgeParameter = {'Height':WP['Height'],'Velocity': cw, 'Angle':WP['Angle']}
h = WedgeParameter['Height']
angle = WedgeParameter['Angle'] *np.pi/180
cw = WedgeParameter['Velocity']
B = F.PlaneWaveSweep(0,(np.array([-angle]),np.array([-angle])),(range(N),range(N)),cw)
Th = MeasureThickness(B,fs,N,p,h,angle,cw,cl,T)
print(h)
print(angle*180/np.pi)
print(Th)
del(F)
F = f.LinearCapture(fs,[Scans['AScans'][0]],p,64,WedgeParameters=WedgeParameter)
F.ProcessScans(100,100)
sweepangles = np.arange(0,3,0.25) * np.pi/180
PC = F.PlaneWaveSweep(0,sweepangles,(np.array(range(32)),np.array(range(32,64))), cw)
S = np.array([MeasureProbeOffset(PC[i,:],sweepangles[i],fs,N,p,h,angle,cw,cs,Th)[0] for i in range(PC.shape[0])])
m = np.argmax(S)
Offset = MeasureProbeOffset(PC[m,:],sweepangles[m],fs,N,p,h,angle,cw,cs,Th)[1]
print('Offset is:')
print(Offset)