import numpy as np
import dascore as dc
patch = dc.get_example_patch()
# The 80th percentile of every window of 100 samples.
out = patch.window(time=100, samples=True).reduce(np.percentile, 80)
# Only the complete windows, a second long and half a second apart.
means = patch.window(time=1, step=0.5, ends="drop").mean()
assert not np.isnan(means.data).any()reduce
reduce(
self ,
function: collections.abc.Callable | str[Callable, str] ,
*args ,
**kwargs ,
)
Reduce each window to one value with a function.
Parameters
| Parameter | Description |
|---|---|
| function |
Given an array with one more axis than the data, the last, which holds each window’s samples, and an axis=-1 keywordnaming it, which it reduces. One of "mean", "median","min", "max", "std" or "sum" names the NumPyfunction. |
| *args, **kwargs | Passed on to the function. |
Returns
Patch One value for each window, in float64 (complex for complex data), along the windowed dimension. A window is labelled by one of the input’s samples, the one its align names, so with a step of one sample the patch keeps its shape and coordinates; align="middle" labels it halfway between its ends instead.
Examples
Note
- A window with no overlap or step given advances one sample.
- Only one dimension can be windowed.
- A reduction named by a string, with nothing else given to it, may be answered by pandas when the window is long, which is much faster and agrees with NumPy to rounding: a few parts in ten million for float32, less for float64.