rolling_filter#

movement.filtering.rolling_filter(data, window, statistic='median', min_periods=None, print_report=False)[source]#

Apply a rolling window filter across time.

This function uses xarray.DataArray.rolling() to apply a rolling window filter across the time dimension of the input data and computes the specified statistic over each window.

Parameters:
  • data (xarray.DataArray) – The input data array.

  • window (int) – The size of the rolling window, representing the fixed number of observations used for each window.

  • statistic (str) – Which statistic to compute over the rolling window. Options are median, mean, max, and min. The default is median.

  • min_periods (int) – Minimum number of observations in the window required to have a value (otherwise result is NaN). The default, None, is equivalent to setting min_periods equal to the size of the window. This argument is directly passed to the min_periods parameter of xarray.DataArray.rolling().

  • print_report (bool) – Whether to print a report on the number of NaNs in the dataset before and after smoothing. Default is False.

Returns:

The filtered data array.

Return type:

xarray.DataArray

Notes

By default, whenever one or more NaNs are present in the window, a NaN is returned to the output array. As a result, any stretch of NaNs present in the input data will be propagated proportionally to the size of the window (specifically, by floor(window/2)). To control this behaviour, the min_periods option can be used to specify the minimum number of non-NaN values required in the window to compute a result. For example, setting min_periods=1 will result in the filter returning NaNs only when all values in the window are NaN, since 1 non-NaN value is sufficient to compute the result.