-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSynthRadScan.py
More file actions
182 lines (144 loc) · 6.14 KB
/
Copy pathSynthRadScan.py
File metadata and controls
182 lines (144 loc) · 6.14 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
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
import numpy as np
def SynthRadScan(r, p, b, JJ_, verbose=False, nharmonics=5):
"""
r = radial node vector (cm)
p = pressure matrix (radial x harmonic spectrum)
b = hydrophone element radius (cm)
returns SpecOut, a structure containing p_r and p_c, vectors of averaged
peak rarefactional and compressional pressure and first (up to) 5
averaged harmonic pressure amplitudes, all as a function of radius.
Also contains the averaged waveform on axis.
"""
class SpecOutClass(object):
pass
# JJ = number of radial nodes; KK = number of harmonics
[_, KK] = np.shape(p)
# mesh spacing near axis
dr_min = r[1]
debug = False
if (debug):
print(JJ_)
print(KK)
print( type(np.ceil(10*b/dr_min) ) )
# matrix of spatially averaged pressure values
p_h = np.zeros( (int(JJ_),int(KK)), dtype=complex )
# number of points over which to spatially average
NN = np.max( [int(4), int(np.ceil(10*b/dr_min))] )
dr = b / (NN - 1)
x = np.linspace(0, b, int(NN) )
q = np.zeros((int(NN),KK), dtype=complex)
U = np.zeros((int(2*KK),), dtype=complex)
for kk in np.arange(0, KK):
if debug: print( kk, np.shape(q[:,kk]), np.shape(x), np.shape(r), np.shape( p[:,kk] ), np.shape( interp(x, r, p[:,kk]) ) )
q[:,kk] = np.interp(x, r, p[:,kk])
p_h[0,kk] = dr * np.trapezoid(q[:,kk] * x)
for jj in np.arange(1,int(JJ_), dtype=int):
if (r[jj] < b):
# if element overlays central axis
# setup for "inner circle"
lowerlimit = 0
upperlimit = b - r[jj]
NN = np.ceil(10.0 * (upperlimit - lowerlimit) / dr_min)
dr = (upperlimit - lowerlimit) / (NN - 1)
x = np.linspace(lowerlimit, upperlimit, int(NN))
q = np.zeros((int(NN),KK), dtype=complex)
for kk in np.arange(0, KK, dtype=int):
if (debug): print( kk, np.shape(x), np.shape(r), np.shape(p[:,kk]) )
q[:,kk] = np.interp(x, r, p[:,kk])
p_h[jj,kk] = dr * np.trapezoid( np.conj( np.transpose(q[:,kk]) ) * x )
# setup for outer crescent
lowerlimit = b - r[jj]
upperlimit = r[jj] + b
NN = np.ceil( 10*(upperlimit - lowerlimit) / dr_min)
dr = (upperlimit - lowerlimit) / (NN - 1)
x = np.linspace(lowerlimit, upperlimit, int(NN))
q = np.zeros((int(NN),KK), dtype=complex)
for kk in np.arange(0, KK, dtype=int):
q[:,kk] = np.interp(x, r, p[:,kk])
W = weight(x, r[jj], b)
p_h[jj,kk] = p_h[jj,kk] + dr * np.trapezoid( np.conj( np.transpose( q[:,kk] )) * W * x)
else:
lowerlimit = r[jj] - b
upperlimit = r[jj] + b
NN = np.ceil(10*(upperlimit - lowerlimit) / dr_min)
dr = (upperlimit - lowerlimit)/(NN-1)
if (debug): print( upperlimit, lowerlimit, NN, r[jj], b, dr_min)
x = np.linspace(lowerlimit, upperlimit, int(NN))
q = np.zeros((int(NN), KK), dtype=complex)
for kk in np.arange(0, KK, dtype=int):
if (debug): print( np.shape(x), np.shape(r), np.shape(p[:,0]), np.shape(q[:,kk]), np.shape(p_h[jj,kk]) )
q[:,kk] = np.interp(x, r, p[:,kk])
W = weight(x, r[jj], b)
p_h[jj,kk] = dr * np.trapezoid( np.conj( np.transpose(q[:,kk] )) * W * x)
p_h = 2.0*p_h/b/b
p5 = np.abs( p_h[:,0:np.min([nharmonics,KK])] )
p_r = np.zeros((int(JJ_),))
p_c = np.zeros((int(JJ_),))
# determine peak compressional p_c and rarefactional p_r pressure
if (KK == 1):
# linear case - do nothing
for jj in np.arange(0, JJ_, dtype=int):
p_c[jj] = np.abs( p_h[jj, 0] )
p_r = -p_c
else:
# nonlinear case - transform to time domain
# in each radial node jj
for jj in np.arange(JJ_-1, 0, -1, dtype=int):
if debug: print( JJ_, JJ_-1, jj, np.shape(U), np.shape( U[1:KK+1] ), np.shape( np.conj( p_h[jj,:] ) ), np.shape( U[2*KK-1:KK+1:-1] ), np.shape(p_h[jj, 0:KK-2]) )
U[1:KK+1] = np.conj( p_h[jj,:] )
U[2*KK-1:KK+1:-1] = p_h[jj, 0:KK-2]
# transform to time domain:
U = KK * np.fft.ifft(U)
p_r[jj] = np.min( np.real(U) )
p_c[jj] = np.max( np.real(U) )
SpecOut = SpecOutClass()
SpecOut.w = U
SpecOut.pr = p_r
SpecOut.pc = p_c
SpecOut.p5 = p5
SpecOut.I = p_r # placeholder; intensity is assigned in WAKZK()
return SpecOut
def weight(r, r0, b):
import warnings
#np.seterr(all='print')
arg = (r*r + r0*r0 - b*b) / (2.0*r0*r)
cond = np.abs(arg-1.0)
v = np.argwhere(cond >= 0.0)
x = np.zeros(np.shape(arg))
# print("v =", v)
# print("size v:", np.shape(v))
# if (np.size(v,0) > 1):
# print("\t", v[1,:] )
# print("size arg:", np.size(arg))
with warnings.catch_warnings():
warnings.filterwarnings('error')
for i in np.arange(0, np.size(arg) ):
if (np.size(v,0) != 0):
if i in v[0, :]:
x[i] = 0.0
print("replaced i", i, "with zero.")
else:
x[i] = np.real( np.arccos( arg[i] ) / np.pi )
# try:
# x[i] = np.real( np.arccos( arg[i] )/np.pi )
# except Warning as e:
# print('Houston, we have a warning:', e)
# print(i, )
# x[i] = 0.0
# pass
# for i in np.arange(0, np.size(arg) ):
# try:
# x[i] = np.real( np.arccos( arg[i] )/np.pi )
# except Warning:
# print(i)
# x[i] = 0.0
# for i in np.arange(0, np.size(arg) ):
# if (np.size(v,0) != 0):
# if i in v[0,:]:
# x[i] = 0.0
# else:
# x[i] = np.real( np.arccos( arg[i] )/np.pi )
#c = np.size( x[np.isnan(x)] )
# print(a, c, np.transpose(v), arg, x, np.isnan(x).sum() )
#x[np.isnan(x)] = 0.0
return x