From ffed36749c0b4ab964502433eb482e71a0fdf682 Mon Sep 17 00:00:00 2001
From: pcain-usgs <pcain@usgs.gov>
Date: Tue, 12 May 2020 14:18:13 -0600
Subject: [PATCH] Add controller arguments, change interval to period, and
 reformat interval method

---
 geomagio/algorithm/DbDtAlgorithm.py | 33 +++++++++++----
 geomagio/algorithm/DbDtAlgoritm.py  | 64 -----------------------------
 2 files changed, 25 insertions(+), 72 deletions(-)
 delete mode 100644 geomagio/algorithm/DbDtAlgoritm.py

diff --git a/geomagio/algorithm/DbDtAlgorithm.py b/geomagio/algorithm/DbDtAlgorithm.py
index 8c1abaaa2..dd4caa06e 100644
--- a/geomagio/algorithm/DbDtAlgorithm.py
+++ b/geomagio/algorithm/DbDtAlgorithm.py
@@ -1,19 +1,23 @@
 from .Algorithm import Algorithm
-from ..TimeseriesUtility import create_empty_trace, get_interval_from_delta
+from ..TimeseriesUtility import (
+    create_empty_trace,
+    get_interval_from_delta,
+    get_delta_from_interval,
+)
 
 import numpy as np
 from obspy.core import Stream, Stats
 
 
 class DbDtAlgorithm(Algorithm):
-    def __init__(self, inchannels=None, outchannels=None, interval=None):
+    def __init__(self, inchannels=None, outchannels=None, period=None):
         """
         Derivative algorithm that takes derivative of timeseries using second order central differences(numpy.gradient)
         """
         Algorithm.__init__(self, inchannels=None, outchannels=None)
         self.inchannels = inchannels
         self.outchannels = outchannels
-        self.interval = interval
+        self.period = period
 
     def process(self, stream):
         """
@@ -32,9 +36,9 @@ class DbDtAlgorithm(Algorithm):
         for trace in stream:
             dbdt = np.diff(trace.data)
             stats = Stats(trace.stats)
-            stats.channel = "{}__DDT".format(stats.channel)
+            stats.channel = "{}_DDT".format(stats.channel)
             trace_out = create_empty_trace(
-                starttime=stats.starttime + self.interval,
+                starttime=stats.starttime + self.period,
                 endtime=stats.endtime,
                 observatory=stats.station,
                 type=stats.location,
@@ -48,17 +52,30 @@ class DbDtAlgorithm(Algorithm):
             out += trace_out
         return out
 
-    def get_interval(self, start):
+    def get_input_interval(self, start, end, observatory=None, channels=None):
         """
         Adjust time interval for input data.
         Parameters
         ----------
+        start : obspy.core.UTCDatetime
+            input starttime
         end : obspy.core.UTCDatetime
             input endtime
         Returns
         -------
+        start : obspy.core.UTCDatetime
+            output starttime
         end : obspy.core.UTCDatetime
             output endtime
         """
-        start -= self.interval
-        return start
+        start -= self.period
+        return (start, end)
+
+    def configure(self, arguments):
+        """Configure algorithm using comand line arguments.
+        Parameters
+        ----------
+        arguments: Namespace
+            parsed command line arguments
+        """
+        self.period = get_delta_from_interval(arguments.interval)
diff --git a/geomagio/algorithm/DbDtAlgoritm.py b/geomagio/algorithm/DbDtAlgoritm.py
deleted file mode 100644
index b2c1bf638..000000000
--- a/geomagio/algorithm/DbDtAlgoritm.py
+++ /dev/null
@@ -1,64 +0,0 @@
-from .Algorithm import Algorithm
-from ..TimeseriesUtility import create_empty_trace, get_interval_from_delta
-
-import numpy as np
-from obspy.core import Stream, Stats
-
-
-class DbDtAlgorithm(Algorithm):
-    def __init__(self, inchannels=None, outchannels=None, interval=None):
-        """
-        Derivative algorithm that takes derivative of timeseries using second order central differences(numpy.gradient)
-        """
-        Algorithm.__init__(self, inchannels=None, outchannels=None)
-        self.inchannels = inchannels
-        self.outchannels = outchannels
-        self.interval = interval
-
-    def process(self, stream):
-        """
-        Run algorithm for a stream.
-        Processes all traces in the stream.
-        Parameters
-        ----------
-        stream : obspy.core.Stream
-            stream of data to process
-        Returns
-        -------
-        out : obspy.core.Stream
-            stream containing 1 trace per original trace.
-        """
-        out = Stream()
-        for trace in stream:
-            dbdt = np.diff(trace.data)
-            stats = Stats(trace.stats)
-            stats.channel = "{}__DDT".format(stats.channel)
-            trace_out = create_empty_trace(
-                starttime=stats.starttime,
-                endtime=stats.endtime,
-                observatory=stats.station,
-                type=stats.location,
-                interval=get_interval_from_delta(stats.delta),
-                channel=stats.channel,
-                network=stats.network,
-                station=stats.station,
-                location=stats.location,
-            )
-            trace_out.data = dbdt
-            out += trace_out
-        return out
-
-    def get_interval(self, end):
-        """
-        Adjust time interval for input data.
-        Parameters
-        ----------
-        end : obspy.core.UTCDatetime
-            input endtime
-        Returns
-        -------
-        end : obspy.core.UTCDatetime
-            output endtime
-        """
-        end += self.interval
-        return end
-- 
GitLab