From 02aa2586fea67b468e9b30cbe96c3e47bf51f124 Mon Sep 17 00:00:00 2001 From: Marcus Herrmann <marcus.herrmann@sed.ethz.ch> Date: Mon, 10 Oct 2016 20:29:53 +0200 Subject: [PATCH] Improve trimming of stream during gappy days --- TM/io.py | 24 ++++++++++++++---------- 1 file changed, 14 insertions(+), 10 deletions(-) diff --git a/TM/io.py b/TM/io.py index a257812..2d25e44 100644 --- a/TM/io.py +++ b/TM/io.py @@ -839,27 +839,31 @@ def get_ready_chunk(chunkTime, chunkLength): chunkStream += get_waveform( config.network, config.station, channel, chunkTime, chunkLength) - # Get the start/end-times of all traces - starttime_common = [x.stats.starttime for x in chunkStream] - endtime_common = [x.stats.endtime for x in chunkStream] - if min(endtime_common) <= max(starttime_common): + # Determine starts & /ends of all traces + starts = [x.stats.starttime for x in chunkStream] + ends = [x.stats.endtime for x in chunkStream] + if min(ends) <= max(starts): raise Exception("No common data among the traces. Skip it.") + except Exception: raise # To pass the exception to the calling function else: pass - # Cut the stream to the common start/end - chunkStream.trim(max(starttime_common), min(endtime_common)) - # Cut the stream to the max start/end among all traces, rest to 0 (get most out of it) -# dailyStream.trim(min(starttime_common), max(endtime_common), pad=True, fill_value=0) - # TODO: if gaps present, do this for each chunk to ensure same total lengths - # will need to separate_masked_trace(), but it's difficult for three traces + # Trim the stream to the max start/end among all traces + chunkStream.trim(max(starts), min(ends)) +# # Trim rest to 0 (get most out of it) +# dailyStream.trim(min(starts), max(ends), pad=True, fill_value=0) # Create a bandpassed stream (perhaps resampled) # (not necessarily parallel) chunkStream_BP = waveform_processing_parallel(chunkStream, 'bandpass') # (keeps original) + # Trim again (since some short data chunks may have been removed) + starts = [x.stats.starttime for x in chunkStream_BP] + ends = [x.stats.endtime for x in chunkStream_BP] + chunkStream_BP.trim(max(starts), min(ends)) + for idx, tr in enumerate(chunkStream_BP): # Check if there are "unnecessary" masks == all mask entries are False # This might happen when a former gappy trace was trimmed and now -- GitLab