hyperdd 0.1__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- hyperdd/__init__.py +3 -0
- hyperdd/config.py +186 -0
- hyperdd/core/__init__.py +0 -0
- hyperdd/core/cluster.py +65 -0
- hyperdd/core/datatypes.py +65 -0
- hyperdd/core/dtres.py +44 -0
- hyperdd/core/jacobian.py +152 -0
- hyperdd/core/kernels.py +71 -0
- hyperdd/core/partials.py +126 -0
- hyperdd/core/partials_obs.py +243 -0
- hyperdd/core/partition.py +158 -0
- hyperdd/core/skip.py +83 -0
- hyperdd/core/weighting.py +103 -0
- hyperdd/geodesy/__init__.py +0 -0
- hyperdd/geodesy/coordinates.py +286 -0
- hyperdd/geodesy/delaz_vec.py +65 -0
- hyperdd/hypoDD.py +1167 -0
- hyperdd/io/__init__.py +0 -0
- hyperdd/io/readers.py +312 -0
- hyperdd/io/writers.py +153 -0
- hyperdd/models/__init__.py +0 -0
- hyperdd/models/velocity.py +447 -0
- hyperdd/models/velocity_numba.py +238 -0
- hyperdd/models/velocity_sr.py +228 -0
- hyperdd/solvers/__init__.py +0 -0
- hyperdd/solvers/lsqr.py +424 -0
- hyperdd/solvers/schur.py +136 -0
- hyperdd/solvers/sparse_chol.py +221 -0
- hyperdd/solvers/stats.py +116 -0
- hyperdd/solvers/svd.py +312 -0
- hyperdd-0.1.0.dist-info/METADATA +16 -0
- hyperdd-0.1.0.dist-info/RECORD +35 -0
- hyperdd-0.1.0.dist-info/WHEEL +5 -0
- hyperdd-0.1.0.dist-info/entry_points.txt +2 -0
- hyperdd-0.1.0.dist-info/top_level.txt +1 -0
|
@@ -0,0 +1,447 @@
|
|
|
1
|
+
"""
|
|
2
|
+
1-D layered velocity model travel-time routines.
|
|
3
|
+
|
|
4
|
+
Exact reimplementation of the Fortran subroutines vmodel.f, ttime.f,
|
|
5
|
+
direct1.f, refract.f, and tiddid.f from hypoDD.
|
|
6
|
+
|
|
7
|
+
All arrays use 0-based Python indexing. Layer indices run 0..nl-1.
|
|
8
|
+
"""
|
|
9
|
+
|
|
10
|
+
import math
|
|
11
|
+
|
|
12
|
+
import numpy as np
|
|
13
|
+
from numpy.typing import NDArray
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
# ---------------------------------------------------------------------------
|
|
17
|
+
# vmodel (vmodel.f)
|
|
18
|
+
# ---------------------------------------------------------------------------
|
|
19
|
+
def vmodel(
|
|
20
|
+
nl: int,
|
|
21
|
+
v: NDArray[np.float64],
|
|
22
|
+
top: NDArray[np.float64],
|
|
23
|
+
depth: float,
|
|
24
|
+
) -> tuple[NDArray[np.float64], NDArray[np.float64], int, float]:
|
|
25
|
+
"""Extract needed information from the layered velocity model.
|
|
26
|
+
|
|
27
|
+
Parameters
|
|
28
|
+
----------
|
|
29
|
+
nl : int
|
|
30
|
+
Number of layers.
|
|
31
|
+
v : array, shape (nl,)
|
|
32
|
+
Velocity of each layer (km/s).
|
|
33
|
+
top : array, shape (nl,)
|
|
34
|
+
Depth to top of each layer (km).
|
|
35
|
+
depth : float
|
|
36
|
+
Depth of event (km).
|
|
37
|
+
|
|
38
|
+
Returns
|
|
39
|
+
-------
|
|
40
|
+
vsq : array, shape (nl,)
|
|
41
|
+
Squared velocities.
|
|
42
|
+
thk : array, shape (nl-1,)
|
|
43
|
+
Layer thicknesses (thk[i] = top[i+1] - top[i]).
|
|
44
|
+
jl : int
|
|
45
|
+
0-indexed event layer.
|
|
46
|
+
tkj : float
|
|
47
|
+
Depth of event below top of event layer.
|
|
48
|
+
"""
|
|
49
|
+
vsq = np.empty(nl, dtype=np.float64)
|
|
50
|
+
for i in range(nl):
|
|
51
|
+
vsq[i] = v[i] * v[i]
|
|
52
|
+
|
|
53
|
+
# Find event layer.
|
|
54
|
+
# Fortran (1-indexed): jl = nl, then for i=1..nl if depth <= top(i) then
|
|
55
|
+
# jl = i-1; break.
|
|
56
|
+
# In 0-indexed Python: jl = nl-1 (deepest layer), then for i=0..nl-1 if
|
|
57
|
+
# depth <= top[i] then jl = i-1; break.
|
|
58
|
+
# Note: Fortran i=1 corresponds to Python i=0; Fortran jl=i-1=0 would be
|
|
59
|
+
# invalid in Fortran (layer 0 doesn't exist). In practice top[0] is
|
|
60
|
+
# usually 0 or negative, and depth > 0, so the condition fires at i >= 1
|
|
61
|
+
# in Fortran (i >= 1 in Python). We guard against i=0 yielding jl=-1
|
|
62
|
+
# the same way Fortran guards against it (it doesn't -- the model is
|
|
63
|
+
# assumed valid with depth > top(1)).
|
|
64
|
+
jl = nl - 1 # default: deepest layer (0-indexed)
|
|
65
|
+
for i in range(nl):
|
|
66
|
+
if depth <= top[i]:
|
|
67
|
+
jl = i - 1
|
|
68
|
+
break
|
|
69
|
+
|
|
70
|
+
# Layer thicknesses
|
|
71
|
+
thk = np.empty(nl, dtype=np.float64)
|
|
72
|
+
for i in range(nl - 1):
|
|
73
|
+
thk[i] = top[i + 1] - top[i]
|
|
74
|
+
# thk[nl-1] is unused but we zero it for safety
|
|
75
|
+
if nl > 0:
|
|
76
|
+
thk[nl - 1] = 0.0
|
|
77
|
+
|
|
78
|
+
tkj = depth - top[jl]
|
|
79
|
+
|
|
80
|
+
return vsq, thk, jl, tkj
|
|
81
|
+
|
|
82
|
+
|
|
83
|
+
# ---------------------------------------------------------------------------
|
|
84
|
+
# tiddid (tiddid.f)
|
|
85
|
+
# ---------------------------------------------------------------------------
|
|
86
|
+
def tiddid(
|
|
87
|
+
jl: int,
|
|
88
|
+
nl: int,
|
|
89
|
+
v: NDArray[np.float64],
|
|
90
|
+
vsq: NDArray[np.float64],
|
|
91
|
+
thk: NDArray[np.float64],
|
|
92
|
+
) -> tuple[NDArray[np.float64], NDArray[np.float64]]:
|
|
93
|
+
"""Compute intercept times and critical distances for refracted rays.
|
|
94
|
+
|
|
95
|
+
Determines the travel-time intercept ``tid`` and critical distance ``did``
|
|
96
|
+
for a seismic ray originating at the top of layer *jl*, refracting in
|
|
97
|
+
layer *m*, and terminating at the top of layer 0.
|
|
98
|
+
|
|
99
|
+
Parameters
|
|
100
|
+
----------
|
|
101
|
+
jl : int
|
|
102
|
+
0-indexed event layer.
|
|
103
|
+
nl : int
|
|
104
|
+
Number of layers.
|
|
105
|
+
v, vsq, thk : arrays
|
|
106
|
+
Velocity, squared velocity, and thickness arrays.
|
|
107
|
+
|
|
108
|
+
Returns
|
|
109
|
+
-------
|
|
110
|
+
tid, did : arrays, shape (nl,)
|
|
111
|
+
Travel-time intercept and critical distance for refraction in each
|
|
112
|
+
layer *m* (only indices jl+1..nl-1 are meaningful).
|
|
113
|
+
"""
|
|
114
|
+
tid = np.zeros(nl, dtype=np.float64)
|
|
115
|
+
did = np.zeros(nl, dtype=np.float64)
|
|
116
|
+
|
|
117
|
+
# Fortran: j1 = jl + 1, loop m = j1..nl (1-indexed)
|
|
118
|
+
# Python: loop m = jl+1 .. nl-1 (0-indexed)
|
|
119
|
+
for m in range(jl + 1, nl):
|
|
120
|
+
tid[m] = 0.0
|
|
121
|
+
did[m] = 0.0
|
|
122
|
+
tid1 = 0.0
|
|
123
|
+
tid2 = 0.0
|
|
124
|
+
did1 = 0.0
|
|
125
|
+
did2 = 0.0
|
|
126
|
+
# Fortran: l = 1..m-1 (1-indexed, i.e. layers 1 to m-1)
|
|
127
|
+
# Python: l = 0..m-1 (0-indexed, i.e. layers 0 to m-1)
|
|
128
|
+
for l in range(m): # l = 0 .. m-1
|
|
129
|
+
if vsq[m] <= vsq[l]:
|
|
130
|
+
# m is a low-velocity layer relative to l
|
|
131
|
+
tid[m] = 100000.0
|
|
132
|
+
did[m] = 100000.0
|
|
133
|
+
break
|
|
134
|
+
sqt = math.sqrt(vsq[m] - vsq[l])
|
|
135
|
+
tim = thk[l] * sqt / (v[l] * v[m])
|
|
136
|
+
dimm = thk[l] * v[l] / sqt
|
|
137
|
+
if l < jl:
|
|
138
|
+
# Layers above event layer
|
|
139
|
+
tid1 += tim
|
|
140
|
+
did1 += dimm
|
|
141
|
+
else:
|
|
142
|
+
# Layers below and including event layer
|
|
143
|
+
tid2 += tim
|
|
144
|
+
did2 += dimm
|
|
145
|
+
if tid[m] != 100000.0:
|
|
146
|
+
tid[m] = tid1 + 2.0 * tid2
|
|
147
|
+
did[m] = did1 + 2.0 * did2
|
|
148
|
+
|
|
149
|
+
return tid, did
|
|
150
|
+
|
|
151
|
+
|
|
152
|
+
# ---------------------------------------------------------------------------
|
|
153
|
+
# refract (refract.f)
|
|
154
|
+
# ---------------------------------------------------------------------------
|
|
155
|
+
def refract(
|
|
156
|
+
nl: int,
|
|
157
|
+
v: NDArray[np.float64],
|
|
158
|
+
vsq: NDArray[np.float64],
|
|
159
|
+
thk: NDArray[np.float64],
|
|
160
|
+
jl: int,
|
|
161
|
+
tkj: float,
|
|
162
|
+
delta: float,
|
|
163
|
+
) -> tuple[int, float, float]:
|
|
164
|
+
"""Find the refracted ray with the smallest travel time.
|
|
165
|
+
|
|
166
|
+
Parameters
|
|
167
|
+
----------
|
|
168
|
+
nl : int
|
|
169
|
+
Number of layers.
|
|
170
|
+
v, vsq, thk : arrays
|
|
171
|
+
Velocity model arrays.
|
|
172
|
+
jl : int
|
|
173
|
+
0-indexed event layer.
|
|
174
|
+
tkj : float
|
|
175
|
+
Depth of event within its layer.
|
|
176
|
+
delta : float
|
|
177
|
+
Epicentral distance (km).
|
|
178
|
+
|
|
179
|
+
Returns
|
|
180
|
+
-------
|
|
181
|
+
kk : int
|
|
182
|
+
0-indexed refracting layer for fastest refracted ray (0 if none).
|
|
183
|
+
tref : float
|
|
184
|
+
Travel time of fastest refracted ray.
|
|
185
|
+
xovmax : float
|
|
186
|
+
Upper bound on delta for which the direct ray can be first arrival.
|
|
187
|
+
"""
|
|
188
|
+
tid, did = tiddid(jl, nl, v, vsq, thk)
|
|
189
|
+
|
|
190
|
+
tref = 100000.0
|
|
191
|
+
kk = 0
|
|
192
|
+
|
|
193
|
+
tinj = np.zeros(nl, dtype=np.float64)
|
|
194
|
+
didj = np.zeros(nl, dtype=np.float64)
|
|
195
|
+
tr = np.full(nl, 100000.0, dtype=np.float64)
|
|
196
|
+
|
|
197
|
+
# Fortran: j1 = jl + 1, loop m = j1..nl (1-indexed)
|
|
198
|
+
# Python: m = jl+1 .. nl-1 (0-indexed)
|
|
199
|
+
for m in range(jl + 1, nl):
|
|
200
|
+
if tid[m] == 100000.0:
|
|
201
|
+
tr[m] = 100000.0
|
|
202
|
+
continue
|
|
203
|
+
sqt = math.sqrt(vsq[m] - vsq[jl])
|
|
204
|
+
tinj[m] = tid[m] - tkj * sqt / (v[m] * v[jl])
|
|
205
|
+
didj[m] = did[m] - tkj * v[jl] / sqt
|
|
206
|
+
tr[m] = tinj[m] + delta / v[m]
|
|
207
|
+
if didj[m] > delta:
|
|
208
|
+
tr[m] = 100000.0
|
|
209
|
+
if tr[m] < tref:
|
|
210
|
+
tref = tr[m]
|
|
211
|
+
kk = m
|
|
212
|
+
|
|
213
|
+
# If there is no refracted ray
|
|
214
|
+
if tref == 100000.0:
|
|
215
|
+
xovmax = 100000.0
|
|
216
|
+
kk = 0
|
|
217
|
+
return kk, tref, xovmax
|
|
218
|
+
|
|
219
|
+
# Find lx: first layer below event layer that is not low-velocity
|
|
220
|
+
# Fortran: m = jl+1 (1-indexed), while tid(m)==100000 m=m+1; lx=m
|
|
221
|
+
# Python: m = jl+1 (0-indexed)
|
|
222
|
+
m = jl + 1
|
|
223
|
+
while tid[m] == 100000.0:
|
|
224
|
+
m += 1
|
|
225
|
+
lx = m
|
|
226
|
+
|
|
227
|
+
# Check whether event is in first layer
|
|
228
|
+
# Fortran: jl == 1 (1-indexed) => Python: jl == 0
|
|
229
|
+
if jl == 0:
|
|
230
|
+
xovmax = tinj[lx] * v[lx] * v[0] / (v[lx] - v[0])
|
|
231
|
+
return kk, tref, xovmax
|
|
232
|
+
|
|
233
|
+
# Find jx: first layer at/above event layer that is not low-velocity
|
|
234
|
+
# Fortran starts at m = jl (1-indexed), decrements m.
|
|
235
|
+
# Recomputes tid(m) for layers from jl downward.
|
|
236
|
+
# Python: m starts at jl (0-indexed).
|
|
237
|
+
m = jl
|
|
238
|
+
while True:
|
|
239
|
+
tid[m] = 0.0
|
|
240
|
+
# Fortran: m1 = m - 1, loop l = 1..m1 (1-indexed)
|
|
241
|
+
# Python: loop l = 0..m-1 (0-indexed)
|
|
242
|
+
for l in range(m):
|
|
243
|
+
if vsq[m] <= vsq[l]:
|
|
244
|
+
tid[m] = 100000.0
|
|
245
|
+
break
|
|
246
|
+
sqt = math.sqrt(vsq[m] - vsq[l])
|
|
247
|
+
tim = thk[l] * sqt / (v[l] * v[m])
|
|
248
|
+
tid[m] += tim
|
|
249
|
+
m -= 1
|
|
250
|
+
# Fortran: if (tid(m+1) < 100000 .or. m == 1) exit
|
|
251
|
+
# (m+1 in Fortran = m+1 in Python after decrement)
|
|
252
|
+
if tid[m + 1] < 100000.0 or m == 0:
|
|
253
|
+
break
|
|
254
|
+
|
|
255
|
+
if tid[m + 1] < 100000.0:
|
|
256
|
+
jx = m + 1
|
|
257
|
+
xovmax = (tinj[lx] - tid[jx]) * v[lx] * v[jx] / (v[lx] - v[jx])
|
|
258
|
+
else:
|
|
259
|
+
# jx == 1 in Fortran (layer 1, 1-indexed) => layer 0 in Python
|
|
260
|
+
xovmax = tinj[lx] * v[lx] * v[0] / (v[lx] - v[0])
|
|
261
|
+
|
|
262
|
+
return kk, tref, xovmax
|
|
263
|
+
|
|
264
|
+
|
|
265
|
+
# ---------------------------------------------------------------------------
|
|
266
|
+
# direct1 (direct1.f)
|
|
267
|
+
# ---------------------------------------------------------------------------
|
|
268
|
+
def direct1(
|
|
269
|
+
nl: int,
|
|
270
|
+
v: NDArray[np.float64],
|
|
271
|
+
vsq: NDArray[np.float64],
|
|
272
|
+
thk: NDArray[np.float64],
|
|
273
|
+
jl: int,
|
|
274
|
+
tkj: float,
|
|
275
|
+
delta: float,
|
|
276
|
+
depth: float,
|
|
277
|
+
) -> tuple[float, float, float]:
|
|
278
|
+
"""Compute travel time for the direct (upward-departing) ray.
|
|
279
|
+
|
|
280
|
+
Parameters
|
|
281
|
+
----------
|
|
282
|
+
nl : int
|
|
283
|
+
Number of layers.
|
|
284
|
+
v, vsq, thk : arrays
|
|
285
|
+
Velocity model arrays.
|
|
286
|
+
jl : int
|
|
287
|
+
0-indexed event layer.
|
|
288
|
+
tkj : float
|
|
289
|
+
Depth of event within its layer.
|
|
290
|
+
delta : float
|
|
291
|
+
Epicentral distance (km).
|
|
292
|
+
depth : float
|
|
293
|
+
Event depth (km).
|
|
294
|
+
|
|
295
|
+
Returns
|
|
296
|
+
-------
|
|
297
|
+
tdir : float
|
|
298
|
+
Direct-ray travel time.
|
|
299
|
+
u : float
|
|
300
|
+
Sine of the take-off angle.
|
|
301
|
+
x : float
|
|
302
|
+
Horizontal travel distance in the event layer.
|
|
303
|
+
"""
|
|
304
|
+
# Fortran: jl == 1 (1-indexed) => Python: jl == 0
|
|
305
|
+
if jl == 0:
|
|
306
|
+
# Focus in surface layer
|
|
307
|
+
r = math.hypot(depth, delta)
|
|
308
|
+
tdir = r / v[0]
|
|
309
|
+
u = delta / r
|
|
310
|
+
x = delta
|
|
311
|
+
return tdir, u, x
|
|
312
|
+
|
|
313
|
+
# Find the fastest layer (lmax) above and including jl
|
|
314
|
+
lmax = jl
|
|
315
|
+
tklmax = tkj
|
|
316
|
+
vlmax = v[jl]
|
|
317
|
+
# Fortran: j1 = jl - 1, loop l = 1..j1 (1-indexed, layers above jl)
|
|
318
|
+
# Python: j1 = jl, loop l = 0..jl-1 (0-indexed, layers above jl)
|
|
319
|
+
j1 = jl # number of layers above event layer (indices 0..jl-1)
|
|
320
|
+
for l in range(j1):
|
|
321
|
+
if v[l] > vlmax:
|
|
322
|
+
lmax = l
|
|
323
|
+
tklmax = thk[l]
|
|
324
|
+
vlmax = v[l]
|
|
325
|
+
|
|
326
|
+
# CHANGE BY E.KISSLING MARCH 1984
|
|
327
|
+
if tklmax <= 0.05:
|
|
328
|
+
tklmax = 0.05
|
|
329
|
+
|
|
330
|
+
# Initial bounds on sine of take-off angle
|
|
331
|
+
ua = (v[jl] / vlmax) * delta / math.sqrt(delta**2 + depth**2)
|
|
332
|
+
ub = (v[jl] / vlmax) * delta / math.sqrt(delta**2 + tklmax**2)
|
|
333
|
+
|
|
334
|
+
# Calculate horizontal travel distances
|
|
335
|
+
uasq = ua**2
|
|
336
|
+
ubsq = ub**2
|
|
337
|
+
# CHANGE BY E.KISSLING MARCH 1984
|
|
338
|
+
if ubsq >= 1.0:
|
|
339
|
+
ubsq = 0.99999
|
|
340
|
+
if uasq >= 1.0:
|
|
341
|
+
uasq = 0.99999
|
|
342
|
+
|
|
343
|
+
xa = tkj * ua / math.sqrt(1.0 - uasq)
|
|
344
|
+
|
|
345
|
+
if lmax == jl:
|
|
346
|
+
xb = delta
|
|
347
|
+
else:
|
|
348
|
+
xb = tkj * ub / math.sqrt(1.0 - ubsq)
|
|
349
|
+
|
|
350
|
+
dela = xa
|
|
351
|
+
delb = xb
|
|
352
|
+
for l in range(j1):
|
|
353
|
+
dela += thk[l] * ua / math.sqrt(vsq[jl] / vsq[l] - uasq)
|
|
354
|
+
ubdiv = math.sqrt(vsq[jl] / vsq[l] - ubsq)
|
|
355
|
+
if ubdiv <= 1.0e-20:
|
|
356
|
+
ubdiv = 1.0e-20
|
|
357
|
+
delb += thk[l] * ub / math.sqrt(vsq[jl] / vsq[l] - ubsq)
|
|
358
|
+
|
|
359
|
+
# False-position iteration (max 25 iterations)
|
|
360
|
+
del_ = 0.0
|
|
361
|
+
usq = 0.0
|
|
362
|
+
x = 0.0
|
|
363
|
+
u = 0.0
|
|
364
|
+
for kount in range(25):
|
|
365
|
+
if (delb - dela) < 0.02:
|
|
366
|
+
x = 0.5 * (xa + xb)
|
|
367
|
+
u = x / math.sqrt(x**2 + tkj**2)
|
|
368
|
+
usq = u**2
|
|
369
|
+
break
|
|
370
|
+
x = xa + (delta - dela) * (xb - xa) / (delb - dela)
|
|
371
|
+
u = x / math.sqrt(x**2 + tkj**2)
|
|
372
|
+
usq = u**2
|
|
373
|
+
del_ = x
|
|
374
|
+
for l in range(j1):
|
|
375
|
+
del_ += thk[l] * u / math.sqrt(vsq[jl] / vsq[l] - usq)
|
|
376
|
+
xtest = del_ - delta
|
|
377
|
+
if abs(xtest) < 0.02:
|
|
378
|
+
break
|
|
379
|
+
if xtest < 0.0:
|
|
380
|
+
xa = x
|
|
381
|
+
dela = del_
|
|
382
|
+
else:
|
|
383
|
+
xb = x
|
|
384
|
+
delb = del_
|
|
385
|
+
|
|
386
|
+
# Calculate direct-ray travel time
|
|
387
|
+
tdir = math.sqrt(x**2 + tkj**2) / v[jl]
|
|
388
|
+
for l in range(j1):
|
|
389
|
+
tdir += thk[l] * v[jl] / (vsq[l] * math.sqrt(vsq[jl] / vsq[l] - usq))
|
|
390
|
+
tdir -= (u / v[jl]) * (del_ - delta)
|
|
391
|
+
|
|
392
|
+
return tdir, u, x
|
|
393
|
+
|
|
394
|
+
|
|
395
|
+
# ---------------------------------------------------------------------------
|
|
396
|
+
# ttime (ttime.f)
|
|
397
|
+
# ---------------------------------------------------------------------------
|
|
398
|
+
def ttime(
|
|
399
|
+
delta: float,
|
|
400
|
+
depth: float,
|
|
401
|
+
nl: int,
|
|
402
|
+
v: NDArray[np.float64],
|
|
403
|
+
top: NDArray[np.float64],
|
|
404
|
+
) -> tuple[float, float]:
|
|
405
|
+
"""Determine the fastest travel time between source and receiver.
|
|
406
|
+
|
|
407
|
+
Parameters
|
|
408
|
+
----------
|
|
409
|
+
delta : float
|
|
410
|
+
Epicentral distance (km).
|
|
411
|
+
depth : float
|
|
412
|
+
Focal depth of source (km).
|
|
413
|
+
nl : int
|
|
414
|
+
Number of layers in velocity model.
|
|
415
|
+
v : array, shape (nl,)
|
|
416
|
+
Velocity in each layer (km/s).
|
|
417
|
+
top : array, shape (nl,)
|
|
418
|
+
Depth to top of each layer (km).
|
|
419
|
+
|
|
420
|
+
Returns
|
|
421
|
+
-------
|
|
422
|
+
t : float
|
|
423
|
+
Minimum travel time (s).
|
|
424
|
+
ain : float
|
|
425
|
+
Angle of emergence at source (degrees).
|
|
426
|
+
"""
|
|
427
|
+
vsq, thk, jl, tkj = vmodel(nl, v, top, depth)
|
|
428
|
+
kk, tref, xovmax = refract(nl, v, vsq, thk, jl, tkj, delta)
|
|
429
|
+
|
|
430
|
+
# Assume refracted path is faster initially
|
|
431
|
+
t = tref
|
|
432
|
+
ain = 0.0
|
|
433
|
+
|
|
434
|
+
# Compute the take-off angle for refracted ray
|
|
435
|
+
if kk > 0:
|
|
436
|
+
u_ref = v[jl] / v[kk]
|
|
437
|
+
ain = math.asin(u_ref) * 57.2958
|
|
438
|
+
|
|
439
|
+
if delta <= xovmax:
|
|
440
|
+
tdir, u, x = direct1(nl, v, vsq, thk, jl, tkj, delta, depth)
|
|
441
|
+
# Compare travel times
|
|
442
|
+
if tref > tdir:
|
|
443
|
+
# Direct time is the minimum
|
|
444
|
+
t = tdir
|
|
445
|
+
ain = 180.0 - math.asin(u) * 57.2958
|
|
446
|
+
|
|
447
|
+
return t, ain
|
|
@@ -0,0 +1,238 @@
|
|
|
1
|
+
"""Numba-accelerated 1-D layered velocity model travel-time routine.
|
|
2
|
+
|
|
3
|
+
Single JIT-compiled function that inlines vmodel, tiddid, refract, and
|
|
4
|
+
direct1 for maximum performance. Falls back to the pure-Python scalar
|
|
5
|
+
version if Numba is not available.
|
|
6
|
+
"""
|
|
7
|
+
|
|
8
|
+
import numpy as np
|
|
9
|
+
|
|
10
|
+
try:
|
|
11
|
+
from numba import jit
|
|
12
|
+
HAS_NUMBA = True
|
|
13
|
+
except ImportError:
|
|
14
|
+
HAS_NUMBA = False
|
|
15
|
+
def jit(*args, **kwargs):
|
|
16
|
+
def decorator(fn):
|
|
17
|
+
return fn
|
|
18
|
+
if args and callable(args[0]):
|
|
19
|
+
return args[0]
|
|
20
|
+
return decorator
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
@jit(nopython=True, cache=True)
|
|
24
|
+
def ttime_numba(delta, depth, nl, v, top):
|
|
25
|
+
"""Compute travel time and emergence angle (Numba-accelerated).
|
|
26
|
+
|
|
27
|
+
Exact reimplementation of ttime.f with vmodel, tiddid, refract, and
|
|
28
|
+
direct1 inlined for JIT compilation.
|
|
29
|
+
|
|
30
|
+
Parameters
|
|
31
|
+
----------
|
|
32
|
+
delta : float
|
|
33
|
+
Epicentral distance (km).
|
|
34
|
+
depth : float
|
|
35
|
+
Focal depth (km).
|
|
36
|
+
nl : int
|
|
37
|
+
Number of layers.
|
|
38
|
+
v : ndarray (nl,)
|
|
39
|
+
Layer velocities (km/s).
|
|
40
|
+
top : ndarray (nl,)
|
|
41
|
+
Layer top depths (km).
|
|
42
|
+
|
|
43
|
+
Returns
|
|
44
|
+
-------
|
|
45
|
+
t : float
|
|
46
|
+
Travel time (s).
|
|
47
|
+
ain : float
|
|
48
|
+
Emergence angle (degrees).
|
|
49
|
+
"""
|
|
50
|
+
# --- vmodel ---
|
|
51
|
+
vsq = np.empty(nl, dtype=np.float64)
|
|
52
|
+
for i in range(nl):
|
|
53
|
+
vsq[i] = v[i] * v[i]
|
|
54
|
+
|
|
55
|
+
jl = nl - 1
|
|
56
|
+
for i in range(nl):
|
|
57
|
+
if depth <= top[i]:
|
|
58
|
+
jl = i - 1
|
|
59
|
+
break
|
|
60
|
+
|
|
61
|
+
thk = np.empty(nl, dtype=np.float64)
|
|
62
|
+
for i in range(nl - 1):
|
|
63
|
+
thk[i] = top[i + 1] - top[i]
|
|
64
|
+
thk[nl - 1] = 0.0
|
|
65
|
+
tkj = depth - top[jl]
|
|
66
|
+
|
|
67
|
+
# --- tiddid ---
|
|
68
|
+
tid = np.zeros(nl, dtype=np.float64)
|
|
69
|
+
did = np.zeros(nl, dtype=np.float64)
|
|
70
|
+
for m in range(jl + 1, nl):
|
|
71
|
+
tid1 = 0.0
|
|
72
|
+
tid2 = 0.0
|
|
73
|
+
did1 = 0.0
|
|
74
|
+
did2 = 0.0
|
|
75
|
+
bad = False
|
|
76
|
+
for l in range(m):
|
|
77
|
+
if vsq[m] <= vsq[l]:
|
|
78
|
+
tid[m] = 100000.0
|
|
79
|
+
did[m] = 100000.0
|
|
80
|
+
bad = True
|
|
81
|
+
break
|
|
82
|
+
sqt = np.sqrt(vsq[m] - vsq[l])
|
|
83
|
+
tim = thk[l] * sqt / (v[l] * v[m])
|
|
84
|
+
dimm = thk[l] * v[l] / sqt
|
|
85
|
+
if l < jl:
|
|
86
|
+
tid1 += tim
|
|
87
|
+
did1 += dimm
|
|
88
|
+
else:
|
|
89
|
+
tid2 += tim
|
|
90
|
+
did2 += dimm
|
|
91
|
+
if not bad:
|
|
92
|
+
tid[m] = tid1 + 2.0 * tid2
|
|
93
|
+
did[m] = did1 + 2.0 * did2
|
|
94
|
+
|
|
95
|
+
# --- refract ---
|
|
96
|
+
tref = 100000.0
|
|
97
|
+
kk = 0
|
|
98
|
+
tinj = np.zeros(nl, dtype=np.float64)
|
|
99
|
+
didj = np.zeros(nl, dtype=np.float64)
|
|
100
|
+
|
|
101
|
+
for m in range(jl + 1, nl):
|
|
102
|
+
if tid[m] >= 100000.0:
|
|
103
|
+
continue
|
|
104
|
+
sqt = np.sqrt(vsq[m] - vsq[jl])
|
|
105
|
+
tinj[m] = tid[m] - tkj * sqt / (v[m] * v[jl])
|
|
106
|
+
didj[m] = did[m] - tkj * v[jl] / sqt
|
|
107
|
+
tr_m = tinj[m] + delta / v[m]
|
|
108
|
+
if didj[m] > delta:
|
|
109
|
+
tr_m = 100000.0
|
|
110
|
+
if tr_m < tref:
|
|
111
|
+
tref = tr_m
|
|
112
|
+
kk = m
|
|
113
|
+
|
|
114
|
+
xovmax = 100000.0
|
|
115
|
+
if tref < 100000.0:
|
|
116
|
+
lx = jl + 1
|
|
117
|
+
while lx < nl and tid[lx] >= 100000.0:
|
|
118
|
+
lx += 1
|
|
119
|
+
if lx < nl:
|
|
120
|
+
if jl == 0:
|
|
121
|
+
xovmax = tinj[lx] * v[lx] * v[0] / (v[lx] - v[0])
|
|
122
|
+
else:
|
|
123
|
+
mm = jl
|
|
124
|
+
while True:
|
|
125
|
+
tid[mm] = 0.0
|
|
126
|
+
for l in range(mm):
|
|
127
|
+
if vsq[mm] <= vsq[l]:
|
|
128
|
+
tid[mm] = 100000.0
|
|
129
|
+
break
|
|
130
|
+
sqt = np.sqrt(vsq[mm] - vsq[l])
|
|
131
|
+
tid[mm] += thk[l] * sqt / (v[l] * v[mm])
|
|
132
|
+
mm -= 1
|
|
133
|
+
if tid[mm + 1] < 100000.0 or mm == 0:
|
|
134
|
+
break
|
|
135
|
+
if tid[mm + 1] < 100000.0:
|
|
136
|
+
jx = mm + 1
|
|
137
|
+
xovmax = ((tinj[lx] - tid[jx])
|
|
138
|
+
* v[lx] * v[jx] / (v[lx] - v[jx]))
|
|
139
|
+
else:
|
|
140
|
+
xovmax = tinj[lx] * v[lx] * v[0] / (v[lx] - v[0])
|
|
141
|
+
else:
|
|
142
|
+
kk = 0
|
|
143
|
+
|
|
144
|
+
# Initial: assume refracted
|
|
145
|
+
t = tref
|
|
146
|
+
ain = 0.0
|
|
147
|
+
if kk > 0:
|
|
148
|
+
ain = np.arcsin(v[jl] / v[kk]) * 57.2958
|
|
149
|
+
|
|
150
|
+
# --- direct1 ---
|
|
151
|
+
if delta <= xovmax:
|
|
152
|
+
if jl == 0:
|
|
153
|
+
r = np.sqrt(depth * depth + delta * delta)
|
|
154
|
+
tdir = r / v[0]
|
|
155
|
+
u = delta / r
|
|
156
|
+
del_ = delta
|
|
157
|
+
else:
|
|
158
|
+
lmax = jl
|
|
159
|
+
tklmax = tkj
|
|
160
|
+
vlmax = v[jl]
|
|
161
|
+
for l in range(jl):
|
|
162
|
+
if v[l] > vlmax:
|
|
163
|
+
lmax = l
|
|
164
|
+
tklmax = thk[l]
|
|
165
|
+
vlmax = v[l]
|
|
166
|
+
if tklmax <= 0.05:
|
|
167
|
+
tklmax = 0.05
|
|
168
|
+
|
|
169
|
+
ratio = v[jl] / vlmax
|
|
170
|
+
ua = ratio * delta / np.sqrt(delta * delta + depth * depth)
|
|
171
|
+
ub = ratio * delta / np.sqrt(delta * delta + tklmax * tklmax)
|
|
172
|
+
uasq = ua * ua
|
|
173
|
+
ubsq = ub * ub
|
|
174
|
+
if ubsq >= 1.0:
|
|
175
|
+
ubsq = 0.99999
|
|
176
|
+
if uasq >= 1.0:
|
|
177
|
+
uasq = 0.99999
|
|
178
|
+
|
|
179
|
+
xa = tkj * ua / np.sqrt(1.0 - uasq)
|
|
180
|
+
if lmax == jl:
|
|
181
|
+
xb = delta
|
|
182
|
+
else:
|
|
183
|
+
xb = tkj * ub / np.sqrt(1.0 - ubsq)
|
|
184
|
+
|
|
185
|
+
dela = xa
|
|
186
|
+
delb = xb
|
|
187
|
+
for l in range(jl):
|
|
188
|
+
dela += thk[l] * ua / np.sqrt(vsq[jl] / vsq[l] - uasq)
|
|
189
|
+
ubdiv = vsq[jl] / vsq[l] - ubsq
|
|
190
|
+
if ubdiv <= 1.0e-40:
|
|
191
|
+
ubdiv = 1.0e-40
|
|
192
|
+
delb += thk[l] * ub / np.sqrt(ubdiv)
|
|
193
|
+
|
|
194
|
+
x = 0.0
|
|
195
|
+
u = 0.0
|
|
196
|
+
usq = 0.0
|
|
197
|
+
del_ = 0.0
|
|
198
|
+
for kount in range(25):
|
|
199
|
+
if (delb - dela) < 0.02:
|
|
200
|
+
x = 0.5 * (xa + xb)
|
|
201
|
+
u = x / np.sqrt(x * x + tkj * tkj)
|
|
202
|
+
usq = u * u
|
|
203
|
+
break
|
|
204
|
+
denom = delb - dela
|
|
205
|
+
if abs(denom) < 1e-30:
|
|
206
|
+
denom = 1e-30
|
|
207
|
+
x = xa + (delta - dela) * (xb - xa) / denom
|
|
208
|
+
u = x / np.sqrt(x * x + tkj * tkj)
|
|
209
|
+
usq = u * u
|
|
210
|
+
del_ = x
|
|
211
|
+
for l in range(jl):
|
|
212
|
+
dv = vsq[jl] / vsq[l] - usq
|
|
213
|
+
if dv <= 1e-40:
|
|
214
|
+
dv = 1e-40
|
|
215
|
+
del_ += thk[l] * u / np.sqrt(dv)
|
|
216
|
+
xtest = del_ - delta
|
|
217
|
+
if abs(xtest) < 0.02:
|
|
218
|
+
break
|
|
219
|
+
if xtest < 0.0:
|
|
220
|
+
xa = x
|
|
221
|
+
dela = del_
|
|
222
|
+
else:
|
|
223
|
+
xb = x
|
|
224
|
+
delb = del_
|
|
225
|
+
|
|
226
|
+
tdir = np.sqrt(x * x + tkj * tkj) / v[jl]
|
|
227
|
+
for l in range(jl):
|
|
228
|
+
dv = vsq[jl] / vsq[l] - usq
|
|
229
|
+
if dv <= 1e-40:
|
|
230
|
+
dv = 1e-40
|
|
231
|
+
tdir += thk[l] * v[jl] / (vsq[l] * np.sqrt(dv))
|
|
232
|
+
tdir -= (u / v[jl]) * (del_ - delta)
|
|
233
|
+
|
|
234
|
+
if tref > tdir:
|
|
235
|
+
t = tdir
|
|
236
|
+
ain = 180.0 - np.arcsin(u) * 57.2958
|
|
237
|
+
|
|
238
|
+
return t, ain
|