median_filter#

movement.filtering.median_filter(data, window, min_periods=None, print_report=True)[source]#

Smooth data by applying a median filter over time.

Parameters:
  • data (xarray.DataArray) – The input data to be smoothed.

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

  • 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 True.

Returns:

The data smoothed using a median filter with the provided parameters.

Return type:

xarray.DataArray

Notes

By default, whenever one or more NaNs are present in the smoothing 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 median.