Skip to content

Commit 748366f

Browse files
committed
Remove average_by argument and add documentation and examples for aggregate_by
1 parent efce634 commit 748366f

File tree

1 file changed

+27
-9
lines changed

1 file changed

+27
-9
lines changed

huracanpy/tc/_ace.py

+27-9
Original file line numberDiff line numberDiff line change
@@ -12,18 +12,40 @@
1212
def ace(
1313
wind,
1414
aggregate_by=None,
15-
average_by=None,
1615
threshold=34 * units("knots"),
1716
wind_units="m s-1",
1817
):
19-
r"""Calculate accumulate cyclone energy (ACE) for each track
18+
r"""Calculate accumulate cyclone energy (ACE)
2019
2120
.. math:: \mathrm{ACE} = 10^{-4} \sum v_\mathrm{max}^2 \quad (v_\mathrm{max} \ge 34 \mathrm{kn})
2221
22+
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.
24+
25+
For example, to calculate the ACE of each individual track, doing
26+
27+
>>> ace_by_track = huracanpy.tc.ace(tracks.wind, aggregate_by=tracks.track_id)
28+
29+
will return a DataArray with track_id as a coordinate and the sum of ACE for each
30+
track as the data. Note that this is equivalent to using groupby:
31+
32+
>>> ace_by_point = huracanpy.tc.ace(tracks.wind)
33+
>>> ace_by_track = ace_by_point.groupby(tracks.track_id).sum()
34+
35+
To calculate the average ACE by track, you can do
36+
37+
>>> ace_by_track_mean = ace_by_track.mean()
38+
39+
Similarly to calculate a climatological mean ACE by year, run
40+
41+
>>> climatological_ace = huracanpy.tc.ace(tracks.wind, aggregate_by=tracks.time.dt.year).mean()
42+
2343
Parameters
2444
----------
2545
wind : array_like
2646
Maximum velocity of a tropical cyclone associated with the tracks dataset
47+
aggregate_by : array_like
48+
Variable to take the sum of ACE values across. Must have the same length as wind
2749
threshold : scalar, default=34 knots
2850
ACE is set to zero below this threshold wind speed. The default argument is in
2951
knots. To pass an argument with units, use :py:mod:`metpy.units`, otherwise any
@@ -45,9 +67,6 @@ def ace(
4567
if aggregate_by is not None:
4668
ace_values = ace_values.groupby(aggregate_by).sum()
4769

48-
if average_by is not None:
49-
ace_values = ace_values.groupby(average_by).sum().mean()
50-
5170
return ace_values
5271

5372

@@ -56,7 +75,6 @@ def pace(
5675
wind=None,
5776
model=None,
5877
aggregate_by=None,
59-
average_by=None,
6078
threshold_wind=None,
6179
threshold_pressure=None,
6280
wind_units="m s-1",
@@ -90,6 +108,9 @@ def pace(
90108
pressure : array_like
91109
wind : array_like, optional
92110
model : str, class, or object, optional
111+
aggregate_by : array_like
112+
Variable to take the sum of PACE values across. Must have the same length as
113+
pressure/wind. For examples, see the documentation for `huracanpy.tc.ace`
93114
threshold_wind : scalar, optional
94115
threshold_pressure : scalar, optional
95116
wind_units : str, default="m s-1"
@@ -115,9 +136,6 @@ def pace(
115136
if aggregate_by is not None:
116137
pace_values = pace_values.groupby(aggregate_by).sum()
117138

118-
if average_by is not None:
119-
pace_values = pace_values.groupby(average_by).sum().mean()
120-
121139
return pace_values, model
122140

123141

0 commit comments

Comments
 (0)