savgol_filter#

movement.filtering.savgol_filter(data, window, polyorder=2, print_report=True, **kwargs)[source]#

Smooth data by applying a Savitzky-Golay 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.

  • polyorder (int) – The order of the polynomial used to fit the samples. Must be less than window. By default, a polyorder of 2 is used.

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

  • **kwargs (dict) – Additional keyword arguments are passed to scipy.signal.savgol_filter(). Note that the axis keyword argument may not be overridden.

Returns:

The data smoothed using a Savitzky-Golay filter with the provided parameters.

Return type:

xarray.DataArray

Notes

Uses the scipy.signal.savgol_filter() function to apply a Savitzky-Golay filter to the input data. See the SciPy documentation for more information on that function. Whenever one or more NaNs are present in a smoothing window of the input data, 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)). Note that, unlike movement.filtering.median_filter(), there is no min_periods option to control this behaviour.