import numpy as np
import dascore as dc
= dc.get_example_patch()
patch
# Calculate mean along time axis
= patch.aggregate("time", method=np.nanmean)
patch_time
# Calculate median distance along distance dimension
= patch.aggregate("distance", method=np.nanmedian)
patch_dist
# Calculate the mean, and remove the associated dimension
= patch.aggregate(
patch_mean_no_dim "time", method="mean", dim_reduce="squeeze"
)
# Aggregate by the min value and keep the mean of the dimension
= patch.aggregate(
patch_mean_min "distance", method="min", dim_reduce="mean",
)
aggregate
aggregate(
patch: Patch ,
dim: str | collections.abc.Sequence[str, collections.abc.Sequence[str], None] = None,
method: str | collections.abc.Callable[str, Callable] = mean,
dim_reduce: str | collections.abc.Callable[str, Callable] = empty,
)-> ‘PatchType’
Aggregate values along a specified dimension.
Parameters
Parameter | Description |
---|---|
patch | The input Patch. |
dim |
The dimension along which aggregations are to be performed. If None, apply aggregation to all dimensions sequentially. If a sequence, apply sequentially in order provided. |
dim_reduce |
How to reduce the dimensional coordinate associated with the aggregated axis. Can be the name of any valid aggregator, a callable, “empty” (the default) - which returns and empty coord, or “squeeze” which drops the coordinate. For dimensions with datetime or timedelta datatypes, if the operation fails it will automatically be applied to the coordinates converted to floats then the output converted back to the appropriate time type. |
method |
The aggregation to apply along dimension. Options are: mean median min max sum std first last |
See Also
- See also the aggregation shortcut methods in the aggregate module.