pymovements.gaze.transforms.savitzky_golay#

pymovements.gaze.transforms.savitzky_golay(*, window_length: int, degree: int, sampling_rate: float, n_components: int, input_column: str, output_column: str | None = None, derivative: int = 0, padding: str | float | int | None = 'nearest') pl.Expr#

Apply a 1-D Savitzky-Golay filter to a column|_|:cite:p:SavitzkyGolay1964.

Parameters:
  • window_length (int) – The length of the filter window (i.e., the number of coefficients). If padding is None, window_length must be less than or equal to the length of the input.

  • degree (int) – The degree of the polynomial used to fit the samples. degree must be less than window_length.

  • sampling_rate (float) – The spacing of the samples to which the filter will be applied. This is only used if deriv > 0. Default is 1.0.

  • n_components (int) – Number of components in input column.

  • input_column (str) – The input column name.

  • output_column (str | None) – The output column name. (default: None)

  • derivative (int) – The order of the derivative to compute. This must be a nonnegative integer. The default is 0, which means to filter the data without differentiating. (default: 0)

  • padding (str | float | int | None) – Must be either None, a scalar or one of the strings mirror, nearest or wrap. This determines the type of extension to use for the padded signal to which the filter is applied. When passing None, no extension padding is used. Instead, a degree degree polynomial is fit to the last window_length values of the edges, and this polynomial is used to evaluate the last window_length // 2 output values. When passing a scalar value, data will be padded using the passed value. See the Notes for more details on the padding methods mirror, nearest or wrap. (default: ‘nearest’)

Returns:

The respective polars expression

Return type:

pl.Expr

Notes

Details on the padding options:

  • None: No padding extension is used.

  • scalar value (int or float): The padding extension contains the specified scalar value.

  • mirror: Repeats the values at the edges in reverse order. The value closest to the edge is not included.

  • nearest: The padding extension contains the nearest input value.

  • wrap: The padding extension contains the values from the other end of the array.

Given the input is [1, 2, 3, 4, 5, 6, 7, 8], and window_length is 7, the following table shows the padded data for the various padding options:

mode

padding

input

padding

None

-  -  -

1  2  3  4  5  6  7  8

-  -  -

0

0  0  0

1  2  3  4  5  6  7  8

0  0  0

1

1  1  1

1  2  3  4  5  6  7  8

1  1  1

nearest

1  1  1

1  2  3  4  5  6  7  8

8  8  8

mirror

4  3  2

1  2  3  4  5  6  7  8

7  6  5

wrap

6  7  8

1  2  3  4  5  6  7  8

1  2  3