From 33b48289ea5e3356e5e087a8c7fa55f12527f4fd Mon Sep 17 00:00:00 2001 From: "E. Joshua Rigler" <erigler@usgs.gov> Date: Mon, 1 Oct 2018 15:47:06 -0600 Subject: [PATCH] Properly handle adjusted/provisional data type - allow adjusted and provisional strings in --type controller argument - allow adjusted, provisional, and definitive strings in _get_url() in TimeseriesFactory - return appropriate abbreviation for adjusted/provisional data type - translate adjuste/prvisional to A0 location code in EdgeFactory - only write out DECBAS for variation/reported data types - translate adjusted/provisional to A0 location code in IMFJSONWriter.py - in several places I set it up so that 'variation' and 'reported' were synonymous, although I am not sure I found every such instance. --- geomagio/Controller.py | 7 ++++++- geomagio/TimeseriesFactory.py | 18 ++++++++++++------ geomagio/edge/EdgeFactory.py | 4 +++- geomagio/iaga2002/IAGA2002Writer.py | 4 +++- geomagio/imfjson/IMFJSONWriter.py | 6 +++++- 5 files changed, 29 insertions(+), 10 deletions(-) diff --git a/geomagio/Controller.py b/geomagio/Controller.py index 346070be5..2a1515c55 100644 --- a/geomagio/Controller.py +++ b/geomagio/Controller.py @@ -605,7 +605,12 @@ def parse_args(args): help='Channels H, E, Z, etc') parser.add_argument('--type', default='variation', - choices=['variation', 'quasi-definitive', 'definitive']) + choices=['variation', + 'reported', + 'provisional', + 'adjusted', + 'quasi-definitive', + 'definitive']) parser.add_argument('--rename-input-channel', action='append', help='Rename an input channel after it is read', diff --git a/geomagio/TimeseriesFactory.py b/geomagio/TimeseriesFactory.py index 3f08bac14..ecf1e3d5f 100644 --- a/geomagio/TimeseriesFactory.py +++ b/geomagio/TimeseriesFactory.py @@ -308,7 +308,8 @@ class TimeseriesFactory(object): observatory code. date : obspy.core.UTCDateTime day to fetch (only year, month, day are used) - type : {'variation', 'quasi-definitive', 'definitive'} + type : {'variation', 'reported', 'provisional', 'adjusted', + 'quasi-definitive', 'definitive'} data type. interval : {'minute', 'second', 'hourly', 'daily'} data interval. @@ -431,11 +432,11 @@ class TimeseriesFactory(object): type_abbr = None if type == 'definitive': type_abbr = 'd' - elif type == 'provisional': + elif type == 'provisional' or type == 'adjusted': type_abbr = 'p' elif type == 'quasi-definitive': type_abbr = 'q' - elif type == 'variation': + elif type == 'variation' or 'reported': type_abbr = 'v' else: raise TimeseriesFactoryException( @@ -449,7 +450,8 @@ class TimeseriesFactory(object): Parameters ---------- - type : {'variation', 'quasi-definitive'} + type : {'variation', 'reported', 'provisional', 'adjusted', + 'quasi-definitive', 'quasidefinitive', 'definitive' } Returns ------- @@ -461,10 +463,14 @@ class TimeseriesFactory(object): if ``type`` is not supported. """ type_name = None - if type == 'variation': + if type == 'variation' or type == 'reported': type_name = '' - elif type == 'quasi-definitive': + elif type == 'provisional' or type == 'adjusted': + type_name = 'Provisional' + elif type == 'quasi-definitive' or type == 'quasidefinitive': type_name = 'QuasiDefinitive' + elif type == 'definitive': + type_name = 'Definitive' else: raise TimeseriesFactoryException( 'Unsupported type "%s"' % type) diff --git a/geomagio/edge/EdgeFactory.py b/geomagio/edge/EdgeFactory.py index 048251551..4f3811f7d 100644 --- a/geomagio/edge/EdgeFactory.py +++ b/geomagio/edge/EdgeFactory.py @@ -440,8 +440,10 @@ class EdgeFactory(TimeseriesFactory): if self.locationCode is not None: location = self.locationCode else: - if type == 'variation': + if type == 'variation' or type == 'reported': location = 'R0' + elif type == 'adjusted' or type == 'provisional': + location = 'A0' elif type == 'quasi-definitive': location = 'Q0' elif type == 'definitive': diff --git a/geomagio/iaga2002/IAGA2002Writer.py b/geomagio/iaga2002/IAGA2002Writer.py index 461daa08b..c9769160d 100644 --- a/geomagio/iaga2002/IAGA2002Writer.py +++ b/geomagio/iaga2002/IAGA2002Writer.py @@ -106,7 +106,9 @@ class IAGA2002Writer(object): an array containing formatted strings of header data. """ comments = [] - if 'declination_base' in stats and stats.declination_base is not None: + if ('declination_base' in stats and + stats.declination_base is not None and + (stats.data_type == 'variation' or stats.data_type == 'reported')): comments.append('DECBAS {:<8d}' '(Baseline declination value in tenths of minutes East' ' (0-216,000)).'.format(stats.declination_base)) diff --git a/geomagio/imfjson/IMFJSONWriter.py b/geomagio/imfjson/IMFJSONWriter.py index 91c6f5aa9..cc3c213c2 100644 --- a/geomagio/imfjson/IMFJSONWriter.py +++ b/geomagio/imfjson/IMFJSONWriter.py @@ -78,8 +78,12 @@ class IMFJSONWriter(object): edge_channel = trace.stats.channel metadata['channel'] = edge_channel if stats.location == "": - if stats.data_type == 'variation': + if (stats.data_type == 'variation' or + stats.data_type == 'reported'): stats.location = 'R0' + elif (stats.data_type == 'adjusted' or + stats.data_type == 'provisional'): + stats.location = 'A0' elif stats.data_type == 'quasi-definitive': stats.location = 'Q0' elif stats.data_type == 'definitive': -- GitLab