Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
G
geomag-algorithms
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container Registry
Model registry
Operate
Environments
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
ghsc
National Geomagnetism Program
geomag-algorithms
Commits
f2bb6eda
Commit
f2bb6eda
authored
4 years ago
by
Cain, Payton David
Browse files
Options
Downloads
Patches
Plain Diff
Create decimal parameter, add null test
parent
8ecd0806
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
test/residual_test/residual_test.py
+43
-10
43 additions, 10 deletions
test/residual_test/residual_test.py
with
43 additions
and
10 deletions
test/residual_test/residual_test.py
+
43
−
10
View file @
f2bb6eda
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
)
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment