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
9ff59d7d
Commit
9ff59d7d
authored
9 years ago
by
Hal Simpson
Browse files
Options
Downloads
Patches
Plain Diff
created TimeseriesUtilities to hold gap detection routines
parent
c5803452
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
geomagio/TimeseriesUtilities.py
+56
-0
56 additions, 0 deletions
geomagio/TimeseriesUtilities.py
with
56 additions
and
0 deletions
geomagio/TimeseriesUtilities.py
0 → 100644
+
56
−
0
View file @
9ff59d7d
"""
Timeseries Utilities
"""
import
numpy.ma
as
ma
import
obspy
import
numpy
def
get_timeseries_gaps
(
timeseries
,
channels
,
starttime
,
endtime
):
gaps
=
{}
for
channel
in
channels
:
stream_gap
=
get_stream_gaps
(
timeseries
.
select
(
channel
=
channel
),
starttime
,
endtime
)
gaps
[
channel
]
=
stream_gap
return
gaps
def
get_stream_gaps
(
stream
,
starttime
,
endtime
):
gaps
=
[]
gap
=
None
i
=
0
data
=
stream
[
0
].
data
length
=
len
(
data
)
for
i
in
xrange
(
0
,
length
):
if
numpy
.
isnan
(
data
[
i
])
and
gap
is
None
:
gap
=
[
starttime
+
i
*
60
]
if
not
numpy
.
isnan
(
data
[
i
])
and
gap
is
not
None
:
gap
.
append
(
starttime
+
(
i
-
1
)
*
60
)
gaps
.
append
(
gap
)
gap
=
None
if
gap
is
not
None
:
gap
.
append
(
endtime
)
gaps
.
append
(
gap
)
return
gaps
def
get_merged_gaps
(
gaps
,
channels
):
all_gaps
=
[]
gap_stream
=
[]
for
channel
in
channels
:
gap_stream
.
extend
(
gaps
[
channel
])
sorted_gaps
=
sorted
(
gap_stream
,
key
=
lambda
starttime
:
starttime
[
1
])
merged_gaps
=
[]
new_gap
=
None
gap
=
sorted_gaps
[
0
]
for
i
in
range
(
1
,
len
(
sorted_gaps
)):
nxtgap
=
sorted_gaps
[
i
]
if
nxtgap
[
0
]
>=
gap
[
0
]
and
nxtgap
[
0
]
<=
gap
[
1
]:
if
nxtgap
[
1
]
>
gap
[
1
]:
gap
[
1
]
=
nxtgap
[
1
]
else
:
merged_gaps
.
append
(
gap
)
gap
=
nxtgap
merged_gaps
.
append
(
gap
)
return
merged_gaps
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