diff --git a/docs/algorithms/Average_usage.md b/docs/algorithms/Average_usage.md new file mode 100644 index 0000000000000000000000000000000000000000..ab2bd82d7f006c7538998c723627462629594e28 --- /dev/null +++ b/docs/algorithms/Average_usage.md @@ -0,0 +1,58 @@ +Average Algorithm Usage +======================== + +The average algorithm takes data streams from multiple observatories +over one channel and returns a single averaged data stream. + + +### Example +To compute the average of H over the observatories of HON and SJG + +``` +geomag.py \ + --algorithm average \ + --observatory HON SJG GUA \ + --type variation \ + --interval minute \ + --inchannels H \ + --outchannels H \ + --starttime 2017-07-04T00:00:00Z \ + --endtime 2017-07-04T00:10:00Z \ + --input edge \ + --output iaga2002 \ + --output-stdout +``` + +### Output + +``` + Format IAGA-2002 | + Source of Data United States Geological Survey (USGS) | + Station Name USGS | + IAGA CODE USGS | + Geodetic Latitude 40.137 | + Geodetic Longitude 254.764 | + Elevation 1682 | + Reported HNULNULNUL | + Sensor Orientation HDZF | + Digital Sampling 100.0 second | + Data Interval Type 1-minute calculated | + Data Type variation | + # DECBAS 0 (Baseline declination value in | + # tenths of minutes East (0-216,000)). | + # CONDITIONS OF USE: The Conditions of Use for data provided | + # through INTERMAGNET and acknowledgement templates can be found at | + # www.intermagnet.org | +DATE TIME DOY USGSH USGSNUL USGSNUL USGSNUL| +2017-07-04 00:00:00.000 185 29854.29 99999.00 99999.00 99999.00 +2017-07-04 00:01:00.000 185 29854.31 99999.00 99999.00 99999.00 +2017-07-04 00:02:00.000 185 29854.28 99999.00 99999.00 99999.00 +2017-07-04 00:03:00.000 185 29854.18 99999.00 99999.00 99999.00 +2017-07-04 00:04:00.000 185 29854.15 99999.00 99999.00 99999.00 +2017-07-04 00:05:00.000 185 29854.20 99999.00 99999.00 99999.00 +2017-07-04 00:06:00.000 185 29854.22 99999.00 99999.00 99999.00 +2017-07-04 00:07:00.000 185 29854.35 99999.00 99999.00 99999.00 +2017-07-04 00:08:00.000 185 29854.52 99999.00 99999.00 99999.00 +2017-07-04 00:09:00.000 185 29854.69 99999.00 99999.00 99999.00 +2017-07-04 00:10:00.000 185 29854.76 99999.00 99999.00 99999.00 +``` diff --git a/geomagio/algorithm/AverageAlgorithm.py b/geomagio/algorithm/AverageAlgorithm.py index f030fd0e357008f1158bde2cb00fe792f132b058..092bad2db6f0016cea0ff9af3480f00aac21d0a9 100644 --- a/geomagio/algorithm/AverageAlgorithm.py +++ b/geomagio/algorithm/AverageAlgorithm.py @@ -29,11 +29,13 @@ class AverageAlgorithm(Algorithm): """ - def __init__(self): + def __init__(self, observatories=None, channel=None): Algorithm.__init__(self) self._npts = -1 self._stt = -1 self._stats = None + self.observatories = observatories + self.outchannel = channel self.observatoryMetadata = ObservatoryMetadata() def check_stream(self, timeseries): @@ -86,6 +88,12 @@ class AverageAlgorithm(Algorithm): new stream object containing the averaged values. """ + # If outchannel is not initialized it defaults to the + # input channel of the timeseries + if not self.outchannel: + self.outchannel = timeseries[0].stats.channel + + # Run checks on input timeseries self.check_stream(timeseries) # initialize array for data to be appended @@ -166,13 +174,12 @@ class AverageAlgorithm(Algorithm): """ self.observatories = arguments.observatory - if len(arguments.outchannels) > 1: - raise AlgorithmException( - 'Only 1 channel can be specified') if arguments.outchannels: + if len(arguments.outchannels) > 1: + raise AlgorithmException( + 'Only 1 channel can be specified') self.outchannel = arguments.outchannels[0] - else: - self.outchannel = 'MSD' + self.scales = arguments.average_observatory_scale if self.scales[0] is not None: if len(self.observatories) != len(self.scales):