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
65436427
Commit
65436427
authored
2 years ago
by
Jeremy M Fee
Browse files
Options
Downloads
Patches
Plain Diff
Add get_previous_interval method and test
parent
6355305d
No related branches found
No related tags found
1 merge request
!186
update interval no longer shrinks with recursion
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
geomagio/Controller.py
+26
-4
26 additions, 4 deletions
geomagio/Controller.py
test/Controller_test.py
+21
-1
21 additions, 1 deletion
test/Controller_test.py
with
47 additions
and
5 deletions
geomagio/Controller.py
+
26
−
4
View file @
65436427
...
@@ -426,11 +426,10 @@ class Controller(object):
...
@@ -426,11 +426,10 @@ class Controller(object):
# check for fillable gap at start
# check for fillable gap at start
if
output_gap
[
0
]
==
starttime
:
if
output_gap
[
0
]
==
starttime
:
# found fillable gap at start, recurse to previous interval
# found fillable gap at start, recurse to previous interval
delta
=
TimeseriesUtility
.
get_delta_from_interval
(
output
_interval
)
recurse_starttime
,
recurse_endtime
=
get_previous
_interval
(
recurse_
starttime
=
(
start
=
starttime
,
starttime
-
(
endtime
-
starttime
)
-
delta
*
bool
(
update_count
)
end
=
endtime
,
)
)
recurse_endtime
=
starttime
-
delta
self
.
run_as_update
(
self
.
run_as_update
(
algorithm
=
algorithm
,
algorithm
=
algorithm
,
observatory
=
observatory
,
observatory
=
observatory
,
...
@@ -638,6 +637,29 @@ def get_output_factory(args):
...
@@ -638,6 +637,29 @@ def get_output_factory(args):
return
output_factory
return
output_factory
def
get_previous_interval
(
start
:
UTCDateTime
,
end
:
UTCDateTime
,
)
->
Tuple
[
UTCDateTime
,
UTCDateTime
]:
"""
Get previous interval for given interval.
Parameters
----------
start
start of interval
end
end of interval
Returns
-------
Previous interval of approximately the same size.
Interval is rounded to nearest second, and ends one microsecond earlier.
"""
# round to nearest second to recover removed microsecond from repeated calls
interval_size
=
round
(
end
-
start
)
return
(
start
-
interval_size
,
start
-
1e-6
)
def
get_realtime_interval
(
interval_seconds
:
int
)
->
Tuple
[
UTCDateTime
,
UTCDateTime
]:
def
get_realtime_interval
(
interval_seconds
:
int
)
->
Tuple
[
UTCDateTime
,
UTCDateTime
]:
# calculate endtime/starttime
# calculate endtime/starttime
now
=
UTCDateTime
()
now
=
UTCDateTime
()
...
...
This diff is collapsed.
Click to expand it.
test/Controller_test.py
+
21
−
1
View file @
65436427
...
@@ -6,7 +6,7 @@ from geomagio.algorithm import Algorithm
...
@@ -6,7 +6,7 @@ from geomagio.algorithm import Algorithm
from
geomagio.iaga2002
import
IAGA2002Factory
from
geomagio.iaga2002
import
IAGA2002Factory
# needed to emulate geomag.py script
# needed to emulate geomag.py script
from
geomagio.Controller
import
_main
,
parse_args
from
geomagio.Controller
import
_main
,
get_previous_interval
,
parse_args
# needed to copy SqDistAlgorithm statefile
# needed to copy SqDistAlgorithm statefile
from
shutil
import
copy
from
shutil
import
copy
...
@@ -290,3 +290,23 @@ def test_controller_update_sqdist():
...
@@ -290,3 +290,23 @@ def test_controller_update_sqdist():
)
)
expected
=
expected_factory
.
get_timeseries
(
starttime
=
starttime1
,
endtime
=
endtime6
)
expected
=
expected_factory
.
get_timeseries
(
starttime
=
starttime1
,
endtime
=
endtime6
)
assert_allclose
(
actual
,
expected
)
assert_allclose
(
actual
,
expected
)
def
test_get_previous_interval
():
"""
Test get_previous_interval produces stable interval sizes
"""
# initial interval is one hour
start
=
UTCDateTime
(
"
2022-01-05T00:00:00Z
"
)
end
=
UTCDateTime
(
"
2022-01-05T01:00:00Z
"
)
# previous interval starts at beginning of previous hour
previous
=
get_previous_interval
(
start
=
start
,
end
=
end
)
assert
previous
==
(
UTCDateTime
(
"
2022-01-04T23:00:00
"
),
UTCDateTime
(
"
2022-01-04T23:59:59.999999Z
"
),
)
# previous interval still starts at beginning of previous hour
# even though interval is one microsecond smaller
previous
=
get_previous_interval
(
*
previous
)
assert
previous
==
(
UTCDateTime
(
"
2022-01-04T22:00:00
"
),
UTCDateTime
(
"
2022-01-04T22:59:59.999999Z
"
),
)
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