Skip to content
Snippets Groups Projects
Commit c5913ca7 authored by Jeremy M Fee's avatar Jeremy M Fee
Browse files

Update Algorithm and FilterAlgorithm can_produce_data to use utility methods

parent 62a163fd
No related branches found
No related tags found
No related merge requests found
......@@ -88,7 +88,9 @@ class Algorithm(object):
return (start, end)
def can_produce_data(self, starttime, endtime, stream):
"""Can Product data
"""Can Produce data
By default require all channels to have data at the same time.
Parameters
----------
......@@ -99,17 +101,11 @@ class Algorithm(object):
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=stream,
channels=self.get_required_channels()))
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
return TimeseriesUtility.has_all_channels(
stream,
self.get_required_channels(),
starttime,
endtime)
def get_next_starttime(self):
"""Check whether algorithm has a stateful start time.
......
......@@ -5,8 +5,7 @@ import scipy.signal as sps
from numpy.lib import stride_tricks as npls
from obspy.core import Stream, Stats
import json
from ..TimeseriesUtility import get_delta_from_interval
from .. import TimeseriesUtility
STEPS = [
{ # 10 Hz to one second filter
......@@ -101,6 +100,26 @@ class FilterAlgorithm(Algorithm):
steps.append(step)
return steps
def can_produce_data(self, starttime, endtime, stream):
"""Can Produce data
The FilterAlgorithm can produce data for each channel independently.
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 create_trace(self, channel, stats, data):
"""Utility to create a new trace object.
This may be necessary for more sophisticated metadata
......@@ -282,8 +301,8 @@ class FilterAlgorithm(Algorithm):
Algorithm.configure(self, arguments)
# intialize filter with command line arguments
self.coeff_filename = arguments.filter_coefficients
input_interval = arguments.input_interval
output_interval = arguments.output_interval
self.input_sample_period = get_delta_from_interval(input_interval)
self.output_sample_period = get_delta_from_interval(output_interval)
self.input_sample_period = TimeseriesUtility.get_delta_from_interval(
arguments.input_interval or arguments.interval)
self.output_sample_period = TimeseriesUtility.get_delta_from_interval(
arguments.output_interval or arguments.interval)
self.load_state()
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment