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
626229a2
Commit
626229a2
authored
4 years ago
by
Cain, Payton David
Browse files
Options
Downloads
Patches
Plain Diff
Add comments to methods
parent
5e39d47f
No related branches found
No related tags found
2 merge requests
!146
Release CMO metadata to production
,
!17
Implement hourly/daily filtering products
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
geomagio/algorithm/FilterAlgorithm.py
+36
-1
36 additions, 1 deletion
geomagio/algorithm/FilterAlgorithm.py
with
36 additions
and
1 deletion
geomagio/algorithm/FilterAlgorithm.py
+
36
−
1
View file @
626229a2
...
@@ -44,16 +44,42 @@ STEPS = [
...
@@ -44,16 +44,42 @@ STEPS = [
def
get_step_time_shift
(
step
):
def
get_step_time_shift
(
step
):
"""
Calculates the time shift generated in each filtering step
Parameters
----------
step: dict
Dictionary object holding information about a given filter step
Returns
-------
shift: float
Time shift value
"""
input_sample_period
=
step
[
"
input_sample_period
"
]
input_sample_period
=
step
[
"
input_sample_period
"
]
numtaps
=
len
(
step
[
"
window
"
])
numtaps
=
len
(
step
[
"
window
"
])
return
input_sample_period
*
((
numtaps
-
1
)
/
2
)
shift
=
input_sample_period
*
((
numtaps
-
1
)
/
2
)
return
shift
def
get_valid_interval
(
step
,
start
,
end
):
def
get_valid_interval
(
step
,
start
,
end
):
"""
Searches for a valid interval to process averaging steps
Parameters
----------
step: dict
Dictionary object holding information about a given filter step
Returns
-------
start: UTCDateTime
starttime of valid interval
end: UTCDateTime
endtime of valid interval
"""
# get first interval
# get first interval
interval_start
=
start
-
(
start
.
timestamp
%
step
[
"
output_sample_period
"
])
interval_start
=
start
-
(
start
.
timestamp
%
step
[
"
output_sample_period
"
])
start
=
interval_start
start
=
interval_start
interval_end
=
start
+
step
[
"
output_sample_period
"
]
-
step
[
"
input_sample_period
"
]
interval_end
=
start
+
step
[
"
output_sample_period
"
]
-
step
[
"
input_sample_period
"
]
# update interval endtime until it reaches the interval end belongs to
while
end
>
interval_end
:
while
end
>
interval_end
:
interval_start
=
interval_end
+
step
[
"
input_sample_period
"
]
interval_start
=
interval_end
+
step
[
"
input_sample_period
"
]
interval_end
=
(
interval_end
=
(
...
@@ -148,6 +174,7 @@ class FilterAlgorithm(Algorithm):
...
@@ -148,6 +174,7 @@ class FilterAlgorithm(Algorithm):
return
steps
return
steps
def
_validate_steps
(
self
):
def
_validate_steps
(
self
):
"""
Verifies whether or not firfirlter steps have an odd number of coefficients
"""
for
step
in
self
.
steps
:
for
step
in
self
.
steps
:
if
step
[
"
type
"
]
==
"
firfilter
"
and
len
(
step
[
"
window
"
])
%
2
!=
1
:
if
step
[
"
type
"
]
==
"
firfilter
"
and
len
(
step
[
"
window
"
])
%
2
!=
1
:
raise
ValueError
(
"
Firfilter requires an odd number of coefficients
"
)
raise
ValueError
(
"
Firfilter requires an odd number of coefficients
"
)
...
@@ -249,6 +276,14 @@ class FilterAlgorithm(Algorithm):
...
@@ -249,6 +276,14 @@ class FilterAlgorithm(Algorithm):
return
out
return
out
def
align_trace
(
self
,
step
,
trace
):
def
align_trace
(
self
,
step
,
trace
):
"""
Aligns trace to handle trailing or missing values.
Parameters
----------
step: dict
Dictionary object holding information about a given filter step
trace: obspy.core.trace
trace holding data and stats(starttime/endtime) to manipulate in alignment
"""
start
=
trace
.
stats
.
starttime
start
=
trace
.
stats
.
starttime
numtaps
=
len
(
step
[
"
window
"
])
numtaps
=
len
(
step
[
"
window
"
])
shift
=
get_step_time_shift
(
step
)
shift
=
get_step_time_shift
(
step
)
...
...
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