From efde8d12af4e00168c4cc8b6982017f6610e3fb1 Mon Sep 17 00:00:00 2001 From: Jeremy Fee <jmfee@usgs.gov> Date: Fri, 13 May 2016 12:23:00 -0600 Subject: [PATCH] Update parse_string to accept observatory, type, interval, and channels being parsed --- geomagio/TimeseriesFactory.py | 8 ++++++-- geomagio/iaga2002/IAGA2002Factory.py | 10 ++++++---- geomagio/iaga2002/StreamIAGA2002Factory.py | 4 +++- geomagio/imfv283/IMFV283Factory.py | 6 +++--- geomagio/pcdcp/PCDCPFactory.py | 6 +++--- geomagio/pcdcp/StreamPCDCPFactory.py | 4 +++- 6 files changed, 24 insertions(+), 14 deletions(-) diff --git a/geomagio/TimeseriesFactory.py b/geomagio/TimeseriesFactory.py index 2a99522f5..fb0ba2f64 100644 --- a/geomagio/TimeseriesFactory.py +++ b/geomagio/TimeseriesFactory.py @@ -105,7 +105,11 @@ class TimeseriesFactory(object): channels=channels) data = Util.read_url(url) try: - timeseries += self.parse_string(data) + timeseries += self.parse_string(data, + observatory=observatory, + type=type, + interval=interval, + channels=channels) except NotImplementedError: raise NotImplementedError('"get_timeseries" not implemented') except Exception as e: @@ -115,7 +119,7 @@ class TimeseriesFactory(object): timeseries.trim(starttime, endtime) return timeseries - def parse_string(self, data): + def parse_string(self, data, **kwargs): """Parse the contents of a string in the format of an IAGA2002 file. Parameters diff --git a/geomagio/iaga2002/IAGA2002Factory.py b/geomagio/iaga2002/IAGA2002Factory.py index 83154283b..0faadc7e7 100644 --- a/geomagio/iaga2002/IAGA2002Factory.py +++ b/geomagio/iaga2002/IAGA2002Factory.py @@ -34,21 +34,23 @@ class IAGA2002Factory(TimeseriesFactory): def __init__(self, **kwargs): TimeseriesFactory.__init__(self, **kwargs) - def parse_string(self, iaga2002String): + def parse_string(self, data, observatory=None, **kwargs): """Parse the contents of a string in the format of an IAGA2002 file. Parameters ---------- iaga2002String : str string containing IAGA2002 content. - + observatory : str + observatory in case headers are unavailable. + parses observatory from headers when available. Returns ------- obspy.core.Stream parsed data. """ - parser = IAGA2002Parser() - parser.parse(iaga2002String) + parser = IAGA2002Parser(observatory=observatory) + parser.parse(data) metadata = parser.metadata starttime = obspy.core.UTCDateTime(parser.times[0]) endtime = obspy.core.UTCDateTime(parser.times[-1]) diff --git a/geomagio/iaga2002/StreamIAGA2002Factory.py b/geomagio/iaga2002/StreamIAGA2002Factory.py index 208a190ba..7532aef0a 100644 --- a/geomagio/iaga2002/StreamIAGA2002Factory.py +++ b/geomagio/iaga2002/StreamIAGA2002Factory.py @@ -28,7 +28,9 @@ class StreamIAGA2002Factory(IAGA2002Factory): Notes: Calls IAGA2002Factory.parse_string in place of IAGA2002Factory.get_timeseries. """ - return IAGA2002Factory.parse_string(self, self._stream.read()) + return IAGA2002Factory.parse_string(self, + data=self._stream.read(), + observatory=observatory) def put_timeseries(self, timeseries, starttime=None, endtime=None, channels=None, type=None, interval=None): diff --git a/geomagio/imfv283/IMFV283Factory.py b/geomagio/imfv283/IMFV283Factory.py index f7b493f7e..effeec974 100644 --- a/geomagio/imfv283/IMFV283Factory.py +++ b/geomagio/imfv283/IMFV283Factory.py @@ -70,12 +70,12 @@ class IMFV283Factory(TimeseriesFactory): stats.channel, 'variation', 'minute') return timeseries - def parse_string(self, imfV283String): + def parse_string(self, data, **kwargs): """Parse the contents of a string in the format of an IMFV283 file. Parameters ---------- - IMFV283String : str + data : str string containing IMFV283 content. Returns @@ -84,7 +84,7 @@ class IMFV283Factory(TimeseriesFactory): parsed data. """ parser = IMFV283Parser() - parser.parse(imfV283String) + parser.parse(data) stream = parser.stream stream.merge() diff --git a/geomagio/pcdcp/PCDCPFactory.py b/geomagio/pcdcp/PCDCPFactory.py index 0cfc04d20..107d9bbe3 100644 --- a/geomagio/pcdcp/PCDCPFactory.py +++ b/geomagio/pcdcp/PCDCPFactory.py @@ -36,12 +36,12 @@ class PCDCPFactory(TimeseriesFactory): def __init__(self, **kwargs): TimeseriesFactory.__init__(self, **kwargs) - def parse_string(self, pcdcpString): + def parse_string(self, data, **kwargs): """Parse the contents of a string in the format of a pcdcp file. Parameters ---------- - pcdcpString : str + data : str String containing PCDCP content. Returns @@ -50,7 +50,7 @@ class PCDCPFactory(TimeseriesFactory): Parsed data. """ parser = PCDCPParser() - parser.parse(pcdcpString) + parser.parse(data) yr = int(parser.header['year']) yrday = int(parser.header['yearday']) diff --git a/geomagio/pcdcp/StreamPCDCPFactory.py b/geomagio/pcdcp/StreamPCDCPFactory.py index c7bc52925..312e9361c 100644 --- a/geomagio/pcdcp/StreamPCDCPFactory.py +++ b/geomagio/pcdcp/StreamPCDCPFactory.py @@ -28,7 +28,9 @@ class StreamPCDCPFactory(PCDCPFactory): Notes: Calls PCDCPFactory.parse_string in place of PCDCPFactory.get_timeseries. """ - return PCDCPFactory.parse_string(self, self._stream.read()) + return PCDCPFactory.parse_string(self, + data=self._stream.read(), + observatory=observatory) def put_timeseries(self, timeseries, starttime=None, endtime=None, channels=None, type=None, interval=None): -- GitLab