diff --git a/geomagio/pcdcp/PCDCPFactory.py b/geomagio/pcdcp/PCDCPFactory.py index 03b6eb084820bff78baf84371eb7c0c3c4d84ddb..5941528de90c42395fd4c348fbe20bd041e647de 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 dfdde37c4a32cab4a1625c03108f5bacf2e2cf24..f3108c10d57df0d675e0044a7f6eae595b82e9c9 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 e71ad8dc0090e78298262a0ef4929898aec64cb2..ebf5377db7416407cde1cb0e4ee3bc084bb9435d 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 9865fc9b8520de3d5955f53d482a221f4c2bc45a..1522e311e20dcfa9f31847fa9bed4542919f282d 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, )