@@ -233,6 +233,47 @@ def check_keybinding_conflicts(keys):
233
233
raise Exception (err )
234
234
235
235
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
+
236
277
def fetch_waveforms_with_metadata (options , args , config ):
237
278
"""
238
279
Sets up obspy clients and fetches waveforms and metadata according to
@@ -269,7 +310,14 @@ def fetch_waveforms_with_metadata(options, args, config):
269
310
seed_ids_to_fetch = set ()
270
311
for station_combination_key in options .station_combinations :
271
312
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 :
273
321
seed_ids_to_fetch .add (seed_id )
274
322
for seed_id in options .seed_ids :
275
323
seed_ids_to_fetch .add (seed_id )
0 commit comments