From 680e3136ecb9616bef5ddd5eca67e89a5e9ea047 Mon Sep 17 00:00:00 2001 From: Jeremy Fee <jmfee@usgs.gov> Date: Wed, 17 Jun 2020 18:16:00 -0600 Subject: [PATCH] Move prepare_steps call for api users --- geomagio/algorithm/FilterAlgorithm.py | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/geomagio/algorithm/FilterAlgorithm.py b/geomagio/algorithm/FilterAlgorithm.py index 99dd9317e..ee81bb479 100644 --- a/geomagio/algorithm/FilterAlgorithm.py +++ b/geomagio/algorithm/FilterAlgorithm.py @@ -56,6 +56,10 @@ class FilterAlgorithm(Algorithm): self.output_sample_period = output_sample_period self.steps = steps self.load_state() + # ensure correctly aligned coefficients in each step + self.steps = ( + self.steps and [self._prepare_step(step) for step in self.steps] or [] + ) def load_state(self): """Load filter coefficients from json file if custom filter is used. @@ -63,14 +67,11 @@ class FilterAlgorithm(Algorithm): """ if self.coeff_filename is None: return - with open(self.coeff_filename, "r") as f: data = f.read() data = json.loads(data) - if data is None or data == "": return - self.steps = [ { "name": "name" in data and data["name"] or "custom", @@ -79,8 +80,6 @@ class FilterAlgorithm(Algorithm): "window": data["window"], } ] - # ensure correctly aligned coefficients in each step - self.steps = [self._prepare_step(step) for step in self.steps] def save_state(self): """Save algorithm state to a file. -- GitLab