From fd3a5322e71f7483994221f6af27b306700d748e Mon Sep 17 00:00:00 2001 From: pcain-usgs <pcain@usgs.gov> Date: Fri, 16 Oct 2020 14:16:52 -0600 Subject: [PATCH] Change day step case, write tests --- geomagio/algorithm/FilterAlgorithm.py | 2 +- test/TimeseriesUtility_test.py | 28 +++++++++++++++++++++ test/algorithm_test/FilterAlgorithm_test.py | 12 +++++++++ 3 files changed, 41 insertions(+), 1 deletion(-) diff --git a/geomagio/algorithm/FilterAlgorithm.py b/geomagio/algorithm/FilterAlgorithm.py index 84b0f9234..1bdc0cf11 100644 --- a/geomagio/algorithm/FilterAlgorithm.py +++ b/geomagio/algorithm/FilterAlgorithm.py @@ -51,7 +51,7 @@ STEPS = [ { # one minute to one hour filter "name": "One Day", "data_interval": "day", - "data_interval_type": "filtered 1-Day", + "data_interval_type": "filtered 1-day", "input_sample_period": 60.0, "output_sample_period": 86400, "window": sps.windows.boxcar(1440), diff --git a/test/TimeseriesUtility_test.py b/test/TimeseriesUtility_test.py index a664b2e28..c3fbb9185 100644 --- a/test/TimeseriesUtility_test.py +++ b/test/TimeseriesUtility_test.py @@ -55,6 +55,34 @@ 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")) def test_get_stream_gaps(): diff --git a/test/algorithm_test/FilterAlgorithm_test.py b/test/algorithm_test/FilterAlgorithm_test.py index 6a1947183..f235c162a 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, "Average 1-Second") def test_minute(): @@ -94,6 +96,10 @@ 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, "filtered 1-minute (00:15-01:45)" + ) def test_hour(): @@ -138,6 +144,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, "filtered 1-hour") def test_day(): @@ -182,6 +190,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, "filtered 1-day") def test_custom(): @@ -229,6 +239,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(): -- GitLab