From b8523fc46c270d752ffd49150c738843563b2ace Mon Sep 17 00:00:00 2001
From: "E. Joshua Rigler" <erigler@usgs.gov>
Date: Fri, 18 Nov 2022 15:57:19 -0700
Subject: [PATCH 1/2] Make AverageAlgorithm require **any** inputs

Recent attempts to change the AverageAlgorithm to allow fewer than the full
complement of inputs when calculating a mutli-station average were thwarted
by the default can_produce_data() method in the parent Algorithm class, which
required all inputs to be present, when what we now want is **any** inputs to
be present.
---
 geomagio/algorithm/AverageAlgorithm.py | 19 +++++++++++++++++++
 1 file changed, 19 insertions(+)

diff --git a/geomagio/algorithm/AverageAlgorithm.py b/geomagio/algorithm/AverageAlgorithm.py
index 692ff5c8..fe970d63 100644
--- a/geomagio/algorithm/AverageAlgorithm.py
+++ b/geomagio/algorithm/AverageAlgorithm.py
@@ -6,6 +6,7 @@ from __future__ import absolute_import
 from .Algorithm import Algorithm
 from .AlgorithmException import AlgorithmException
 from ..ObservatoryMetadata import ObservatoryMetadata
+from .. import TimeseriesUtility
 import numpy
 import obspy.core
 
@@ -65,6 +66,24 @@ class AverageAlgorithm(Algorithm):
         self.min_count_end = min_count_end
         self.observatoryMetadata = ObservatoryMetadata()
 
+    def can_produce_data(self, starttime, endtime, stream):
+        """Can Produce data
+
+        By default require all channels to have data at the same time.
+
+        Parameters
+        ----------
+        starttime: UTCDateTime
+            start time of requested output
+        end : UTCDateTime
+            end time of requested output
+        stream: obspy.core.Stream
+            The input stream we want to make certain has data for the algorithm
+        """
+        return TimeseriesUtility.has_any_channels(
+            stream, self.get_required_channels(), starttime, endtime
+        )
+
     def check_stream(self, timeseries):
         """checks a stream to make certain the required data
             exists.
-- 
GitLab


From c24e2e9c0bb98180c9d11214b5312b614d9fe69f Mon Sep 17 00:00:00 2001
From: "E. Joshua Rigler" <erigler@usgs.gov>
Date: Fri, 18 Nov 2022 17:24:18 -0700
Subject: [PATCH 2/2] Check for gaps in multi-observatory Stream

The method TimeseriesUtility.get_stream_gaps() would over-write gaps[channel] if
there were multiple Traces in a stream that were the same channel, but different
observatories. This is a typical situation when using the AverageAlgorithm.
---
 geomagio/TimeseriesUtility.py | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/geomagio/TimeseriesUtility.py b/geomagio/TimeseriesUtility.py
index 35716142..2797b938 100644
--- a/geomagio/TimeseriesUtility.py
+++ b/geomagio/TimeseriesUtility.py
@@ -205,7 +205,10 @@ def get_stream_gaps(stream, channels=None):
         channel = trace.stats.channel
         if channels is not None and channel not in channels:
             continue
-        gaps[channel] = get_trace_gaps(trace)
+        if channel in gaps:
+            gaps[channel].extend(get_trace_gaps(trace))
+        else:
+            gaps[channel] = get_trace_gaps(trace)
     return gaps
 
 
-- 
GitLab