Skip to content
Snippets Groups Projects
Commit 46b5cb9a authored by Cain, Payton David's avatar Cain, Payton David
Browse files

Refactor _validate_step

parent 626229a2
No related branches found
No related tags found
2 merge requests!146Release CMO metadata to production,!17Implement hourly/daily filtering products
...@@ -114,7 +114,8 @@ class FilterAlgorithm(Algorithm): ...@@ -114,7 +114,8 @@ class FilterAlgorithm(Algorithm):
self.load_state() self.load_state()
# ensure correctly aligned coefficients in each step # ensure correctly aligned coefficients in each step
self.steps = self.steps or [] self.steps = self.steps or []
self._validate_steps() for step in self.steps:
self._validate_step(step)
def load_state(self): def load_state(self):
"""Load filter coefficients from json file if custom filter is used. """Load filter coefficients from json file if custom filter is used.
...@@ -173,11 +174,10 @@ class FilterAlgorithm(Algorithm): ...@@ -173,11 +174,10 @@ class FilterAlgorithm(Algorithm):
steps.append(step) steps.append(step)
return steps return steps
def _validate_steps(self): def _validate_step(self, step):
"""Verifies whether or not firfirlter steps have an odd number of coefficients""" """Verifies whether or not firfirlter steps have an odd number of coefficients"""
for step in self.steps: if step["type"] == "firfilter" and len(step["window"]) % 2 != 1:
if step["type"] == "firfilter" and len(step["window"]) % 2 != 1: raise ValueError("Firfilter requires an odd number of coefficients")
raise ValueError("Firfilter requires an odd number of coefficients")
def can_produce_data(self, starttime, endtime, stream): def can_produce_data(self, starttime, endtime, stream):
"""Can Produce data """Can Produce data
......
...@@ -292,7 +292,7 @@ def test_align_trace(): ...@@ -292,7 +292,7 @@ def test_align_trace():
assert_equal(filtered[0].stats.endtime, UTCDateTime("2020-08-31T03:29:30")) assert_equal(filtered[0].stats.endtime, UTCDateTime("2020-08-31T03:29:30"))
def test_validate_steps(): def test_validate_step():
"""algorithm_test.FilterAlgorithm_test.test_validate_steps() """algorithm_test.FilterAlgorithm_test.test_validate_steps()
Validates algorithm steps 10 Hz to second with custom coefficients. Validates algorithm steps 10 Hz to second with custom coefficients.
""" """
...@@ -303,14 +303,12 @@ def test_validate_steps(): ...@@ -303,14 +303,12 @@ def test_validate_steps():
half = numtaps // 2 half = numtaps // 2
# check initial assumption # check initial assumption
assert_equal(numtaps % 2, 1) assert_equal(numtaps % 2, 1)
f._validate_steps() f._validate_step(step)
# expect step to raise a value error when window has an even length # expect step to raise a value error when window has an even length
f.steps = [ step = {
{ "window": np.delete(step["window"], numtaps // 2, 0),
"window": np.delete(step["window"], numtaps // 2, 0), "type": "firfilter",
"type": "firfilter", }
} assert_equal(len(step["window"]) % 2, 0)
]
assert_equal(len(f.steps[0]["window"]) % 2, 0)
with pytest.raises(ValueError): with pytest.raises(ValueError):
f._validate_steps() f._validate_step(step)
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