Skip to content

Commit 33bf00c

Browse files
committed
Added More Station-selection Options
* Stations can now be selected using a bounding box as well
1 parent fb1a6f4 commit 33bf00c

File tree

1 file changed

+31
-5
lines changed

1 file changed

+31
-5
lines changed

seismic/extract_event_traces.py

Lines changed: 31 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ def asdf_get_waveforms(ds:FederatedASDFDataSet, network, station, location, chan
7171
return st
7272
# end func
7373

74-
def trim_inventory(inventory, network_list, station_list):
74+
def trim_inventory(inventory, network_list, station_list, bb_bottom_left, bb_top_right):
7575
"""
7676
Function to trim inventory with a given list of networks and stations.
7777
Note that duplicate station-names across different networks are not
@@ -80,6 +80,8 @@ def trim_inventory(inventory, network_list, station_list):
8080
:param inventory: obspy inventory
8181
:param network_list: a space-separated list of networks
8282
:param stations_list: a space-separated list of stations
83+
:param bb_bottom_left: bounding-box coordinates
84+
:param bb_top_right: bounding box coordinates
8385
"""
8486

8587
if(network_list=='*'):
@@ -112,6 +114,15 @@ def trim_inventory(inventory, network_list, station_list):
112114
inventory = subset_inv
113115
# end if
114116

117+
# clip with bounding box
118+
if(bb_bottom_left is not None and bb_top_right is not None):
119+
subset_inv = inventory.select(minlongitude=bb_bottom_left[0],
120+
minlatitude=bb_bottom_left[1],
121+
maxlongitude=bb_top_right[0],
122+
maxlatitude=bb_top_right[1])
123+
inventory = subset_inv
124+
# end if
125+
115126
return inventory
116127
#end func
117128

@@ -387,14 +398,21 @@ def extract_data(recording_timespan_getter, waveform_getter,
387398
# end func
388399

389400
# ---+----------Main---------------------------------
390-
CONTEXT_SETTINGS = dict(help_option_names=['-h', '--help'], show_default=True)
401+
CONTEXT_SETTINGS = dict(help_option_names=['-h', '--help'], show_default=True,
402+
ignore_unknown_options=True)
391403
@click.command()
392404
@click.argument('data-source',
393405
type=click.Path(exists=True))
394406
@click.option('--network-list', default='*', help='A space-separated list of networks (within quotes) to process.', type=str,
395407
show_default=True)
396408
@click.option('--station-list', default='*', help='A space-separated list of stations (within quotes) to process.', type=str,
397409
show_default=True)
410+
@click.option('--bb-bottom-left', type=(float, float), default=(None, None),
411+
help='Bounding box coordinates (lon lat) of bottom left corner to restrict station selection to.',
412+
show_default=True)
413+
@click.option('--bb-top-right', type=(float, float), default=(None, None),
414+
help='Bounding box coordinates (lon lat) of of top right corner to restrict station selection to.',
415+
show_default=True)
398416
@click.option('--gcmt-catalog-file', type=click.Path(dir_okay=False), required=True,
399417
help='Path to gcmt catalog file. ')
400418
@click.option('--output-file', type=click.Path(dir_okay=False, writable=True), required=True,
@@ -448,7 +466,9 @@ def extract_data(recording_timespan_getter, waveform_getter,
448466
'such as ak135, are documented here: https://docs.obspy.org/packages/obspy.taup.html')
449467
@click.option('--dry-run', is_flag=True, default=False, show_default=True,
450468
help='Reports events available to each station, by wave-type and exits without outputting any data. ')
451-
def main(data_source, network_list, station_list, gcmt_catalog_file, output_file, log_folder,
469+
def main(data_source, network_list, station_list,
470+
bb_bottom_left, bb_top_right,
471+
gcmt_catalog_file, output_file, log_folder,
452472
start_time, end_time,
453473
p_data, s_data, sw_data,
454474
p_magnitude_range, s_magnitude_range, sw_magnitude_range,
@@ -467,7 +487,12 @@ def main(data_source, network_list, station_list, gcmt_catalog_file, output_file
467487
output_fn_base = os.path.splitext(os.path.basename(output_file))[0]
468488
log = setup_logger('__func__', os.path.join(log_folder, output_fn_base + '.log'))
469489

470-
# sanity check
490+
# sanity checks
491+
if(len([None for item in (bb_bottom_left, bb_top_right) if None in item]) == 1):
492+
raise(RuntimeError('Both --bb-bottom-left and --bb-top-right must be specified for '
493+
'restricting stations to a bounding box'))
494+
# end if
495+
471496
owave_types = defaultdict(bool)
472497
if(not(p_data or s_data or sw_data)):
473498
assert 0, 'At least one from [--p-data, --s-data, --sw-data] must be specified. Aborting'
@@ -530,7 +555,8 @@ def main(data_source, network_list, station_list, gcmt_catalog_file, output_file
530555
inventory = fds.get_inventory()
531556

532557
log.info('Trimming inventory...')
533-
inventory = trim_inventory(inventory, network_list=network_list, station_list=station_list)
558+
inventory = trim_inventory(inventory, network_list=network_list, station_list=station_list,
559+
bb_bottom_left=bb_bottom_left, bb_top_right=bb_top_right)
534560
netsta_df = DataFrame(columns=['net.sta', 'lon', 'lat'])
535561
netsta_count = 0
536562
for net in inventory.networks:

0 commit comments

Comments
 (0)