From c41aa34738509777cd354564d89cc435d92c8565 Mon Sep 17 00:00:00 2001 From: Jason Regina Date: Fri, 9 Feb 2024 09:19:15 -0600 Subject: [PATCH 1/5] change example to use lower case h for hour --- python/events/README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/python/events/README.md b/python/events/README.md index a608e859..222629b1 100644 --- a/python/events/README.md +++ b/python/events/README.md @@ -61,7 +61,7 @@ observations = observations.drop_duplicates( # Resample to hourly, keep first measurement in each 1-hour bin observations = observations.groupby([ 'usgs_site_code', - Grouper(key='value_date', freq='H') + Grouper(key='value_date', freq='h') ]).first().ffill() # Detect events @@ -69,7 +69,7 @@ events = observations['value'].groupby( level='usgs_site_code').apply( list_events_helper, level='usgs_site_code', - halflife='6H', + halflife='6h', window='7D' ) From 1e8c0bb9d8b0d32f464f3dfe99f79067166fe206 Mon Sep 17 00:00:00 2001 From: Jason Regina Date: Fri, 9 Feb 2024 09:19:27 -0600 Subject: [PATCH 2/5] change tests to use lower case h for hour --- python/events/tests/test_decomposition.py | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/python/events/tests/test_decomposition.py b/python/events/tests/test_decomposition.py index 62d52522..fd5d3ee8 100644 --- a/python/events/tests/test_decomposition.py +++ b/python/events/tests/test_decomposition.py @@ -23,12 +23,12 @@ def test_list_events(): index=pd.date_range( start=pd.to_datetime('2018-01-01'), periods=len(t), - freq='H'), + freq='h'), name='streamflow' ) # Detect event - events = ev.list_events(series, '6H', '7D') + events = ev.list_events(series, '6h', '7D') # Should detect a single event assert len(events.index) == 1 @@ -56,12 +56,12 @@ def test_list_events_noise(): index=pd.date_range( start=pd.to_datetime('2018-01-01'), periods=len(t), - freq='H'), + freq='h'), name='streamflow' ) # Detect event - events = ev.list_events(series, '6H', '7D', '6H', '7H') + events = ev.list_events(series, '6h', '7D', '6h', '7h') # Should detect a single event assert len(events.index) == 1 @@ -80,7 +80,7 @@ def test_local_minimum_datetime_exception(): with pytest.raises(Exception): idx = ev.find_local_minimum( pd.Timestamp('2020-01-01 01:00'), - '3H', + '3h', series ) @@ -91,7 +91,7 @@ def test_origin_not_idx(): index=pd.date_range( start=pd.to_datetime('2018-01-01'), periods=10, - freq='H'), + freq='h'), name='streamflow' ) @@ -99,7 +99,7 @@ def test_origin_not_idx(): with pytest.raises(Exception): idx = ev.find_local_minimum( pd.Timestamp('2020-01-01 01:00'), - '3H', + '3h', series ) @@ -110,7 +110,7 @@ def test_bad_time_series_idx(): index=[i for i in range(5)] ) with pytest.raises(Exception): - events = ev.list_events(series, '6H', '7D') + events = ev.list_events(series, '6h', '7D') # Not monotonic series = pd.Series( @@ -125,7 +125,7 @@ def test_bad_time_series_idx(): name='streamflow' ) with pytest.raises(Exception): - events = ev.list_events(series, '6H', '7D') + events = ev.list_events(series, '6h', '7D') # Duplicated series = pd.Series( @@ -140,7 +140,7 @@ def test_bad_time_series_idx(): name='streamflow' ) with pytest.raises(Exception): - events = ev.list_events(series, '6H', '7D') + events = ev.list_events(series, '6h', '7D') def test_null_warning(): series = pd.Series( @@ -155,4 +155,4 @@ def test_null_warning(): name='streamflow' ) with pytest.warns(UserWarning): - events = ev.list_events(series, '6H', '7D') + events = ev.list_events(series, '6h', '7D') From 3f395641e2806cfee4120af38ca47e227c0396fd Mon Sep 17 00:00:00 2001 From: Jason Regina Date: Fri, 9 Feb 2024 09:19:41 -0600 Subject: [PATCH 3/5] change methods and docstrings to use lower case h for hour --- .../events/event_detection/decomposition.py | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/python/events/src/hydrotools/events/event_detection/decomposition.py b/python/events/src/hydrotools/events/event_detection/decomposition.py index 5f184e10..1c9c3f30 100644 --- a/python/events/src/hydrotools/events/event_detection/decomposition.py +++ b/python/events/src/hydrotools/events/event_detection/decomposition.py @@ -212,8 +212,8 @@ def mark_event_flows( series: pd.Series, halflife: Union[float, str, pd.Timedelta], window: Union[int, pd.tseries.offsets.DateOffset, pd.Index], - minimum_event_duration: Union[pd.Timedelta, datetime.timedelta, np.timedelta64, str, int] = '0H', - start_radius: Union[pd.Timedelta, datetime.timedelta, np.timedelta64, str, int] = '0H' + minimum_event_duration: Union[pd.Timedelta, datetime.timedelta, np.timedelta64, str, int] = '0h', + start_radius: Union[pd.Timedelta, datetime.timedelta, np.timedelta64, str, int] = '0h' ) -> pd.Series: """Model the trend in a streamflow time series by taking the max of two rolling minimum filters applied in a forward and @@ -236,10 +236,10 @@ def mark_event_flows( window: int, offset, or BaseIndexer subclass, required Size of the moving window for `pandas.Series.rolling.min`. This filter is used to model the trend in `series`. - minimum_event_duration: pandas.Timedelta, datetime.timedelta, numpy.timedelta64, str, int, optional, default '0H' + minimum_event_duration: pandas.Timedelta, datetime.timedelta, numpy.timedelta64, str, int, optional, default '0h' Enforce a minimum event duration. This should generally be set equal to halflife to reduce the number of false positives flagged as events. - start_radius: pandas.Timedelta, datetime.timedelta, numpy.timedelta64, str, int, optional, default '0H' + start_radius: pandas.Timedelta, datetime.timedelta, numpy.timedelta64, str, int, optional, default '0h' Shift event starts to a local minimum. Phase shifts imparted on the original signal may advance or delay event start times depending upon how much smoothing is required to eliminate noise. @@ -293,8 +293,8 @@ def list_events( series: pd.Series, halflife: Union[float, str, pd.Timedelta], window: Union[int, pd.tseries.offsets.DateOffset, pd.Index], - minimum_event_duration: Union[pd.Timedelta, datetime.timedelta, np.timedelta64, str, int] = '0H', - start_radius: Union[pd.Timedelta, datetime.timedelta, np.timedelta64, str, int] = '0H' + minimum_event_duration: Union[pd.Timedelta, datetime.timedelta, np.timedelta64, str, int] = '0h', + start_radius: Union[pd.Timedelta, datetime.timedelta, np.timedelta64, str, int] = '0h' ) -> pd.DataFrame: """Apply time series decomposition to mark event values in a streamflow time series. Discretize continuous event values into indiviual events. @@ -312,10 +312,10 @@ def list_events( window: int, offset, or BaseIndexer subclass, required Size of the moving window for `pandas.Series.rolling.min`. This filter is used to model the trend in `series`. - minimum_event_duration: pandas.Timedelta, datetime.timedelta, numpy.timedelta64, str, int, optional, default '0H' + minimum_event_duration: pandas.Timedelta, datetime.timedelta, numpy.timedelta64, str, int, optional, default '0h' Enforce a minimum event duration. This should generally be set equal to halflife to reduce the number of false positives flagged as events. - start_radius: pandas.Timedelta, datetime.timedelta, numpy.timedelta64, str, int, optional, default '0H' + start_radius: pandas.Timedelta, datetime.timedelta, numpy.timedelta64, str, int, optional, default '0h' Shift event starts to a local minimum. Phase shifts imparted on the original signal may advance or delay event start times depending upon how much smoothing is required to eliminate noise. From 200bc0318eeeca2441b0b65e9cf4428f6a03d750 Mon Sep 17 00:00:00 2001 From: Jason Regina Date: Fri, 9 Feb 2024 09:26:08 -0600 Subject: [PATCH 4/5] specify boolean series type to avoid future warning --- .../src/hydrotools/events/event_detection/decomposition.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/python/events/src/hydrotools/events/event_detection/decomposition.py b/python/events/src/hydrotools/events/event_detection/decomposition.py index 1c9c3f30..8fbc3e99 100644 --- a/python/events/src/hydrotools/events/event_detection/decomposition.py +++ b/python/events/src/hydrotools/events/event_detection/decomposition.py @@ -153,12 +153,12 @@ def event_boundaries(event_points: pd.Series): """ # Identify event starts - forward_shift = event_points.shift(1).fillna(False) + forward_shift = event_points.shift(1).astype(bool).fillna(False) starts = (event_points & ~forward_shift) starts = starts[starts] # Identify event ends - backward_shift = event_points.shift(-1).fillna(False) + backward_shift = event_points.shift(-1).astype(bool).fillna(False) ends = (event_points & ~backward_shift) ends = ends[ends] From 152bd556dad2709826db467e84ee6087fe89a809 Mon Sep 17 00:00:00 2001 From: Jason Regina Date: Fri, 9 Feb 2024 09:36:09 -0600 Subject: [PATCH 5/5] bump events to 1.1.6 --- python/events/src/hydrotools/events/event_detection/_version.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/python/events/src/hydrotools/events/event_detection/_version.py b/python/events/src/hydrotools/events/event_detection/_version.py index 9b102be7..1436d8fe 100644 --- a/python/events/src/hydrotools/events/event_detection/_version.py +++ b/python/events/src/hydrotools/events/event_detection/_version.py @@ -1 +1 @@ -__version__ = "1.1.5" +__version__ = "1.1.6"