diff --git a/geomagio/Controller.py b/geomagio/Controller.py index f6517a4cc9bf97149c9305fc519953c0112622af..7111ef576923149835b1d7146fad99ef34f0cb38 100644 --- a/geomagio/Controller.py +++ b/geomagio/Controller.py @@ -490,7 +490,11 @@ def main(args): if args.realtime: if args.realtime is True: # convert interval to number of seconds - if args.interval == "minute": + if args.interval == "day": + args.realtime = 172800 + elif args.interval == "hour": + args.realtime = 7200 + elif args.interval == "minute": args.realtime = 3600 else: args.realtime = 600 @@ -700,6 +704,8 @@ def parse_args(args): const=True, help=""" Run the last N seconds. + Default 172800 (last 2 days) when interval is day, + Default 7200 (last 2 hours) when interval is hour, Default 3600 (last hour) when interval is minute, Default 600 (last 10 minutes) otherwise. """, diff --git a/geomagio/ObservatoryMetadata.py b/geomagio/ObservatoryMetadata.py index add0c6355615233959e8b47408cc15df10bb4a06..593310d86bc5921bd98f63ee7155ee5bbafba78c 100644 --- a/geomagio/ObservatoryMetadata.py +++ b/geomagio/ObservatoryMetadata.py @@ -1,5 +1,32 @@ """Factory that loads metadata for an observatory""" +# default metadata for available time intervals +DEFAULT_INTERVAL_SPECIFIC = { + "day": { + "data_interval_type": "1-day (00:00-23:59)", + "filter_comments": [ + "Scalar and Vector 1-day values are computed from average of 1-minute values in the day (00:00-23:59)", + ], + }, + "hour": { + "data_interval_type": "1-hour (00-59)", + "filter_comments": [ + "Scalar and Vector 1-hour values are computed from average of 1-minute values in the hour (00-59)", + ], + }, + "minute": { + "data_interval_type": "1-minute", + "filter_comments": [ + "Scalar and Vector 1-minute values are computed from 1 Hz values using an INTERMAGNET gaussian filter centered on the start of the minute (00:30-01:30)." + ], + }, + "second": { + "data_interval_type": "1-second", + "filter_comments": [ + "Vector 1-second values are computed from 10 Hz values using a Blackman filter (123 taps, cutoff 0.25Hz) centered on the start of the second." + ], + }, +} # default metadata for the 14 USGS observatories. DEFAULT_METADATA = { @@ -19,19 +46,7 @@ DEFAULT_METADATA = { + " through INTERMAGNET and acknowledgement templates" + " can be found at www.intermagnet.org", }, - "interval_specific": { - "minute": { - "data_interval_type": "filtered 1-minute (00:15-01:45) ", - "filter_comments": [ - "Vector 1-minute values are computed" - + " from 1-second values using the INTERMAGNET gaussian" - + " filter centered on the minute. Scalar 1-minute values" - + " are computed from 1-second values using the" - + " INTERMAGNET gaussian filter centered on the minute. " - ], - }, - "second": {"data_interval_type": "Average 1-Second"}, - }, + "interval_specific": DEFAULT_INTERVAL_SPECIFIC, }, "BOU": { "metadata": { @@ -49,19 +64,7 @@ DEFAULT_METADATA = { + " through INTERMAGNET and acknowledgement templates" + " can be found at www.intermagnet.org", }, - "interval_specific": { - "minute": { - "data_interval_type": "filtered 1-minute (00:15-01:45) ", - "filter_comments": [ - "Vector 1-minute values are computed" - + " from 1-second values using the INTERMAGNET gaussian" - + " filter centered on the minute. Scalar 1-minute values" - + " are computed from 1-second values using the" - + " INTERMAGNET gaussian filter centered on the minute. " - ], - }, - "second": {"data_interval_type": "Average 1-Second"}, - }, + "interval_specific": DEFAULT_INTERVAL_SPECIFIC, }, "TST": { "metadata": { @@ -79,19 +82,7 @@ DEFAULT_METADATA = { + " through INTERMAGNET and acknowledgement templates" + " can be found at www.intermagnet.org", }, - "interval_specific": { - "minute": { - "data_interval_type": "filtered 1-minute (00:15-01:45) ", - "filter_comments": [ - "Vector 1-minute values are computed" - + " from 1-second values using the INTERMAGNET gaussian" - + " filter centered on the minute. Scalar 1-minute values" - + " are computed from 1-second values using the" - + " INTERMAGNET gaussian filter centered on the minute. " - ], - }, - "second": {"data_interval_type": "Average 1-Second"}, - }, + "interval_specific": DEFAULT_INTERVAL_SPECIFIC, }, "BRW": { "metadata": { @@ -109,19 +100,7 @@ DEFAULT_METADATA = { + " through INTERMAGNET and acknowledgement templates" + " can be found at www.intermagnet.org", }, - "data_interval_type": { - "minute": { - "data_interval_type": "filtered 1-minute (00:15-01:45) ", - "filter_comments": [ - "Vector 1-minute values are computed" - + " from 1-second values using the INTERMAGNET gaussian" - + " filter centered on the minute. Scalar 1-minute values" - + " are computed from 1-second values using the" - + " INTERMAGNET gaussian filter centered on the minute. " - ], - }, - "second": {"data_interval_type": "Average 1-Second"}, - }, + "interval_specific": DEFAULT_INTERVAL_SPECIFIC, }, "BRT": { "metadata": { @@ -139,19 +118,7 @@ DEFAULT_METADATA = { + " through INTERMAGNET and acknowledgement templates" + " can be found at www.intermagnet.org", }, - "data_interval_type": { - "minute": { - "data_interval_type": "filtered 1-minute (00:15-01:45) ", - "filter_comments": [ - "Vector 1-minute values are computed" - + " from 1-second values using the INTERMAGNET gaussian" - + " filter centered on the minute. Scalar 1-minute values" - + " are computed from 1-second values using the" - + " INTERMAGNET gaussian filter centered on the minute. " - ], - }, - "second": {"data_interval_type": "Average 1-Second"}, - }, + "interval_specific": DEFAULT_INTERVAL_SPECIFIC, }, "BSL": { "metadata": { @@ -169,19 +136,7 @@ DEFAULT_METADATA = { + " through INTERMAGNET and acknowledgement templates" + " can be found at www.intermagnet.org", }, - "interval_specific": { - "minute": { - "data_interval_type": "filtered 1-minute (00:15-01:45) ", - "filter_comments": [ - "Vector 1-minute values are computed" - + " from 1-second values using the INTERMAGNET gaussian" - + " filter centered on the minute. Scalar 1-minute values" - + " are computed from 1-second values using the" - + " INTERMAGNET gaussian filter centered on the minute. " - ], - }, - "second": {"data_interval_type": "Average 1-Second"}, - }, + "interval_specific": DEFAULT_INTERVAL_SPECIFIC, }, "CMO": { "metadata": { @@ -198,7 +153,8 @@ DEFAULT_METADATA = { "conditions_of_use": "The Conditions of Use for data provided" + " through INTERMAGNET and acknowledgement templates" + " can be found at www.intermagnet.org", - } + }, + "interval_specific": DEFAULT_INTERVAL_SPECIFIC, }, "CMT": { "metadata": { @@ -215,7 +171,8 @@ DEFAULT_METADATA = { "conditions_of_use": "The Conditions of Use for data provided" + " through INTERMAGNET and acknowledgement templates" + " can be found at www.intermagnet.org", - } + }, + "interval_specific": DEFAULT_INTERVAL_SPECIFIC, }, "DED": { "metadata": { @@ -233,19 +190,7 @@ DEFAULT_METADATA = { + " through INTERMAGNET and acknowledgement templates" + " can be found at www.intermagnet.org", }, - "interval_specific": { - "minute": { - "data_interval_type": "filtered 1-minute (00:15-01:45) ", - "filter_comments": [ - "Vector 1-minute values are computed" - + " from 1-second values using the INTERMAGNET gaussian" - + " filter centered on the minute. Scalar 1-minute values" - + " are computed from 1-second values using the" - + " INTERMAGNET gaussian filter centered on the minute. " - ], - }, - "second": {"data_interval_type": "Average 1-Second"}, - }, + "interval_specific": DEFAULT_INTERVAL_SPECIFIC, }, "DHT": { "metadata": { @@ -263,19 +208,7 @@ DEFAULT_METADATA = { + " through INTERMAGNET and acknowledgement templates" + " can be found at www.intermagnet.org", }, - "interval_specific": { - "minute": { - "data_interval_type": "filtered 1-minute (00:15-01:45) ", - "filter_comments": [ - "Vector 1-minute values are computed" - + " from 1-second values using the INTERMAGNET gaussian" - + " filter centered on the minute. Scalar 1-minute values" - + " are computed from 1-second values using the" - + " INTERMAGNET gaussian filter centered on the minute. " - ], - }, - "second": {"data_interval_type": "Average 1-Second"}, - }, + "interval_specific": DEFAULT_INTERVAL_SPECIFIC, }, "FRD": { "metadata": { @@ -293,19 +226,7 @@ DEFAULT_METADATA = { + " through INTERMAGNET and acknowledgement templates" + " can be found at www.intermagnet.org", }, - "interval_specific": { - "minute": { - "data_interval_type": "filtered 1-minute (00:15-01:45) ", - "filter_comments": [ - "Vector 1-minute values are computed" - + " from 1-second values using the INTERMAGNET gaussian" - + " filter centered on the minute. Scalar 1-minute values" - + " are computed from 1-second values using the" - + " INTERMAGNET gaussian filter centered on the minute. " - ], - }, - "second": {"data_interval_type": "Average 1-Second"}, - }, + "interval_specific": DEFAULT_INTERVAL_SPECIFIC, }, "FDT": { "metadata": { @@ -323,19 +244,7 @@ DEFAULT_METADATA = { + " through INTERMAGNET and acknowledgement templates" + " can be found at www.intermagnet.org", }, - "interval_specific": { - "minute": { - "data_interval_type": "filtered 1-minute (00:15-01:45) ", - "filter_comments": [ - "Vector 1-minute values are computed" - + " from 1-second values using the INTERMAGNET gaussian" - + " filter centered on the minute. Scalar 1-minute values" - + " are computed from 1-second values using the" - + " INTERMAGNET gaussian filter centered on the minute. " - ], - }, - "second": {"data_interval_type": "Average 1-Second"}, - }, + "interval_specific": DEFAULT_INTERVAL_SPECIFIC, }, "FRN": { "metadata": { @@ -353,19 +262,7 @@ DEFAULT_METADATA = { + " through INTERMAGNET and acknowledgement templates" + " can be found at www.intermagnet.org", }, - "interval_specific": { - "minute": { - "data_interval_type": "filtered 1-minute (00:15-01:45) ", - "filter_comments": [ - "Vector 1-minute values are computed" - + " from 1-second values using the INTERMAGNET gaussian" - + " filter centered on the minute. Scalar 1-minute values" - + " are computed from 1-second values using the" - + " INTERMAGNET gaussian filter centered on the minute. " - ], - }, - "second": {"data_interval_type": "Average 1-Second"}, - }, + "interval_specific": DEFAULT_INTERVAL_SPECIFIC, }, "GUA": { "metadata": { @@ -383,19 +280,7 @@ DEFAULT_METADATA = { + " through INTERMAGNET and acknowledgement templates" + " can be found at www.intermagnet.org", }, - "interval_specific": { - "minute": { - "data_interval_type": "filtered 1-minute (00:15-01:45) ", - "filter_comments": [ - "Vector 1-minute values are computed" - + " from 1-second values using the INTERMAGNET gaussian" - + " filter centered on the minute. Scalar 1-minute values" - + " are computed from 1-second values using the" - + " INTERMAGNET gaussian filter centered on the minute. " - ], - }, - "second": {"data_interval_type": "Average 1-Second"}, - }, + "interval_specific": DEFAULT_INTERVAL_SPECIFIC, }, "HON": { "metadata": { @@ -413,19 +298,7 @@ DEFAULT_METADATA = { + " through INTERMAGNET and acknowledgement templates" + " can be found at www.intermagnet.org", }, - "interval_specific": { - "minute": { - "data_interval_type": "filtered 1-minute (00:15-01:45) ", - "filter_comments": [ - "Vector 1-minute values are computed" - + " from 1-second values using the INTERMAGNET gaussian" - + " filter centered on the minute. Scalar 1-minute values" - + " are computed from 1-second values using the" - + " INTERMAGNET gaussian filter centered on the minute. " - ], - }, - "second": {"data_interval_type": "Average 1-Second"}, - }, + "interval_specific": DEFAULT_INTERVAL_SPECIFIC, }, "KAK": { "metadata": { @@ -443,10 +316,7 @@ DEFAULT_METADATA = { + " through INTERMAGNET and acknowledgement templates" + " can be found at www.intermagnet.org", }, - "interval_specific": { - "minute": {"data_interval_type": "filtered 1-minute (00:15-01:45)"}, - "second": {"data_interval_type": ""}, - }, + "interval_specific": DEFAULT_INTERVAL_SPECIFIC, }, "NEW": { "metadata": { @@ -464,19 +334,7 @@ DEFAULT_METADATA = { + " through INTERMAGNET and acknowledgement templates" + " can be found at www.intermagnet.org", }, - "interval_specific": { - "minute": { - "data_interval_type": "filtered 1-minute (00:15-01:45) ", - "filter_comments": [ - "Vector 1-minute values are computed" - + " from 1-second values using the INTERMAGNET gaussian" - + " filter centered on the minute. Scalar 1-minute values" - + " are computed from 1-second values using the" - + " INTERMAGNET gaussian filter centered on the minute. " - ], - }, - "second": {"data_interval_type": "Average 1-Second"}, - }, + "interval_specific": DEFAULT_INTERVAL_SPECIFIC, }, "SHU": { "metadata": { @@ -494,19 +352,7 @@ DEFAULT_METADATA = { + " through INTERMAGNET and acknowledgement templates" + " can be found at www.intermagnet.org", }, - "interval_specific": { - "minute": { - "data_interval_type": "filtered 1-minute (00:15-01:45) ", - "filter_comments": [ - "Vector 1-minute values are computed" - + " from 1-second values using the INTERMAGNET gaussian" - + " filter centered on the minute. Scalar 1-minute values" - + " are computed from 1-second values using the" - + " INTERMAGNET gaussian filter centered on the minute. " - ], - }, - "second": {"data_interval_type": "Average 1-Second"}, - }, + "interval_specific": DEFAULT_INTERVAL_SPECIFIC, }, "SIT": { "metadata": { @@ -524,19 +370,7 @@ DEFAULT_METADATA = { + " through INTERMAGNET and acknowledgement templates" + " can be found at www.intermagnet.org", }, - "interval_specific": { - "minute": { - "data_interval_type": "filtered 1-minute (00:15-01:45) ", - "filter_comments": [ - "Vector 1-minute values are computed" - + " from 1-second values using the INTERMAGNET gaussian" - + " filter centered on the minute. Scalar 1-minute values" - + " are computed from 1-second values using the" - + " INTERMAGNET gaussian filter centered on the minute. " - ], - }, - "second": {"data_interval_type": "Average 1-Second"}, - }, + "interval_specific": DEFAULT_INTERVAL_SPECIFIC, }, "SJG": { "metadata": { @@ -554,19 +388,7 @@ DEFAULT_METADATA = { + " through INTERMAGNET and acknowledgement templates" + " can be found at www.intermagnet.org", }, - "interval_specific": { - "minute": { - "data_interval_type": "filtered 1-minute (00:15-01:45) ", - "filter_comments": [ - "Vector 1-minute values are computed" - + " from 1-second values using the INTERMAGNET gaussian" - + " filter centered on the minute. Scalar 1-minute values" - + " are computed from 1-second values using the" - + " INTERMAGNET gaussian filter centered on the minute. " - ], - }, - "second": {"data_interval_type": "Average 1-Second"}, - }, + "interval_specific": DEFAULT_INTERVAL_SPECIFIC, }, "TUC": { "metadata": { @@ -584,19 +406,7 @@ DEFAULT_METADATA = { + " through INTERMAGNET and acknowledgement templates" + " can be found at www.intermagnet.org", }, - "interval_specific": { - "minute": { - "data_interval_type": "filtered 1-minute (00:15-01:45) ", - "filter_comments": [ - "Vector 1-minute values are computed" - + " from 1-second values using the INTERMAGNET gaussian" - + " filter centered on the minute. Scalar 1-minute values" - + " are computed from 1-second values using the" - + " INTERMAGNET gaussian filter centered on the minute. " - ], - }, - "second": {"data_interval_type": "Average 1-Second"}, - }, + "interval_specific": DEFAULT_INTERVAL_SPECIFIC, }, "USGS": { "metadata": { @@ -614,13 +424,7 @@ DEFAULT_METADATA = { + " through INTERMAGNET and acknowledgement templates" + " can be found at www.intermagnet.org", }, - "interval_specific": { - "minute": { - "data_interval_type": "1-minute calculated", - "filter_comments": [], - }, - "hour": {"data_interval_type": "1-hour calculated"}, - }, + "interval_specific": DEFAULT_INTERVAL_SPECIFIC, }, "BLC": { "metadata": { @@ -638,10 +442,7 @@ DEFAULT_METADATA = { + " through INTERMAGNET and acknowledgement templates" + " can be found at www.intermagnet.org", }, - "interval_specific": { - "minute": {"data_interval_type": "filtered 1-minute (00:15-01:45)"}, - "second": {"data_interval_type": ""}, - }, + "interval_specific": DEFAULT_INTERVAL_SPECIFIC, }, "BRD": { "metadata": { @@ -659,10 +460,7 @@ DEFAULT_METADATA = { + " through INTERMAGNET and acknowledgement templates" + " can be found at www.intermagnet.org", }, - "interval_specific": { - "minute": {"data_interval_type": "filtered 1-minute (00:15-01:45)"}, - "second": {"data_interval_type": ""}, - }, + "interval_specific": DEFAULT_INTERVAL_SPECIFIC, }, "CBB": { "metadata": { @@ -680,10 +478,7 @@ DEFAULT_METADATA = { + " through INTERMAGNET and acknowledgement templates" + " can be found at www.intermagnet.org", }, - "interval_specific": { - "minute": {"data_interval_type": "filtered 1-minute (00:15-01:45)"}, - "second": {"data_interval_type": ""}, - }, + "interval_specific": DEFAULT_INTERVAL_SPECIFIC, }, "EUA": { "metadata": { @@ -701,10 +496,7 @@ DEFAULT_METADATA = { + " through INTERMAGNET and acknowledgement templates" + " can be found at www.intermagnet.org", }, - "interval_specific": { - "minute": {"data_interval_type": "filtered 1-minute (00:15-01:45)"}, - "second": {"data_interval_type": ""}, - }, + "interval_specific": DEFAULT_INTERVAL_SPECIFIC, }, "FCC": { "metadata": { @@ -722,10 +514,7 @@ DEFAULT_METADATA = { + " through INTERMAGNET and acknowledgement templates" + " can be found at www.intermagnet.org", }, - "interval_specific": { - "minute": {"data_interval_type": "filtered 1-minute (00:15-01:45)"}, - "second": {"data_interval_type": ""}, - }, + "interval_specific": DEFAULT_INTERVAL_SPECIFIC, }, "HAD": { "metadata": { @@ -743,10 +532,7 @@ DEFAULT_METADATA = { + " through INTERMAGNET and acknowledgement templates" + " can be found at www.intermagnet.org", }, - "interval_specific": { - "minute": {"data_interval_type": "filtered 1-minute (00:15-01:45)"}, - "second": {"data_interval_type": ""}, - }, + "interval_specific": DEFAULT_INTERVAL_SPECIFIC, }, "HER": { "metadata": { @@ -764,10 +550,7 @@ DEFAULT_METADATA = { + " through INTERMAGNET and acknowledgement templates" + " can be found at www.intermagnet.org", }, - "interval_specific": { - "minute": {"data_interval_type": "filtered 1-minute (00:15-01:45)"}, - "second": {"data_interval_type": ""}, - }, + "interval_specific": DEFAULT_INTERVAL_SPECIFIC, }, "IQA": { "metadata": { @@ -785,10 +568,7 @@ DEFAULT_METADATA = { + " through INTERMAGNET and acknowledgement templates" + " can be found at www.intermagnet.org", }, - "interval_specific": { - "minute": {"data_interval_type": "filtered 1-minute (00:15-01:45)"}, - "second": {"data_interval_type": ""}, - }, + "interval_specific": DEFAULT_INTERVAL_SPECIFIC, }, "MEA": { "metadata": { @@ -806,10 +586,7 @@ DEFAULT_METADATA = { + " through INTERMAGNET and acknowledgement templates" + " can be found at www.intermagnet.org", }, - "interval_specific": { - "minute": {"data_interval_type": "filtered 1-minute (00:15-01:45)"}, - "second": {"data_interval_type": ""}, - }, + "interval_specific": DEFAULT_INTERVAL_SPECIFIC, }, "OTT": { "metadata": { @@ -827,10 +604,7 @@ DEFAULT_METADATA = { + " through INTERMAGNET and acknowledgement templates" + " can be found at www.intermagnet.org", }, - "interval_specific": { - "minute": {"data_interval_type": "filtered 1-minute (00:15-01:45)"}, - "second": {"data_interval_type": ""}, - }, + "interval_specific": DEFAULT_INTERVAL_SPECIFIC, }, "RES": { "metadata": { @@ -848,10 +622,7 @@ DEFAULT_METADATA = { + " through INTERMAGNET and acknowledgement templates" + " can be found at www.intermagnet.org", }, - "interval_specific": { - "minute": {"data_interval_type": "filtered 1-minute (00:15-01:45)"}, - "second": {"data_interval_type": ""}, - }, + "interval_specific": DEFAULT_INTERVAL_SPECIFIC, }, "SNK": { "metadata": { @@ -869,10 +640,7 @@ DEFAULT_METADATA = { + " through INTERMAGNET and acknowledgement templates" + " can be found at www.intermagnet.org", }, - "interval_specific": { - "minute": {"data_interval_type": "filtered 1-minute (00:15-01:45)"}, - "second": {"data_interval_type": ""}, - }, + "interval_specific": DEFAULT_INTERVAL_SPECIFIC, }, "STJ": { "metadata": { @@ -890,10 +658,7 @@ DEFAULT_METADATA = { + " through INTERMAGNET and acknowledgement templates" + " can be found at www.intermagnet.org", }, - "interval_specific": { - "minute": {"data_interval_type": "filtered 1-minute (00:15-01:45)"}, - "second": {"data_interval_type": ""}, - }, + "interval_specific": DEFAULT_INTERVAL_SPECIFIC, }, "VIC": { "metadata": { @@ -911,10 +676,7 @@ DEFAULT_METADATA = { + " through INTERMAGNET and acknowledgement templates" + " can be found at www.intermagnet.org", }, - "interval_specific": { - "minute": {"data_interval_type": "filtered 1-minute (00:15-01:45)"}, - "second": {"data_interval_type": ""}, - }, + "interval_specific": DEFAULT_INTERVAL_SPECIFIC, }, "YKC": { "metadata": { @@ -932,20 +694,11 @@ DEFAULT_METADATA = { + " through INTERMAGNET and acknowledgement templates" + " can be found at www.intermagnet.org", }, - "interval_specific": { - "minute": {"data_interval_type": "filtered 1-minute (00:15-01:45)"}, - "second": {"data_interval_type": ""}, - }, + "interval_specific": DEFAULT_INTERVAL_SPECIFIC, }, } -DEFAULT_INTERVAL_SPECIFIC = { - "minute": {"data_interval_type": "filtered 1-minute (00:15-01:45) "}, - "second": {"data_interval_type": "Average 1-Second"}, -} - - class ObservatoryMetadata(object): """Helper class for providing all the metadata needed for a geomag timeseries. diff --git a/geomagio/TimeseriesUtility.py b/geomagio/TimeseriesUtility.py index 418bbe9c17a04b903d83a8906b133eefb37f48ce..459287dbe69add0b6dc98da98cd56d8395e18bd2 100644 --- a/geomagio/TimeseriesUtility.py +++ b/geomagio/TimeseriesUtility.py @@ -2,6 +2,7 @@ from builtins import range from datetime import datetime import math +import sys import numpy import obspy.core @@ -46,6 +47,13 @@ def create_empty_trace( trace_starttime = obspy.core.UTCDateTime( numpy.ceil(starttime.timestamp / delta) * delta ) + if delta > 60.0: + trace_starttime += (delta - 60) / 2 + if trace_starttime > endtime: + sys.stderr.write( + "Starttime greater than endtime, adjusting request to one sample" + ) + endtime = trace_starttime stats.starttime = trace_starttime stats.delta = delta # Calculate number of valid samples up to or before endtime diff --git a/geomagio/algorithm/FilterAlgorithm.py b/geomagio/algorithm/FilterAlgorithm.py index 49353c0cd980c592d4d64c46fed27ddb178e4dac..50aa2f729b5204ff1940567ff32fd62477df2be2 100644 --- a/geomagio/algorithm/FilterAlgorithm.py +++ b/geomagio/algorithm/FilterAlgorithm.py @@ -14,31 +14,51 @@ from .. import TimeseriesUtility STEPS = [ { # 10 Hz to one second filter "name": "10Hz", + "data_interval": "second", + "data_interval_type": "1-second", "input_sample_period": 0.1, "output_sample_period": 1.0, "window": sps.firwin(123, 0.25, window="blackman", fs=10.0), "type": "firfilter", + "filter_comments": [ + "Vector 1-second values are computed from 10 Hz values using a Blackman filter (123 taps, cutoff 0.25Hz) centered on the start of the second." + ], }, { # one second to one minute filter "name": "Intermagnet One Minute", + "data_interval": "minute", + "data_interval_type": "1-minute", "input_sample_period": 1.0, "output_sample_period": 60.0, "window": sps.get_window(window=("gaussian", 15.8734), Nx=91), "type": "firfilter", + "filter_comments": [ + "Scalar and Vector 1-minute values are computed from 1 Hz values using an INTERMAGNET gaussian filter centered on the start of the minute (00:30-01:30)." + ], }, { # one minute to one hour filter "name": "One Hour", + "data_interval": "hour", + "data_interval_type": "1-hour (00-59)", "input_sample_period": 60.0, "output_sample_period": 3600.0, "window": sps.windows.boxcar(60), "type": "average", + "filter_comments": [ + "Scalar and Vector 1-hour values are computed from average of 1-minute values in the hour (00-59)", + ], }, - { # one minute to one hour filter + { # one minute to one day filter "name": "One Day", + "data_interval": "day", + "data_interval_type": "1-day (00:00-23:59)", "input_sample_period": 60.0, "output_sample_period": 86400, "window": sps.windows.boxcar(1440), "type": "average", + "filter_comments": [ + "Scalar and Vector 1-day values are computed from average of 1-minute values in the day (00:00-23:59)", + ], }, ] @@ -129,6 +149,15 @@ class FilterAlgorithm(Algorithm): self.steps = [ { "name": "name" in data and data["name"] or "custom", + "data_interval": TimeseriesUtility.get_interval_from_delta( + self.output_sample_period + ), + "data_interval_type": "filtered custom interval", + "filter_comments": "filter_comments" in data + and data["filter_comments"] + or [ + "Data produced by filter utilizing custom coefficients and intervals." + ], "input_sample_period": self.input_sample_period, "output_sample_period": self.output_sample_period, "window": data["window"], @@ -268,6 +297,9 @@ class FilterAlgorithm(Algorithm): filtered = self.firfilter(data, window, decimation) stats = Stats(trace.stats) stats.delta = output_sample_period + stats.data_interval = step["data_interval"] + stats.data_interval_type = step["data_interval_type"] + stats.filter_comments = step["filter_comments"] stats.starttime = starttime stats.npts = len(filtered) trace_out = self.create_trace(stats.channel, stats, filtered) diff --git a/test/ObservatoryMetadata_test.py b/test/ObservatoryMetadata_test.py index 902abffbbb523c61581055f2d0eb4e5a27b920d5..ca3d5ada427824296aef9b8547a27b8c828a5448 100644 --- a/test/ObservatoryMetadata_test.py +++ b/test/ObservatoryMetadata_test.py @@ -1,6 +1,6 @@ """Tests for ObservatoryMetadata.py""" -from geomagio import ObservatoryMetadata +from geomagio.ObservatoryMetadata import ObservatoryMetadata, DEFAULT_INTERVAL_SPECIFIC from numpy.testing import assert_equal import obspy.core @@ -22,26 +22,16 @@ METADATA = { + " through INTERMAGNET and acknowledgement templates" + " can be found at www.intermagnet.org", }, - "interval_specific": { - "minute": { - "data_interval_type": "filtered 1-minute (00:15-01:45) ", - "filter_comments": [ - "Vector 1-minute values are computed" - + " from 1-second values using the INTERMAGNET gaussian" - + " filter centered on the minute. Scalar 1-minute values" - + " are computed from 1-second values using the" - + " INTERMAGNET gaussian filter centered on the minute. " - ], - }, - "second": {"data_interval_type": "Average 1-Second"}, - }, + "interval_specific": DEFAULT_INTERVAL_SPECIFIC, } } DATA_INTERVAL_TYPE = { - "minute": {"data_interval_type": "filtered 1-minute (00:29-01:30) "}, - "second": {"data_interval_type": "filtered 1-Second"}, + "day": {"data_interval_type": "1-day"}, + "hour": {"data_interval_type": "1-hour"}, + "minute": {"data_interval_type": "1-minute"}, + "second": {"data_interval_type": "1-second"}, } @@ -65,4 +55,4 @@ def test_set_metadata(): observatorymetadata.set_metadata(stats, "BOU", "MVH", "quasi-definitive", "second") assert_equal(stats["declination_base"], 20000) print(stats) - assert_equal(stats["data_interval_type"], "Average 1-Second") + assert_equal(stats["data_interval_type"], "1-second") diff --git a/test/TimeseriesUtility_test.py b/test/TimeseriesUtility_test.py index a664b2e28a718e42e57553ca9c57d29aa02bae15..0259364ed35d9a5ce0b58a4b7d6379a7dd6e48ec 100644 --- a/test/TimeseriesUtility_test.py +++ b/test/TimeseriesUtility_test.py @@ -55,6 +55,49 @@ def test_create_empty_trace(): TimeseriesUtility.pad_timeseries(timeseries, starttime - 90, endtime + 90) assert_equal(len(trace3.data), trace3.stats.npts) assert_equal(timeseries[0].stats.starttime, timeseries[2].stats.starttime) + # test hourly/daily starttime shift + hour_trace = TimeseriesUtility.create_empty_trace( + starttime=trace1.stats.starttime, + endtime=trace1.stats.endtime, + observatory=observatory, + channel="F", + type="variation", + interval="hour", + network=network, + station=trace1.stats.station, + location=location, + ) + + assert_equal(hour_trace.stats.starttime, UTCDateTime("2018-01-01T00:29:30Z")) + + day_trace = TimeseriesUtility.create_empty_trace( + starttime=trace1.stats.starttime, + endtime=trace1.stats.endtime, + observatory=observatory, + channel="F", + type="variation", + interval="day", + network=network, + station=trace1.stats.station, + location=location, + ) + + assert_equal(day_trace.stats.starttime, UTCDateTime("2018-01-01T11:59:30Z")) + + short_trace = TimeseriesUtility.create_empty_trace( + starttime=trace1.stats.starttime, + endtime=trace1.stats.starttime + 1, + observatory=observatory, + channel="F", + type="variation", + interval="day", + network=network, + station=trace1.stats.station, + location=location, + ) + + assert_equal(short_trace.stats.starttime, UTCDateTime("2018-01-01T11:59:30Z")) + assert_equal(short_trace.stats.endtime, short_trace.stats.starttime) def test_get_stream_gaps(): diff --git a/test/algorithm_test/FilterAlgorithm_test.py b/test/algorithm_test/FilterAlgorithm_test.py index 6a1947183d7d685bad3a6b2edec43bd51db86cc7..b4c21d45afc0581d78d340d7310cdf6cdeb1e30a 100644 --- a/test/algorithm_test/FilterAlgorithm_test.py +++ b/test/algorithm_test/FilterAlgorithm_test.py @@ -51,6 +51,8 @@ def test_second(): assert_almost_equal(w_filt.data, w.data, 2) assert_equal(filtered[0].stats.starttime, UTCDateTime("2020-01-06T00:00:00Z")) assert_equal(filtered[0].stats.endtime, UTCDateTime("2020-01-06T04:00:00Z")) + assert_equal(u_filt.stats.data_interval, "second") + assert_equal(u_filt.stats.data_interval_type, "1-second") def test_minute(): @@ -94,6 +96,8 @@ def test_minute(): assert_almost_equal(w_filt.data, w.data, 2) assert_equal(filtered[0].stats.starttime, UTCDateTime("2020-01-06T00:00:00Z")) assert_equal(filtered[0].stats.endtime, UTCDateTime("2020-01-06T04:00:00Z")) + assert_equal(filtered[0].stats.data_interval, "minute") + assert_equal(filtered[0].stats.data_interval_type, "1-minute") def test_hour(): @@ -138,6 +142,8 @@ def test_hour(): assert_almost_equal(f_filt.data, f.data, 2) assert_equal(filtered[0].stats.starttime, UTCDateTime("2020-08-31T00:29:30")) assert_equal(filtered[0].stats.endtime, UTCDateTime("2020-08-31T03:29:30")) + assert_equal(filtered[0].stats.data_interval, "hour") + assert_equal(filtered[0].stats.data_interval_type, "1-hour (00-59)") def test_day(): @@ -182,6 +188,8 @@ def test_day(): assert_almost_equal(f_filt.data, f.data, 2) assert_equal(filtered[0].stats.starttime, UTCDateTime("2020-08-27T11:59:30")) assert_equal(filtered[0].stats.endtime, UTCDateTime("2020-08-30T11:59:30")) + assert_equal(filtered[0].stats.data_interval, "day") + assert_equal(filtered[0].stats.data_interval_type, "1-day (00:00-23:59)") def test_custom(): @@ -229,6 +237,8 @@ def test_custom(): assert_almost_equal(w_filt.data, w.data, 2) assert_equal(filtered[0].stats.starttime, UTCDateTime("2020-01-06T00:00:00Z")) assert_equal(filtered[0].stats.endtime, UTCDateTime("2020-01-06T04:00:00Z")) + assert_equal(filtered[0].stats.data_interval, "second") + assert_equal(filtered[0].stats.data_interval_type, "filtered custom interval") def test_starttime_shift():