Skip to content

Commit ede1af3

Browse files
committed
Change aggregate_by to sum_by
1 parent 38c5b5b commit ede1af3

File tree

4 files changed

+23
-33
lines changed

4 files changed

+23
-33
lines changed

huracanpy/_accessor.py

+2-4
Original file line numberDiff line numberDiff line change
@@ -545,9 +545,7 @@ def get_track_duration(self, time_name="time", track_id_name="track_id"):
545545

546546
def get_track_ace(self, wind_name="wind", track_id_name="track_id", **kwargs):
547547
return tc.ace(
548-
self._dataset[wind_name],
549-
aggregate_by=self._dataset[track_id_name],
550-
**kwargs,
548+
self._dataset[wind_name], sum_by=self._dataset[track_id_name], **kwargs
551549
)
552550

553551
def get_track_pace(
@@ -560,7 +558,7 @@ def get_track_pace(
560558
return tc.pace(
561559
self._dataset[pressure_name],
562560
wind,
563-
aggregate_by=self._dataset[track_id_name],
561+
sum_by=self._dataset[track_id_name],
564562
**kwargs,
565563
)
566564

huracanpy/tc/_ace.py

+11-11
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111

1212
def ace(
1313
wind,
14-
aggregate_by=None,
14+
sum_by=None,
1515
threshold=34 * units("knots"),
1616
wind_units="m s-1",
1717
):
@@ -20,11 +20,11 @@ def ace(
2020
.. math:: \mathrm{ACE} = 10^{-4} \sum v_\mathrm{max}^2 \quad (v_\mathrm{max} \ge 34 \mathrm{kn})
2121
2222
By default, this function will return the "ACE" for each individual point in `wind`.
23-
To calculate more useful quantities of ACE, use the `aggregate_by` keyword.
23+
To calculate more useful quantities of ACE, use the `sum_by` keyword.
2424
2525
For example, to calculate the ACE of each individual track, doing
2626
27-
>>> ace_by_track = huracanpy.tc.ace(tracks.wind, aggregate_by=tracks.track_id)
27+
>>> ace_by_track = huracanpy.tc.ace(tracks.wind, sum_by=tracks.track_id)
2828
2929
will return a DataArray with track_id as a coordinate and the sum of ACE for each
3030
track as the data. Note that this is equivalent to using groupby:
@@ -38,13 +38,13 @@ def ace(
3838
3939
Similarly to calculate a climatological mean ACE by year, run
4040
41-
>>> climatological_ace = huracanpy.tc.ace(tracks.wind, aggregate_by=tracks.time.dt.year).mean()
41+
>>> climatological_ace = huracanpy.tc.ace(tracks.wind,sum_by=tracks.time.dt.year).mean()
4242
4343
Parameters
4444
----------
4545
wind : array_like
4646
Maximum velocity of a tropical cyclone associated with the tracks dataset
47-
aggregate_by : array_like
47+
sum_by : array_like
4848
Variable to take the sum of ACE values across. Must have the same length as wind
4949
threshold : scalar, default=34 knots
5050
ACE is set to zero below this threshold wind speed. The default argument is in
@@ -64,8 +64,8 @@ def ace(
6464

6565
ace_values = get_ace(wind, threshold, wind_units)
6666

67-
if aggregate_by is not None:
68-
ace_values = ace_values.groupby(aggregate_by).sum()
67+
if sum_by is not None:
68+
ace_values = ace_values.groupby(sum_by).sum()
6969

7070
return ace_values
7171

@@ -74,7 +74,7 @@ def pace(
7474
pressure,
7575
wind=None,
7676
model=None,
77-
aggregate_by=None,
77+
sum_by=None,
7878
threshold_wind=None,
7979
threshold_pressure=None,
8080
wind_units="m s-1",
@@ -108,7 +108,7 @@ def pace(
108108
pressure : array_like
109109
wind : array_like, optional
110110
model : str, class, or object, optional
111-
aggregate_by : array_like
111+
sum_by : array_like
112112
Variable to take the sum of PACE values across. Must have the same length as
113113
pressure/wind. For examples, see the documentation for `huracanpy.tc.ace`
114114
threshold_wind : scalar, optional
@@ -133,8 +133,8 @@ def pace(
133133
**kwargs,
134134
)
135135

136-
if aggregate_by is not None:
137-
pace_values = pace_values.groupby(aggregate_by).sum()
136+
if sum_by is not None:
137+
pace_values = pace_values.groupby(sum_by).sum()
138138

139139
return pace_values, model
140140

tests/test_accessor.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,7 @@ def test_get_methods():
166166
ace_acc = data.hrcn.get_track_ace(
167167
wind_name="wind10",
168168
)
169-
ace_fct = huracanpy.tc.ace(data.wind10, aggregate_by=data.track_id)
169+
ace_fct = huracanpy.tc.ace(data.wind10, sum_by=data.track_id)
170170
np.testing.assert_array_equal(
171171
ace_acc,
172172
ace_fct,
@@ -177,7 +177,7 @@ def test_get_methods():
177177
pace_acc, _ = data.hrcn.get_track_pace(
178178
wind_name="wind10",
179179
)
180-
pace_fct, _ = huracanpy.tc.pace(data.slp, data.wind10, aggregate_by=data.track_id)
180+
pace_fct, _ = huracanpy.tc.pace(data.slp, data.wind10, sum_by=data.track_id)
181181
np.testing.assert_array_equal(
182182
pace_acc,
183183
pace_fct,

tests/test_tc/test_ace.py

+8-16
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,16 @@
55

66

77
@pytest.mark.parametrize(
8-
"aggregate_by, result",
8+
"sum_by, result",
99
[(None, [10.0894797]), ("track_id", [3.03623809, 2.21637375, 4.83686787])],
1010
)
11-
def test_ace(aggregate_by, result):
11+
def test_ace(sum_by, result):
1212
data = huracanpy.load(huracanpy.example_csv_file, source="csv")
1313

14-
if aggregate_by is not None:
15-
aggregate_by = data[aggregate_by]
16-
ace = huracanpy.tc.ace(data.wind10, aggregate_by=aggregate_by)
17-
if aggregate_by is None:
14+
if sum_by is not None:
15+
sum_by = data[sum_by]
16+
ace = huracanpy.tc.ace(data.wind10, sum_by=sum_by)
17+
if sum_by is None:
1818
ace = ace.sum()
1919

2020
np.testing.assert_allclose(ace, result)
@@ -25,19 +25,11 @@ def test_ace(aggregate_by, result):
2525
def test_pace():
2626
data = huracanpy.load(huracanpy.example_csv_file, source="csv")
2727
# Pass wind values to fit a (quadratic) model to the pressure-wind relationship
28-
pace, model = huracanpy.tc.pace(
29-
data.slp,
30-
data.wind10,
31-
aggregate_by=data.track_id,
32-
)
28+
pace, model = huracanpy.tc.pace(data.slp, data.wind10, sum_by=data.track_id)
3329

3430
np.testing.assert_allclose(pace, np.array([4.34978137, 2.65410482, 6.09892875]))
3531

3632
# Call with the already fit model instead of wind values
37-
pace, _ = huracanpy.tc.pace(
38-
data.slp,
39-
model=model,
40-
aggregate_by=data.track_id,
41-
)
33+
pace, _ = huracanpy.tc.pace(data.slp, model=model, sum_by=data.track_id)
4234

4335
np.testing.assert_allclose(pace, np.array([4.34978137, 2.65410482, 6.09892875]))

0 commit comments

Comments
 (0)