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

Default algorithm's matrix to identity with no statefile

parent e317427f
No related branches found
No related tags found
2 merge requests!146Release CMO metadata to production,!68Identity Default for Adjusted Algorithm
...@@ -23,7 +23,7 @@ class AdjustedMatrix(BaseModel): ...@@ -23,7 +23,7 @@ class AdjustedMatrix(BaseModel):
""" """
matrix: Optional[Any] = None matrix: Optional[Any] = None
pier_correction: Optional[float] = None pier_correction: float = 0
metrics: Optional[List[Metric]] = None metrics: Optional[List[Metric]] = None
starttime: Optional[UTCDateTime] = None starttime: Optional[UTCDateTime] = None
endtime: Optional[UTCDateTime] = None endtime: Optional[UTCDateTime] = None
......
...@@ -43,7 +43,11 @@ class AdjustedAlgorithm(Algorithm): ...@@ -43,7 +43,11 @@ class AdjustedAlgorithm(Algorithm):
"""Load algorithm state from a file. """Load algorithm state from a file.
File name is self.statefile. File name is self.statefile.
""" """
# Adjusted matrix defaults to identity matrix
matrix_size = len([c for c in self.get_input_channels() if c != "F"]) + 1
matrix = np.eye(matrix_size)
if self.statefile is None: if self.statefile is None:
self.matrix = AdjustedMatrix(matrix=matrix)
return return
try: try:
with open(self.statefile, "r") as f: with open(self.statefile, "r") as f:
...@@ -51,12 +55,9 @@ class AdjustedAlgorithm(Algorithm): ...@@ -51,12 +55,9 @@ class AdjustedAlgorithm(Algorithm):
data = json.loads(data) data = json.loads(data)
except IOError as err: except IOError as err:
raise FileNotFoundError("statefile not found") raise FileNotFoundError("statefile not found")
# Adjusted matrix defaults to identity matrix
matrix_size = len([c for c in self.get_input_channels() if c != "F"]) + 1
if "pier_correction" in data: if "pier_correction" in data:
self.matrix = AdjustedMatrix(**data) self.matrix = AdjustedMatrix(**data)
elif "PC" in data: elif "PC" in data:
matrix = np.eye(matrix_size)
# read data from legacy format # read data from legacy format
for row in range(matrix_size): for row in range(matrix_size):
for col in range(matrix_size): for col in range(matrix_size):
......
from geomagio.adjusted import AdjustedMatrix from geomagio.adjusted import AdjustedMatrix
from geomagio.algorithm import AdjustedAlgorithm from geomagio.algorithm import AdjustedAlgorithm
import geomagio.iaga2002 as i2 import geomagio.iaga2002 as i2
from numpy.testing import assert_almost_equal, assert_equal from numpy.testing import assert_almost_equal, assert_array_equal, assert_equal
def test_construct(): def test_construct():
...@@ -24,7 +24,7 @@ def assert_streams_almost_equal(adjusted, expected, channels): ...@@ -24,7 +24,7 @@ def assert_streams_almost_equal(adjusted, expected, channels):
def test_process_XYZF_AdjustedMatrix(): def test_process_XYZF_AdjustedMatrix():
"""algorithm_test.AdjustedAlgorithm_test.test_process() """algorithm_test.AdjustedAlgorithm_test.test_process_XYZF_AdjustedMatrix()
Check adjusted data processing versus files generated from Check adjusted data processing versus files generated from
original script original script
...@@ -72,7 +72,7 @@ def test_process_XYZF_AdjustedMatrix(): ...@@ -72,7 +72,7 @@ def test_process_XYZF_AdjustedMatrix():
def test_process_reverse_polarity_AdjustedMatrix(): def test_process_reverse_polarity_AdjustedMatrix():
"""algorithm_test.AdjustedAlgorithm_test.test_process() """algorithm_test.AdjustedAlgorithm_test.test_process_reverse_polarity_AdjustedMatrix()
Check adjusted data processing versus files generated from Check adjusted data processing versus files generated from
original script. Tests reverse polarity martix. original script. Tests reverse polarity martix.
...@@ -106,7 +106,7 @@ def test_process_reverse_polarity_AdjustedMatrix(): ...@@ -106,7 +106,7 @@ def test_process_reverse_polarity_AdjustedMatrix():
def test_process_XYZF_statefile(): def test_process_XYZF_statefile():
"""algorithm_test.AdjustedAlgorithm_test.test_process() """algorithm_test.AdjustedAlgorithm_test.test_process_XYZF_statefile()
Check adjusted data processing versus files generated from Check adjusted data processing versus files generated from
original script original script
...@@ -131,7 +131,7 @@ def test_process_XYZF_statefile(): ...@@ -131,7 +131,7 @@ def test_process_XYZF_statefile():
def test_process_reverse_polarity_statefile(): def test_process_reverse_polarity_statefile():
"""algorithm_test.AdjustedAlgorithm_test.test_process() """algorithm_test.AdjustedAlgorithm_test.test_process_reverse_polarity_statefile()
Check adjusted data processing versus files generated from Check adjusted data processing versus files generated from
original script. Tests reverse polarity martix. original script. Tests reverse polarity martix.
...@@ -157,3 +157,21 @@ def test_process_reverse_polarity_statefile(): ...@@ -157,3 +157,21 @@ def test_process_reverse_polarity_statefile():
assert_streams_almost_equal( assert_streams_almost_equal(
adjusted=adjusted, expected=expected, channels=["H", "E"] adjusted=adjusted, expected=expected, channels=["H", "E"]
) )
def test_process_no_statefile():
"""algorithm_test.AdjustedAlgorithm_test.test_process_no_statefile()
Check adjusted data processing versus raw data
Uses default AdjustedMatrix with identity transform
"""
# initialize adjusted algorithm with no statefile
a = AdjustedAlgorithm()
# load boulder Jan 16 files from /etc/ directory
with open("etc/adjusted/BOU201601vmin.min") as f:
raw = i2.IAGA2002Factory().parse_string(f.read())
# process hezf (raw) channels with identity transform
adjusted = a.process(raw)
for i in range(len(adjusted)):
assert_array_equal(adjusted[i].data, raw[i].data)
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