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

Fix minor unit test failures:

- MiniSeedInputClient expects a stream as input, not a trace
  (like RawInputClient), and unit tests were designed around this;
  I reverted _put_channel() to its original design, which sends an
  entire stream instead of one trace at a time.
- I forgot to include a tiny change to RawInputClient_test that was
  part of the original (abandoned) MR
- I also made the read client timeout configurable
parent 2e7a766f
No related branches found
No related tags found
1 merge request!386Overhaul EdgeFactory and MiniSeedFactory for Edge data migration
This commit is part of merge request !386. Comments created here will be created in the context of that merge request.
...@@ -70,6 +70,8 @@ class MiniSeedFactory(TimeseriesFactory): ...@@ -70,6 +70,8 @@ class MiniSeedFactory(TimeseriesFactory):
sncl_mode: {'geomag','legacy'} sncl_mode: {'geomag','legacy'}
force mode to convert common names to SEED SNCL codes (that is, force mode to convert common names to SEED SNCL codes (that is,
station, network, channel, location codes); default = legacy station, network, channel, location codes); default = legacy
timeout: float
timeout for NEIC client; default=10
See Also See Also
-------- --------
...@@ -105,6 +107,7 @@ class MiniSeedFactory(TimeseriesFactory): ...@@ -105,6 +107,7 @@ class MiniSeedFactory(TimeseriesFactory):
convert_channels: Optional[List[str]] = None, convert_channels: Optional[List[str]] = None,
scale_factor: Optional[int] = None, scale_factor: Optional[int] = None,
sncl_mode: Optional[str] = "geomag", sncl_mode: Optional[str] = "geomag",
timeout: Optional[float] = None,
): ):
TimeseriesFactory.__init__(self, observatory, channels, type, interval) TimeseriesFactory.__init__(self, observatory, channels, type, interval)
self.host = host or "edgecwb.usgs.gov" self.host = host or "edgecwb.usgs.gov"
...@@ -116,6 +119,7 @@ class MiniSeedFactory(TimeseriesFactory): ...@@ -116,6 +119,7 @@ class MiniSeedFactory(TimeseriesFactory):
self.convert_channels = convert_channels or [] self.convert_channels = convert_channels or []
self.scale_factor = scale_factor self.scale_factor = scale_factor
self.sncl_mode = sncl_mode self.sncl_mode = sncl_mode
self.timeout = timeout or 10
if sncl_mode == "legacy": if sncl_mode == "legacy":
self.get_sncl = LegacySNCL.get_sncl self.get_sncl = LegacySNCL.get_sncl
elif sncl_mode == "geomag": elif sncl_mode == "geomag":
...@@ -123,6 +127,10 @@ class MiniSeedFactory(TimeseriesFactory): ...@@ -123,6 +127,10 @@ class MiniSeedFactory(TimeseriesFactory):
else: else:
raise TimeseriesFactoryException("Unrecognized SNCL mode") raise TimeseriesFactoryException("Unrecognized SNCL mode")
# instantiate clients immediately; allows mock clients if/when needed
self.client = neic.Client(self.host)
self.write_client = MiniSeedInputClient(self.host)
def get_timeseries( def get_timeseries(
self, self,
starttime: UTCDateTime, starttime: UTCDateTime,
...@@ -262,6 +270,8 @@ class MiniSeedFactory(TimeseriesFactory): ...@@ -262,6 +270,8 @@ class MiniSeedFactory(TimeseriesFactory):
starttime, starttime,
endtime, endtime,
) )
# close socket
self.write_client.close()
def get_calculated_timeseries( def get_calculated_timeseries(
self, self,
...@@ -407,9 +417,11 @@ class MiniSeedFactory(TimeseriesFactory): ...@@ -407,9 +417,11 @@ class MiniSeedFactory(TimeseriesFactory):
data = Stream() data = Stream()
for port in ports: for port in ports:
try: try:
client = neic.Client(self.host, port, timeout=10)
data += client.get_waveforms( self.client.port = port
self.client.timeout = self.timeout
data += self.client.get_waveforms(
sncl.network, sncl.network,
sncl.station, sncl.station,
sncl.location, sncl.location,
...@@ -638,9 +650,8 @@ class MiniSeedFactory(TimeseriesFactory): ...@@ -638,9 +650,8 @@ class MiniSeedFactory(TimeseriesFactory):
stream_masked = self._convert_stream_to_masked( stream_masked = self._convert_stream_to_masked(
timeseries=timeseries, channel=channel timeseries=timeseries, channel=channel
) )
stream_split = stream_masked.split() stream_send = Stream()
for trace in stream_masked.split():
for trace in stream_split:
trace_send = trace.copy() trace_send = trace.copy()
trace_send.trim(starttime, endtime) trace_send.trim(starttime, endtime)
if channel == "D": if channel == "D":
...@@ -657,21 +668,18 @@ class MiniSeedFactory(TimeseriesFactory): ...@@ -657,21 +668,18 @@ class MiniSeedFactory(TimeseriesFactory):
# everything else (mostly magnetics stored as picoteslas) # everything else (mostly magnetics stored as picoteslas)
trace_send.data = trace_send.data * (self.scale_factor or 1e3) trace_send.data = trace_send.data * (self.scale_factor or 1e3)
if self.write_port: trace_send.stats.station = sncl.station
# FIXME: input clients should be rewritten for consistency, trace_send.stats.location = sncl.location
# allowing us to clean up stuff like this if-else-block trace_send.stats.network = sncl.network
msic = MiniSeedInputClient( trace_send.stats.channel = sncl.channel
self.host, self.write_port, self.write_encoding stream_send += trace_send
) # FIXME: MiniSeedInputClient sends a stream, while
trace_send.stats.station = sncl.station # RawInputClient sends a trace; these write
trace_send.stats.location = sncl.location # clients should be re-written for consistency
trace_send.stats.network = sncl.network self.write_client.host = self.host
trace_send.stats.channel = sncl.channel self.write_client.port = self.write_port
stream_send = Stream(trace_send) self.write_client.encoding = self.write_encoding
msic.send(stream_send) self.write_client.send(stream_send)
msic.close()
else:
raise TimeseriesFactoryException("Valid write port was not specified.")
def _set_metadata( def _set_metadata(
self, self,
......
...@@ -51,7 +51,8 @@ def test_raw_input_client(): ...@@ -51,7 +51,8 @@ def test_raw_input_client():
location=location, location=location,
network=network, network=network,
) )
trace_send = EdgeFactory()._convert_trace_to_int(trace.copy()) trace_send = trace.copy()
trace_send.data = numpy.int32(trace_send.data * 1000)
client.send_trace("minute", trace_send) client.send_trace("minute", trace_send)
# verify data was sent # verify data was sent
assert_equal(len(client.last_send), 1) assert_equal(len(client.last_send), 1)
......
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