Skip to content
Snippets Groups Projects
Algorithm.py 2.35 KiB
Newer Older
  • Learn to ignore specific revisions
  • """Algorithm Interface."""
    
        """Base class for geomag algorithms
    
        Parameters
        ----------
        channels: array_like
            the list of channels to be processed.
    
        Notes
        -----
        An algorithm processes a stream of timeseries to produce new timeseries.
    
    Hal Simpson's avatar
    Hal Simpson committed
        def __init__(self, inchannels=None, outchannels=None):
            self._inchannels = inchannels
            self._outchannels = outchannels
    
            """Process a stream of data.
    
    
            Parameters
            ----------
            stream : obspy.core.Stream
                input data
    
            Returns
            -------
            obspy.core.Stream
                resulting data
            """
            return stream.copy()
    
            """Get input channels
    
            Returns
            -------
            array_like
                list of channels the algorithm needs to operate.
            """
    
    Hal Simpson's avatar
    Hal Simpson committed
            return self._inchannels
    
            """Get output channels
    
            Returns
            -------
            array_like
                list of channels the algorithm will be returning.
            """
    
    Hal Simpson's avatar
    Hal Simpson committed
            return self._outchannels
    
        def get_input_interval(self, start, end):
    
    Hal Simpson's avatar
    Hal Simpson committed
            """Get Input Interval
    
    
            start : UTCDateTime
                start time of requested output
            end : UTCDateTime
                end time of requested output
    
    
    Hal Simpson's avatar
    Hal Simpson committed
            Returns
            -------
    
            tuple : (input_start, input_end)
                start and end of required input to generate requested output.
    
    Hal Simpson's avatar
    Hal Simpson committed
            """
    
            return (start, end)
    
    
        def can_produce_data(self, starttime, endtime, stream):
            """Can Product data
    
            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
            """
            input_gaps = TimeseriesUtility.get_merged_gaps(
                    TimeseriesUtility.get_stream_gaps(stream))
            for input_gap in input_gaps:
                # Check for gaps that include the entire range
                if (starttime >= input_gap[0] and
                        starttime <= input_gap[1] and
                        endtime < input_gap[2]):
                    return False
            return True