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, preferring the retained samples and then the original axis before masked samples were removed. If neither is uniform,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.With masked data, windows spanning a masked gap can produce unreliable derivatives at nearby unmasked points. Combining regular subsampling with masked blocks can also give incorrect automatic scaling away from the gaps; supply the signed spacing of the retained samples as
deltain that case. See the masked-data notes insavgolfor details.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