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
46b5cb9a
Commit
46b5cb9a
authored
4 years ago
by
Cain, Payton David
Browse files
Options
Downloads
Patches
Plain Diff
Refactor _validate_step
parent
626229a2
No related branches found
Branches containing commit
No related tags found
Tags containing commit
2 merge requests
!146
Release CMO metadata to production
,
!17
Implement hourly/daily filtering products
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
geomagio/algorithm/FilterAlgorithm.py
+5
-5
5 additions, 5 deletions
geomagio/algorithm/FilterAlgorithm.py
test/algorithm_test/FilterAlgorithm_test.py
+8
-10
8 additions, 10 deletions
test/algorithm_test/FilterAlgorithm_test.py
with
13 additions
and
15 deletions
geomagio/algorithm/FilterAlgorithm.py
+
5
−
5
View file @
46b5cb9a
...
@@ -114,7 +114,8 @@ class FilterAlgorithm(Algorithm):
...
@@ -114,7 +114,8 @@ class FilterAlgorithm(Algorithm):
self
.
load_state
()
self
.
load_state
()
# ensure correctly aligned coefficients in each step
# ensure correctly aligned coefficients in each step
self
.
steps
=
self
.
steps
or
[]
self
.
steps
=
self
.
steps
or
[]
self
.
_validate_steps
()
for
step
in
self
.
steps
:
self
.
_validate_step
(
step
)
def
load_state
(
self
):
def
load_state
(
self
):
"""
Load filter coefficients from json file if custom filter is used.
"""
Load filter coefficients from json file if custom filter is used.
...
@@ -173,11 +174,10 @@ class FilterAlgorithm(Algorithm):
...
@@ -173,11 +174,10 @@ class FilterAlgorithm(Algorithm):
steps
.
append
(
step
)
steps
.
append
(
step
)
return
steps
return
steps
def
_validate_step
s
(
self
):
def
_validate_step
(
self
,
step
):
"""
Verifies whether or not firfirlter steps have an odd number of coefficients
"""
"""
Verifies whether or not firfirlter steps have an odd number of coefficients
"""
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
"
)
def
can_produce_data
(
self
,
starttime
,
endtime
,
stream
):
def
can_produce_data
(
self
,
starttime
,
endtime
,
stream
):
"""
Can Produce data
"""
Can Produce data
...
...
This diff is collapsed.
Click to expand it.
test/algorithm_test/FilterAlgorithm_test.py
+
8
−
10
View file @
46b5cb9a
...
@@ -292,7 +292,7 @@ def test_align_trace():
...
@@ -292,7 +292,7 @@ def test_align_trace():
assert_equal
(
filtered
[
0
].
stats
.
endtime
,
UTCDateTime
(
"
2020-08-31T03:29:30
"
))
assert_equal
(
filtered
[
0
].
stats
.
endtime
,
UTCDateTime
(
"
2020-08-31T03:29:30
"
))
def
test_validate_step
s
():
def
test_validate_step
():
"""
algorithm_test.FilterAlgorithm_test.test_validate_steps()
"""
algorithm_test.FilterAlgorithm_test.test_validate_steps()
Validates algorithm steps 10 Hz to second with custom coefficients.
Validates algorithm steps 10 Hz to second with custom coefficients.
"""
"""
...
@@ -303,14 +303,12 @@ def test_validate_steps():
...
@@ -303,14 +303,12 @@ def test_validate_steps():
half
=
numtaps
//
2
half
=
numtaps
//
2
# check initial assumption
# check initial assumption
assert_equal
(
numtaps
%
2
,
1
)
assert_equal
(
numtaps
%
2
,
1
)
f
.
_validate_step
s
()
f
.
_validate_step
(
step
)
# expect step to raise a value error when window has an even length
# expect step to raise a value error when window has an even length
f
.
steps
=
[
step
=
{
{
"
window
"
:
np
.
delete
(
step
[
"
window
"
],
numtaps
//
2
,
0
),
"
window
"
:
np
.
delete
(
step
[
"
window
"
],
numtaps
//
2
,
0
),
"
type
"
:
"
firfilter
"
,
"
type
"
:
"
firfilter
"
,
}
}
assert_equal
(
len
(
step
[
"
window
"
])
%
2
,
0
)
]
assert_equal
(
len
(
f
.
steps
[
0
][
"
window
"
])
%
2
,
0
)
with
pytest
.
raises
(
ValueError
):
with
pytest
.
raises
(
ValueError
):
f
.
_validate_step
s
()
f
.
_validate_step
(
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