import dascore as dc
# Simple example for rolling mean function
patch = dc.get_example_patch()
# apply rolling over 1 second with 0.5 step
mean_patch = patch.rolling(time=1, step=0.5).mean()
# drop nan at the start of the time axis.
out = mean_patch.dropna("time")rolling
rolling(
patch: Patch ,
step = None,
center = False,
engine: Literal[‘numpy’, ‘pandas’, None] = None,
samples = False,
overlap = None,
**kwargs ,
)-> ’_NumpyPatchRoller | _PandasPatchRoller’
Apply a rolling function along a specified dimension.
See also the rolling section of the processing tutorial and the smoothing recipe.
Parameters
| Parameter | Description |
|---|---|
| patch | The patch to apply the rolling function to. |
| step |
Evaluate every nth result, like slicing the output. This changes the output length and is mutually exclusive with overlap.
|
| center | Label each window by its center rather than its right edge. |
| engine |
"numpy" uses sliding_window_view and "pandas" usespandas.rolling. None selects pandas when the step is below 10and the squeezed patch has fewer than two dimensions. Otherwise it selects NumPy; there, named reductions (mean, sum, std, …) of windows spanning 100 or more steps run through pandas when it agrees with NumPy up to rounding, which is much faster. Explicit pandas supports at most two dimensions and raises ParameterErrorabove that. |
| samples |
If True, the values in kwargs and step represent samples along a dimension. Must be integers. Otherwise, values are assumed to have same units as the specified dimension, or have units attached. |
| overlap |
Window overlap in coordinate units, samples, or percent. When given,step = window - overlap; percentages are relative to the window.
|
| **kwargs |
Dimension and window size, such as time=10.
|
Rolling follows Pandas DataFrame.rolling semantics. With no step, the output retains the input shape. When center=False, incomplete leading windows are NaN; when center=True, incomplete windows at both edges are NaN. Use Patch.dropna to remove them. A step downsamples that output. For example, the mean of [0, 1, 2, 3, 4, 5] is:
- window 2:
[NaN, 0.5, 1.5, 2.5, 3.5, 4.5] - window 3:
[NaN, NaN, 1, 2, 3, 4] - window 3, step 2:
[NaN, 1, 3] - window 3, step 3:
[NaN, 2]
apply receives the rolling dimension as the last axis of each window; custom functions should reduce that axis. Extra arguments passed to apply are forwarded to the function.