spectrochempy.differentiate

differentiate(dataset, derivative_order=1, *, size=5, polynomial_order=2, delta=None, dim=-1, mode='interp', cval=0.0)[source]

Differentiate a spectrum using a Savitzky-Golay polynomial filter.

This is a discoverable differentiation interface to savgol; it computes a smoothed numerical derivative and does not use a separate finite-difference implementation.

Parameters:
  • dataset (NDDataset) – Input dataset to differentiate.

  • derivative_order (int, optional, default: 1) – Order of the derivative. This maps to the deriv parameter of savgol. It must be a positive integer not greater than polynomial_order.

  • size (int, optional, default: 5) – Size of the Savitzky-Golay window. It must be a positive odd integer.

  • polynomial_order (int, optional, default: 2) – Order of the polynomial fitted within each window. This maps to the order parameter of savgol and must be less than size.

  • delta (float or None, optional, default: None) – Signed sample spacing. When None, savgol derives it from a uniformly spaced coordinate. If that is not possible, savgol warns and falls back to index-based spacing.

  • dim (int or str, optional, default: -1) – Axis along which to differentiate. A dimension name such as "x" or an integer axis index can be used.

  • mode (str, optional, default: "interp") – Extension mode passed to the Savitzky-Golay filter.

  • cval (float, optional, default: 0.0) – Padding value used when mode="constant".

Returns:

NDDataset – Smoothed derivative with the metadata produced by the equivalent savgol call.

See also

savgol

General Savitzky-Golay filtering and differentiation interface.

Notes

The call differentiate(dataset, derivative_order=n, size=w, polynomial_order=p) is equivalent to savgol(dataset, deriv=n, size=w, order=p). Coordinate spacing, sign, units, masks, title, history, dimension selection, and numerical validation follow savgol unchanged. This facade additionally requires a positive derivative order no greater than the polynomial order.

Examples

>>> first_derivative = scp.differentiate(  
...     dataset,
...     derivative_order=1,
...     size=15,
...     polynomial_order=3,
... )

Examples using spectrochempy.differentiate

Savitzky-Golay derivatives on a synthetic spectrum

Savitzky-Golay derivatives on a synthetic spectrum