Aggregate

class of dascore.proc.aggregate
inherits from: dascore.proc.aggregate._Reduction, PatchProcessor, DascoreBaseModel, pydantic.main.BaseModel
source

Aggregate(
    *args ,
    dim: Any = None,
    method: Any = mean,
    dim_reduce: Any = empty,
)-> None

Aggregate values along a specified dimension.

Note

The output stays on the patch’s array backend. A method the array API standard has no name for, such as a median or a callable, runs through NumPy and warns before the result is converted back; most shortcuts, such as Patch.mean, avoid that round trip, so prefer one where it fits.

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 a length 1 partial 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:
first
last
max
mean
median
min
std
sum

See Also

Examples

import numpy as np
import dascore as dc
patch = dc.get_example_patch()

# Calculate mean along time axis
patch_time = patch.aggregate("time", method=np.nanmean)

# Calculate median distance along distance dimension
patch_dist = patch.aggregate("distance", method=np.nanmedian)

# Calculate the mean, and remove the associated dimension
patch_mean_no_dim = patch.aggregate(
    "time", method="mean", dim_reduce="squeeze"
)

# Aggregate by the min value and keep the mean of the dimension
patch_mean_min = patch.aggregate(
    "distance", method="min", dim_reduce="mean",
)

Methods

Name Description
check Refuse a patch which does not carry what the operation needs.
get_metadata Return the reduced metadata, and each reduced axis in turn.
kernel Return the data reduced along each axis in turn.
model_copy Copy the model, dropping cached values the update invalidates.
new Create new instance with some attributed updated.
aggregate Aggregate values along a specified dimension.
reconcile Return metadata or a patch holding the final data; default as is.
run Run the operation: check, get_metadata, kernel, reconcile, record.