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
eec2ab7c
Commit
eec2ab7c
authored
9 years ago
by
Hal Simpson
Browse files
Options
Downloads
Patches
Plain Diff
added comments, refactored is_new_data to use gap_is_new_data, and created gap_is_new_data
parent
1d3db2d4
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
geomagio/TimeseriesUtilities.py
+91
-0
91 additions, 0 deletions
geomagio/TimeseriesUtilities.py
with
91 additions
and
0 deletions
geomagio/TimeseriesUtilities.py
+
91
−
0
View file @
eec2ab7c
...
@@ -4,6 +4,27 @@ import obspy
...
@@ -4,6 +4,27 @@ import obspy
import
numpy
import
numpy
def
get_timeseries_gaps
(
timeseries
,
channels
,
starttime
,
endtime
):
def
get_timeseries_gaps
(
timeseries
,
channels
,
starttime
,
endtime
):
"""
Get gaps in a given timeseries
Parameters
----------
timeseries: obspy.core.stream
the stream to check for gaps in
channels: array_like
list of channels to look for gaps in
starttime: obspy.core.UTCDateTime
time of first sample.
endtime: obspy.core.UTCDateTime
time of last sample.
Returns
-------
dictionary of channel gaps arrays
Notes
-----
Returns a dictionary with channel: gaps array pairs. Where the gaps array
consists of arrays of starttime/endtime pairs representing each gap.
"""
gaps
=
{}
gaps
=
{}
for
channel
in
channels
:
for
channel
in
channels
:
stream_gap
=
get_stream_gaps
(
stream_gap
=
get_stream_gaps
(
...
@@ -14,6 +35,20 @@ def get_timeseries_gaps(timeseries, channels, starttime, endtime):
...
@@ -14,6 +35,20 @@ def get_timeseries_gaps(timeseries, channels, starttime, endtime):
def
get_stream_gaps
(
stream
,
starttime
,
endtime
):
def
get_stream_gaps
(
stream
,
starttime
,
endtime
):
"""
Gets gaps in a stream representing a single channel
Parameters
----------
stream: obspy.core.stream
a stream containing a single channel of data.
starttime: obspy.core.UTCDateTime
time of first sample.
endtime: obspy.core.UTCDateTime
time of last sample.
Returns
-------
array of gaps
"""
gaps
=
[]
gaps
=
[]
gap
=
None
gap
=
None
...
@@ -34,6 +69,24 @@ def get_stream_gaps(stream, starttime, endtime):
...
@@ -34,6 +69,24 @@ def get_stream_gaps(stream, starttime, endtime):
return
gaps
return
gaps
def
get_merged_gaps
(
gaps
,
channels
):
def
get_merged_gaps
(
gaps
,
channels
):
"""
Get gaps merged across channels/streams
Parameters
----------
gaps: dictionary
contains channel/gap array pairs
channels: array_like
array of channels to look for gaps in
Returns
-------
array_like
an array of startime/endtime arrays representing gaps.
Notes
-----
Takes an dictionary of gaps, and merges those gaps across channels,
returning an array of the merged gaps.
"""
all_gaps
=
[]
all_gaps
=
[]
gap_stream
=
[]
gap_stream
=
[]
for
channel
in
channels
:
for
channel
in
channels
:
...
@@ -59,6 +112,18 @@ def get_merged_gaps(gaps, channels):
...
@@ -59,6 +112,18 @@ def get_merged_gaps(gaps, channels):
return
merged_gaps
return
merged_gaps
def
is_new_data
(
input_gaps
,
output_gaps
):
def
is_new_data
(
input_gaps
,
output_gaps
):
"""
Is new data available in gaps
Parameters
----------
input_gaps: array_like
an array of startime/endtime gap pairs holding the input gaps
output_gaps: array_like
an array of starttime/endtime gap pairs holding the ouput gaps
Returns
boolean
True if there
'
s new data available, False otherwise
"""
for
output_gap
in
output_gaps
:
for
output_gap
in
output_gaps
:
for
input_gap
in
input_gaps
:
for
input_gap
in
input_gaps
:
if
(
output_gap
[
0
]
>=
input_gap
[
0
]
and
if
(
output_gap
[
0
]
>=
input_gap
[
0
]
and
...
@@ -67,7 +132,33 @@ def is_new_data(input_gaps, output_gaps):
...
@@ -67,7 +132,33 @@ def is_new_data(input_gaps, output_gaps):
return
False
return
False
return
True
return
True
def
gap_is_new_data
(
input_gaps
,
output_gap
):
"""
Is new data available for a single gap
Parameters
----------
input_gaps: array_like
an array of startime/endtime gap pairs holding the input gaps
output_gaps: array_like
starttime/endtime pair representing a single gap
Returns
boolean
True if there
'
s new data available for the gap, False otherwise
"""
for
input_gap
in
input_gaps
:
if
(
output_gap
[
0
]
>=
input_gap
[
0
]
and
output_gap
[
0
]
<=
input_gap
[
1
]
and
output_gap
[
1
]
<=
input_gap
[
1
]):
return
False
return
True
def
get_seconds_of_interval
(
interval
):
def
get_seconds_of_interval
(
interval
):
"""
Gets number of seconds for a given interval string
Parameters
----------
interval: string
The string representing an interval size
"""
if
interval
==
'
second
'
:
if
interval
==
'
second
'
:
return
1
return
1
if
interval
==
'
minute
'
:
if
interval
==
'
minute
'
:
...
...
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