Scatter Correction¶
spectrakit.scatter.scatter_msc ¶
Apply Multiplicative Scatter Correction.
Each spectrum is corrected by fitting a linear regression against a reference spectrum (default: mean spectrum), then subtracting the intercept and dividing by the slope.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
intensities
|
ndarray
|
Spectral intensities, shape |
required |
reference
|
ndarray | None
|
Reference spectrum, shape |
None
|
Returns:
| Type | Description |
|---|---|
ndarray
|
MSC-corrected 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 a single spectrum is provided without a reference. |
Source code in src/spectrakit/scatter/msc.py
spectrakit.scatter.scatter_emsc ¶
scatter_emsc(
intensities: ndarray,
reference: ndarray | None = None,
poly_order: int = DEFAULT_POLY_ORDER,
) -> np.ndarray
Apply Extended Multiplicative Signal Correction.
Extends MSC by also modeling polynomial baseline variations. Fits each spectrum as a linear combination of the reference spectrum plus orthogonal polynomial (Legendre) terms, then corrects by removing the polynomial and scatter contributions.
Uses Legendre polynomials instead of monomials for improved numerical conditioning of the design matrix.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
intensities
|
ndarray
|
Spectral intensities, shape |
required |
reference
|
ndarray | None
|
Reference spectrum, shape |
None
|
poly_order
|
int
|
Maximum polynomial order for baseline modeling. Set to 0 to disable polynomial correction (equivalent to MSC). |
DEFAULT_POLY_ORDER
|
Returns:
| Type | Description |
|---|---|
ndarray
|
EMSC-corrected 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 a single spectrum is provided without a reference,
or if |