Skip to content

Commit 3f67952

Browse files
authored
Merge pull request #73 from megies/time_dependent_station_combos
add possibility to specify complex, time-dependent station combinations
2 parents b8af03c + 70ac946 commit 3f67952

File tree

2 files changed

+74
-1
lines changed

2 files changed

+74
-1
lines changed

obspyck/example.cfg

+25
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,31 @@ S = blue
5757
[station_combinations]
5858
EXAMPLE1 = II.PFO.00.LH?,GE.APE..LH?,GE.PSZ..LH?,CI.BBR..LH*,IV.PRMA..LH?,G.RER..LH*
5959
EXAMPLE2 = 7A.W01..LH?,CI.BBR..LH*
60+
# for complex, time-dependent station combinations use an exclamation mark
61+
# followed by a corresponding section title where the station combination is
62+
# defined
63+
EXAMPLE3 = !station_combination_BW
64+
65+
[station_combination_BW]
66+
# this is an example section for a complex, time-dependent station combination.
67+
# this can be useful e.g. in case of instrumentation changes that go along with
68+
# a change in channel naming or when stations get added or removed in the
69+
# field. each entry consists of a stream identifier as the key and zero, one or
70+
# two timestamps to denote for which times the stream should be fetched.
71+
# All times interpreted as UTC.
72+
#
73+
# if value is empty, always fetch stream, regardless of requested time
74+
GR.FUR..HH? =
75+
# otherwise, value can be..
76+
# - two timestamps separated by a comma, to fetch stream only for times in
77+
# between these two timestamps
78+
BW.RTBE..HH? = 2017-07-01,2017-10-01
79+
# - a timestamp preceded by a "larger than" sign, to fetch stream only for times after the
80+
# given timestamp (including it, so this is actually evaluated as >=)
81+
BW.RMOA..HH? = >2017-07-04T15:00:00
82+
# - a comma followed by a timestamp, to fetch stream only for times before the
83+
# given timestamp (including it, so this is actually evaluated as <=)
84+
BW.RMOA..EH? = <2017-07-04T11:40:00
6085

6186
[seed_id_lookup]
6287
# wildcards ("?", "*") and regex (e.g. "[EH]*") are only allowed in channel!

obspyck/util.py

+49-1
Original file line numberDiff line numberDiff line change
@@ -233,6 +233,47 @@ def check_keybinding_conflicts(keys):
233233
raise Exception(err)
234234

235235

236+
def resolve_complex_station_combination(config, section_title, time):
237+
"""
238+
Resolve complex time-dependent station combination from config file
239+
"""
240+
seed_ids = set()
241+
for key, value in config.items(section_title):
242+
# no value: always use that stream
243+
if not value:
244+
seed_ids.add(key)
245+
# two comma separated time stamps: only use stream if requested time is
246+
# in between given timestamps
247+
elif ',' in value:
248+
start, end = map(UTCDateTime, value.split(','))
249+
if end < start:
250+
msg = ("Invalid configuration in section [{}], stream '{}'. "
251+
"End time larger than start time for used time "
252+
"span.").format(section_title, key)
253+
raise ValueError(msg)
254+
if start <= time <= end:
255+
seed_ids.add(key)
256+
# timestamp preceded by smaller-than sign: only use stream if requested
257+
# time is smaller than specified timestamp
258+
elif value[0] == '<':
259+
end = UTCDateTime(value[1:])
260+
if time <= end:
261+
seed_ids.add(key)
262+
# timestamp preceded by larger-than sign: only use stream if requested
263+
# time is after the specified timestamp
264+
elif value[0] == '>':
265+
start = UTCDateTime(value[1:])
266+
if time >= start:
267+
seed_ids.add(key)
268+
else:
269+
msg = ("Invalid configuration in section [{}], stream '{}'. "
270+
"Value can be empty, two comma-separated time stamps or "
271+
"one timestamp preceded by either '>' or '<'.").format(
272+
section_title, key)
273+
raise ValueError(msg)
274+
return seed_ids
275+
276+
236277
def fetch_waveforms_with_metadata(options, args, config):
237278
"""
238279
Sets up obspy clients and fetches waveforms and metadata according to
@@ -269,7 +310,14 @@ def fetch_waveforms_with_metadata(options, args, config):
269310
seed_ids_to_fetch = set()
270311
for station_combination_key in options.station_combinations:
271312
seed_ids = config.get("station_combinations", station_combination_key)
272-
for seed_id in seed_ids.split(","):
313+
# starts with an exclamation mark: lookup seed ids from that section
314+
if seed_ids[0] == '!':
315+
seed_ids = resolve_complex_station_combination(
316+
config, seed_ids[1:], t1)
317+
# otherwise a list of comma-separated stream labels
318+
else:
319+
seed_ids = seed_ids.split(",")
320+
for seed_id in seed_ids:
273321
seed_ids_to_fetch.add(seed_id)
274322
for seed_id in options.seed_ids:
275323
seed_ids_to_fetch.add(seed_id)

0 commit comments

Comments
 (0)