xrscipy.other.signal.savgol_filter

xrscipy.other.signal.savgol_filter(darray: DataArray, window_length: int, polyorder: int, deriv: int = 0, delta: float = None, dim: str = None, mode: str = 'interp', cval: float = 0.0) DataArray

Apply a Savitzky-Golay filter to an array.

This is a 1-d filter. If darray has dimension greater than 1, dim determines the dimension along which the filter is applied. :param darray: An xarray type data to be filtered. If values of darray are not

a single or double precision floating point array, it will be converted to type numpy.float64 before filtering.

Parameters:
  • window_length (int) – The length of the filter window (i.e. the number of coefficients). window_length must be a positive odd integer. If mode is ‘interp’, window_length must be less than or equal to the size of darray.

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

  • deriv (int, optional) – 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.

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

  • dim (string, optional) – Specifies the dimension along which the filter is applied. For 1-d darray finds the only dimension, if not specified. For multi dimensional darray, the dimension for the filtering has to be specified, otherwise raises ValueError. Default is None.

  • mode (str, optional) – Must be ‘mirror’, ‘constant’, ‘nearest’, ‘wrap’ or ‘interp’. This determines the type of extension to use for the padded signal to which the filter is applied. When mode is ‘constant’, the padding value is given by cval. See the Notes for more details on ‘mirror’, ‘constant’, ‘wrap’, and ‘nearest’. When the ‘interp’ mode is selected (the default), no extension is used. Instead, a degree polyorder 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.

  • cval (scalar, optional) – Value to fill past the edges of the input if mode is ‘constant’. Default is 0.0.

Returns:

y – The filtered data.

Return type:

DataArray, same shape as darray