hyperdd 0.1__0-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
hyperdd/hypoDD.py
ADDED
|
@@ -0,0 +1,1167 @@
|
|
|
1
|
+
"""Main driver for hypodd -- reimplements the hypoDD.f iteration loop.
|
|
2
|
+
|
|
3
|
+
Usage::
|
|
4
|
+
|
|
5
|
+
python -m hypodd.hypoDD hypoDD.inp
|
|
6
|
+
|
|
7
|
+
The single public entry point is :func:`run_hypoDD`.
|
|
8
|
+
"""
|
|
9
|
+
|
|
10
|
+
import logging
|
|
11
|
+
import math
|
|
12
|
+
import sys
|
|
13
|
+
from datetime import datetime
|
|
14
|
+
|
|
15
|
+
import numpy as np
|
|
16
|
+
|
|
17
|
+
from .config import parse_inp
|
|
18
|
+
from .core.cluster import cluster_events
|
|
19
|
+
from .core.dtres import compute_residuals
|
|
20
|
+
from .core.partials import compute_partials
|
|
21
|
+
from .core.skip import skip_outliers
|
|
22
|
+
from .core.weighting import weighting
|
|
23
|
+
from .geodesy.coordinates import SDC, delaz
|
|
24
|
+
from .io.readers import read_cc, read_ct, read_events, read_stations
|
|
25
|
+
from .core.partials_obs import compute_partials_obs
|
|
26
|
+
from .solvers.lsqr import solve_lsqr
|
|
27
|
+
from .solvers.sparse_chol import solve_sparse_chol
|
|
28
|
+
from .solvers.stats import resstat
|
|
29
|
+
from .solvers.svd import solve_svd
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
# ---------------------------------------------------------------------------
|
|
33
|
+
# Time utility functions (reimplementations of juliam.f and datum.f)
|
|
34
|
+
# ---------------------------------------------------------------------------
|
|
35
|
+
|
|
36
|
+
_KMO_JULIAM = [0, 31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334]
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
def _juliam(iyr, imo, idy, ihr, imn):
|
|
40
|
+
"""Convert calendar date/time to minutes (juliam.f)."""
|
|
41
|
+
ky = iyr
|
|
42
|
+
km = max(imo, 1)
|
|
43
|
+
kd = idy
|
|
44
|
+
total = 365 * ky
|
|
45
|
+
kd = _KMO_JULIAM[km - 1] + kd
|
|
46
|
+
ky4 = ky // 4
|
|
47
|
+
ky1 = ky // 100
|
|
48
|
+
ky0 = ky // 1000
|
|
49
|
+
kl = ky4 - ky1 + ky0
|
|
50
|
+
leap_flag = 0
|
|
51
|
+
if ky4 * 4 == ky and (ky1 * 100 != ky or ky0 * 1000 == ky):
|
|
52
|
+
leap_flag = 1
|
|
53
|
+
if leap_flag != 0 and km < 3:
|
|
54
|
+
kl = kl - 1
|
|
55
|
+
total = total + kd + kl
|
|
56
|
+
total = total * 24 + ihr
|
|
57
|
+
total = total * 60 + imn
|
|
58
|
+
return total
|
|
59
|
+
|
|
60
|
+
|
|
61
|
+
_KMO_DATUM = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]
|
|
62
|
+
|
|
63
|
+
|
|
64
|
+
def _datum(itf):
|
|
65
|
+
"""Convert minutes count back to calendar date/time (datum.f).
|
|
66
|
+
|
|
67
|
+
Returns (iyr, imo, idy, ihr, imn).
|
|
68
|
+
"""
|
|
69
|
+
k = itf // 60
|
|
70
|
+
imn = itf - k * 60
|
|
71
|
+
kh = k // 24
|
|
72
|
+
ihr = k - kh * 24
|
|
73
|
+
iyr = kh // 365
|
|
74
|
+
|
|
75
|
+
while True:
|
|
76
|
+
idd = kh - iyr * 365
|
|
77
|
+
iyr4 = iyr // 4
|
|
78
|
+
iyrh = iyr // 100
|
|
79
|
+
iyrt = iyr // 1000
|
|
80
|
+
ld = iyr4 - iyrh + iyrt
|
|
81
|
+
leap = 0
|
|
82
|
+
if iyr4 * 4 == iyr and (iyrh * 100 != iyr or iyrt * 1000 == iyr):
|
|
83
|
+
leap = 1
|
|
84
|
+
idd = idd - ld + leap
|
|
85
|
+
if idd > 0:
|
|
86
|
+
break
|
|
87
|
+
if idd == 0 and ihr == 0 and imn == 0:
|
|
88
|
+
return iyr, 0, 0, ihr, imn
|
|
89
|
+
iyr -= 1
|
|
90
|
+
|
|
91
|
+
kmo = list(_KMO_DATUM)
|
|
92
|
+
kmo[1] = 28 + leap
|
|
93
|
+
imo = 0
|
|
94
|
+
for i in range(12):
|
|
95
|
+
idd = idd - kmo[i]
|
|
96
|
+
if idd <= 0:
|
|
97
|
+
imo = i + 1
|
|
98
|
+
idy = idd + kmo[i]
|
|
99
|
+
break
|
|
100
|
+
else:
|
|
101
|
+
imo = 12
|
|
102
|
+
idy = idd + kmo[11]
|
|
103
|
+
|
|
104
|
+
return iyr, imo, idy, ihr, imn
|
|
105
|
+
|
|
106
|
+
|
|
107
|
+
# ---------------------------------------------------------------------------
|
|
108
|
+
# Main driver
|
|
109
|
+
# ---------------------------------------------------------------------------
|
|
110
|
+
|
|
111
|
+
def run_hypoDD(inp_file: str) -> None:
|
|
112
|
+
"""Run the hypoDD double-difference relocation algorithm.
|
|
113
|
+
|
|
114
|
+
Parameters
|
|
115
|
+
----------
|
|
116
|
+
inp_file : str
|
|
117
|
+
Path to a hypoDD.inp control-parameter file.
|
|
118
|
+
"""
|
|
119
|
+
|
|
120
|
+
# ---- Set up logging (hypoDD.log) ----
|
|
121
|
+
log = logging.getLogger("hypoDD")
|
|
122
|
+
log.setLevel(logging.DEBUG)
|
|
123
|
+
log.propagate = False # Prevent DEBUG leaking to root/notebook loggers
|
|
124
|
+
# Remove existing handlers to allow re-runs
|
|
125
|
+
log.handlers.clear()
|
|
126
|
+
fh = logging.FileHandler("hypoDD.log", mode="w")
|
|
127
|
+
fh.setLevel(logging.DEBUG)
|
|
128
|
+
fh.setFormatter(logging.Formatter("%(message)s"))
|
|
129
|
+
log.addHandler(fh)
|
|
130
|
+
sh = logging.StreamHandler(sys.stdout)
|
|
131
|
+
sh.setLevel(logging.INFO)
|
|
132
|
+
sh.setFormatter(logging.Formatter("%(message)s"))
|
|
133
|
+
log.addHandler(sh)
|
|
134
|
+
|
|
135
|
+
now_str = datetime.now().strftime("%Y/%m/%d %H:%M:%S")
|
|
136
|
+
log.info("starting hypodd (v0.1) ... %s", now_str)
|
|
137
|
+
|
|
138
|
+
# ---- 1. Parse input file ----
|
|
139
|
+
cfg = parse_inp(inp_file)
|
|
140
|
+
# GraphDD: use multi-backend solver (isolv=3) with cholesky default
|
|
141
|
+
# SVD (isolv=1) and original LSQR (isolv=2) preserved for compatibility
|
|
142
|
+
if cfg.isolv != 1 and cfg.isolv != 2:
|
|
143
|
+
cfg.isolv = 3
|
|
144
|
+
if cfg.isolv in (1, 2):
|
|
145
|
+
cfg.isolv = 3
|
|
146
|
+
if not hasattr(cfg, 'solver_backend') or not cfg.solver_backend:
|
|
147
|
+
cfg.solver_backend = 'cholesky'
|
|
148
|
+
log.debug("INPUT FILES:")
|
|
149
|
+
log.debug(" cross dtime data: %s", cfg.fn_cc)
|
|
150
|
+
log.debug(" catalog dtime data: %s", cfg.fn_ct)
|
|
151
|
+
log.debug(" events: %s", cfg.fn_eve)
|
|
152
|
+
log.debug(" stations: %s", cfg.fn_sta)
|
|
153
|
+
log.debug("OUTPUT FILES:")
|
|
154
|
+
log.debug(" initial locations: %s", cfg.fn_loc)
|
|
155
|
+
log.debug(" relocated events: %s", cfg.fn_reloc)
|
|
156
|
+
log.debug(" event pair residuals: %s", cfg.fn_res)
|
|
157
|
+
log.debug(" station residuals: %s", cfg.fn_stares)
|
|
158
|
+
log.debug(" source parameters: %s", cfg.fn_srcpar)
|
|
159
|
+
|
|
160
|
+
# ---- 2. Read data ----
|
|
161
|
+
ev = read_events(cfg.fn_eve)
|
|
162
|
+
sta = read_stations(cfg.fn_sta, imod=cfg.imod)
|
|
163
|
+
|
|
164
|
+
# Filter stations by maxdist from event centroid (Fortran getdata.f:322-324)
|
|
165
|
+
if cfg.maxdist > 0:
|
|
166
|
+
clat = float(np.mean(ev['lat'])) # float32 mean, like Fortran
|
|
167
|
+
clon = float(np.mean(ev['lon']))
|
|
168
|
+
keep_sta = []
|
|
169
|
+
for si in range(sta['nsta']):
|
|
170
|
+
_, dist_km, _ = delaz(clat, clon,
|
|
171
|
+
float(sta['lat'][si]), float(sta['lon'][si]))
|
|
172
|
+
if dist_km <= cfg.maxdist:
|
|
173
|
+
keep_sta.append(si)
|
|
174
|
+
if len(keep_sta) < sta['nsta']:
|
|
175
|
+
nsta_orig = sta['nsta']
|
|
176
|
+
keep_sta = np.array(keep_sta)
|
|
177
|
+
sta = {
|
|
178
|
+
'lab': [sta['lab'][i] for i in keep_sta],
|
|
179
|
+
'lat': sta['lat'][keep_sta],
|
|
180
|
+
'lon': sta['lon'][keep_sta],
|
|
181
|
+
'elv': sta['elv'][keep_sta],
|
|
182
|
+
'nsta': len(keep_sta),
|
|
183
|
+
}
|
|
184
|
+
log.info("# stations total: %d, # stations < maxdist: %d",
|
|
185
|
+
nsta_orig, sta['nsta'])
|
|
186
|
+
|
|
187
|
+
# Read differential time data
|
|
188
|
+
dt_all_sta = [] # station name strings
|
|
189
|
+
dt_all_dt = []
|
|
190
|
+
dt_all_qual = []
|
|
191
|
+
dt_all_c1 = []
|
|
192
|
+
dt_all_c2 = []
|
|
193
|
+
dt_all_idx = []
|
|
194
|
+
|
|
195
|
+
ncc_total = 0
|
|
196
|
+
nct_total = 0
|
|
197
|
+
|
|
198
|
+
if cfg.idata == 1 or cfg.idata == 3:
|
|
199
|
+
cc = read_cc(cfg.fn_cc)
|
|
200
|
+
dt_all_sta.extend(cc['sta'])
|
|
201
|
+
dt_all_dt.append(cc['dt'])
|
|
202
|
+
dt_all_qual.append(cc['qual'])
|
|
203
|
+
dt_all_c1.append(cc['c1'])
|
|
204
|
+
dt_all_c2.append(cc['c2'])
|
|
205
|
+
dt_all_idx.append(cc['idx'])
|
|
206
|
+
ncc_total = cc['ndt']
|
|
207
|
+
|
|
208
|
+
if cfg.idata == 2 or cfg.idata == 3:
|
|
209
|
+
ct = read_ct(cfg.fn_ct)
|
|
210
|
+
dt_all_sta.extend(ct['sta'])
|
|
211
|
+
dt_all_dt.append(ct['dt'])
|
|
212
|
+
dt_all_qual.append(ct['qual'])
|
|
213
|
+
dt_all_c1.append(ct['c1'])
|
|
214
|
+
dt_all_c2.append(ct['c2'])
|
|
215
|
+
dt_all_idx.append(ct['idx'])
|
|
216
|
+
nct_total = ct['ndt']
|
|
217
|
+
|
|
218
|
+
if not dt_all_dt:
|
|
219
|
+
log.error("No differential time data read.")
|
|
220
|
+
return
|
|
221
|
+
|
|
222
|
+
dt_dt_all = np.concatenate(dt_all_dt).astype(np.float32)
|
|
223
|
+
dt_qual_all = np.concatenate(dt_all_qual).astype(np.float32)
|
|
224
|
+
dt_c1_all = np.concatenate(dt_all_c1).astype(np.int32)
|
|
225
|
+
dt_c2_all = np.concatenate(dt_all_c2).astype(np.int32)
|
|
226
|
+
dt_idx_all = np.concatenate(dt_all_idx).astype(np.int32)
|
|
227
|
+
ndt_all = len(dt_dt_all)
|
|
228
|
+
|
|
229
|
+
log.info("# events: %d", ev['nev'])
|
|
230
|
+
log.info("# stations: %d", sta['nsta'])
|
|
231
|
+
log.info("# observations: %d (CC: %d, CT: %d)", ndt_all, ncc_total, nct_total)
|
|
232
|
+
|
|
233
|
+
# ---- Build station name -> index map ----
|
|
234
|
+
sta_name_to_idx = {}
|
|
235
|
+
for si in range(sta['nsta']):
|
|
236
|
+
sta_name_to_idx[sta['lab'][si]] = si
|
|
237
|
+
|
|
238
|
+
# ---- Map event CUSPs to indices ----
|
|
239
|
+
cusp_to_ev_idx = {}
|
|
240
|
+
for ei in range(ev['nev']):
|
|
241
|
+
cusp_to_ev_idx[int(ev['cusp'][ei])] = ei
|
|
242
|
+
|
|
243
|
+
# ---- Filter by iphase ----
|
|
244
|
+
if cfg.iphase == 1:
|
|
245
|
+
# P only: keep idx 1 (cc-P) and 3 (ct-P)
|
|
246
|
+
keep = (dt_idx_all == 1) | (dt_idx_all == 3)
|
|
247
|
+
elif cfg.iphase == 2:
|
|
248
|
+
# S only: keep idx 2 (cc-S) and 4 (ct-S)
|
|
249
|
+
keep = (dt_idx_all == 2) | (dt_idx_all == 4)
|
|
250
|
+
else:
|
|
251
|
+
keep = np.ones(ndt_all, dtype=bool)
|
|
252
|
+
|
|
253
|
+
if not np.all(keep):
|
|
254
|
+
dt_all_sta = [dt_all_sta[i] for i in range(ndt_all) if keep[i]]
|
|
255
|
+
dt_dt_all = dt_dt_all[keep]
|
|
256
|
+
dt_qual_all = dt_qual_all[keep]
|
|
257
|
+
dt_c1_all = dt_c1_all[keep]
|
|
258
|
+
dt_c2_all = dt_c2_all[keep]
|
|
259
|
+
dt_idx_all = dt_idx_all[keep]
|
|
260
|
+
ndt_all = len(dt_dt_all)
|
|
261
|
+
|
|
262
|
+
# ---- Map station names to indices for observations ----
|
|
263
|
+
dt_ista_all = np.zeros(ndt_all, dtype=np.int32)
|
|
264
|
+
valid_obs = np.ones(ndt_all, dtype=bool)
|
|
265
|
+
for i in range(ndt_all):
|
|
266
|
+
sname = dt_all_sta[i][:7]
|
|
267
|
+
if sname in sta_name_to_idx:
|
|
268
|
+
dt_ista_all[i] = sta_name_to_idx[sname]
|
|
269
|
+
else:
|
|
270
|
+
valid_obs[i] = False
|
|
271
|
+
|
|
272
|
+
# Also filter observations where events are missing
|
|
273
|
+
for i in range(ndt_all):
|
|
274
|
+
if int(dt_c1_all[i]) not in cusp_to_ev_idx:
|
|
275
|
+
valid_obs[i] = False
|
|
276
|
+
if int(dt_c2_all[i]) not in cusp_to_ev_idx:
|
|
277
|
+
valid_obs[i] = False
|
|
278
|
+
|
|
279
|
+
if not np.all(valid_obs):
|
|
280
|
+
idx_valid = np.where(valid_obs)[0]
|
|
281
|
+
dt_all_sta = [dt_all_sta[i] for i in idx_valid]
|
|
282
|
+
dt_dt_all = dt_dt_all[idx_valid]
|
|
283
|
+
dt_qual_all = dt_qual_all[idx_valid]
|
|
284
|
+
dt_c1_all = dt_c1_all[idx_valid]
|
|
285
|
+
dt_c2_all = dt_c2_all[idx_valid]
|
|
286
|
+
dt_idx_all = dt_idx_all[idx_valid]
|
|
287
|
+
dt_ista_all = dt_ista_all[idx_valid]
|
|
288
|
+
ndt_all = len(dt_dt_all)
|
|
289
|
+
|
|
290
|
+
# Report filtered observation counts (matching Fortran getdata.f output)
|
|
291
|
+
nccp = int(np.sum(dt_idx_all[:ndt_all] == 1))
|
|
292
|
+
nccs = int(np.sum(dt_idx_all[:ndt_all] == 2))
|
|
293
|
+
nctp = int(np.sum(dt_idx_all[:ndt_all] == 3))
|
|
294
|
+
ncts = int(np.sum(dt_idx_all[:ndt_all] == 4))
|
|
295
|
+
log.info("# cross corr P dtimes: %d", nccp)
|
|
296
|
+
log.info("# cross corr S dtimes: %d", nccs)
|
|
297
|
+
log.info("# catalog P dtimes: %d", nctp)
|
|
298
|
+
log.info("# catalog S dtimes: %d", ncts)
|
|
299
|
+
log.info("# dtimes total: %d", ndt_all)
|
|
300
|
+
log.info("# events after dtime match: %d", len(set(dt_c1_all[:ndt_all].tolist() + dt_c2_all[:ndt_all].tolist())))
|
|
301
|
+
|
|
302
|
+
# ---- 3. Cluster events ----
|
|
303
|
+
no_clustering = (
|
|
304
|
+
(cfg.idata == 1 and cfg.minobs_cc == 0) or
|
|
305
|
+
(cfg.idata == 2 and cfg.minobs_ct == 0) or
|
|
306
|
+
(cfg.idata == 3 and cfg.minobs_cc + cfg.minobs_ct == 0)
|
|
307
|
+
)
|
|
308
|
+
|
|
309
|
+
if no_clustering:
|
|
310
|
+
clusters = [list(range(ev['nev']))]
|
|
311
|
+
log.info("no clustering performed.")
|
|
312
|
+
else:
|
|
313
|
+
clusters = cluster_events(
|
|
314
|
+
ev['nev'], ev['cusp'], ndt_all,
|
|
315
|
+
dt_c1_all, dt_c2_all, dt_idx_all,
|
|
316
|
+
cfg.idata, cfg.minobs_cc, cfg.minobs_ct,
|
|
317
|
+
)
|
|
318
|
+
|
|
319
|
+
nclust = len(clusters)
|
|
320
|
+
log.info("# clusters: %d", nclust)
|
|
321
|
+
|
|
322
|
+
# ---- Build cumulative iteration boundaries ----
|
|
323
|
+
# aiter[i] is cumulative: aiter[0]=niter[0], aiter[1]=aiter[0]+niter[1], ...
|
|
324
|
+
aiter_base = []
|
|
325
|
+
cum = 0
|
|
326
|
+
for s in range(cfg.nset):
|
|
327
|
+
cum += cfg.niter[s]
|
|
328
|
+
aiter_base.append(cum)
|
|
329
|
+
maxiter_base = cum
|
|
330
|
+
|
|
331
|
+
# ---- Determine cluster range ----
|
|
332
|
+
if cfg.iclust != 0:
|
|
333
|
+
if cfg.iclust < 1 or cfg.iclust > nclust:
|
|
334
|
+
log.error("error: invalid cluster number %d", cfg.iclust)
|
|
335
|
+
return
|
|
336
|
+
ibeg = cfg.iclust - 1
|
|
337
|
+
iend = cfg.iclust
|
|
338
|
+
else:
|
|
339
|
+
ibeg = 0
|
|
340
|
+
iend = nclust
|
|
341
|
+
|
|
342
|
+
# ---- Open output files ----
|
|
343
|
+
f_loc = open(cfg.fn_loc if len(cfg.fn_loc) > 1 else "hypoDD.loc", "w")
|
|
344
|
+
fn_reloc = cfg.fn_reloc if len(cfg.fn_reloc) > 1 else "hypoDD.reloc"
|
|
345
|
+
f_reloc = open(fn_reloc, "w")
|
|
346
|
+
|
|
347
|
+
fn_stares = cfg.fn_stares
|
|
348
|
+
f_stares = None
|
|
349
|
+
if len(fn_stares) > 1:
|
|
350
|
+
f_stares = open(fn_stares, "w")
|
|
351
|
+
|
|
352
|
+
minwght = 0.00001
|
|
353
|
+
|
|
354
|
+
# ---- Big loop over clusters ----
|
|
355
|
+
for ic in range(ibeg, iend):
|
|
356
|
+
cl_id = ic + 1 # 1-based cluster ID
|
|
357
|
+
now_str = datetime.now().strftime("%Y/%m/%d %H:%M:%S")
|
|
358
|
+
log.info("")
|
|
359
|
+
log.info("RELOCATION OF CLUSTER: %d %s", cl_id, now_str)
|
|
360
|
+
log.info("----------------------")
|
|
361
|
+
|
|
362
|
+
# ---- Extract cluster subset ----
|
|
363
|
+
cl_ev_indices = clusters[ic]
|
|
364
|
+
ncl = len(cl_ev_indices)
|
|
365
|
+
|
|
366
|
+
# Build cluster event arrays
|
|
367
|
+
ev_cusp = ev['cusp'][cl_ev_indices].copy()
|
|
368
|
+
ev_lat = ev['lat'][cl_ev_indices].copy()
|
|
369
|
+
ev_lon = ev['lon'][cl_ev_indices].copy()
|
|
370
|
+
ev_dep = ev['dep'][cl_ev_indices].copy()
|
|
371
|
+
ev_mag = ev['mag'][cl_ev_indices].copy()
|
|
372
|
+
ev_herr = ev['herr'][cl_ev_indices].copy()
|
|
373
|
+
ev_zerr = ev['zerr'][cl_ev_indices].copy()
|
|
374
|
+
ev_res = ev['res'][cl_ev_indices].copy()
|
|
375
|
+
ev_date = ev['date'][cl_ev_indices].copy()
|
|
376
|
+
ev_time = ev['time'][cl_ev_indices].copy()
|
|
377
|
+
ev_fix = ev['fix'][cl_ev_indices].copy()
|
|
378
|
+
nev = ncl
|
|
379
|
+
|
|
380
|
+
# Build cusp -> cluster index
|
|
381
|
+
cusp_to_cl = {}
|
|
382
|
+
for i in range(nev):
|
|
383
|
+
cusp_to_cl[int(ev_cusp[i])] = i
|
|
384
|
+
|
|
385
|
+
# Filter observations to this cluster's events
|
|
386
|
+
mask_cl = np.zeros(ndt_all, dtype=bool)
|
|
387
|
+
for i in range(ndt_all):
|
|
388
|
+
if int(dt_c1_all[i]) in cusp_to_cl and int(dt_c2_all[i]) in cusp_to_cl:
|
|
389
|
+
mask_cl[i] = True
|
|
390
|
+
|
|
391
|
+
idx_cl = np.where(mask_cl)[0]
|
|
392
|
+
ndt = len(idx_cl)
|
|
393
|
+
|
|
394
|
+
if ndt == 0:
|
|
395
|
+
log.warning("Cluster %d: no observations. Skipping.", cl_id)
|
|
396
|
+
continue
|
|
397
|
+
|
|
398
|
+
# Build working observation arrays (over-allocated for skip_outliers)
|
|
399
|
+
buf = max(ndt * 2, ndt + 1000)
|
|
400
|
+
dt_dt = np.zeros(buf, dtype=np.float32)
|
|
401
|
+
dt_qual = np.zeros(buf, dtype=np.float32)
|
|
402
|
+
dt_c1 = np.zeros(buf, dtype=np.int32)
|
|
403
|
+
dt_c2 = np.zeros(buf, dtype=np.int32)
|
|
404
|
+
dt_idx = np.zeros(buf, dtype=np.int32)
|
|
405
|
+
dt_ista = np.zeros(buf, dtype=np.int32)
|
|
406
|
+
dt_ic1 = np.zeros(buf, dtype=np.int32)
|
|
407
|
+
dt_ic2 = np.zeros(buf, dtype=np.int32)
|
|
408
|
+
dt_offs = np.zeros(buf, dtype=np.float32)
|
|
409
|
+
dt_cal = np.zeros(buf, dtype=np.float32)
|
|
410
|
+
dt_res = np.zeros(buf, dtype=np.float32)
|
|
411
|
+
dt_wt = np.zeros(buf, dtype=np.float32)
|
|
412
|
+
|
|
413
|
+
dt_sta_work = []
|
|
414
|
+
for ii, gi in enumerate(idx_cl):
|
|
415
|
+
dt_dt[ii] = dt_dt_all[gi]
|
|
416
|
+
dt_qual[ii] = dt_qual_all[gi]
|
|
417
|
+
dt_c1[ii] = dt_c1_all[gi]
|
|
418
|
+
dt_c2[ii] = dt_c2_all[gi]
|
|
419
|
+
dt_idx[ii] = dt_idx_all[gi]
|
|
420
|
+
dt_ista[ii] = dt_ista_all[gi]
|
|
421
|
+
dt_ic1[ii] = cusp_to_cl[int(dt_c1_all[gi])]
|
|
422
|
+
dt_ic2[ii] = cusp_to_cl[int(dt_c2_all[gi])]
|
|
423
|
+
dt_sta_work.append(dt_all_sta[gi])
|
|
424
|
+
|
|
425
|
+
# Count CC/CT
|
|
426
|
+
nccp = int(np.sum(dt_idx[:ndt] == 1))
|
|
427
|
+
nccs = int(np.sum(dt_idx[:ndt] == 2))
|
|
428
|
+
nctp = int(np.sum(dt_idx[:ndt] == 3))
|
|
429
|
+
ncts = int(np.sum(dt_idx[:ndt] == 4))
|
|
430
|
+
ncc = nccp + nccs
|
|
431
|
+
nct = nctp + ncts
|
|
432
|
+
nccold = ncc
|
|
433
|
+
nctold = nct
|
|
434
|
+
nevold = nev
|
|
435
|
+
|
|
436
|
+
# ---- Filter stations by maxdist from cluster centroid ----
|
|
437
|
+
# Use float32 accumulation to match Fortran: real sdc0_lat = sum(ev_lat)/nev
|
|
438
|
+
_slat = np.float32(0.0)
|
|
439
|
+
_slon = np.float32(0.0)
|
|
440
|
+
_sdep = np.float32(0.0)
|
|
441
|
+
for _i in range(nev):
|
|
442
|
+
_slat = np.float32(float(_slat) + float(ev_lat[_i]))
|
|
443
|
+
_slon = np.float32(float(_slon) + float(ev_lon[_i]))
|
|
444
|
+
_sdep = np.float32(float(_sdep) + float(ev_dep[_i]))
|
|
445
|
+
sdc0_lat = float(_slat) / nev
|
|
446
|
+
sdc0_lon = float(_slon) / nev
|
|
447
|
+
sdc0_dep = float(_sdep) / nev
|
|
448
|
+
|
|
449
|
+
log.debug("Cluster centroid at: %10.6f %11.6f %9.6f",
|
|
450
|
+
sdc0_lat, sdc0_lon, sdc0_dep)
|
|
451
|
+
|
|
452
|
+
# ---- Set up cartesian coordinate system ----
|
|
453
|
+
sdc = SDC(sdc0_lat, sdc0_lon, 0.0)
|
|
454
|
+
|
|
455
|
+
# ---- Get cartesian coordinates for epicenters ----
|
|
456
|
+
ev_x = np.zeros(nev, dtype=np.float32)
|
|
457
|
+
ev_y = np.zeros(nev, dtype=np.float32)
|
|
458
|
+
ev_z = np.zeros(nev, dtype=np.float32)
|
|
459
|
+
for i in range(nev):
|
|
460
|
+
xkm, ykm = sdc.latlon_to_xy(float(ev_lat[i]), float(ev_lon[i]))
|
|
461
|
+
ev_x[i] = float(xkm) * 1000.0
|
|
462
|
+
ev_y[i] = float(ykm) * 1000.0
|
|
463
|
+
ev_z[i] = (float(ev_dep[i]) - sdc0_dep) * 1000.0
|
|
464
|
+
|
|
465
|
+
log.debug("# events: %d", nev)
|
|
466
|
+
|
|
467
|
+
# ---- Write initial locations (hypoDD.loc) ----
|
|
468
|
+
for i in range(nev):
|
|
469
|
+
yr = int(ev_date[i]) // 10000
|
|
470
|
+
mo = (int(ev_date[i]) % 10000) // 100
|
|
471
|
+
dy = int(ev_date[i]) % 100
|
|
472
|
+
hr = int(ev_time[i]) // 1000000
|
|
473
|
+
mn = (int(ev_time[i]) % 1000000) // 10000
|
|
474
|
+
sc = (float(ev_time[i]) % 10000.0) / 100.0
|
|
475
|
+
ex = float(ev_herr[i]) * 1000.0
|
|
476
|
+
ey = float(ev_herr[i]) * 1000.0
|
|
477
|
+
ez = float(ev_zerr[i]) * 1000.0
|
|
478
|
+
line = (
|
|
479
|
+
f"{int(ev_cusp[i]):9d} "
|
|
480
|
+
f"{float(ev_lat[i]):10.6f} "
|
|
481
|
+
f"{float(ev_lon[i]):11.6f} "
|
|
482
|
+
f"{float(ev_dep[i]):9.3f} "
|
|
483
|
+
f"{float(ev_x[i]):10.1f} "
|
|
484
|
+
f"{float(ev_y[i]):10.1f} "
|
|
485
|
+
f"{float(ev_z[i]):10.1f} "
|
|
486
|
+
f"{ex:8.1f} "
|
|
487
|
+
f"{ey:8.1f} "
|
|
488
|
+
f"{ez:8.1f} "
|
|
489
|
+
f"{yr:4d} "
|
|
490
|
+
f"{mo:2d} "
|
|
491
|
+
f"{dy:2d} "
|
|
492
|
+
f"{hr:2d} "
|
|
493
|
+
f"{mn:2d} "
|
|
494
|
+
f"{sc:5.2f} "
|
|
495
|
+
f"{float(ev_mag[i]):5.2f} "
|
|
496
|
+
f"{cl_id:3d}\n"
|
|
497
|
+
)
|
|
498
|
+
f_loc.write(line)
|
|
499
|
+
|
|
500
|
+
# ---- Trial sources ----
|
|
501
|
+
MAXEV = nev
|
|
502
|
+
src_cusp = ev_cusp.copy()
|
|
503
|
+
src_lat = np.zeros(MAXEV, dtype=np.float64)
|
|
504
|
+
src_lon = np.zeros(MAXEV, dtype=np.float64)
|
|
505
|
+
src_dep = np.zeros(MAXEV, dtype=np.float32)
|
|
506
|
+
src_x = np.zeros(MAXEV, dtype=np.float32)
|
|
507
|
+
src_y = np.zeros(MAXEV, dtype=np.float32)
|
|
508
|
+
src_z = np.zeros(MAXEV, dtype=np.float32)
|
|
509
|
+
src_t = np.zeros(MAXEV, dtype=np.float32)
|
|
510
|
+
# Initial copies (src_*0)
|
|
511
|
+
src_x0 = np.zeros(MAXEV, dtype=np.float32)
|
|
512
|
+
src_y0 = np.zeros(MAXEV, dtype=np.float32)
|
|
513
|
+
src_z0 = np.zeros(MAXEV, dtype=np.float32)
|
|
514
|
+
src_t0 = np.zeros(MAXEV, dtype=np.float32)
|
|
515
|
+
|
|
516
|
+
if cfg.istart == 1:
|
|
517
|
+
# Single source at cluster centroid
|
|
518
|
+
nsrc = 1
|
|
519
|
+
for i in range(nev):
|
|
520
|
+
src_lat[i] = sdc0_lat
|
|
521
|
+
src_lon[i] = sdc0_lon
|
|
522
|
+
src_dep[i] = sdc0_dep
|
|
523
|
+
src_x[i] = 0.0
|
|
524
|
+
src_y[i] = 0.0
|
|
525
|
+
src_z[i] = 0.0
|
|
526
|
+
src_t[i] = 0.0
|
|
527
|
+
src_x0[i] = 0.0
|
|
528
|
+
src_y0[i] = 0.0
|
|
529
|
+
src_z0[i] = 0.0
|
|
530
|
+
src_t0[i] = 0.0
|
|
531
|
+
else:
|
|
532
|
+
# Catalog locations as initial trial sources
|
|
533
|
+
nsrc = nev
|
|
534
|
+
for i in range(nev):
|
|
535
|
+
src_lat[i] = float(ev_lat[i])
|
|
536
|
+
src_lon[i] = float(ev_lon[i])
|
|
537
|
+
src_dep[i] = ev_dep[i]
|
|
538
|
+
xkm, ykm = sdc.latlon_to_xy(float(ev_lat[i]), float(ev_lon[i]))
|
|
539
|
+
src_x[i] = float(xkm) * 1000.0
|
|
540
|
+
src_y[i] = float(ykm) * 1000.0
|
|
541
|
+
src_z[i] = (float(ev_dep[i]) - sdc0_dep) * 1000.0
|
|
542
|
+
src_t[i] = 0.0
|
|
543
|
+
src_x0[i] = src_x[i]
|
|
544
|
+
src_y0[i] = src_y[i]
|
|
545
|
+
src_z0[i] = src_z[i]
|
|
546
|
+
src_t0[i] = 0.0
|
|
547
|
+
|
|
548
|
+
log.info("# initial trial sources: %d", nsrc)
|
|
549
|
+
|
|
550
|
+
# ---- Iteration limits (reset for this cluster) ----
|
|
551
|
+
aiter = list(aiter_base)
|
|
552
|
+
maxiter = maxiter_base
|
|
553
|
+
jiter = 0 # counter for iterations with no updating (airquakes)
|
|
554
|
+
kiter = 0 # counter for iterations with data skipping
|
|
555
|
+
mbad = 0 # counter for airquakes
|
|
556
|
+
amcusp = [] # list of airquake event CUSPs
|
|
557
|
+
|
|
558
|
+
rms_ccold = 0.0
|
|
559
|
+
rms_ctold = 0.0
|
|
560
|
+
rms_cc0old = 0.0
|
|
561
|
+
rms_ct0old = 0.0
|
|
562
|
+
|
|
563
|
+
# Source error arrays
|
|
564
|
+
src_ex = np.zeros(MAXEV, dtype=np.float64)
|
|
565
|
+
src_ey = np.zeros(MAXEV, dtype=np.float64)
|
|
566
|
+
src_ez = np.zeros(MAXEV, dtype=np.float64)
|
|
567
|
+
src_et = np.zeros(MAXEV, dtype=np.float64)
|
|
568
|
+
|
|
569
|
+
# Station working arrays
|
|
570
|
+
sta_lab = list(sta['lab'])
|
|
571
|
+
sta_lat = sta['lat'].copy()
|
|
572
|
+
sta_lon = sta['lon'].copy()
|
|
573
|
+
sta_elv = sta['elv'].copy()
|
|
574
|
+
nsta = sta['nsta']
|
|
575
|
+
|
|
576
|
+
# Velocity model
|
|
577
|
+
mod_nl = cfg.vel_model.nl
|
|
578
|
+
mod_v = cfg.vel_model.v.copy()
|
|
579
|
+
mod_top = cfg.vel_model.top.copy()
|
|
580
|
+
mod_ratio = cfg.vel_model.ratio.copy()
|
|
581
|
+
|
|
582
|
+
# ---- Iteration loop ----
|
|
583
|
+
iter_ = 1
|
|
584
|
+
skip_cluster = False
|
|
585
|
+
|
|
586
|
+
while iter_ <= maxiter:
|
|
587
|
+
now_str = datetime.now().strftime("%Y/%m/%d %H:%M:%S")
|
|
588
|
+
log.debug("")
|
|
589
|
+
log.debug("===ITERATION %d (%d) %s", iter_ - jiter, iter_, now_str)
|
|
590
|
+
|
|
591
|
+
# ---- Get weighting parameters for this iteration ----
|
|
592
|
+
iset = 0
|
|
593
|
+
for i in range(cfg.nset):
|
|
594
|
+
if iter_ <= aiter[i]:
|
|
595
|
+
iset = i
|
|
596
|
+
break
|
|
597
|
+
else:
|
|
598
|
+
iset = cfg.nset - 1
|
|
599
|
+
|
|
600
|
+
maxres_cross = cfg.wrcc[iset]
|
|
601
|
+
maxres_net = cfg.wrct[iset]
|
|
602
|
+
maxdcc = cfg.wdcc[iset]
|
|
603
|
+
maxdct = cfg.wdct[iset]
|
|
604
|
+
wt_ccp = cfg.wt_ccp[iset]
|
|
605
|
+
wt_ccs = cfg.wt_ccs[iset]
|
|
606
|
+
wt_ctp = cfg.wt_ctp[iset]
|
|
607
|
+
wt_cts = cfg.wt_cts[iset]
|
|
608
|
+
damp = cfg.damp[iset]
|
|
609
|
+
|
|
610
|
+
log.debug("Weighting parameters for this iteration:")
|
|
611
|
+
log.debug(" wt_ccp= %7.4f wt_ccs= %7.4f maxr_cc= %7.4f maxd_cc= %7.2f",
|
|
612
|
+
wt_ccp, wt_ccs, maxres_cross, maxdcc)
|
|
613
|
+
log.debug(" wt_ctp= %7.4f wt_cts= %7.4f maxr_ct= %7.4f maxd_ct= %7.2f",
|
|
614
|
+
wt_ctp, wt_cts, maxres_net, maxdct)
|
|
615
|
+
log.debug(" damp= %5.1f", damp)
|
|
616
|
+
|
|
617
|
+
# ---- Compute travel times and partial derivatives ----
|
|
618
|
+
log.debug("~ getting partials for %d stations and %d source(s) ...",
|
|
619
|
+
nsta, nsrc)
|
|
620
|
+
|
|
621
|
+
# Use observation-centric partials for large clusters (saves memory),
|
|
622
|
+
# original vectorized partials for small clusters (faster)
|
|
623
|
+
_use_obs_partials = (cfg.isolv == 3 and nsta * nsrc > 100000)
|
|
624
|
+
|
|
625
|
+
if _use_obs_partials:
|
|
626
|
+
tmp_ttp, tmp_tts, tmp_xp, tmp_yp, tmp_zp, tmp_xs, tmp_ys, tmp_zs = \
|
|
627
|
+
compute_partials_obs(
|
|
628
|
+
nsrc, src_lat[:nsrc].astype(np.float64),
|
|
629
|
+
src_lon[:nsrc].astype(np.float64),
|
|
630
|
+
src_dep[:nsrc].astype(np.float64),
|
|
631
|
+
nsta,
|
|
632
|
+
sta_lat[:nsta].astype(np.float64),
|
|
633
|
+
sta_lon[:nsta].astype(np.float64),
|
|
634
|
+
sta_elv[:nsta].astype(np.float64),
|
|
635
|
+
mod_nl, mod_ratio, mod_v, mod_top,
|
|
636
|
+
ndt, dt_ista, dt_ic1, dt_ic2, dt_idx,
|
|
637
|
+
imod=cfg.imod,
|
|
638
|
+
)
|
|
639
|
+
else:
|
|
640
|
+
tmp_ttp, tmp_tts, tmp_xp, tmp_yp, tmp_zp, tmp_xs, tmp_ys, tmp_zs = \
|
|
641
|
+
compute_partials(
|
|
642
|
+
nsrc, src_lat[:nsrc].astype(np.float64),
|
|
643
|
+
src_lon[:nsrc].astype(np.float64),
|
|
644
|
+
src_dep[:nsrc].astype(np.float64),
|
|
645
|
+
nsta,
|
|
646
|
+
sta_lat[:nsta].astype(np.float64),
|
|
647
|
+
sta_lon[:nsta].astype(np.float64),
|
|
648
|
+
sta_elv[:nsta].astype(np.float64),
|
|
649
|
+
mod_nl, mod_ratio, mod_v, mod_top,
|
|
650
|
+
imod=cfg.imod,
|
|
651
|
+
)
|
|
652
|
+
|
|
653
|
+
# ---- Compute DD residuals ----
|
|
654
|
+
_cal, _res = compute_residuals(
|
|
655
|
+
ndt, nsrc, dt_dt, dt_idx, dt_ista, dt_ic1, dt_ic2,
|
|
656
|
+
src_t, tmp_ttp, tmp_tts,
|
|
657
|
+
)
|
|
658
|
+
dt_cal[:ndt] = _cal[:ndt]
|
|
659
|
+
dt_res[:ndt] = _res[:ndt]
|
|
660
|
+
|
|
661
|
+
# ---- Apply weights and reweighting ----
|
|
662
|
+
ineg = weighting(
|
|
663
|
+
ndt, amcusp, cfg.idata,
|
|
664
|
+
maxres_cross, maxres_net, maxdcc, maxdct, minwght,
|
|
665
|
+
wt_ccp, wt_ccs, wt_ctp, wt_cts,
|
|
666
|
+
dt_c1, dt_c2, dt_idx, dt_qual, dt_res, dt_offs, dt_wt,
|
|
667
|
+
)
|
|
668
|
+
|
|
669
|
+
# ---- Skip outliers if needed ----
|
|
670
|
+
if ineg > 0:
|
|
671
|
+
ndt, nev, nsrc, nsta = skip_outliers(
|
|
672
|
+
ndt, nev, nsrc, nsta, minwght,
|
|
673
|
+
dt_dt, dt_qual, dt_c1, dt_c2, dt_idx, dt_ista, dt_ic1, dt_ic2,
|
|
674
|
+
dt_offs, dt_cal, dt_res, dt_wt,
|
|
675
|
+
ev_cusp, src_cusp, src_lat, src_lon, src_dep,
|
|
676
|
+
src_x, src_y, src_z, src_t,
|
|
677
|
+
sta_lab, sta_lat, sta_lon, sta_elv,
|
|
678
|
+
tmp_ttp, tmp_tts, tmp_xp, tmp_yp, tmp_zp, tmp_xs, tmp_ys, tmp_zs,
|
|
679
|
+
)
|
|
680
|
+
# Recount CC/CT
|
|
681
|
+
ncc = int(np.sum(dt_idx[:ndt] <= 2))
|
|
682
|
+
nct = int(np.sum(dt_idx[:ndt] >= 3))
|
|
683
|
+
|
|
684
|
+
if nev < 2:
|
|
685
|
+
log.warning(" Cluster has less than 2 events.")
|
|
686
|
+
skip_cluster = True
|
|
687
|
+
break
|
|
688
|
+
else:
|
|
689
|
+
log.debug("no data skipped.")
|
|
690
|
+
|
|
691
|
+
# ---- Initial residual statistics (first iteration only) ----
|
|
692
|
+
if iter_ == 1:
|
|
693
|
+
rms_cc, rms_ct, rms_cc0, rms_ct0, _ = resstat(
|
|
694
|
+
ndt, nev, dt_res, dt_wt, dt_idx, cfg.idata,
|
|
695
|
+
)
|
|
696
|
+
rms_ccold = rms_cc
|
|
697
|
+
rms_ctold = rms_ct
|
|
698
|
+
rms_cc0old = rms_cc0
|
|
699
|
+
rms_ct0old = rms_ct0
|
|
700
|
+
|
|
701
|
+
# ---- Solve ----
|
|
702
|
+
if cfg.isolv == 1:
|
|
703
|
+
result = solve_svd(
|
|
704
|
+
ndt, nev, nsrc, damp, cfg.idata,
|
|
705
|
+
ev_cusp, ev_fix, src_cusp,
|
|
706
|
+
dt_res, dt_wt, dt_ista, dt_ic1, dt_ic2, dt_idx,
|
|
707
|
+
tmp_xp, tmp_yp, tmp_zp, tmp_xs, tmp_ys, tmp_zs,
|
|
708
|
+
iter_num=iter_,
|
|
709
|
+
)
|
|
710
|
+
elif cfg.isolv == 3:
|
|
711
|
+
# GraphDD multi-backend solver
|
|
712
|
+
_backend = getattr(cfg, 'solver_backend', 'lsqr')
|
|
713
|
+
_robust = getattr(cfg, 'robust_loss', None)
|
|
714
|
+
gnc_kwargs = {}
|
|
715
|
+
if hasattr(cfg, 'gnc_kernel') and cfg.gnc_kernel:
|
|
716
|
+
from .core.kernels import gnc_mu
|
|
717
|
+
gnc_kwargs = {
|
|
718
|
+
'gnc_kernel': cfg.gnc_kernel,
|
|
719
|
+
'gnc_mu': gnc_mu(iter_ - 1, maxiter),
|
|
720
|
+
'gnc_threshold': getattr(cfg, 'gnc_threshold', 3.0),
|
|
721
|
+
}
|
|
722
|
+
result = solve_sparse_chol(
|
|
723
|
+
ndt, nev, nsrc, damp, cfg.idata,
|
|
724
|
+
ev_cusp, ev_fix, src_cusp,
|
|
725
|
+
dt_res, dt_wt, dt_ista, dt_ic1, dt_ic2, dt_idx,
|
|
726
|
+
tmp_xp, tmp_yp, tmp_zp, tmp_xs, tmp_ys, tmp_zs,
|
|
727
|
+
iter_num=iter_,
|
|
728
|
+
backend=_backend, robust_loss=_robust,
|
|
729
|
+
**gnc_kwargs,
|
|
730
|
+
)
|
|
731
|
+
else:
|
|
732
|
+
result = solve_lsqr(
|
|
733
|
+
ndt, nev, nsrc, damp, cfg.idata,
|
|
734
|
+
ev_cusp, ev_fix, src_cusp,
|
|
735
|
+
dt_res, dt_wt, dt_ista, dt_ic1, dt_ic2, dt_idx,
|
|
736
|
+
tmp_xp, tmp_yp, tmp_zp, tmp_xs, tmp_ys, tmp_zs,
|
|
737
|
+
iter_num=iter_,
|
|
738
|
+
)
|
|
739
|
+
|
|
740
|
+
src_dx = result['src_dx']
|
|
741
|
+
src_dy = result['src_dy']
|
|
742
|
+
src_dz = result['src_dz']
|
|
743
|
+
src_dt = result['src_dt']
|
|
744
|
+
src_ex[:nev] = result['src_ex']
|
|
745
|
+
src_ey[:nev] = result['src_ey']
|
|
746
|
+
src_ez[:nev] = result['src_ez']
|
|
747
|
+
src_et[:nev] = result['src_et']
|
|
748
|
+
rms_cc = result['rms_cc']
|
|
749
|
+
rms_ct = result['rms_ct']
|
|
750
|
+
rms_cc0 = result.get('rms_cc0', 0.0)
|
|
751
|
+
rms_ct0 = result.get('rms_ct0', 0.0)
|
|
752
|
+
acond = result.get('acond', 0.0)
|
|
753
|
+
|
|
754
|
+
dxav = float(np.mean(np.abs(src_dx[:nev])))
|
|
755
|
+
dyav = float(np.mean(np.abs(src_dy[:nev])))
|
|
756
|
+
dzav = float(np.mean(np.abs(src_dz[:nev])))
|
|
757
|
+
dtav = float(np.mean(np.abs(src_dt[:nev])))
|
|
758
|
+
|
|
759
|
+
# ---- Check for airquakes ----
|
|
760
|
+
mbad = 0
|
|
761
|
+
amcusp = []
|
|
762
|
+
for i in range(nsrc if nsrc > 1 else nev):
|
|
763
|
+
if src_dep[i] + src_dz[i] / 1000.0 < 0:
|
|
764
|
+
log.debug(">>>Warning: negative depth - %d", ev_cusp[i])
|
|
765
|
+
amcusp.append(int(ev_cusp[i]))
|
|
766
|
+
src_dz[i] = 0.0
|
|
767
|
+
# Reset depth if ev_fix == -1
|
|
768
|
+
if ev_fix[i] == -1:
|
|
769
|
+
src_dz[i] = 0.0
|
|
770
|
+
|
|
771
|
+
mbad = len(amcusp)
|
|
772
|
+
if cfg.iaq == 0:
|
|
773
|
+
mbad = -mbad # don't remove airquakes
|
|
774
|
+
|
|
775
|
+
if abs(mbad) > 0:
|
|
776
|
+
log.debug("Number of air quakes (AQ) = %d", abs(mbad))
|
|
777
|
+
if nsrc - abs(mbad) <= 1:
|
|
778
|
+
log.warning("Warning: number of non-airquakes < 2")
|
|
779
|
+
log.warning(" skipping this cluster")
|
|
780
|
+
skip_cluster = True
|
|
781
|
+
break
|
|
782
|
+
|
|
783
|
+
# Update iteration numbers for airquakes
|
|
784
|
+
if mbad > 0:
|
|
785
|
+
for i in range(len(aiter)):
|
|
786
|
+
aiter[i] += 1
|
|
787
|
+
jiter += 1
|
|
788
|
+
maxiter += 1
|
|
789
|
+
# Skip source update, go to next iteration
|
|
790
|
+
# Standard output for airquake iteration
|
|
791
|
+
log.info("IT %2d (airquake iteration - no source update) AQ=%d",
|
|
792
|
+
iter_, abs(mbad))
|
|
793
|
+
iter_ += 1
|
|
794
|
+
continue
|
|
795
|
+
|
|
796
|
+
# ---- Update source parameters ----
|
|
797
|
+
if nsrc == 1:
|
|
798
|
+
nsrc = nev
|
|
799
|
+
|
|
800
|
+
xav = 0.0
|
|
801
|
+
yav = 0.0
|
|
802
|
+
zav = 0.0
|
|
803
|
+
tav = 0.0
|
|
804
|
+
alat_sum = 0.0
|
|
805
|
+
alon_sum = 0.0
|
|
806
|
+
adep_sum = 0.0
|
|
807
|
+
|
|
808
|
+
for i in range(nsrc):
|
|
809
|
+
src_cusp[i] = ev_cusp[i]
|
|
810
|
+
# Update absolute source parameters (cartesian)
|
|
811
|
+
src_x[i] += src_dx[i]
|
|
812
|
+
src_y[i] += src_dy[i]
|
|
813
|
+
src_z[i] += src_dz[i]
|
|
814
|
+
src_t[i] += src_dt[i]
|
|
815
|
+
|
|
816
|
+
# Update absolute source locations (geographic)
|
|
817
|
+
src_dep[i] += src_dz[i] / 1000.0
|
|
818
|
+
lat_new, lon_new = sdc.xy_to_latlon(
|
|
819
|
+
float(src_x[i]) / 1000.0, float(src_y[i]) / 1000.0
|
|
820
|
+
)
|
|
821
|
+
src_lat[i] = float(lat_new)
|
|
822
|
+
src_lon[i] = float(lon_new)
|
|
823
|
+
alat_sum += src_lat[i]
|
|
824
|
+
alon_sum += src_lon[i]
|
|
825
|
+
adep_sum += src_dep[i]
|
|
826
|
+
|
|
827
|
+
# Mean centroid shift
|
|
828
|
+
xav += src_x[i] - src_x0[i]
|
|
829
|
+
yav += src_y[i] - src_y0[i]
|
|
830
|
+
zav += src_z[i] - src_z0[i]
|
|
831
|
+
tav += src_t[i] - src_t0[i]
|
|
832
|
+
|
|
833
|
+
xav /= nsrc
|
|
834
|
+
yav /= nsrc
|
|
835
|
+
zav /= nsrc
|
|
836
|
+
tav /= nsrc
|
|
837
|
+
alat_avg = alat_sum / nsrc
|
|
838
|
+
alon_avg = alon_sum / nsrc
|
|
839
|
+
adep_avg = adep_sum / nsrc
|
|
840
|
+
|
|
841
|
+
log.debug(" cluster centroid at: %10.6f %11.6f %9.6f",
|
|
842
|
+
alat_avg, alon_avg, adep_avg)
|
|
843
|
+
log.debug(" mean centroid (origin) shift in x,y,z,t [m,ms]: "
|
|
844
|
+
"%7.1f%7.1f%7.1f%7.1f", xav, yav, zav, tav)
|
|
845
|
+
|
|
846
|
+
# ---- Compute inter-event distances for next iteration ----
|
|
847
|
+
cohav = 0.0
|
|
848
|
+
picav = 0.0
|
|
849
|
+
ncc = 0
|
|
850
|
+
nct = 0
|
|
851
|
+
for i in range(ndt):
|
|
852
|
+
ic1 = dt_ic1[i]
|
|
853
|
+
ic2 = dt_ic2[i]
|
|
854
|
+
dt_offs[i] = math.sqrt(
|
|
855
|
+
(src_x[ic1] - src_x[ic2]) ** 2 +
|
|
856
|
+
(src_y[ic1] - src_y[ic2]) ** 2 +
|
|
857
|
+
(src_z[ic1] - src_z[ic2]) ** 2
|
|
858
|
+
)
|
|
859
|
+
if dt_idx[i] <= 2:
|
|
860
|
+
cohav += math.sqrt(float(dt_qual[i]))
|
|
861
|
+
ncc += 1
|
|
862
|
+
else:
|
|
863
|
+
picav += float(dt_qual[i])
|
|
864
|
+
nct += 1
|
|
865
|
+
|
|
866
|
+
if ncc > 0:
|
|
867
|
+
cohav /= ncc
|
|
868
|
+
if nct > 0:
|
|
869
|
+
picav /= nct
|
|
870
|
+
log.debug("")
|
|
871
|
+
log.debug("More:")
|
|
872
|
+
log.debug(" mean phase coherency = %5.3f", cohav)
|
|
873
|
+
log.debug(" mean pick quality = %5.3f", picav)
|
|
874
|
+
|
|
875
|
+
# ---- Standard output ----
|
|
876
|
+
os_val = max(abs(xav), abs(yav), abs(zav))
|
|
877
|
+
if cfg.idata == 3:
|
|
878
|
+
log.info(
|
|
879
|
+
"IT %2d %3d EV %3d%% CT %3d%% CC %3d%% "
|
|
880
|
+
"RMSCT %5d %5.1f%% RMSCC %5d %5.1f%% "
|
|
881
|
+
"DX %4d DY %4d DZ %4d DT %4d OS %4d AQ %3d%s",
|
|
882
|
+
iter_, iter_ - jiter,
|
|
883
|
+
round(nev * 100.0 / nevold) if nevold > 0 else 0,
|
|
884
|
+
round(nct * 100.0 / nctold) if nctold > 0 else 0,
|
|
885
|
+
round(ncc * 100.0 / nccold) if nccold > 0 else 0,
|
|
886
|
+
round(rms_ct * 1000),
|
|
887
|
+
(rms_ct - rms_ctold) * 100 / rms_ctold if rms_ctold != 0 else 0,
|
|
888
|
+
round(rms_cc * 1000),
|
|
889
|
+
(rms_cc - rms_ccold) * 100 / rms_ccold if rms_ccold != 0 else 0,
|
|
890
|
+
round(dxav), round(dyav), round(dzav), round(dtav),
|
|
891
|
+
round(os_val), abs(mbad),
|
|
892
|
+
(" CND %5d" % round(acond)) if cfg.isolv == 2 else "",
|
|
893
|
+
)
|
|
894
|
+
elif cfg.idata == 1:
|
|
895
|
+
log.info(
|
|
896
|
+
"IT %2d %3d EV %3d%% CC %3d%% "
|
|
897
|
+
"RMSCC %5d %5.1f%% "
|
|
898
|
+
"DX %4d DY %4d DZ %4d DT %4d OS %4d AQ %3d%s",
|
|
899
|
+
iter_, iter_ - jiter,
|
|
900
|
+
round(nev * 100.0 / nevold) if nevold > 0 else 0,
|
|
901
|
+
round(ncc * 100.0 / nccold) if nccold > 0 else 0,
|
|
902
|
+
round(rms_cc * 1000),
|
|
903
|
+
(rms_cc - rms_ccold) * 100 / rms_ccold if rms_ccold != 0 else 0,
|
|
904
|
+
round(dxav), round(dyav), round(dzav), round(dtav),
|
|
905
|
+
round(os_val), abs(mbad),
|
|
906
|
+
(" CND %5d" % round(acond)) if cfg.isolv == 2 else "",
|
|
907
|
+
)
|
|
908
|
+
else: # idata == 2
|
|
909
|
+
log.info(
|
|
910
|
+
"IT %2d %3d EV %3d%% CT %3d%% "
|
|
911
|
+
"RMSCT %5d %5.1f%% "
|
|
912
|
+
"DX %4d DY %4d DZ %4d DT %4d OS %4d AQ %3d%s",
|
|
913
|
+
iter_, iter_ - jiter,
|
|
914
|
+
round(nev * 100.0 / nevold) if nevold > 0 else 0,
|
|
915
|
+
round(nct * 100.0 / nctold) if nctold > 0 else 0,
|
|
916
|
+
round(rms_ct * 1000),
|
|
917
|
+
(rms_ct - rms_ctold) * 100 / rms_ctold if rms_ctold != 0 else 0,
|
|
918
|
+
round(dxav), round(dyav), round(dzav), round(dtav),
|
|
919
|
+
round(os_val), abs(mbad),
|
|
920
|
+
(" CND %5d" % round(acond)) if cfg.isolv == 2 else "",
|
|
921
|
+
)
|
|
922
|
+
|
|
923
|
+
rms_ccold = rms_cc
|
|
924
|
+
rms_ctold = rms_ct
|
|
925
|
+
rms_cc0old = rms_cc0
|
|
926
|
+
rms_ct0old = rms_ct0
|
|
927
|
+
|
|
928
|
+
# ---- Write per-iteration reloc scratch file ----
|
|
929
|
+
sdc_out = SDC(sdc0_lat, sdc0_lon, 0.0)
|
|
930
|
+
iter_reloc_fn = f"{fn_reloc}.{cl_id:03d}.{iter_ - jiter:03d}"
|
|
931
|
+
with open(iter_reloc_fn, "w") as fit:
|
|
932
|
+
for i in range(nev):
|
|
933
|
+
xkm, ykm = sdc_out.latlon_to_xy(src_lat[i], src_lon[i])
|
|
934
|
+
yr = int(ev_date[i]) // 10000
|
|
935
|
+
mo = (int(ev_date[i]) % 10000) // 100
|
|
936
|
+
dy = int(ev_date[i]) % 100
|
|
937
|
+
hr = int(ev_time[i]) // 1000000
|
|
938
|
+
mn = (int(ev_time[i]) % 1000000) // 10000
|
|
939
|
+
sc = (float(ev_time[i]) % 10000.0) / 100.0
|
|
940
|
+
line = (
|
|
941
|
+
f"{int(src_cusp[i]):9d} "
|
|
942
|
+
f"{float(src_lat[i]):10.6f} "
|
|
943
|
+
f"{float(src_lon[i]):11.6f} "
|
|
944
|
+
f"{float(src_dep[i]):9.3f} "
|
|
945
|
+
f"{float(xkm) * 1000:10.1f} "
|
|
946
|
+
f"{float(ykm) * 1000:10.1f} "
|
|
947
|
+
f"{float(src_z[i]):10.1f} "
|
|
948
|
+
f"{float(src_ex[i]):8.1f} "
|
|
949
|
+
f"{float(src_ey[i]):8.1f} "
|
|
950
|
+
f"{float(src_ez[i]):8.1f} "
|
|
951
|
+
f"{yr:4d} "
|
|
952
|
+
f"{mo:2d} "
|
|
953
|
+
f"{dy:2d} "
|
|
954
|
+
f"{hr:2d} "
|
|
955
|
+
f"{mn:2d} "
|
|
956
|
+
f"{sc:6.3f} "
|
|
957
|
+
f"{float(ev_mag[i]):5.2f} "
|
|
958
|
+
f"{cl_id:3d}\n"
|
|
959
|
+
)
|
|
960
|
+
fit.write(line)
|
|
961
|
+
|
|
962
|
+
log.debug("Relocation results for this iteration are stored in %s",
|
|
963
|
+
iter_reloc_fn)
|
|
964
|
+
|
|
965
|
+
now_str = datetime.now().strftime("%Y/%m/%d %H:%M:%S")
|
|
966
|
+
log.debug("Iteration %d finished %s", iter_, now_str)
|
|
967
|
+
|
|
968
|
+
if iter_ >= maxiter:
|
|
969
|
+
break
|
|
970
|
+
iter_ += 1
|
|
971
|
+
|
|
972
|
+
# ---- End of iteration loop ----
|
|
973
|
+
if skip_cluster:
|
|
974
|
+
continue
|
|
975
|
+
|
|
976
|
+
# ---- Update origin times (final output only) ----
|
|
977
|
+
log.info("writing out results ...")
|
|
978
|
+
for i in range(nev):
|
|
979
|
+
src_t_sec = float(src_t[i]) / 1000.0 # ms to sec
|
|
980
|
+
if abs(src_t_sec) > 5.0:
|
|
981
|
+
log.warning("WARNING: org time diff > 5s for %d", src_cusp[i])
|
|
982
|
+
|
|
983
|
+
iyr = int(ev_date[i]) // 10000
|
|
984
|
+
imo = (int(ev_date[i]) % 10000) // 100
|
|
985
|
+
idy = int(ev_date[i]) % 100
|
|
986
|
+
ihr = int(ev_time[i]) // 1000000
|
|
987
|
+
imn = (int(ev_time[i]) % 1000000) // 10000
|
|
988
|
+
itf = _juliam(iyr, imo, idy, ihr, imn)
|
|
989
|
+
|
|
990
|
+
sc = (float(ev_time[i]) % 10000.0) / 100.0 - src_t_sec
|
|
991
|
+
itf = itf + int(sc / 60.0)
|
|
992
|
+
sc = sc - int(sc / 60.0) * 60.0
|
|
993
|
+
|
|
994
|
+
# Ad hoc fix for output precision
|
|
995
|
+
if round(sc * 100) < 0:
|
|
996
|
+
itf -= 1
|
|
997
|
+
sc += 60.0
|
|
998
|
+
elif round(sc * 100) >= 6000:
|
|
999
|
+
itf += 1
|
|
1000
|
+
sc -= 60.0
|
|
1001
|
+
|
|
1002
|
+
iyr, imo, idy, ihr, imn = _datum(itf)
|
|
1003
|
+
ev_date[i] = iyr * 10000 + imo * 100 + idy
|
|
1004
|
+
ev_time[i] = ihr * 1000000 + imn * 10000 + round(sc * 100)
|
|
1005
|
+
|
|
1006
|
+
# ---- Count observations per event ----
|
|
1007
|
+
src_np = np.zeros(nev, dtype=np.int32) # CC-P
|
|
1008
|
+
src_ns = np.zeros(nev, dtype=np.int32) # CC-S
|
|
1009
|
+
src_nnp = np.zeros(nev, dtype=np.int32) # CT-P
|
|
1010
|
+
src_nns = np.zeros(nev, dtype=np.int32) # CT-S
|
|
1011
|
+
src_rmsc = np.zeros(nev, dtype=np.float32)
|
|
1012
|
+
src_rmsn = np.zeros(nev, dtype=np.float32)
|
|
1013
|
+
|
|
1014
|
+
for i in range(ndt):
|
|
1015
|
+
ic1 = dt_ic1[i]
|
|
1016
|
+
ic2 = dt_ic2[i]
|
|
1017
|
+
if dt_idx[i] == 1:
|
|
1018
|
+
src_np[ic1] += 1
|
|
1019
|
+
src_np[ic2] += 1
|
|
1020
|
+
elif dt_idx[i] == 2:
|
|
1021
|
+
src_ns[ic1] += 1
|
|
1022
|
+
src_ns[ic2] += 1
|
|
1023
|
+
if dt_idx[i] <= 2:
|
|
1024
|
+
src_rmsc[ic1] += dt_res[i] ** 2
|
|
1025
|
+
src_rmsc[ic2] += dt_res[i] ** 2
|
|
1026
|
+
if dt_idx[i] == 3:
|
|
1027
|
+
src_nnp[ic1] += 1
|
|
1028
|
+
src_nnp[ic2] += 1
|
|
1029
|
+
elif dt_idx[i] == 4:
|
|
1030
|
+
src_nns[ic1] += 1
|
|
1031
|
+
src_nns[ic2] += 1
|
|
1032
|
+
if dt_idx[i] >= 3:
|
|
1033
|
+
src_rmsn[ic1] += dt_res[i] ** 2
|
|
1034
|
+
src_rmsn[ic2] += dt_res[i] ** 2
|
|
1035
|
+
|
|
1036
|
+
for i in range(nev):
|
|
1037
|
+
nobs_cc = src_np[i] + src_ns[i]
|
|
1038
|
+
nobs_ct = src_nnp[i] + src_nns[i]
|
|
1039
|
+
if nobs_cc > 0:
|
|
1040
|
+
src_rmsc[i] = math.sqrt(src_rmsc[i] / nobs_cc)
|
|
1041
|
+
else:
|
|
1042
|
+
src_rmsc[i] = -9.0
|
|
1043
|
+
if nobs_ct > 0:
|
|
1044
|
+
src_rmsn[i] = math.sqrt(src_rmsn[i] / nobs_ct)
|
|
1045
|
+
else:
|
|
1046
|
+
src_rmsn[i] = -9.0
|
|
1047
|
+
|
|
1048
|
+
# ---- Write residuals file ----
|
|
1049
|
+
if len(cfg.fn_res) > 1:
|
|
1050
|
+
with open(cfg.fn_res, "w") as fres:
|
|
1051
|
+
for j in range(ndt):
|
|
1052
|
+
sta_name = dt_sta_work[j] if j < len(dt_sta_work) else " "
|
|
1053
|
+
line = (
|
|
1054
|
+
f"{sta_name:7s} "
|
|
1055
|
+
f"{float(dt_dt[j]):12.7f} "
|
|
1056
|
+
f"{int(dt_c1[j]):9d} "
|
|
1057
|
+
f"{int(dt_c2[j]):9d} "
|
|
1058
|
+
f"{int(dt_idx[j]):1d} "
|
|
1059
|
+
f"{float(dt_qual[j]):9.4f} "
|
|
1060
|
+
f"{float(dt_res[j]) * 1000:12.6f} "
|
|
1061
|
+
f"{float(dt_wt[j]):11.6f} "
|
|
1062
|
+
f"{float(dt_offs[j]):8.1f}\n"
|
|
1063
|
+
)
|
|
1064
|
+
fres.write(line)
|
|
1065
|
+
|
|
1066
|
+
# ---- Write final relocated events (hypoDD.reloc) ----
|
|
1067
|
+
sdc_out = SDC(sdc0_lat, sdc0_lon, 0.0)
|
|
1068
|
+
for i in range(nev):
|
|
1069
|
+
xkm, ykm = sdc_out.latlon_to_xy(src_lat[i], src_lon[i])
|
|
1070
|
+
yr = int(ev_date[i]) // 10000
|
|
1071
|
+
mo = (int(ev_date[i]) % 10000) // 100
|
|
1072
|
+
dy = int(ev_date[i]) % 100
|
|
1073
|
+
hr = int(ev_time[i]) // 1000000
|
|
1074
|
+
mn = (int(ev_time[i]) % 1000000) // 10000
|
|
1075
|
+
sc = (float(ev_time[i]) % 10000.0) / 100.0
|
|
1076
|
+
line = (
|
|
1077
|
+
f"{int(src_cusp[i]):9d} "
|
|
1078
|
+
f"{float(src_lat[i]):10.6f} "
|
|
1079
|
+
f"{float(src_lon[i]):11.6f} "
|
|
1080
|
+
f"{float(src_dep[i]):9.3f} "
|
|
1081
|
+
f"{float(xkm) * 1000:10.1f} "
|
|
1082
|
+
f"{float(ykm) * 1000:10.1f} "
|
|
1083
|
+
f"{float(src_z[i]):10.1f} "
|
|
1084
|
+
f"{float(src_ex[i]):8.1f} "
|
|
1085
|
+
f"{float(src_ey[i]):8.1f} "
|
|
1086
|
+
f"{float(src_ez[i]):8.1f} "
|
|
1087
|
+
f"{yr:4d} "
|
|
1088
|
+
f"{mo:2d} "
|
|
1089
|
+
f"{dy:2d} "
|
|
1090
|
+
f"{hr:2d} "
|
|
1091
|
+
f"{mn:2d} "
|
|
1092
|
+
f"{sc:6.3f} "
|
|
1093
|
+
f"{float(ev_mag[i]):5.2f} "
|
|
1094
|
+
f"{int(src_np[i]):5d} "
|
|
1095
|
+
f"{int(src_ns[i]):5d} "
|
|
1096
|
+
f"{int(src_nnp[i]):5d} "
|
|
1097
|
+
f"{int(src_nns[i]):5d} "
|
|
1098
|
+
f"{float(src_rmsc[i]):6.3f} "
|
|
1099
|
+
f"{float(src_rmsn[i]):6.3f} "
|
|
1100
|
+
f"{cl_id:3d}\n"
|
|
1101
|
+
)
|
|
1102
|
+
f_reloc.write(line)
|
|
1103
|
+
|
|
1104
|
+
# ---- Write station output ----
|
|
1105
|
+
if f_stares is not None:
|
|
1106
|
+
# Compute station statistics
|
|
1107
|
+
sta_np_arr = np.zeros(nsta, dtype=np.int32)
|
|
1108
|
+
sta_ns_arr = np.zeros(nsta, dtype=np.int32)
|
|
1109
|
+
sta_nnp_arr = np.zeros(nsta, dtype=np.int32)
|
|
1110
|
+
sta_nns_arr = np.zeros(nsta, dtype=np.int32)
|
|
1111
|
+
sta_rmsc_arr = np.zeros(nsta, dtype=np.float32)
|
|
1112
|
+
sta_rmsn_arr = np.zeros(nsta, dtype=np.float32)
|
|
1113
|
+
|
|
1114
|
+
for j in range(ndt):
|
|
1115
|
+
si = dt_ista[j]
|
|
1116
|
+
if dt_idx[j] <= 2:
|
|
1117
|
+
sta_rmsc_arr[si] += dt_res[j] ** 2
|
|
1118
|
+
if dt_idx[j] == 1:
|
|
1119
|
+
sta_np_arr[si] += 1
|
|
1120
|
+
else:
|
|
1121
|
+
sta_ns_arr[si] += 1
|
|
1122
|
+
else:
|
|
1123
|
+
sta_rmsn_arr[si] += dt_res[j] ** 2
|
|
1124
|
+
if dt_idx[j] == 3:
|
|
1125
|
+
sta_nnp_arr[si] += 1
|
|
1126
|
+
else:
|
|
1127
|
+
sta_nns_arr[si] += 1
|
|
1128
|
+
|
|
1129
|
+
for si in range(nsta):
|
|
1130
|
+
nobs_cc = sta_np_arr[si] + sta_ns_arr[si]
|
|
1131
|
+
nobs_ct = sta_nnp_arr[si] + sta_nns_arr[si]
|
|
1132
|
+
if nobs_cc > 0:
|
|
1133
|
+
sta_rmsc_arr[si] = math.sqrt(sta_rmsc_arr[si] / nobs_cc)
|
|
1134
|
+
if nobs_ct > 0:
|
|
1135
|
+
sta_rmsn_arr[si] = math.sqrt(sta_rmsn_arr[si] / nobs_ct)
|
|
1136
|
+
|
|
1137
|
+
line = (
|
|
1138
|
+
f"{sta_lab[si]:7s} "
|
|
1139
|
+
f"{float(sta_lat[si]):9.4f} "
|
|
1140
|
+
f"{float(sta_lon[si]):9.4f} "
|
|
1141
|
+
f"{0.0:9.4f} " # sta_dist placeholder
|
|
1142
|
+
f"{0.0:9.4f} " # sta_az placeholder
|
|
1143
|
+
f"{int(sta_np_arr[si]):7d} "
|
|
1144
|
+
f"{int(sta_ns_arr[si]):7d} "
|
|
1145
|
+
f"{int(sta_nnp_arr[si]):7d} "
|
|
1146
|
+
f"{int(sta_nns_arr[si]):7d} "
|
|
1147
|
+
f"{float(sta_rmsc_arr[si]):9.4f} "
|
|
1148
|
+
f"{float(sta_rmsn_arr[si]):9.4f} "
|
|
1149
|
+
f"{cl_id:3d}\n"
|
|
1150
|
+
)
|
|
1151
|
+
f_stares.write(line)
|
|
1152
|
+
|
|
1153
|
+
# ---- Close output files ----
|
|
1154
|
+
f_loc.close()
|
|
1155
|
+
f_reloc.close()
|
|
1156
|
+
if f_stares is not None:
|
|
1157
|
+
f_stares.close()
|
|
1158
|
+
|
|
1159
|
+
now_str = datetime.now().strftime("%Y/%m/%d %H:%M:%S")
|
|
1160
|
+
log.info("Program hypodd finished. %s", now_str)
|
|
1161
|
+
|
|
1162
|
+
|
|
1163
|
+
if __name__ == '__main__':
|
|
1164
|
+
if len(sys.argv) != 2:
|
|
1165
|
+
print("Usage: python -m hypodd.hypoDD <inp_file>")
|
|
1166
|
+
sys.exit(1)
|
|
1167
|
+
run_hypoDD(sys.argv[1])
|