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 thederivparameter ofsavgol. It must be a positive integer not greater thanpolynomial_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 theorderparameter ofsavgoland must be less thansize.delta (
floatorNone, optional, default:None) β Signed sample spacing. WhenNone,savgolderives it from a uniformly spaced coordinate. If that is not possible,savgolwarns and falls back to index-based spacing.dim (
intorstr, 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 whenmode="constant".
- Returns:
NDDatasetβ Smoothed derivative with the metadata produced by the equivalentsavgolcall.
See also
savgolGeneral Savitzky-Golay filtering and differentiation interface.
Notes
The call
differentiate(dataset, derivative_order=n, size=w, polynomial_order=p)is equivalent tosavgol(dataset, deriv=n, size=w, order=p). Coordinate spacing, sign, units, masks, title, history, dimension selection, and numerical validation followsavgolunchanged. 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