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
Admin message
Maintenance scheduled for Thursday, April 10, from 5 PM to 6 PM ET.
Show more breadcrumbs
ghsc
National Geomagnetism Program
geomag-algorithms
Commits
f21f5135
Commit
f21f5135
authored
4 years ago
by
Cain, Payton David
Browse files
Options
Downloads
Patches
Plain Diff
Insert sample readings into test metadata
parent
43a734d6
No related branches found
No related tags found
2 merge requests
!146
Release CMO metadata to production
,
!63
Add Readings to test metadata
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
geomagio/residual/Reading.py
+32
-1
32 additions, 1 deletion
geomagio/residual/Reading.py
test_metadata.py
+47
-0
47 additions, 0 deletions
test_metadata.py
with
79 additions
and
1 deletion
geomagio/residual/Reading.py
+
32
−
1
View file @
f21f5135
...
@@ -2,7 +2,7 @@ import collections
...
@@ -2,7 +2,7 @@ import collections
from
typing
import
Dict
,
List
,
Optional
from
typing
import
Dict
,
List
,
Optional
from
typing_extensions
import
Literal
from
typing_extensions
import
Literal
from
obspy
import
Stream
from
obspy
import
Stream
,
UTCDateTime
from
pydantic
import
BaseModel
from
pydantic
import
BaseModel
from
..
import
TimeseriesUtility
from
..
import
TimeseriesUtility
...
@@ -97,3 +97,34 @@ class Reading(BaseModel):
...
@@ -97,3 +97,34 @@ class Reading(BaseModel):
time
=
measurement
.
time
,
time
=
measurement
.
time
,
default
=
default_existing
and
measurement
.
f
or
None
,
default
=
default_existing
and
measurement
.
f
or
None
,
)
)
@property
def
time
(
self
)
->
Optional
[
UTCDateTime
]:
h
=
self
.
get_absolute
(
"
H
"
)
if
h
:
return
h
.
endtime
return
None
@property
def
valid
(
self
)
->
bool
:
"""
ensures that readings used in calculations have been marked as valid
Attributes
----------
readings: list containing valid and invalid readings
"""
if
(
self
.
get_absolute
(
"
D
"
).
valid
==
True
and
self
.
get_absolute
(
"
H
"
).
valid
==
True
and
self
.
get_absolute
(
"
Z
"
).
valid
==
True
):
return
True
def
get_absolute
(
self
,
element
:
str
,
)
->
Optional
[
Absolute
]:
for
absolute
in
self
.
absolutes
:
if
absolute
.
element
==
element
:
return
absolute
return
None
This diff is collapsed.
Click to expand it.
test_metadata.py
+
47
−
0
View file @
f21f5135
import
json
from
obspy
import
UTCDateTime
from
obspy
import
UTCDateTime
from
geomagio.residual.SpreadsheetAbsolutesFactory
import
SpreadsheetAbsolutesFactory
from
geomagio
import
metadata
from
geomagio.api.db
import
database
,
metadata_table
from
geomagio.api.db
import
database
,
metadata_table
from
geomagio.api.ws.Observatory
import
OBSERVATORIES
from
geomagio.api.ws.Observatory
import
OBSERVATORIES
from
geomagio.metadata
import
Metadata
,
MetadataCategory
from
geomagio.metadata
import
Metadata
,
MetadataCategory
from
geomagio.residual
import
WebAbsolutesFactory
,
MeasurementType
test_metadata
=
[
test_metadata
=
[
...
@@ -109,6 +113,49 @@ for observatory in OBSERVATORIES:
...
@@ -109,6 +113,49 @@ for observatory in OBSERVATORIES:
)
)
)
)
# add null readings
starttime
=
UTCDateTime
(
"
2020-01-01
"
)
endtime
=
UTCDateTime
(
"
2020-01-07
"
)
readings
=
WebAbsolutesFactory
().
get_readings
(
observatory
=
"
BOU
"
,
starttime
=
UTCDateTime
(
"
2020-01-01
"
),
endtime
=
UTCDateTime
(
"
2020-01-07
"
),
)
for
reading
in
readings
:
json_string
=
reading
.
json
()
reading_dict
=
json
.
loads
(
json_string
)
test_metadata
.
append
(
Metadata
(
category
=
MetadataCategory
.
READING
,
created_by
=
"
test_metadata.py
"
,
reviewed_by
=
reading
.
metadata
[
"
reviewer
"
],
starttime
=
reading
.
time
,
station
=
"
BOU
"
,
metadata
=
reading_dict
,
metadata_valid
=
reading
.
valid
,
)
)
reading
=
SpreadsheetAbsolutesFactory
().
parse_spreadsheet
(
"
etc/residual/DED-20140952332.xlsm
"
)
json_string
=
reading
.
json
()
reading_dict
=
json
.
loads
(
json_string
)
test_metadata
.
append
(
Metadata
(
category
=
MetadataCategory
.
READING
,
created_by
=
"
test_metadata.py
"
,
starttime
=
reading
.
time
,
station
=
"
DED
"
,
metadata
=
reading_dict
,
metadata_valid
=
reading
.
valid
,
)
)
async
def
load_test_metadata
():
async
def
load_test_metadata
():
await
database
.
connect
()
await
database
.
connect
()
...
...
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