Derivatives¶
spectrakit.derivative.derivative_savgol ¶
derivative_savgol(
intensities: ndarray,
window_length: int = DEFAULT_WINDOW_LENGTH,
polyorder: int = DEFAULT_POLYORDER,
deriv: int = DEFAULT_DERIV,
delta: float = 1.0,
) -> np.ndarray
Compute spectral derivative using Savitzky-Golay filter.
Simultaneously smooths and differentiates spectral data. First and second derivatives are the most commonly used in chemometrics.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
intensities
|
ndarray
|
Spectral intensities, shape |
required |
window_length
|
int
|
Length of the filter window (must be odd and
greater than |
DEFAULT_WINDOW_LENGTH
|
polyorder
|
int
|
Order of the polynomial used to fit the samples. |
DEFAULT_POLYORDER
|
deriv
|
int
|
Order of the derivative to compute. Common values: 1 (first derivative) or 2 (second derivative). |
DEFAULT_DERIV
|
delta
|
float
|
Spacing of the samples to which the filter is applied.
Used to scale the derivative by |
1.0
|
Returns:
| Type | Description |
|---|---|
ndarray
|
Derivative spectrum, same shape as input. |
Raises:
| Type | Description |
|---|---|
SpectrumShapeError
|
If input is not 1-D or 2-D. |
EmptySpectrumError
|
If input has zero elements. |
ValueError
|
If parameters are invalid (window_length not odd, polyorder >= window_length, deriv < 0, delta <= 0). |
Source code in src/spectrakit/derivative/savgol.py
spectrakit.derivative.derivative_gap_segment ¶
derivative_gap_segment(
intensities: ndarray,
gap: int = DEFAULT_GAP,
segment: int = DEFAULT_SEGMENT,
deriv: int = DEFAULT_DERIV,
) -> np.ndarray
Compute gap-segment derivative (Norris-Williams method).
Averages over segment points then takes differences separated
by gap points. Commonly used for NIR pre-treatment.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
intensities
|
ndarray
|
Spectral intensities, shape |
required |
gap
|
int
|
Gap size (number of points between segments). |
DEFAULT_GAP
|
segment
|
int
|
Segment size (number of points to average). |
DEFAULT_SEGMENT
|
deriv
|
int
|
Derivative order. 1 = first derivative, 2 = second. |
DEFAULT_DERIV
|
Returns:
| Type | Description |
|---|---|
ndarray
|
Derivative spectrum, same shape as input (padded with zeros |
ndarray
|
at edges where the computation is undefined). |
Raises:
| Type | Description |
|---|---|
SpectrumShapeError
|
If input is not 1-D or 2-D. |
EmptySpectrumError
|
If input has zero elements. |
ValueError
|
If |