From 06a629a040ad2ce08a16d12f53e5fa1e2efd8e9a Mon Sep 17 00:00:00 2001 From: "E. Joshua Rigler" <erigler@usgs.gov> Date: Fri, 5 Jan 2024 19:47:19 -0700 Subject: [PATCH] Instantiate EdgeFactory with a scaleFactor Prior to this, a scale factor of 1000 was applied to all data written (via raw input client) prior to writing to edge server. This is still the default, but now user can change this scale factor. This will allow the EdgeFactory to be used to read data it did not write, and rescale it if necessary. Note: default is 1000, not 1, for backward compatibility. --- geomagio/edge/EdgeFactory.py | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/geomagio/edge/EdgeFactory.py b/geomagio/edge/EdgeFactory.py index 7f681f25..87e254c2 100644 --- a/geomagio/edge/EdgeFactory.py +++ b/geomagio/edge/EdgeFactory.py @@ -60,6 +60,10 @@ class EdgeFactory(TimeseriesFactory): locationCode: str the location code for the given edge server, overrides type in get_timeseries/put_timeseries + scaleFactor: int + 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 See Also -------- @@ -86,6 +90,7 @@ class EdgeFactory(TimeseriesFactory): interval: Optional[DataInterval] = None, observatoryMetadata: Optional[ObservatoryMetadata] = None, locationCode: Optional[str] = None, + scaleFactor: int = 1000, ): TimeseriesFactory.__init__(self, observatory, channels, type, interval) if port == 2060: @@ -102,6 +107,7 @@ class EdgeFactory(TimeseriesFactory): self.interval = interval self.observatoryMetadata = observatoryMetadata or ObservatoryMetadata() self.locationCode = locationCode + self.scaleFactor = scaleFactor def get_timeseries( self, @@ -245,7 +251,7 @@ class EdgeFactory(TimeseriesFactory): make a copy before calling if they don't want that side effect. """ 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: """convert geomag edge traces stored as decimal, to ints by multiplying @@ -265,7 +271,7 @@ class EdgeFactory(TimeseriesFactory): the trace must be a masked array. """ 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) return trace -- GitLab