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
7c5440b6
Commit
7c5440b6
authored
3 years ago
by
Cain, Payton David
Browse files
Options
Downloads
Patches
Plain Diff
add residual entrypoint, raise errors for missing measurements
parent
70dc3739
No related branches found
No related tags found
2 merge requests
!146
Release CMO metadata to production
,
!91
Residual Calculation for Web Service
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
geomagio/api/ws/algorithms.py
+35
-1
35 additions, 1 deletion
geomagio/api/ws/algorithms.py
geomagio/residual/Calculation.py
+6
-3
6 additions, 3 deletions
geomagio/residual/Calculation.py
geomagio/residual/Measurement.py
+2
-1
2 additions, 1 deletion
geomagio/residual/Measurement.py
with
43 additions
and
5 deletions
geomagio/api/ws/algorithms.py
+
35
−
1
View file @
7c5440b6
from
fastapi
import
APIRouter
,
Depends
from
typing
import
List
from
fastapi
import
APIRouter
,
Depends
,
HTTPException
from
starlette.responses
import
Response
from
starlette.responses
import
Response
from
...
import
TimeseriesFactory
from
...
import
TimeseriesFactory
from
...algorithm
import
DbDtAlgorithm
from
...algorithm
import
DbDtAlgorithm
from
...residual
import
(
calculate
,
Reading
,
MARK_TYPES
,
INCLINATION_TYPES
,
DECLINATION_TYPES
,
)
from
.DataApiQuery
import
DataApiQuery
from
.DataApiQuery
import
DataApiQuery
from
.data
import
format_timeseries
,
get_data_factory
,
get_data_query
,
get_timeseries
from
.data
import
format_timeseries
,
get_data_factory
,
get_data_query
,
get_timeseries
...
@@ -25,3 +34,28 @@ def get_dbdt(
...
@@ -25,3 +34,28 @@ def get_dbdt(
return
format_timeseries
(
return
format_timeseries
(
timeseries
=
timeseries
,
format
=
query
.
format
,
elements
=
elements
timeseries
=
timeseries
,
format
=
query
.
format
,
elements
=
elements
)
)
@router.post
(
"
/algorithms/residual
"
,
response_model
=
Reading
)
def
calculate_residual
(
reading
:
Reading
,
adjust_reference
:
bool
=
True
):
missing_types
=
get_missing_measurement_types
(
reading
=
reading
)
if
len
(
missing_types
)
!=
0
:
error_message
=
"
,
"
.
join
(
t
.
value
for
t
in
missing_types
)
raise
HTTPException
(
status_code
=
400
,
detail
=
f
"
Missing
{
error_message
}
measurements in input reading
"
,
)
return
calculate
(
reading
=
reading
,
adjust_reference
=
adjust_reference
)
def
get_missing_measurement_types
(
reading
:
Reading
)
->
List
[
str
]:
measurement_types
=
[
m
.
measurement_type
for
m
in
reading
.
measurements
]
missing_types
=
[]
missing_types
.
extend
(
[
type
for
type
in
DECLINATION_TYPES
if
type
not
in
measurement_types
]
)
missing_types
.
extend
(
[
type
for
type
in
INCLINATION_TYPES
if
type
not
in
measurement_types
]
)
missing_types
.
extend
([
type
for
type
in
MARK_TYPES
if
type
not
in
measurement_types
])
return
missing_types
This diff is collapsed.
Click to expand it.
geomagio/residual/Calculation.py
+
6
−
3
View file @
7c5440b6
...
@@ -28,7 +28,10 @@ def calculate(reading: Reading, adjust_reference: bool = True) -> Reading:
...
@@ -28,7 +28,10 @@ def calculate(reading: Reading, adjust_reference: bool = True) -> Reading:
NOTE: rest of reading object is shallow copy.
NOTE: rest of reading object is shallow copy.
"""
"""
# reference measurement, used to adjust absolutes
# reference measurement, used to adjust absolutes
reference
=
reading
[
mt
.
WEST_DOWN
][
0
]
try
:
reference
=
adjust_reference
and
reading
[
mt
.
WEST_DOWN
][
0
]
or
None
except
:
raise
ValueError
(
f
"
Missing
{
mt
.
WEST_DOWN
.
value
}
measurement
"
)
# calculate inclination
# calculate inclination
inclination
,
f
,
i_mean
=
calculate_I
(
inclination
,
f
,
i_mean
=
calculate_I
(
hemisphere
=
reading
.
hemisphere
,
measurements
=
reading
.
measurements
hemisphere
=
reading
.
hemisphere
,
measurements
=
reading
.
measurements
...
@@ -39,13 +42,13 @@ def calculate(reading: Reading, adjust_reference: bool = True) -> Reading:
...
@@ -39,13 +42,13 @@ def calculate(reading: Reading, adjust_reference: bool = True) -> Reading:
corrected_f
=
corrected_f
,
corrected_f
=
corrected_f
,
inclination
=
inclination
,
inclination
=
inclination
,
mean
=
i_mean
,
mean
=
i_mean
,
reference
=
adjust_
reference
and
reference
or
None
,
reference
=
reference
,
)
)
absoluteD
,
meridian
=
calculate_D_absolute
(
absoluteD
,
meridian
=
calculate_D_absolute
(
azimuth
=
reading
.
azimuth
,
azimuth
=
reading
.
azimuth
,
h_baseline
=
absoluteH
.
baseline
,
h_baseline
=
absoluteH
.
baseline
,
measurements
=
reading
.
measurements
,
measurements
=
reading
.
measurements
,
reference
=
adjust_
reference
and
reference
or
None
,
reference
=
reference
,
)
)
# populate diagnostics object with averaged measurements
# populate diagnostics object with averaged measurements
diagnostics
=
Diagnostics
(
diagnostics
=
Diagnostics
(
...
...
This diff is collapsed.
Click to expand it.
geomagio/residual/Measurement.py
+
2
−
1
View file @
7c5440b6
...
@@ -54,7 +54,8 @@ def average_measurement(
...
@@ -54,7 +54,8 @@ def average_measurement(
measurements
=
[
m
for
m
in
measurements
if
m
.
measurement_type
in
types
]
measurements
=
[
m
for
m
in
measurements
if
m
.
measurement_type
in
types
]
if
len
(
measurements
)
==
0
:
if
len
(
measurements
)
==
0
:
# no measurements to average
# no measurements to average
return
None
error_message
=
"
,
"
.
join
(
t
.
value
for
t
in
types
)
raise
ValueError
(
f
"
Missing
{
error_message
}
measurements
"
)
starttime
=
safe_min
([
m
.
time
.
timestamp
for
m
in
measurements
if
m
.
time
])
starttime
=
safe_min
([
m
.
time
.
timestamp
for
m
in
measurements
if
m
.
time
])
endtime
=
safe_max
([
m
.
time
.
timestamp
for
m
in
measurements
if
m
.
time
])
endtime
=
safe_max
([
m
.
time
.
timestamp
for
m
in
measurements
if
m
.
time
])
measurement
=
AverageMeasurement
(
measurement
=
AverageMeasurement
(
...
...
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