From 195c42401514f14b279dbd4873cd32b19a195ee7 Mon Sep 17 00:00:00 2001 From: "E. Joshua Rigler" <erigler@usgs.gov> Date: Wed, 7 Dec 2022 19:42:54 -0700 Subject: [PATCH] Fix has_any_channels method The has_any_channels method in TimeseriesUtility.py did not properly handle streams with multiple traces with the same channel, but different stations (or networks, or locations). It should work now. --- geomagio/TimeseriesUtility.py | 25 ++++++++++++++----------- 1 file changed, 14 insertions(+), 11 deletions(-) diff --git a/geomagio/TimeseriesUtility.py b/geomagio/TimeseriesUtility.py index 2797b938..c54d7498 100644 --- a/geomagio/TimeseriesUtility.py +++ b/geomagio/TimeseriesUtility.py @@ -388,17 +388,20 @@ def has_any_channels(stream, channels, starttime, endtime): bool: True if any data found between starttime/endtime """ # process if any channels have data not covering the time range - input_gaps = get_stream_gaps(stream=stream, channels=channels) - for channel in channels: - if channel not in input_gaps: - continue - channel_gaps = input_gaps[channel] - if len(channel_gaps) == 0: - # no gaps in channel - return True - for gap in channel_gaps: - if not (starttime >= gap[0] and starttime <= gap[1] and endtime < gap[2]): - # gap doesn't span channel + for trace in stream: + if trace.stats.channel in channels: + gaps = get_trace_gaps(trace) + if len(gaps) == 0: + # no gaps in trace; + # "any" critierion achieved for stream + return True + nodata = [ + (starttime >= gap[0] and starttime <= gap[1] and endtime < gap[2]) + for gap in gaps + ] + if not any(nodata): + # no gaps in trace span interval; + # "any" criterion achieved for stream return True # didn't find any data return False -- GitLab