spectrochempy.savgol
- savgol(dataset, size=5, order=2, dim=-1, delta=None, **kwargs)[source]
Savitzky-Golay filter.
Wrapper of scpy.signal.savgol(). See the documentation of this function for more details.
- Parameters:
dataset (
NDDataset) – Input dataset to filter.size (
int, optional, default: 5) – The size of the smoothing window.order (
int, optional, default: 2) – The order of the polynomial used to fit the data.ordermust be less than size.dim (
intorstr, optional, default: -1) – Axis along which to apply the filter. Accepts a dimension name (e.g."x") or an integer index (e.g.-1for the last axis).delta (
floatorNone, optional, default:None) – Sample spacing passed toscipy.signal.savgol_filter.None(default) — whenderiv > 0, the signed spacing is automatically derived from the coordinate of the processed axis if the coordinate is uniformly spaced. On a non-uniform or missing coordinate a warning is emitted and the index-baseddelta=1.0is used as a fallback.A numeric value — passed directly to SciPy with its sign. The value is interpreted in the current unit of the selected coordinate. No unit-based correction (
_reversed) is applied. For a descending coordinate, supply a negativedeltaif the derivative should follow the physical axis.
Changed in version 0.12.5: Default changed from
1.0toNone(auto-detect).Changed in version 0.12.5: Explicit
deltais now passed to SciPy with its sign. The former_reversedunit-based correction is no longer applied whendeltais explicitly provided.**kwargs (keyword arguments, optional) – Additional keyword arguments passed to the filter.
- Returns:
NDDataset– Smoothed data.- Other Parameters:
deriv (
int, optional, default: 0) – The order of the derivative to compute.mode (
str, optional, default: ‘nearest’) – The mode parameter determines how the array borders are handled.cval (
float, optional, default: 0.0) – Value to fill past edges of input if mode is ‘constant’.log_level (
str, optional, default: ‘WARNING’) – The log level for the filter.
See also
FilterFilter processing.
Notes
When
deltaisNone(the default), the sample spacing is detected from the coordinate and passed directly toscipy.signal.savgol_filter. The Savitzky-Golay algorithm is fundamentally index-based; the detected delta scales the derivative coefficients during the convolution.When
deltais a numeric value, it is passed to SciPy exactly as provided, with its sign. The coordinate units (cm⁻¹,ppm, etc.) have no effect on the result in this case. The user is responsible for the sign convention.Units. For
deriv > 0with a physically scaled delta (auto-detected from a uniform coordinate or explicitly provided when the coordinate carries units), the output units aresource_units / coordinate_units**deriv. For example, a first derivative of absorbance with respect tocm⁻¹yieldsabsorbance·cm. Smoothing (deriv=0) and index-based fallbacks preserve the source units unchanged. If the source has no units, the result has no units regardless of the coordinate.Changed in version 0.12.5: Units are now propagated for physically scaled derivative paths. Smoothing and index fallbacks keep source units.
Examples using spectrochempy.savgol
Savitzky-Golay derivatives on a synthetic spectrum