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
8196df8e
Commit
8196df8e
authored
3 years ago
by
Cain, Payton David
Browse files
Options
Downloads
Patches
Plain Diff
split streams by interval
parent
64c1940d
No related branches found
No related tags found
2 merge requests
!146
Release CMO metadata to production
,
!82
Add _pre_process method to MiniSeedInputClient
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
geomagio/TimeseriesUtility.py
+45
-0
45 additions, 0 deletions
geomagio/TimeseriesUtility.py
geomagio/edge/MiniSeedInputClient.py
+35
-2
35 additions, 2 deletions
geomagio/edge/MiniSeedInputClient.py
with
80 additions
and
2 deletions
geomagio/TimeseriesUtility.py
+
45
−
0
View file @
8196df8e
...
@@ -568,3 +568,48 @@ def round_usecs(time):
...
@@ -568,3 +568,48 @@ def round_usecs(time):
if
rounded_usecs
!=
usecs
:
if
rounded_usecs
!=
usecs
:
time
=
time
.
replace
(
microsecond
=
rounded_usecs
)
time
=
time
.
replace
(
microsecond
=
rounded_usecs
)
return
time
return
time
def
split_streams_by_interval
(
stream
,
interval
):
"""
Splits streams by interval
Parameters:
-----------
stream: obspy.core.Stream
stream of input data
interval: int
interval streams will be split by
Returns:
--------
out_streams: List[obspy.core.Stream]
list of streams split by interval
"""
delta
=
stream
[
0
].
stats
.
delta
interval_start
=
stream
[
0
].
stats
.
starttime
.
timestamp
times
=
stream
[
0
].
times
(
"
timestamp
"
)
interval_ends
=
times
[
times
%
interval
==
0
]
-
delta
if
not
interval_ends
.
any
():
return
[
stream
]
out_streams
=
[]
for
interval_end
in
interval_ends
:
# should only occur with stream starttime occuring at midnight
if
interval_end
==
interval_start
-
delta
:
continue
stream_copy
=
stream
.
copy
()
pad_timeseries
(
timeseries
=
stream_copy
,
starttime
=
obspy
.
core
.
UTCDateTime
(
interval_start
),
endtime
=
obspy
.
core
.
UTCDateTime
(
interval_end
),
)
out_streams
.
append
(
stream_copy
)
interval_start
=
interval_end
+
delta
# last trim will extend from interval_start to the end of the original input stream
pad_timeseries
(
stream
,
starttime
=
obspy
.
core
.
UTCDateTime
(
interval_start
),
endtime
=
stream
[
0
].
stats
.
endtime
,
)
out_streams
.
append
(
stream
)
return
out_streams
This diff is collapsed.
Click to expand it.
geomagio/edge/MiniSeedInputClient.py
+
35
−
2
View file @
8196df8e
...
@@ -3,6 +3,8 @@ import io
...
@@ -3,6 +3,8 @@ import io
import
socket
import
socket
import
sys
import
sys
from
..TimeseriesUtility
import
split_streams_by_interval
class
MiniSeedInputClient
(
object
):
class
MiniSeedInputClient
(
object
):
"""
Client to write MiniSeed formatted data to Edge.
"""
Client to write MiniSeed formatted data to Edge.
...
@@ -74,12 +76,43 @@ class MiniSeedInputClient(object):
...
@@ -74,12 +76,43 @@ class MiniSeedInputClient(object):
self
.
connect
()
self
.
connect
()
# convert stream to miniseed
# convert stream to miniseed
buf
=
io
.
BytesIO
()
buf
=
io
.
BytesIO
()
stream
=
self
.
_pre_process
(
stream
)
streams
=
self
.
_pre_process
(
stream
)
stream
.
write
(
buf
,
encoding
=
self
.
encoding
,
format
=
"
MSEED
"
,
reclen
=
512
)
for
stream
in
streams
:
stream
.
write
(
buf
,
format
=
"
MSEED
"
,
reclen
=
512
)
# send data
# send data
self
.
socket
.
sendall
(
buf
.
getvalue
())
self
.
socket
.
sendall
(
buf
.
getvalue
())
def
_pre_process
(
self
,
stream
):
def
_pre_process
(
self
,
stream
):
"""
Encodes and splits streams at daily intervals
Paramters:
----------
stream: obspy.core.stream
stream of input data
Returns:
--------
streams: List[obspy.core.stream]
list of encoded streams split at daily intervals
"""
stream
=
self
.
__encode_stream
(
stream
)
streams
=
split_streams_by_interval
(
stream
,
interval
=
86400
)
return
streams
def
__encode_stream
(
self
,
stream
):
"""
Ensures that factory encoding matches output data encoding
Parameters:
-----------
stream: obspy.core.Stream
stream of input data
Returns:
--------
stream: obspy.core.Stream
stream with matching data encoding to factory specification
"""
for
trace
in
stream
:
for
trace
in
stream
:
if
trace
.
data
.
dtype
!=
self
.
encoding
:
if
trace
.
data
.
dtype
!=
self
.
encoding
:
trace
.
data
=
trace
.
data
.
astype
(
self
.
encoding
)
trace
.
data
=
trace
.
data
.
astype
(
self
.
encoding
)
...
...
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