From b72580570c947daab330e081575e89c3b730e472 Mon Sep 17 00:00:00 2001 From: Jeremy Fee <jmfee@usgs.gov> Date: Fri, 13 May 2016 13:28:22 -0600 Subject: [PATCH] Make less common IAGAWriter header fields optional --- geomagio/iaga2002/IAGA2002Writer.py | 37 ++++++++++++++++++----------- 1 file changed, 23 insertions(+), 14 deletions(-) diff --git a/geomagio/iaga2002/IAGA2002Writer.py b/geomagio/iaga2002/IAGA2002Writer.py index cd070075a..b54052f6a 100644 --- a/geomagio/iaga2002/IAGA2002Writer.py +++ b/geomagio/iaga2002/IAGA2002Writer.py @@ -60,22 +60,31 @@ class IAGA2002Writer(object): """ buf = [] buf.append(self._format_header('Format', 'IAGA-2002')) - buf.append(self._format_header('Source of Data', stats.agency_name)) - buf.append(self._format_header('Station Name', stats.station_name)) + if 'agency_name' in stats: + buf.append(self._format_header('Source of Data', stats.agency_name)) + if 'station_name' in stats: + buf.append(self._format_header('Station Name', stats.station_name)) buf.append(self._format_header('IAGA CODE', stats.station)) - buf.append(self._format_header('Geodetic Latitude', - stats.geodetic_latitude)) - buf.append(self._format_header('Geodetic Longitude', - stats.geodetic_longitude)) - buf.append(self._format_header('Elevation', stats.elevation)) + if 'geodetic_latitude' in stats: + buf.append(self._format_header('Geodetic Latitude', + str(stats.geodetic_latitude))) + if 'geodetic_longitude' in stats: + buf.append(self._format_header('Geodetic Longitude', + str(stats.geodetic_longitude))) + if 'elevation' in stats: + buf.append(self._format_header('Elevation', stats.elevation)) buf.append(self._format_header('Reported', ''.join(channels))) - buf.append(self._format_header('Sensor Orientation', - stats.sensor_orientation)) - buf.append(self._format_header('Digital Sampling', - str(1 / stats.sensor_sampling_rate) + ' second')) - buf.append(self._format_header('Data Interval Type', - stats.data_interval_type)) - buf.append(self._format_header('Data Type', stats.data_type)) + if 'sensor_orientation' in stats: + buf.append(self._format_header('Sensor Orientation', + stats.sensor_orientation)) + if 'sensor_sampling_rate' in stats: + buf.append(self._format_header('Digital Sampling', + str(1 / stats.sensor_sampling_rate) + ' second')) + if 'data_interval_type' in stats: + buf.append(self._format_header('Data Interval Type', + stats.data_interval_type)) + if 'data_type' in stats: + buf.append(self._format_header('Data Type', stats.data_type)) return ''.join(buf) def _format_comments(self, stats): -- GitLab