@@ -105,7 +105,7 @@ def test_regroup_daily_to_7D():
105
105
t = pd .date_range (start = "2000-01-01" , end = "2000-01-28" , freq = "1D" )
106
106
values = 1 + np .arange (t .size )
107
107
precip = xr .DataArray (values , coords = {"T" : t })
108
- precip_int = calc .regroup (precip , group = "7D" , method = " sum" )
108
+ precip_int = calc .regroup (precip , group = "7D" ). sum ( )
109
109
110
110
np .testing .assert_array_equal (
111
111
precip_int , precip .resample (T = "7D" ).sum (skipna = True , min_count = 7 ).dropna ("T" )
@@ -121,8 +121,8 @@ def test_regroup_daily_to_pentad():
121
121
values_leap = 1 + np .arange (t_leap .size )
122
122
precip = xr .DataArray (values , coords = {"T" : t })
123
123
precip_leap = xr .DataArray (values_leap , coords = {"T" : t_leap })
124
- precip_pentad = calc .regroup (precip , group = "pentad" , method = " sum" )
125
- precip_pentad_leap = calc .regroup (precip_leap , group = "pentad" , method = " sum" )
124
+ precip_pentad = calc .regroup (precip , group = "pentad" ). sum ( )
125
+ precip_pentad_leap = calc .regroup (precip_leap , group = "pentad" ). sum ( )
126
126
127
127
np .testing .assert_array_equal (precip_pentad .data , [
128
128
15. , 40. , 65. , 90. , 115. , 140. , 165. , 190. , 215. , 240. , 265. ,
@@ -141,7 +141,7 @@ def test_regroup_daily_to_8day():
141
141
t = pd .date_range (start = "2020-11-01T120000" , end = "2021-02-01T120000" , freq = "1D" )
142
142
values = 1 + np .arange (t .size )
143
143
precip = xr .DataArray (values , coords = {"T" : t })
144
- precip_8day = calc .regroup (precip , group = "8day" , method = " sum" )
144
+ precip_8day = calc .regroup (precip , group = "8day" ). sum ( )
145
145
146
146
np .testing .assert_array_equal (precip_8day .data , [
147
147
92. , 156. , 220. , 284. , 348. , 412. , 351. , 524. , 588. , 652. , 716.
@@ -152,7 +152,7 @@ def test_regroup_daily_to_dekad():
152
152
t = pd .date_range (start = "2020-01-01T120000" , end = "2020-03-09T120000" , freq = "1D" )
153
153
values = 1 + np .arange (t .size )
154
154
precip = xr .DataArray (values , coords = {"T" : t })
155
- precip_dekad = calc .regroup (precip , group = "dekad" , method = " sum" )
155
+ precip_dekad = calc .regroup (precip , group = "dekad" ). sum ( )
156
156
157
157
np .testing .assert_array_equal (
158
158
precip_dekad .data , [55. , 155. , 286. , 365. , 465. , 504. ]
@@ -163,7 +163,7 @@ def test_regroup_daily_to_16day():
163
163
t = pd .date_range (start = "2000-11-01T120000" , end = "2001-02-01T120000" , freq = "1D" )
164
164
values = 1 + np .arange (t .size )
165
165
precip = xr .DataArray (values , coords = {"T" : t })
166
- precip_16day = calc .regroup (precip , group = "16day" , method = " sum" )
166
+ precip_16day = calc .regroup (precip , group = "16day" ). sum ( )
167
167
168
168
np .testing .assert_array_equal (
169
169
precip_16day .data , [376. , 632. , 763. , 1112. , 1368. ]
@@ -174,7 +174,7 @@ def test_regroup_daily_to_1M():
174
174
t = pd .date_range (start = "2000-11-01T120000" , end = "2001-02-01T120000" , freq = "1D" )
175
175
values = 1 + np .arange (t .size )
176
176
precip = xr .DataArray (values , coords = {"T" : t })
177
- precip_month = calc .regroup (precip , group = "1M" , method = " sum" )
177
+ precip_month = calc .regroup (precip , group = "1M" ). sum ( )
178
178
179
179
np .testing .assert_array_equal (
180
180
precip_month .data ,
@@ -186,7 +186,7 @@ def test_regroup_daily_to_5M():
186
186
t = pd .date_range (start = "2000-01-01" , end = "2001-12-31" , freq = "1D" )
187
187
values = 1 + np .arange (t .size )
188
188
precip = xr .DataArray (values , coords = {"T" : t })
189
- precip_month = calc .regroup (precip , group = "5M" , method = " sum" )
189
+ precip_month = calc .regroup (precip , group = "5M" ). sum ( )
190
190
191
191
xr .testing .assert_equal (
192
192
precip_month .isel (T_bins = 0 , drop = True ),
@@ -202,7 +202,7 @@ def test_regroup_daily_to_season1():
202
202
t = pd .date_range (start = "2000-01-01" , end = "2002-12-31" , freq = "1D" )
203
203
values = 1 + np .arange (t .size )
204
204
precip = xr .DataArray (values , coords = {"T" : t })
205
- precip_seas = calc .regroup (precip , group = "14 Dec - 29 Mar" , method = " sum" )
205
+ precip_seas = calc .regroup (precip , group = "14 Dec - 29 Mar" ). sum ( )
206
206
207
207
xr .testing .assert_equal (
208
208
precip_seas .isel (T_bins = 0 , drop = True ),
@@ -230,7 +230,7 @@ def test_regroup_daily_to_season2():
230
230
t = pd .date_range (start = "2000-01-01" , end = "2001-12-31" , freq = "1D" )
231
231
values = 1 + np .arange (t .size )
232
232
precip = xr .DataArray (values , coords = {"T" : t })
233
- precip_seas = calc .regroup (precip , group = "19-29 Feb" , method = " sum" )
233
+ precip_seas = calc .regroup (precip , group = "19-29 Feb" ). sum ( )
234
234
235
235
xr .testing .assert_equal (
236
236
precip_seas .isel (T_bins = 0 , drop = True ),
@@ -246,7 +246,7 @@ def test_regroup_daily_to_season3():
246
246
t = pd .date_range (start = "2000-01-01" , end = "2001-12-31" , freq = "1D" )
247
247
values = 1 + np .arange (t .size )
248
248
precip = xr .DataArray (values , coords = {"T" : t })
249
- precip_seas = calc .regroup (precip , group = "29 Feb - 29 Mar" , method = " sum" )
249
+ precip_seas = calc .regroup (precip , group = "29 Feb - 29 Mar" ). sum ( )
250
250
251
251
xr .testing .assert_equal (
252
252
precip_seas .isel (T_bins = 0 , drop = True ),
@@ -262,7 +262,7 @@ def test_regroup_daily_to_int():
262
262
t = pd .date_range (start = "2000-01-01" , end = "2000-01-28" , freq = "1D" )
263
263
values = 1 + np .arange (t .size )
264
264
precip = xr .DataArray (values , coords = {"T" : t })
265
- precip_int = calc .regroup (precip , group = 4 , method = " sum" )
265
+ precip_int = calc .regroup (precip , group = 4 ). sum ( )
266
266
267
267
np .testing .assert_array_equal (
268
268
precip_int ,
@@ -274,7 +274,7 @@ def test_resample_interval_to_daily():
274
274
t = pd .date_range (start = "2000-01-01" , end = "2000-01-28" , freq = "1D" )
275
275
values = 1 + np .arange (t .size )
276
276
precip = xr .DataArray (values , coords = {"T" : t })
277
- precip_pentad = calc .regroup (precip , group = "pentad" , method = " sum" )
277
+ precip_pentad = calc .regroup (precip , group = "pentad" ). sum ( )
278
278
precip_daily = calc .resample_interval_to_daily (precip_pentad )
279
279
280
280
np .testing .assert_array_equal (precip_daily , [
@@ -287,7 +287,7 @@ def test_resample_interval_to_daily_intensive():
287
287
t = pd .date_range (start = "2000-01-01" , end = "2000-01-28" , freq = "1D" )
288
288
values = 1 + np .arange (t .size )
289
289
precip = xr .DataArray (values , coords = {"T" : t }, attrs = {"units" : "mm/day" })
290
- precip_pentad = calc .regroup (precip , group = "pentad" , method = " mean" )
290
+ precip_pentad = calc .regroup (precip , group = "pentad" ). mean ( )
291
291
precip_daily = calc .resample_interval_to_daily (precip_pentad )
292
292
293
293
np .testing .assert_array_equal (precip_daily , [
@@ -633,19 +633,15 @@ def test_seasonal_onset_date_keeps_returning_same_outputs():
633
633
def test_seasonal_onset_date_keeps_returning_same_outputs_with_regroup ():
634
634
precip = data_test_calc .multi_year_data_sample ()
635
635
onsetsds = calc .regroup (
636
- time_series = precip ,
637
- group = "1 Mar - 20 Jun" ,
638
- method = "map" ,
639
- method_kwargs = {
640
- "func" : calc .onset_date ,
641
- "wet_thresh" : 1 ,
642
- "wet_spell_length" : 3 ,
643
- "wet_spell_thresh" : 20 ,
644
- "min_wet_days" : 1 ,
645
- "dry_spell_length" : 7 ,
646
- "dry_spell_search" : 21 ,
647
- },
648
- )
636
+ time_series = precip , group = "1 Mar - 20 Jun"
637
+ ).map (calc .onset_date , ** {
638
+ "wet_thresh" : 1 ,
639
+ "wet_spell_length" : 3 ,
640
+ "wet_spell_thresh" : 20 ,
641
+ "min_wet_days" : 1 ,
642
+ "dry_spell_length" : 7 ,
643
+ "dry_spell_search" : 21 ,
644
+ })
649
645
# That part could be included in regroup for this specific group case
650
646
onsetsds = onsetsds .isel (T_bins = np .arange (0 , onsetsds .size , 2 ), drop = True )
651
647
# Note that onset_date is written and such a manner that is also outputs T, while
@@ -709,15 +705,11 @@ def test_seasonal_cess_date_keeps_returning_same_outputs_with_regroup():
709
705
time_dim = "T"
710
706
).to_array (name = "soil moisture" ).squeeze ("variable" , drop = True )
711
707
cessds = calc .regroup (
712
- time_series = wb ,
713
- group = "1 Sep - 30 Nov" ,
714
- method = "map" ,
715
- method_kwargs = {
716
- "func" : calc .cess_date_from_sm ,
708
+ time_series = wb , group = "1 Sep - 30 Nov"
709
+ ).map (calc .cess_date_from_sm , ** {
717
710
"dry_thresh" : 5 ,
718
711
"dry_spell_length_thresh" : 3 ,
719
- },
720
- )
712
+ })
721
713
# Not sure what happened to T_bins here
722
714
cessds = cessds .isel (T = np .arange (0 , cessds .size , 2 ), drop = True )
723
715
cess = (cessds + cessds ["T" ]).squeeze ()
@@ -758,18 +750,14 @@ def test_seasonal_cess_date_from_rain_keeps_returning_same_outputs_with_regroup(
758
750
759
751
precip = data_test_calc .multi_year_data_sample ()
760
752
cessds = calc .regroup (
761
- time_series = precip ,
762
- group = "1 Sep - 30 Nov" ,
763
- method = "map" ,
764
- method_kwargs = {
765
- "func" : calc .cess_date_from_rain ,
753
+ time_series = precip , group = "1 Sep - 30 Nov"
754
+ ).map (calc .cess_date_from_rain , ** {
766
755
"dry_thresh" : 5 ,
767
756
"dry_spell_length_thresh" : 3 ,
768
757
"et" : 5 ,
769
758
"taw" : 60 ,
770
759
"sminit" : 33.57026932 , # from previous test sm output on 8/31/2000
771
- }
772
- )
760
+ })
773
761
cessds = cessds .isel (T = np .arange (0 , cessds .size , 2 ), drop = True )
774
762
cess = (cessds + cessds ["T" ]).squeeze ()
775
763
@@ -857,19 +845,15 @@ def test_seasonal_onset_date_with_regroup():
857
845
).rename ("synthetic_precip" )
858
846
859
847
onsetsds = calc .regroup (
860
- time_series = synthetic_precip ,
861
- group = "1 Mar - 20 Jun" ,
862
- method = "map" ,
863
- method_kwargs = {
864
- "func" : calc .onset_date ,
848
+ time_series = synthetic_precip , group = "1 Mar - 20 Jun"
849
+ ).map (calc .onset_date , ** {
865
850
"wet_thresh" : 1 ,
866
851
"wet_spell_length" : 3 ,
867
852
"wet_spell_thresh" : 20 ,
868
853
"min_wet_days" : 1 ,
869
854
"dry_spell_length" : 7 ,
870
855
"dry_spell_search" : 21 ,
871
- },
872
- )
856
+ })
873
857
onsetsds = onsetsds .isel (T_bins = np .arange (0 , onsetsds .size , 2 ), drop = True )
874
858
onsets = (onsetsds + onsetsds ["T" ]).drop_vars ("T" )
875
859
@@ -978,15 +962,11 @@ def test_seasonal_cess_date_with_regroup():
978
962
time_dim = "T"
979
963
).to_array (name = "soil moisture" )
980
964
cessds = calc .regroup (
981
- time_series = wb ,
982
- group = "1 Sep - 30 Nov" ,
983
- method = "map" ,
984
- method_kwargs = {
985
- "func" : calc .cess_date_from_sm ,
965
+ time_series = wb , group = "1 Sep - 30 Nov" ,
966
+ ).map (calc .cess_date_from_sm , ** {
986
967
"dry_thresh" : 5 ,
987
968
"dry_spell_length_thresh" : 3 ,
988
- },
989
- )
969
+ })
990
970
cessds = cessds .isel (T = np .arange (0 , cessds .size , 2 ), drop = True )
991
971
cess = (cessds + cessds ["T" ]).squeeze (drop = True )
992
972
@@ -1081,18 +1061,14 @@ def test_seasonal_cess_date_from_rain_with_regroup():
1081
1061
synthetic_precip ,
1082
1062
).rename ("synthetic_precip" )
1083
1063
cessds = calc .regroup (
1084
- time_series = synthetic_precip ,
1085
- group = "1 Sep - 30 Nov" ,
1086
- method = "map" ,
1087
- method_kwargs = {
1088
- "func" : calc .cess_date_from_rain ,
1064
+ time_series = synthetic_precip , group = "1 Sep - 30 Nov"
1065
+ ).map (calc .cess_date_from_rain , ** {
1089
1066
"dry_thresh" : 5 ,
1090
1067
"dry_spell_length_thresh" : 3 ,
1091
1068
"et" : 5 ,
1092
1069
"taw" : 60 ,
1093
1070
"sminit" : 0 ,
1094
- },
1095
- )
1071
+ })
1096
1072
cessds = cessds .isel (T = np .arange (0 , cessds .size , 2 ), drop = True )
1097
1073
cess = (cessds + cessds ["T" ]).squeeze ()
1098
1074
0 commit comments