-
Notifications
You must be signed in to change notification settings - Fork 1
/
kraken_modaldecomp.py
218 lines (167 loc) · 5.57 KB
/
kraken_modaldecomp.py
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
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
#==================================================================
#
# KRAKEN: Elba waveguide
# Source localization with modal decomposition
# Gambelas, qui 20 jun 2024 12:25:01
# Written by Orlando Camargo Rodriguez
#
#==================================================================
from os import *
import sys
from numpy import *
from matplotlib.pyplot import *
from wkrakenenvfil import *
from readmod import *
from readshd import *
print('Elba waveguide:')
case_title = 'Elba waveguide'
freq = 170.0 # frequency in Hz
zs = array([79.0]) # Source depth
rs = array([ 0.0]) # Auxiliary parameter
rmax = 5437.0
rmaxkm = rmax/1000
nra = 1
rarray = array([rmax]); rarraykm = rarray/1000
first_hyd = 17.7
dhyd = 2
last_hyd = 89.7
zarray = arange(first_hyd,last_hyd+dhyd,dhyd)
nza = zarray.size
layer_info = array([[98.0,1600.0,130.0,1.49,0.1,1.70],
[103.0,1800.0,500.0,1.90,0.90,2.50],
[128.0,2500.0,900.0,2.40,0.01,0.01]])
#==================================================================
#
# Source data
#
#==================================================================
source_data = {"zs":zs, "f":freq}
#==================================================================
#
# Surface data
#
#==================================================================
bc = 'V'
properties = [] # Not required (vacuum over surface)
reflection = [] # Not required for this case
surface_data = {"bc":bc,"properties":properties,"reflection":reflection}
#==================================================================
#
# Scatter data
#
#==================================================================
# Scatter is not required for this case:
bumden = [] # Bump density in ridges/km
eta = [] # Principal radius 1 of bump
xi = [] # Principal radius 2 of bump
scatter_data= {"bumden":bumden,"eta":eta,"xi":xi}
#==================================================================
#
# Sound speed data
#
#==================================================================
sspdata = loadtxt("elba.ssp")
z = sspdata[:,0]; zmax = max( z )
c = sspdata[:,1]
nz = z.size
cs = zeros(nz)
rho = ones(nz)
apt = cs
ast = cs
type = 'H'
itype = 'N'
nmesh = 0 # Number of mesh points (let KRAKEN decide)
sigma = 0.0 # RMS roughness at the surface
clow = 1500.0
chigh = 1800.0
cdata = array([z,c,cs,rho,apt,ast])
ssp_data = {"cdata":cdata,"type":type,"itype":itype,"nmesh":nmesh,"sigma":sigma,"clow":clow,"chigh":chigh,"zbottom":zmax}
#==================================================================
#
# Bottom data
#
#==================================================================
layerp = array([[nmesh, 0.0, layer_info[1,0]],
[nmesh, 0.0, layer_info[2,0]]])
layert = 'HH'
properties = array( layer_info[2,] )
m1 = array( [layer_info[0,],layer_info[0,]] )
m2 = array( [layer_info[1,],layer_info[1,]] )
bdata = array( [m1,m2] )
bdata[0,1,0] = layer_info[1,0]
bdata[1,1,0] = layer_info[2,0]
units = 'W';
bc = 'A';
sigma = 0.0 # Interfacial roughness
bottom_data = {"n":3,"layerp":layerp,"layert":layert,"properties":properties,"bdata":bdata,"units":units,"bc":bc,"sigma":sigma}
#==================================================================
#
# Field data
#
#==================================================================
rp = 0
np = 1
m = 999
rmodes = 'A'
stype = 'R'
thorpe = 'T'
finder = ' '
dr = zeros( nza )
field_data = {"rmax":rmaxkm,"nrr":nra,"rr":rarraykm,"rp":rp,"np":np,"m":m,"rmodes":rmodes,"stype":stype,"thorpe":thorpe,"finder":finder,"rd":zarray,"dr":dr,"nrd":nza}
print( "Generating the observation..." )
wkrakenenvfil('elba',case_title,source_data,surface_data,scatter_data,ssp_data, bottom_data,field_data)
system("krakenc.exe elba")
system("cp field.flp elba.flp")
system("field.exe elba < elba.flp")
filename = 'elba.shd'
pressure,geometry = readshd(filename,nan,nan,nan)
p = squeeze( pressure )
Modes,bc = readmod('elba.mod')
phi = Modes["phi"]
M = phi[0,:].size
zphi = Modes["z" ]
f = abs( zphi - zs )
index = f.argmin()
E = delete(phi, index, axis=0)
E = E[:,0:M-1] # Let's skip the last mode...
a = linalg.lstsq(E,p,rcond=None)[0]
a = a/linalg.norm( a )
print( "Generating the replicas..." )
rmin = 4000.0; rminkm = rmin/1000
rmax = 7000.0; rmaxkm = rmax/1000
nra = 201; rarray = linspace(rmin,rmax,nra); rarraykm = rarray/1000
nzs = 124
zs = linspace(1,124,nzs)
source_data = {"zs":zs, "f":freq}
field_data = {"rmax":rmaxkm,"nrr":nra,"rr":rarraykm,"rp":rp,"np":np,"m":m,"rmodes":rmodes,"stype":stype,"thorpe":thorpe,"finder":finder,"rd":zarray,"dr":dr,"nrd":nza}
wkrakenenvfil('elba',case_title,source_data,surface_data,scatter_data,ssp_data, bottom_data,field_data)
system("krakenc.exe elba")
system("cp field.flp elba.flp")
system("field.exe elba < elba.flp")
filename = 'elba.shd'
pressure,geometry = readshd(filename,nan,nan,nan)
p = squeeze( pressure )
estimator = zeros((nzs,nra))
print('Estimating source range and depth...')
for i in range(nzs):
pii = squeeze( p[i,:,:] )
for j in range(nra):
pj = squeeze( pii[:,j] )
e = linalg.lstsq(E,pj,rcond=None)[0]
e = e/linalg.norm( e )
estimator[i,j] = abs( inner(conj(e),a) )
maxe = amax( estimator )
ji = where( estimator == maxe )
j = ji[0]
i = ji[1]
rsb = rarray[i][0]
zsb = zs[j][0]
thetitle = 'Source located at (' + str(rsb) + ',' + str(zsb) + ') m'
figure()
imshow(estimator,cmap='jet',extent=[rarraykm[0],rarraykm[-1],zs[-1],zs[0]],aspect='auto')
colorbar()
xlabel('Range (km)',fontsize=18)
ylabel('Depth (m)',fontsize=18)
title(thetitle)
show()
print("done.")