Smoothing¶
spectrakit.smooth.smooth_savgol ¶
smooth_savgol(
intensities: ndarray,
window_length: int = DEFAULT_WINDOW_LENGTH,
polyorder: int = DEFAULT_POLYORDER,
) -> np.ndarray
Apply Savitzky-Golay smoothing filter.
Fits successive sub-sets of adjacent data points with a low-degree polynomial by the method of linear least squares.
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
|
Returns:
| Type | Description |
|---|---|
ndarray
|
Smoothed intensities, 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 |
Source code in src/spectrakit/smooth/savgol.py
spectrakit.smooth.smooth_whittaker ¶
smooth_whittaker(
intensities: ndarray,
lam: float = DEFAULT_LAMBDA,
differences: int = DEFAULT_DIFFERENCES,
wavenumbers: ndarray | None = None,
) -> np.ndarray
Apply Whittaker smoother (penalized least squares).
Minimizes the sum of squared residuals plus a penalty on the roughness (measured by finite differences) of the fitted curve.
When wavenumbers are provided, the penalty matrix accounts for non-uniform spacing between spectral points. This is important for spectra measured on instruments with variable point spacing, as the standard uniform-spacing penalty would over- or under-smooth regions with different point densities.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
intensities
|
ndarray
|
Spectral intensities, shape |
required |
lam
|
float
|
Smoothness parameter (lambda). Larger values produce smoother results. Typical range: 1e2 to 1e8. |
DEFAULT_LAMBDA
|
differences
|
int
|
Order of the difference penalty. 2 penalizes curvature (default), 1 penalizes slope. |
DEFAULT_DIFFERENCES
|
wavenumbers
|
ndarray | None
|
Wavenumber axis, shape |
None
|
Returns:
| Type | Description |
|---|---|
ndarray
|
Smoothed intensities, 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 |