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
ff4a458f
Commit
ff4a458f
authored
2 months ago
by
Shavers, Nicholas H
Browse files
Options
Downloads
Plain Diff
Merge branch 'miniseed-file-factory-mvp' into 'master'
MiniSeedFactory - File Implementations Closes
#133
See merge request
!381
parents
88626ae3
a5e8e814
No related branches found
Branches containing commit
No related tags found
Tags containing commit
1 merge request
!381
MiniSeedFactory - File Implementations
Pipeline
#550691
passed
2 months ago
Stage: init
Stage: test
Stage: integration
Stage: deploy
Changes
2
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
geomagio/Controller.py
+23
-20
23 additions, 20 deletions
geomagio/Controller.py
geomagio/edge/MiniSeedFactory.py
+51
-0
51 additions, 0 deletions
geomagio/edge/MiniSeedFactory.py
with
74 additions
and
20 deletions
geomagio/Controller.py
+
23
−
20
View file @
ff4a458f
...
@@ -494,9 +494,13 @@ def get_input_factory(args):
...
@@ -494,9 +494,13 @@ def get_input_factory(args):
input_factory_args
[
"
interval
"
]
=
args
.
input_interval
or
args
.
interval
input_factory_args
[
"
interval
"
]
=
args
.
input_interval
or
args
.
interval
input_factory_args
[
"
observatory
"
]
=
args
.
observatory
input_factory_args
[
"
observatory
"
]
=
args
.
observatory
input_factory_args
[
"
type
"
]
=
args
.
type
input_factory_args
[
"
type
"
]
=
args
.
type
input_type
=
args
.
input
# stream/url arguments
# stream/url arguments
if
args
.
input_file
is
not
None
:
if
args
.
input_file
is
not
None
:
input_stream
=
open
(
args
.
input_file
,
"
r
"
)
if
input_type
==
"
miniseed
"
:
input_stream
=
open
(
args
.
input_file
,
"
rb
"
)
else
:
input_stream
=
open
(
args
.
input_file
,
"
r
"
)
elif
args
.
input_stdin
:
elif
args
.
input_stdin
:
input_stream
=
sys
.
stdin
input_stream
=
sys
.
stdin
elif
args
.
input_url
is
not
None
:
elif
args
.
input_url
is
not
None
:
...
@@ -505,7 +509,6 @@ def get_input_factory(args):
...
@@ -505,7 +509,6 @@ def get_input_factory(args):
input_factory_args
[
"
urlTemplate
"
]
=
args
.
input_url
input_factory_args
[
"
urlTemplate
"
]
=
args
.
input_url
else
:
else
:
input_stream
=
StringIO
(
Util
.
read_url
(
args
.
input_url
))
input_stream
=
StringIO
(
Util
.
read_url
(
args
.
input_url
))
input_type
=
args
.
input
if
input_type
==
"
edge
"
:
if
input_type
==
"
edge
"
:
input_factory
=
edge
.
EdgeFactory
(
input_factory
=
edge
.
EdgeFactory
(
host
=
args
.
input_host
,
host
=
args
.
input_host
,
...
@@ -513,14 +516,6 @@ def get_input_factory(args):
...
@@ -513,14 +516,6 @@ def get_input_factory(args):
locationCode
=
args
.
locationcode
,
locationCode
=
args
.
locationcode
,
**
input_factory_args
,
**
input_factory_args
,
)
)
elif
input_type
==
"
miniseed
"
:
input_factory
=
edge
.
MiniSeedFactory
(
host
=
args
.
input_host
,
port
=
args
.
input_port
,
locationCode
=
args
.
locationcode
,
convert_channels
=
args
.
convert_voltbin
,
**
input_factory_args
,
)
elif
input_type
==
"
goes
"
:
elif
input_type
==
"
goes
"
:
# TODO: deal with other goes arguments
# TODO: deal with other goes arguments
input_factory
=
imfv283
.
GOESIMFV283Factory
(
input_factory
=
imfv283
.
GOESIMFV283Factory
(
...
@@ -556,6 +551,14 @@ def get_input_factory(args):
...
@@ -556,6 +551,14 @@ def get_input_factory(args):
input_factory
=
imfv283
.
IMFV283Factory
(
**
input_factory_args
)
input_factory
=
imfv283
.
IMFV283Factory
(
**
input_factory_args
)
elif
input_type
==
"
pcdcp
"
:
elif
input_type
==
"
pcdcp
"
:
input_factory
=
pcdcp
.
PCDCPFactory
(
**
input_factory_args
)
input_factory
=
pcdcp
.
PCDCPFactory
(
**
input_factory_args
)
elif
input_type
==
"
miniseed
"
:
input_factory
=
edge
.
MiniSeedFactory
(
host
=
args
.
input_host
,
port
=
args
.
input_port
,
locationCode
=
args
.
locationcode
,
convert_channels
=
args
.
convert_voltbin
,
**
input_factory_args
,
)
# wrap stream
# wrap stream
if
input_stream
is
not
None
:
if
input_stream
is
not
None
:
input_factory
=
StreamTimeseriesFactory
(
input_factory
=
StreamTimeseriesFactory
(
...
@@ -615,16 +618,6 @@ def get_output_factory(args):
...
@@ -615,16 +618,6 @@ def get_output_factory(args):
forceout
=
args
.
output_edge_forceout
,
forceout
=
args
.
output_edge_forceout
,
**
output_factory_args
,
**
output_factory_args
,
)
)
elif
output_type
==
"
miniseed
"
:
# TODO: deal with other miniseed arguments
locationcode
=
args
.
outlocationcode
or
args
.
locationcode
or
None
output_factory
=
edge
.
MiniSeedFactory
(
host
=
args
.
output_host
,
port
=
args
.
output_read_port
,
write_port
=
args
.
output_port
,
locationCode
=
locationcode
,
**
output_factory_args
,
)
elif
output_type
==
"
plot
"
:
elif
output_type
==
"
plot
"
:
output_factory
=
PlotTimeseriesFactory
()
output_factory
=
PlotTimeseriesFactory
()
else
:
else
:
...
@@ -641,6 +634,16 @@ def get_output_factory(args):
...
@@ -641,6 +634,16 @@ def get_output_factory(args):
output_factory
=
temperature
.
TEMPFactory
(
**
output_factory_args
)
output_factory
=
temperature
.
TEMPFactory
(
**
output_factory_args
)
elif
output_type
==
"
vbf
"
:
elif
output_type
==
"
vbf
"
:
output_factory
=
vbf
.
VBFFactory
(
**
output_factory_args
)
output_factory
=
vbf
.
VBFFactory
(
**
output_factory_args
)
elif
output_type
==
"
miniseed
"
:
# TODO: deal with other miniseed arguments
locationcode
=
args
.
outlocationcode
or
args
.
locationcode
or
None
output_factory
=
edge
.
MiniSeedFactory
(
host
=
args
.
output_host
,
port
=
args
.
output_read_port
,
write_port
=
args
.
output_port
,
locationCode
=
locationcode
,
**
output_factory_args
,
)
# wrap stream
# wrap stream
if
output_stream
is
not
None
:
if
output_stream
is
not
None
:
output_factory
=
StreamTimeseriesFactory
(
output_factory
=
StreamTimeseriesFactory
(
...
...
This diff is collapsed.
Click to expand it.
geomagio/edge/MiniSeedFactory.py
+
51
−
0
View file @
ff4a458f
...
@@ -10,11 +10,13 @@ Edge is the USGS earthquake hazard centers replacement for earthworm.
...
@@ -10,11 +10,13 @@ Edge is the USGS earthquake hazard centers replacement for earthworm.
"""
"""
from
__future__
import
absolute_import
from
__future__
import
absolute_import
import
io
import
sys
import
sys
from
typing
import
List
,
Optional
from
typing
import
List
,
Optional
import
numpy
import
numpy
import
numpy.ma
import
numpy.ma
from
obspy
import
read
from
obspy.clients.neic
import
client
as
miniseed
from
obspy.clients.neic
import
client
as
miniseed
from
obspy.core
import
Stats
,
Stream
,
Trace
,
UTCDateTime
from
obspy.core
import
Stats
,
Stream
,
Trace
,
UTCDateTime
...
@@ -596,3 +598,52 @@ class MiniSeedFactory(TimeseriesFactory):
...
@@ -596,3 +598,52 @@ class MiniSeedFactory(TimeseriesFactory):
self
.
observatoryMetadata
.
set_metadata
(
self
.
observatoryMetadata
.
set_metadata
(
trace
.
stats
,
observatory
,
channel
,
type
,
interval
trace
.
stats
,
observatory
,
channel
,
type
,
interval
)
)
def
parse_string
(
self
,
data
:
str
,
**
kwargs
)
->
Stream
:
"""
Parse a MiniSEED byte string into an ObsPy Stream.
Parameters
----------
data : str
The MiniSEED content (binary) in string form.
Returns
-------
Stream
An ObsPy Stream object containing the parsed MiniSEED data.
"""
try
:
# If data is already bytes, this is a no-op; if data is a Python string
# containing binary content, encode to bytes.
if
not
isinstance
(
data
,
bytes
):
data
=
data
.
encode
(
"
utf-8
"
,
errors
=
"
ignore
"
)
with
io
.
BytesIO
(
data
)
as
bio
:
st
=
read
(
bio
,
format
=
"
MSEED
"
)
return
st
except
Exception
as
e
:
print
(
f
"
Failed to parse MiniSEED data:
{
str
(
e
)
}
"
)
return
Stream
()
def
write_file
(
self
,
fh
,
timeseries
:
Stream
,
channels
:
list
):
"""
Write an ObsPy Stream to a file handle in MiniSEED format.
Parameters
----------
fh : file-like (writable)
A file handle where data is written. Could be an open file or BytesIO.
timeseries : Stream
Stream containing traces to store.
"""
try
:
# Write to MiniSEED
ts
=
Stream
()
for
channel
in
channels
:
ts
+=
timeseries
.
select
(
channel
=
channel
)
ts
.
write
(
fh
,
format
=
"
MSEED
"
)
except
Exception
as
e
:
raise
TimeseriesFactoryException
(
f
"
Error writing MiniSEED to file:
{
str
(
e
)
}
"
)
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