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

Create decimal parameter, add null test

parent 8ecd0806
No related branches found
No related tags found
No related merge requests found
from numpy.testing import assert_almost_equal from numpy.testing import assert_almost_equal
import pytest import pytest
from geomagio.residual import calculate, Reading, SpreadsheetAbsolutesFactory from obspy.core import UTCDateTime
from geomagio.residual import (
calculate,
Reading,
SpreadsheetAbsolutesFactory,
WebAbsolutesFactory,
)
def assert_readings_equal(expected: Reading, actual: Reading): def assert_readings_equal(expected: Reading, actual: Reading, decimal: float):
""" """
Compares calculation actuals to expected absolutes from spreadsheet Compares calculation actuals to expected absolutes from spreadsheet
""" """
...@@ -13,24 +19,26 @@ def assert_readings_equal(expected: Reading, actual: Reading): ...@@ -13,24 +19,26 @@ def assert_readings_equal(expected: Reading, actual: Reading):
assert_almost_equal( assert_almost_equal(
[expected_absolutes["H"].absolute, expected_absolutes["H"].baseline], [expected_absolutes["H"].absolute, expected_absolutes["H"].baseline],
[actual_absolutes["H"].absolute, actual_absolutes["H"].baseline], [actual_absolutes["H"].absolute, actual_absolutes["H"].baseline],
decimal=1, decimal=decimal,
verbose=True, verbose=True,
) )
assert_almost_equal( assert_almost_equal(
[expected_absolutes["D"].absolute, expected_absolutes["D"].baseline], [expected_absolutes["D"].absolute, expected_absolutes["D"].baseline],
[actual_absolutes["D"].absolute, actual_absolutes["D"].baseline], [actual_absolutes["D"].absolute, actual_absolutes["D"].baseline],
decimal=1, decimal=decimal,
verbose=True, verbose=True,
) )
assert_almost_equal( assert_almost_equal(
[expected_absolutes["Z"].absolute, expected_absolutes["Z"].baseline], [expected_absolutes["Z"].absolute, expected_absolutes["Z"].baseline],
[actual_absolutes["Z"].absolute, actual_absolutes["Z"].baseline], [actual_absolutes["Z"].absolute, actual_absolutes["Z"].baseline],
decimal=1, decimal=decimal,
verbose=True, verbose=True,
) )
assert_almost_equal(
expected.scale_value, actual.scale_value, decimal=1, verbose=True if expected.scale_value:
) assert_almost_equal(
expected.scale_value, actual.scale_value, decimal=1, verbose=True
)
def compare_spreadsheet_absolutes(path): def compare_spreadsheet_absolutes(path):
...@@ -44,6 +52,17 @@ def compare_spreadsheet_absolutes(path): ...@@ -44,6 +52,17 @@ def compare_spreadsheet_absolutes(path):
return reading return reading
def compare_null_absolutes(observatory, starttime, endtime):
"""
Tests functionality of WebAbsolutesFactory and recalculation of absolutes
"""
# establish SpreadsheetAbsolutesFactory for reading test data from Excel
waf = WebAbsolutesFactory()
# Read spreadsheet containing test data
reading = waf.get_readings(observatory, starttime, endtime)[0]
return reading
def test_DED_20140952332(): def test_DED_20140952332():
""" """
Compare calulations to original absolutes obejct from Spreadsheet. Compare calulations to original absolutes obejct from Spreadsheet.
...@@ -53,7 +72,7 @@ def test_DED_20140952332(): ...@@ -53,7 +72,7 @@ def test_DED_20140952332():
# gather absolute from DED test data and recalculate # gather absolute from DED test data and recalculate
reading = compare_spreadsheet_absolutes(path="etc/residual/DED-20140952332.xlsm") reading = compare_spreadsheet_absolutes(path="etc/residual/DED-20140952332.xlsm")
# test results with original spreadsheet values # test results with original spreadsheet values
assert_readings_equal(reading, calculate(reading)) assert_readings_equal(reading, calculate(reading), 1)
def test_BRW_20133650000(): def test_BRW_20133650000():
...@@ -65,4 +84,18 @@ def test_BRW_20133650000(): ...@@ -65,4 +84,18 @@ def test_BRW_20133650000():
# gather absolute from DED test data and recalculate # gather absolute from DED test data and recalculate
reading = compare_spreadsheet_absolutes(path="etc/residual/BRW-20133650000.xlsm") reading = compare_spreadsheet_absolutes(path="etc/residual/BRW-20133650000.xlsm")
# test results with original spreadsheet values # test results with original spreadsheet values
assert_readings_equal(reading, calculate(reading)) assert_readings_equal(reading, calculate(reading), 1)
def test_BOU_20200422():
"""
Compare calulations to original absolutes obejct from web absolutes.
Tests gathering of BOU's metadata for use by calculations.
Tests calculations for null method measurements in units of DMS.
"""
reading = compare_null_absolutes(
observatory="BOU",
starttime=UTCDateTime("2020-04-22T00:00:00Z"),
endtime=UTCDateTime("2020-04-23T00:00:00Z"),
)
assert_readings_equal(reading, calculate(reading), 0.1)
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