From 415df92bdbe4c043e2e1752e5ea94ab2bd0f8873 Mon Sep 17 00:00:00 2001 From: pcain-usgs <pcain@usgs.gov> Date: Tue, 30 Jun 2020 11:41:12 -0600 Subject: [PATCH] Create temperatures option in writer --- geomagio/pcdcp/PCDCPFactory.py | 7 +++++-- geomagio/pcdcp/PCDCPParser.py | 2 ++ geomagio/pcdcp/PCDCPWriter.py | 13 +++++++++---- geomagio/processing/magproc.py | 6 +++++- 4 files changed, 21 insertions(+), 7 deletions(-) diff --git a/geomagio/pcdcp/PCDCPFactory.py b/geomagio/pcdcp/PCDCPFactory.py index 03b6eb084..5941528de 100644 --- a/geomagio/pcdcp/PCDCPFactory.py +++ b/geomagio/pcdcp/PCDCPFactory.py @@ -35,8 +35,11 @@ class PCDCPFactory(TimeseriesFactory): PCDCPParser """ - def __init__(self, **kwargs): + def __init__( + self, temperatures=False, **kwargs, + ): TimeseriesFactory.__init__(self, **kwargs) + self.temperatures = temperatures def parse_string(self, data, **kwargs): """Parse the contents of a string in the format of a pcdcp file. @@ -118,4 +121,4 @@ class PCDCPFactory(TimeseriesFactory): channels : array_like list of channels to store """ - PCDCPWriter().write(fh, timeseries, channels) + PCDCPWriter(temperatures=self.temperatures).write(fh, timeseries, channels) diff --git a/geomagio/pcdcp/PCDCPParser.py b/geomagio/pcdcp/PCDCPParser.py index dfdde37c4..f3108c10d 100644 --- a/geomagio/pcdcp/PCDCPParser.py +++ b/geomagio/pcdcp/PCDCPParser.py @@ -81,6 +81,8 @@ class PCDCPParser(object): if "nT" in self.header["resolution"]: self.resolution = float(self.header["resolution"].split("nT")[0]) + else: + self.resolution = float(self.header["resolution"].split("*")[1]) return diff --git a/geomagio/pcdcp/PCDCPWriter.py b/geomagio/pcdcp/PCDCPWriter.py index e71ad8dc0..ebf5377db 100644 --- a/geomagio/pcdcp/PCDCPWriter.py +++ b/geomagio/pcdcp/PCDCPWriter.py @@ -14,8 +14,9 @@ class PCDCPWriter(object): """PCDCP writer. """ - def __init__(self, empty_value=PCDCPParser.NINES): + def __init__(self, empty_value=PCDCPParser.NINES, temperatures=False): self.empty_value = empty_value + self.temperatures = temperatures def write(self, out, timeseries, channels): """Write timeseries to pcdcp file. @@ -65,17 +66,17 @@ class PCDCPWriter(object): yearday = str(stats.starttime.julday).zfill(3) date = stats.starttime.strftime("%d-%b-%y") - if channels != ["H", "E", "Z", "F"]: + if self.temperatures == True: resolution = "Deg-C*10" channel_str = " ".join(channels) - version = " File Version 1.00\n" + version = "1.00" else: # Choose resolution for 1-sec vs 1-min header. resolution = "0.01nT" if stats.delta == 1: resolution = "0.001nT" channel_str = "".join(channels) - version = " File Version 2.00\n" + version = "2.00" buf.append( observatory @@ -89,7 +90,9 @@ class PCDCPWriter(object): + channel_str + " " + resolution + + " File Version " + version + + "\n" ) return "".join(buf) @@ -164,6 +167,8 @@ class PCDCPWriter(object): time_width = 4 data_width = 8 data_multiplier = 100 + if self.temperatures == True: + data_multiplier = 10 hr_multiplier = 60 mn_multiplier = 1 sc_multiplier = 0 diff --git a/geomagio/processing/magproc.py b/geomagio/processing/magproc.py index 9865fc9b8..1522e311e 100644 --- a/geomagio/processing/magproc.py +++ b/geomagio/processing/magproc.py @@ -94,8 +94,11 @@ def write_pcdcp_file( interval: str, channels: List[str], template: str = PCDCP_FILE_PATTERN, + temperatures=False, ): - PCDCPFactory(urlInterval=86400, urlTemplate=template).put_timeseries( + PCDCPFactory( + urlInterval=86400, urlTemplate=template, temperatures=temperatures + ).put_timeseries( timeseries=timeseries, starttime=starttime, endtime=endtime, @@ -143,6 +146,7 @@ def write_temperature_data( interval="hourly", channels=["UK1", "UK2", "UK3", "UK4"], template=template, + temperatures=True, ) -- GitLab