Skip to content
Snippets Groups Projects
Commit f3b2b991 authored by Erin (Josh) Rigler's avatar Erin (Josh) Rigler
Browse files

Merge branch 'edge_migration_01' into 'master'

Migrating to new edge config - stage 01

See merge request !289
parents c1e6fbb1 1849c616
No related branches found
No related tags found
1 merge request!289Migrating to new edge config - stage 01
Pipeline #372713 passed
...@@ -16,7 +16,7 @@ from typing import List, Optional ...@@ -16,7 +16,7 @@ from typing import List, Optional
import numpy import numpy
import numpy.ma import numpy.ma
from obspy import Stream, Trace, UTCDateTime from obspy import Stream, Trace, UTCDateTime
from obspy.clients import earthworm from obspy.clients import earthworm, neic
from .. import ChannelConverter, TimeseriesUtility from .. import ChannelConverter, TimeseriesUtility
from ..geomag_types import DataInterval, DataType from ..geomag_types import DataInterval, DataType
...@@ -24,6 +24,7 @@ from ..TimeseriesFactory import TimeseriesFactory ...@@ -24,6 +24,7 @@ from ..TimeseriesFactory import TimeseriesFactory
from ..TimeseriesFactoryException import TimeseriesFactoryException from ..TimeseriesFactoryException import TimeseriesFactoryException
from ..ObservatoryMetadata import ObservatoryMetadata from ..ObservatoryMetadata import ObservatoryMetadata
from .RawInputClient import RawInputClient from .RawInputClient import RawInputClient
from .SNCL import SNCL
from .LegacySNCL import LegacySNCL from .LegacySNCL import LegacySNCL
...@@ -38,8 +39,6 @@ class EdgeFactory(TimeseriesFactory): ...@@ -38,8 +39,6 @@ class EdgeFactory(TimeseriesFactory):
the port number the waveserver is listening on. the port number the waveserver is listening on.
write_port: integer write_port: integer
the port number the client is writing to. the port number the client is writing to.
cwbport: int
the port number of the cwb host to connect to.
tag: str tag: str
A tag used by edge to log and associate a socket with a given data A tag used by edge to log and associate a socket with a given data
source source
...@@ -62,8 +61,13 @@ class EdgeFactory(TimeseriesFactory): ...@@ -62,8 +61,13 @@ class EdgeFactory(TimeseriesFactory):
locationCode: str locationCode: str
the location code for the given edge server, overrides type the location code for the given edge server, overrides type
in get_timeseries/put_timeseries in get_timeseries/put_timeseries
cwbhost: str scaleFactor: int
a string represeting the IP number of the cwb host to connect to. all data written to edge (via raw input client) will be scaled
by this integer prior to write; all data read from edge will be
will be divided by this integer after read; default = 1000
snclMapper: {'geomag','legacy'}
a mapper of common channel names to SEED SNCL codes (that is,
station, network, channel, location codes); default = legacy
See Also See Also
-------- --------
...@@ -82,7 +86,6 @@ class EdgeFactory(TimeseriesFactory): ...@@ -82,7 +86,6 @@ class EdgeFactory(TimeseriesFactory):
host: str = "edgecwb.usgs.gov", host: str = "edgecwb.usgs.gov",
port: int = 2060, port: int = 2060,
write_port: int = 7981, write_port: int = 7981,
cwbport: int = 0,
tag: str = "GeomagAlg", tag: str = "GeomagAlg",
forceout: bool = False, forceout: bool = False,
observatory: Optional[str] = None, observatory: Optional[str] = None,
...@@ -91,20 +94,31 @@ class EdgeFactory(TimeseriesFactory): ...@@ -91,20 +94,31 @@ class EdgeFactory(TimeseriesFactory):
interval: Optional[DataInterval] = None, interval: Optional[DataInterval] = None,
observatoryMetadata: Optional[ObservatoryMetadata] = None, observatoryMetadata: Optional[ObservatoryMetadata] = None,
locationCode: Optional[str] = None, locationCode: Optional[str] = None,
cwbhost: Optional[str] = None, scaleFactor: int = 1000,
snclMapper: str = "legacy",
): ):
TimeseriesFactory.__init__(self, observatory, channels, type, interval) TimeseriesFactory.__init__(self, observatory, channels, type, interval)
self.client = earthworm.Client(host, port) if port == 2060:
# earthworm (phasing this out gradually)
self.client = earthworm.Client(host, port)
else:
# CWBQuery/miniseed protocol (preferred)
self.client = neic.Client(host, port)
self.host = host self.host = host
self.port = port self.port = port
self.write_port = write_port self.write_port = write_port
self.cwbport = cwbport
self.tag = tag self.tag = tag
self.forceout = forceout self.forceout = forceout
self.interval = interval self.interval = interval
self.observatoryMetadata = observatoryMetadata or ObservatoryMetadata() self.observatoryMetadata = observatoryMetadata or ObservatoryMetadata()
self.locationCode = locationCode self.locationCode = locationCode
self.cwbhost = cwbhost or "" self.scaleFactor = scaleFactor
if snclMapper == "legacy":
self.get_sncl = LegacySNCL.get_sncl
elif snclMapper == "geomag":
self.get_sncl = SNCL.get_sncl
else:
raise TimeseriesFactoryException("Unrecognized SNCL mapper")
def get_timeseries( def get_timeseries(
self, self,
...@@ -248,7 +262,7 @@ class EdgeFactory(TimeseriesFactory): ...@@ -248,7 +262,7 @@ class EdgeFactory(TimeseriesFactory):
make a copy before calling if they don't want that side effect. make a copy before calling if they don't want that side effect.
""" """
for trace in stream: for trace in stream:
trace.data = numpy.divide(trace.data, 1000.00) trace.data = numpy.divide(trace.data, self.scaleFactor)
def _convert_trace_to_int(self, trace_in: Trace) -> Trace: def _convert_trace_to_int(self, trace_in: Trace) -> Trace:
"""convert geomag edge traces stored as decimal, to ints by multiplying """convert geomag edge traces stored as decimal, to ints by multiplying
...@@ -268,7 +282,7 @@ class EdgeFactory(TimeseriesFactory): ...@@ -268,7 +282,7 @@ class EdgeFactory(TimeseriesFactory):
the trace must be a masked array. the trace must be a masked array.
""" """
trace = trace_in.copy() trace = trace_in.copy()
trace.data = numpy.multiply(trace.data, 1000.00) trace.data = numpy.multiply(trace.data, self.scaleFactor)
trace.data = trace.data.astype(int) trace.data = trace.data.astype(int)
return trace return trace
...@@ -326,7 +340,7 @@ class EdgeFactory(TimeseriesFactory): ...@@ -326,7 +340,7 @@ class EdgeFactory(TimeseriesFactory):
data: Trace data: Trace
timeseries trace of the requested channel data timeseries trace of the requested channel data
""" """
sncl = LegacySNCL.get_sncl( sncl = self.get_sncl(
station=observatory, station=observatory,
data_type=type, data_type=type,
interval=interval, interval=interval,
...@@ -437,7 +451,7 @@ class EdgeFactory(TimeseriesFactory): ...@@ -437,7 +451,7 @@ class EdgeFactory(TimeseriesFactory):
----- -----
RawInputClient seems to only work when sockets are RawInputClient seems to only work when sockets are
""" """
sncl = LegacySNCL.get_sncl( sncl = self.get_sncl(
station=observatory, station=observatory,
data_type=type, data_type=type,
interval=interval, interval=interval,
...@@ -445,18 +459,10 @@ class EdgeFactory(TimeseriesFactory): ...@@ -445,18 +459,10 @@ class EdgeFactory(TimeseriesFactory):
location=self.locationCode, location=self.locationCode,
) )
now = UTCDateTime(datetime.utcnow())
if ((now - endtime) > 864000) and (self.cwbport > 0):
host = self.cwbhost
port = self.cwbport
else:
host = self.host
port = self.write_port
ric = RawInputClient( ric = RawInputClient(
self.tag, self.tag,
host, self.host,
port, self.write_port,
sncl.station, sncl.station,
sncl.channel, sncl.channel,
sncl.location, sncl.location,
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment