smooth#
- pymovements.transforms.smooth(*, method: str, window_length: int, n_components: int, degree: int | None = None, column: str = 'position', padding: str | float | int | None = 'nearest') Expr[source]#
Smooth data in a column.
- Parameters:
method (str) – The method to use for smoothing. See Notes for more details.
window_length (int) – For
moving_averagethis is the window size to calculate the mean of the subsequent samples. Forsavitzky_golaythis is the window size to use for the polynomial fit. Forexponential_moving_averagethis is the span parameter.n_components (int) – Number of components in the input column.
degree (int | None) – The degree of the polynomial to use. This has only an effect if using
savitzky_golayas smoothing method. degree must be less than window_length. (default: None)column (str) – The input column name to which the smoothing is applied. (default: ‘position’)
padding (str | float | int | None) – Must be either
None, a scalar or one of the stringsmirror,nearestorwrap. This determines the type of extension to use for the padded signal to which the filter is applied. When passingNone, no extension padding is used. When passing a scalar value, data will be padded using the passed value. See the Notes for more details on the padding methods. (default: ‘nearest’)
- Returns:
The respective polars expression.
- Return type:
pl.Expr
Notes
The following methods are available for smoothing:
savitzky_golay: Smooth data by applying a Savitzky-Golay filter. Seesavitzky_golay()for further details.moving_average: Smooth data by calculating the mean of the subsequent samples. Each smoothed sample is calculated by the mean of the samples in the window around the sample.exponential_moving_average: Smooth data by exponentially weighted moving average.
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 variouspaddingoptions:mode
padding
input
padding
None- - -1 2 3 4 5 6 7 8- - -00 0 01 2 3 4 5 6 7 80 0 011 1 11 2 3 4 5 6 7 81 1 1nearest1 1 11 2 3 4 5 6 7 88 8 8mirror4 3 21 2 3 4 5 6 7 87 6 5wrap6 7 81 2 3 4 5 6 7 81 2 3