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
991846f2
Commit
991846f2
authored
4 years ago
by
Cain, Payton David
Browse files
Options
Downloads
Patches
Plain Diff
implement get_nearest_time within get_input_interval
parent
bac04f9e
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
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
geomagio/algorithm/FilterAlgorithm.py
+31
-10
31 additions, 10 deletions
geomagio/algorithm/FilterAlgorithm.py
with
31 additions
and
10 deletions
geomagio/algorithm/FilterAlgorithm.py
+
31
−
10
View file @
991846f2
...
...
@@ -61,6 +61,32 @@ def get_step_time_shift(step):
return
shift
def
get_nearest_time
(
step
,
output_time
,
left
=
True
):
size
=
step
[
"
output_sample_period
"
]
interval_start
=
output_time
-
(
output_time
.
timestamp
%
step
[
"
output_sample_period
"
]
)
# shift interval right if needed
if
interval_start
!=
output_time
and
not
left
:
interval_start
+=
step
[
"
output_sample_period
"
]
# position center of filter, data around interval
half_width
=
get_step_time_shift
(
step
)
if
step
[
"
type
"
]
==
"
average
"
:
interval_end
=
interval_start
+
step
[
"
output_sample_period
"
]
filter_center
=
interval_start
+
half_width
data_start
=
interval_start
data_end
=
interval_end
else
:
filter_center
=
interval_start
data_start
=
filter_center
-
half_width
data_end
=
filter_center
+
half_width
return
{
"
time
"
:
filter_center
,
"
data_start
"
:
data_start
,
"
data_end
"
:
data_end
,
}
def
get_valid_interval
(
step
,
start
,
end
):
"""
Searches for a valid interval to process averaging steps
...
...
@@ -376,16 +402,11 @@ class FilterAlgorithm(Algorithm):
end of input required to generate requested output.
"""
steps
=
self
.
get_filter_steps
()
steps
=
np
.
flip
(
steps
)
# calculate start/end from step array
for
step
in
steps
:
if
step
[
"
type
"
]
==
"
average
"
:
start
,
end
=
get_valid_interval
(
step
,
start
,
end
)
else
:
shift
=
get_step_time_shift
(
step
)
shift_step
=
shift
*
step
[
"
input_sample_period
"
]
start
=
start
-
shift_step
end
=
end
+
shift_step
# calculate start/end from inverted step array
for
step
in
reversed
(
steps
):
start_interval
=
get_nearest_time
(
step
=
step
,
output_time
=
start
,
left
=
False
)
end_interval
=
get_nearest_time
(
step
=
step
,
output_time
=
end
,
left
=
True
)
start
,
end
=
start_interval
[
"
data_start
"
],
end_interval
[
"
data_end
"
]
return
(
start
,
end
)
@classmethod
...
...
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