movement.filtering.savgol_filter#

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

Smooth pose tracks by applying a Savitzky-Golay filter over time.

Parameters:
  • ds (xarray.Dataset) – Dataset containing position, confidence scores, and metadata.

  • window_length (int) – The size of the filter window. Window length is interpreted as being in the input dataset’s time unit, which can be inspected with ds.time_unit.

  • polyorder (int) – The order of the polynomial used to fit the samples. Must be less than window_length. 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 filtering. 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:

ds_smoothed – The provided dataset (ds), where pose tracks have been smoothed using a Savitzky-Golay filter with the provided parameters.

Return type:

xarray.Dataset

Notes

Uses the scipy.signal.savgol_filter function to apply a Savitzky-Golay filter to the input dataset’s position variable. See the scipy documentation for more information on that function. Whenever one or more NaNs are present in a filter window of the input dataset, a NaN is returned to the output array. As a result, any stretch of NaNs present in the input dataset will be propagated proportionally to the size of the window in frames (specifically, by floor(window_length/2)). Note that, unlike movement.filtering.median_filter(), there is no min_periods option to control this behaviour.