Skip to content

Commit 3836d34

Browse files
committed
Add --traceid option to plot_pair subparser
1 parent 69e52be commit 3836d34

File tree

3 files changed

+26
-12
lines changed

3 files changed

+26
-12
lines changed

requake/config/parse_arguments.py

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -183,10 +183,19 @@ def parse_arguments(progname='requake'):
183183
type=float, default=None,
184184
help='maximum cross-correlation coefficient (default: %(default)s)'
185185
)
186+
# --- traceid
187+
# a parent parser for the "traceid" option,
188+
# used by several subparsers
189+
traceid = argparse.ArgumentParser(add_help=False)
190+
traceid.add_argument(
191+
'-t', '--traceid', type=str, default=None,
192+
help='use this traceid instead of the one set in the config file'
193+
)
186194
# ---
187195
# --- plot_pair
188196
plot_pair = subparser.add_parser(
189197
'plot_pair',
198+
parents=[traceid],
190199
help='plot traces for a given event pair'
191200
)
192201
plot_pair.add_argument('evid1')
@@ -286,14 +295,6 @@ def parse_arguments(progname='requake'):
286295
'expressed in years. Also note that this option is ignored if '
287296
'the -c/--colorby option is set to "family_number".'
288297
)
289-
# --- traceid
290-
# a parent parser for the "traceid" option,
291-
# used by several subparsers
292-
traceid = argparse.ArgumentParser(add_help=False)
293-
traceid.add_argument(
294-
'-t', '--traceid', type=str, default=None,
295-
help='use this traceid instead of the default one for the family'
296-
)
297298
# ---
298299
# --- print_families
299300
subparser.add_parser(

requake/waveforms/station_metadata.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -233,7 +233,7 @@ def _fetch_coordinates(net, sta, loc, chan, orig_time):
233233

234234
def get_traceid_coords(orig_time=None):
235235
"""
236-
Get coordinates for the trace_ids specified in config file.
236+
Get coordinates for the trace_ids specified in config file or from args.
237237
238238
:param orig_time: origin time
239239
:type orig_time: obspy.UTCDateTime
@@ -247,7 +247,10 @@ def get_traceid_coords(orig_time=None):
247247
if config.inventory is None:
248248
_download_metadata()
249249
traceid_coords = {}
250-
for trace_id in config.catalog_trace_id:
250+
traceid_list = config.catalog_trace_id
251+
if config.args.traceid is not None:
252+
traceid_list.append(config.args.traceid)
253+
for trace_id in traceid_list:
251254
net, sta, loc, chan = trace_id.split('.')
252255
net = net or '@@'
253256
coords = _fetch_coordinates(net, sta, loc, chan, orig_time)

requake/waveforms/waveforms.py

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -242,8 +242,10 @@ def get_event_waveform(ev):
242242
orig_time = ev.orig_time
243243
mag = ev.mag
244244
mag_type = ev.mag_type
245-
traceid = ev.trace_id if config.args.traceid is None\
245+
traceid = (
246+
ev.trace_id if config.args.traceid is None
246247
else config.args.traceid
248+
)
247249
try:
248250
traceid_coords = get_traceid_coords(orig_time)
249251
except MetadataMismatchError as err:
@@ -254,7 +256,15 @@ def get_event_waveform(ev):
254256
'Skipping event.\n'
255257
f'Error message: {msg}'
256258
) from err
257-
coords = traceid_coords[traceid]
259+
try:
260+
coords = traceid_coords[traceid]
261+
except KeyError as err:
262+
msg = str(err).replace('\n', ' ')
263+
raise NoWaveformError(
264+
f'No metadata for trace_id {traceid} '
265+
'in the metadata file. Skipping event.\n'
266+
f'Error message: {msg}'
267+
) from err
258268
trace_lat = coords['latitude']
259269
trace_lon = coords['longitude']
260270
try:

0 commit comments

Comments
 (0)