diff --git a/geomagio/algorithm/FilterAlgorithm.py b/geomagio/algorithm/FilterAlgorithm.py index 1f1d30ae3c44981f2a61e2ae8ef5ff2b9e243173..afcefbf4a94685e40182fcc8c12962bff9d0da91 100644 --- a/geomagio/algorithm/FilterAlgorithm.py +++ b/geomagio/algorithm/FilterAlgorithm.py @@ -114,7 +114,8 @@ class FilterAlgorithm(Algorithm): self.load_state() #  ensure correctly aligned coefficients in each step self.steps = self.steps or [] - self._validate_steps() + for step in self.steps: + self._validate_step(step) def load_state(self): """Load filter coefficients from json file if custom filter is used. @@ -173,11 +174,10 @@ class FilterAlgorithm(Algorithm): steps.append(step) return steps - def _validate_steps(self): + def _validate_step(self, step): """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: - raise ValueError("Firfilter requires an odd number of coefficients") + if step["type"] == "firfilter" and len(step["window"]) % 2 != 1: + raise ValueError("Firfilter requires an odd number of coefficients") def can_produce_data(self, starttime, endtime, stream): """Can Produce data diff --git a/test/algorithm_test/FilterAlgorithm_test.py b/test/algorithm_test/FilterAlgorithm_test.py index 2dcb627e38158de71c1a6ee34cb85bc222f0d1d1..21558ef57d6053d0c3959b488597c87777a128da 100644 --- a/test/algorithm_test/FilterAlgorithm_test.py +++ b/test/algorithm_test/FilterAlgorithm_test.py @@ -292,7 +292,7 @@ def test_align_trace(): 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() Validates algorithm steps 10 Hz to second with custom coefficients. """ @@ -303,14 +303,12 @@ def test_validate_steps(): half = numtaps // 2 # check initial assumption 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 - f.steps = [ - { - "window": np.delete(step["window"], numtaps // 2, 0), - "type": "firfilter", - } - ] - assert_equal(len(f.steps[0]["window"]) % 2, 0) + step = { + "window": np.delete(step["window"], numtaps // 2, 0), + "type": "firfilter", + } + assert_equal(len(step["window"]) % 2, 0) with pytest.raises(ValueError): - f._validate_steps() + f._validate_step(step)