movement.filtering.median_filter#
- movement.filtering.median_filter(ds, window_length, min_periods=None, print_report=True)[source]#
Smooth pose tracks by applying a median 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
.min_periods (int) – Minimum number of observations in 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 themin_periods
parameter ofxarray.DataArray.rolling
.print_report (bool) – Whether to print a report on the number of NaNs in the dataset before and after filtering. Default is
True
.
- Returns:
ds_smoothed – The provided dataset (ds), where pose tracks have been smoothed using a median filter with the provided parameters.
- Return type:
xarray.Dataset
Notes
By default, whenever one or more NaNs are present in the filter window, 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)
). To control this behaviour, themin_periods
option can be used to specify the minimum number of non-NaN values required in the window to compute a result. For example, settingmin_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.