-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathconfig.py
executable file
·318 lines (259 loc) · 11.3 KB
/
config.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
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
# coding: utf-8
"""
This module contains a class and methods that help to configure the behavior of DeepPhasePick method.
Author: Hugo Soto Parada (October, 2020)
Contact: [email protected], [email protected]
"""
import obspy.core as oc
from datetime import datetime
import re, sys, os, shutil, gc
class Config():
"""
Class that initiates user configuration for selecting seismic data and defining how this data is processed in DeepPhasePick.
Parameters
----------
dct_data: dict, optional
dictionary with parameters defining archived waveform data on which DeepPhasePick is applied.
See parameters details in method set_data().
dct_data_params: dict, optional
dictionary with parameters defining how seismic waveforms is processed before phase detection.
See parameters details in method set_data_params().
dct_time: dict, optional
dictionary with parameters defining time windows over which DeepPhasePick is applied.
See parameters details in method set_time().
dct_trigger: dict, optional
dictionary with parameters defining how predicted discrete probability time series are computed when running phase detection on seismic waveforms.
See parameters details in method set_trigger().
dct_picking: dict, optional
dictionary with parameters applied in optional conditions for improving preliminary picks obtained from phase detection.
See parameters details in method set_picking().
"""
def __init__(self, dct_data=None, dct_data_params=None, dct_time=None, dct_trigger=None, dct_picking=None):
self.data = self._set_default_data(dct_data)
self.data_params = self._set_default_data_params(dct_data_params)
self.time = self._set_default_time(dct_time)
self.trigger = self._set_default_trigger(dct_trigger)
self.picking = self._set_default_picking(dct_picking)
def _set_default_data(self, dct_data):
"""
Set default parameters defining archived waveform data on which DeepPhasePick is applied.
Returns
-------
dct: dict
dictionary with defined parameters. See parameters details in method set_data().
"""
dct = {
'stas': [],
'ch': 'HH',
'net': '',
'archive': 'archive',
'opath': 'out',
}
if dct_data is not None:
for k in dct:
if k in dct_data:
dct[k] = dct_data[k]
return dct
def _set_default_data_params(self, dct_data_params):
"""
Set default parameters defining how seismic waveforms is processed before phase detection.
Returns
-------
dct: dict
dictionary with defined parameters. See parameters details in method set_data_params().
"""
dct = {
'samp_freq': 100.,
'st_detrend': True,
'st_resample': True,
'st_filter': None,
'filter_opts': {},
}
if dct_data_params is not None:
for k in dct:
if k in dct_data_params:
dct[k] = dct_data_params[k]
return dct
def _set_default_time(self, dct_time):
"""
Set parameters defining time windows over which DeepPhasePick is applied.
Returns
-------
dct: dict
dictionary with defined parameters. See parameters details in method set_time().
"""
dct = {
'dt_iter': 3600.,
'tstart': oc.UTCDateTime(0),
'tend': oc.UTCDateTime(3600),
}
if dct_time is not None:
for k in dct:
if k in dct_time:
if k in ['tstart', 'tend']:
dct[k] = oc.UTCDateTime(dct_time[k])
else:
dct[k] = dct_time[k]
return dct
def _set_default_trigger(self, dct_trigger):
"""
Set default parameters defining how predicted discrete probability time series are computed when running phase detection on seismic waveforms.
Returns
-------
dct: dict
dictionary with defined parameters. See parameters details in method set_trigger().
"""
dct = {
'n_shift': 10, 'pthres_p': [0.9, .001], 'pthres_s': [0.9, .001], 'max_trig_len': [9e99, 9e99],
}
if dct_trigger is not None:
for k in dct:
if k in dct_trigger:
dct[k] = dct_trigger[k]
return dct
def _set_default_picking(self, dct_picking):
"""
Set default parameters applied in optional conditions for improving preliminary picks obtained from phase detection.
Returns
-------
dct: dict
dictionary with defined parameters. See parameters details in method set_trigger().
"""
dct = {
'op_conds': ['1', '2', '3', '4'],
'tp_th_add': 1.5,
'dt_sp_near': 2.,
'dt_ps_max': 35.,
'dt_sdup_max': 2.,
#
'run_mcd': True,
'mcd_iter': 10,
}
if dct_picking is not None:
for k in dct:
if k in dct_picking:
dct[k] = dct_picking[k]
return dct
def set_data(self, stas, ch, net, archive, opath='out'):
"""
Set parameters defining archived waveform data on which DeepPhasePick is applied.
Parameters
----------
stas: list of str
stations from which waveform data are used.
ch: str
channel code of selected waveforms.
net: str
network code of selected stations.
archive: str
path to the structured or unstructured archive where waveforms are read from.
opath: str, optional
output path where results are stored.
"""
self.data = {
'stas': stas,
'ch': ch,
'net': net,
'archive': archive,
'opath': opath,
}
def set_data_params(self, samp_freq=100., st_detrend=True, st_resample=True, st_filter=None, filter_opts={}):
"""
Set parameters defining how seismic waveforms is processed before phase detection.
Parameters
----------
samp_freq: float, optional
sampling rate [Hz] at which the seismic waveforms will be resampled.
st_detrend: bool, optional
If True, detrend (linear) waveforms on which phase detection is performed.
st_resample: bool, optional
If True, resample waveforms on which phase detection is performed at samp_freq.
st_filter: str, optional
type of filter applied to waveforms on which phase detection is performed. If None, no filter is applied.
See obspy.core.stream.Stream.filter.
filter_opts: dict, optional
Necessary keyword arguments for the respective filter that will be passed on. (e.g. freqmin=1.0, freqmax=20.0 for filter_type="bandpass")
See obspy.core.stream.Stream.filter.
"""
self.data_params = {
'samp_freq': samp_freq,
'st_detrend': st_detrend,
'st_resample': st_resample,
'st_filter': st_filter,
'filter_opts': filter_opts,
}
def set_time(self, dt_iter, tstart, tend):
"""
Set parameters defining time windows over which DeepPhasePick are applied.
Parameters
----------
dt_iter: float
time step (in seconds) between consecutive time windows.
tstarts: str
start time to define time windows, in format "YYYY-MM-DDTHH:MM:SS".
tends: str
end time to define time windows, in format "YYYY-MM-DDTHH:MM:SS".
"""
self.time = {
'dt_iter': dt_iter,
'tstart': oc.UTCDateTime(tstart),
'tend': oc.UTCDateTime(tend),
}
def set_trigger(self, n_shift=10, pthres_p=[0.9,.001], pthres_s=[0.9,.001], max_trig_len=[9e99, 9e99]):
"""
Set parameters defining how predicted discrete probability time series are computed when running phase detection on seismic waveforms
Parameters
----------
n_shift: int, optional
step size (in samples) defining discrete probability time series.
pthres_p: list of float, optional
probability thresholds defining P-phase trigger on (pthres_p[0]) and off (pthres_p[1]) times.
See thres1 and thres2 parameters in obspy trigger_onset function.
pthres_s: list of float, optional
probability thresholds defining S-phase trigger on (pthres_s[0]) and off (pthres_s[1]) times.
See thres1 and thres2 parameters in function obspy.signal.trigger.trigger_onset.
max_trig_len: list of int, optional
maximum lengths (in samples) of triggered P (max_trig_len[0]) and S (max_trig_len[1]) phase.
See max_len parameter in function obspy.signal.trigger.trigger_onset.
"""
self.trigger = {
'n_shift': n_shift,
'pthres_p': pthres_p,
'pthres_s': pthres_s,
'max_trig_len': max_trig_len,
}
def set_picking(self, op_conds=['1','2','3','4'], tp_th_add=1.5, dt_sp_near=2., dt_ps_max=35., dt_sdup_max=2., run_mcd=True, mcd_iter=10):
"""
Set parameters applied in optional conditions for refining preliminary picks obtained from phase detection.
Parameters
----------
op_conds: list of str, optional
optional conditions that are applied on preliminary picks, in order to keep keep/remove presumed true/false preliminary onsets.
These conditions are explained in Supplementary Information of the original publication (https://doi.org/10.31223/X5BC8B).
For example ['1', '2'] indicates that only conditions (1) and (2) are applied.
'1': resolves between P and S phases predicted close in time, with overlapping probability time series
'2': resolves between P and S phases predicted close in time, with no overlapping probability distributions.
'3': discards S picks for which there is no earlier P or P-S predicted picks.
'4': resolves between possible duplicated S phases.
tp_th_add: float, optional
time (in seconds) added to define search time intervals in condition (1).
dt_sp_near: float, optional
time threshold (in seconds) used in condition (2).
dt_ps_max: float, optional
time (in seconds) used to define search time intervals in condition (3).
dt_sdup_max: float, optional
time threshold (in seconds) used in condition (4).
run_mcd: bool, optional
If True, run phase picking in order to refine preliminary picks from phase detection.
mcd_iter: int, optional
number of Monte Carlo Dropout iterations used in phase picking.
"""
self.picking = {
'op_conds': op_conds,
'tp_th_add': tp_th_add,
'dt_sp_near': dt_sp_near,
'dt_ps_max': dt_ps_max,
'dt_sdup_max': dt_sdup_max,
'run_mcd': run_mcd,
'mcd_iter': mcd_iter,
}