savgol_filter#
- movement.filtering.savgol_filter(data, window, polyorder=2, print_report=False, **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, apolyorderof 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
False.**kwargs (dict) – Additional keyword arguments are passed to
scipy.signal.savgol_filter(). Note that theaxiskeyword argument may not be overridden, as the filter is always applied over thetimedimension.
- Returns:
The data smoothed using a Savitzky-Golay filter with the provided parameters.
- Return type:
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, unlikemovement.filtering.rolling_filter(), there is nomin_periodsoption to control this behaviour.The function raises a
ValueErrorif NaNs are found within the signal’s edge windows. To avoid this, fill any edge NaNs before filtering, or switch from the defaultmode='interp'to an alternative edge handling mode (e.g.,mode='nearest'ormode='mirror').