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
81d90bd9
Commit
81d90bd9
authored
4 months ago
by
Wernle, Alexandra Nicole
Browse files
Options
Downloads
Patches
Plain Diff
Pydantic changes
parent
08251027
No related branches found
No related tags found
1 merge request
!344
New MetadataAlgorithm, SpikesAlgorithm, and flag-spikes application
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
geomagio/metadata/flag/Flag.py
+14
-25
14 additions, 25 deletions
geomagio/metadata/flag/Flag.py
with
14 additions
and
25 deletions
geomagio/metadata/flag/Flag.py
+
14
−
25
View file @
81d90bd9
...
...
@@ -2,9 +2,11 @@ from typing import Dict, Union, List, Optional
from
datetime
import
timedelta
from
obspy
import
UTCDateTime
from
pydantic
import
BaseModel
,
Field
,
validator
from
pydantic
import
BaseModel
,
Field
,
field_
validator
from
enum
import
Enum
from
...pydantic_utcdatetime
import
CustomUTCDateTimeType
class
FlagCategory
(
str
,
Enum
):
ARTIFICIAL_DISTURBANCE
=
"
ARTIFICIAL_DISTURBANCE
"
...
...
@@ -68,27 +70,20 @@ class ArtificialDisturbance(Flag):
The type of artificial disturbance(s).
deviation: float
Deviation of an offset in nt.
spikes: List[UTCDateTime]
spikes: List[
Custom
UTCDateTime
Type
]
Array of timestamps as UTCDateTime. Can be a single spike or many spikes.
"""
artificial_disturbance_type
:
ArtificialDisturbanceType
deviation
:
Optional
[
float
]
=
None
spikes
:
Optional
[
List
[
UTCDateTime
]]
=
None
spikes
:
Optional
[
List
[
Custom
UTCDateTime
Type
]]
=
None
def
__init__
(
self
,
*
args
,
**
kwargs
):
super
().
__init__
(
*
args
,
**
kwargs
)
self
.
flag_category
=
"
ARTIFICIAL_DISTURBANCE
"
@validator
(
"
spikes
"
,
always
=
True
)
def
validate_spikes
(
cls
,
spikes
):
if
len
(
spikes
)
==
0
:
raise
ValueError
(
"
Spikes list cannot be empty.
"
)
return
spikes
self
.
flag_category
=
FlagCategory
.
ARTIFICIAL_DISTURBANCE
@validator
(
"
spikes
"
,
always
=
True
)
@
field_
validator
(
"
spikes
"
)
def
check_spikes_duration
(
cls
,
spikes
):
if
spikes
is
None
or
len
(
spikes
)
<
2
:
return
spikes
...
...
@@ -131,12 +126,12 @@ class Gap(Flag):
How the gap is being handled, e.g., backfilled.
"""
cause
:
str
=
None
handling
:
str
=
None
cause
:
Optional
[
str
]
=
None
handling
:
Optional
[
str
]
=
None
def
__init__
(
self
,
*
args
,
**
kwargs
):
super
().
__init__
(
*
args
,
**
kwargs
)
self
.
flag_category
=
"
GAP
"
self
.
flag_category
=
FlagCategory
.
GAP
class
EventType
(
str
,
Enum
):
...
...
@@ -163,13 +158,13 @@ class Event(Flag):
"""
event_type
:
EventType
index
:
int
=
None
scale
:
str
=
None
url
:
str
=
None
index
:
Optional
[
int
]
=
None
scale
:
Optional
[
str
]
=
None
url
:
Optional
[
str
]
=
None
def
__init__
(
self
,
*
args
,
**
kwargs
):
super
().
__init__
(
*
args
,
**
kwargs
)
self
.
flag_category
=
"
EVENT
"
self
.
flag_category
=
FlagCategory
.
EVENT
# More example usage:
...
...
@@ -199,9 +194,3 @@ geomagnetic_storm_data = {
"
index
"
:
7
,
"
url
"
:
"
https://www.swpc.noaa.gov/products/planetary-k-index
"
,
}
spike_instance
=
ArtificialDisturbance
(
**
spikes_data
)
offset_instance
=
ArtificialDisturbance
(
**
offset_data
)
print
(
spike_instance
.
model_dump
())
print
(
offset_instance
.
model_dump
())
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