Preprocessing transforms#
Baseline and detrending#
Baseline correction methods for spectroscopic data.
- class spectoprep.preprocessing.baseline.ALSBaselineCorrection(lam=10000.0, p=0.001, niter=10)[source]#
Bases:
BaseEstimator,TransformerMixinAsymmetric Least Squares Baseline Correction.
This method estimates the baseline of spectra by fitting a smooth curve that preferentially lies beneath the data points.
- Parameters:
- baseline_#
Estimated baseline for each spectrum.
- Type:
ndarray of shape (n_samples, n_features)
- class spectoprep.preprocessing.baseline.DetrendTransformer(method='polynomial', order=2, dspline=100)[source]#
Bases:
BaseEstimator,TransformerMixinA transformer for detrending time series or spectral data using various methods.
- Parameters:
method (str, default='polynomial') – The detrending method to use: - ‘simple’: Linear detrend between first and last points - ‘polynomial’: Polynomial detrend of specified order - ‘spline’: Spline detrend with specified order and spacing
order (int, default=2) – The order of the polynomial or spline fit. Ignored if method=’simple’.
dspline (int, default=100) – The spacing between spline knots. Only used if method=’spline’.
Smoothing#
Smoothing methods for spectroscopic data.
- class spectoprep.preprocessing.smoothing.SavitzkyGolay(filter_win=11, poly_order=2, deriv_order=0)[source]#
Bases:
BaseEstimator,TransformerMixinSavitzky-Golay filter for smoothing and differentiation of data.
- Parameters:
Notes
The Savitzky-Golay filter is a digital smoothing polynomial filter that can preserve the high-frequency components of the signal better than standard averaging techniques.
Scatter correction#
Scatter correction methods for spectroscopic data preprocessing.
- class spectoprep.preprocessing.scatter.StandardNormalVariate[source]#
Bases:
BaseEstimator,TransformerMixinStandard Normal Variate (SNV) transformation.
SNV is a row-wise transformation that centers and scales each spectrum individually. It’s commonly used to remove scatter effects in spectroscopic data.
- mean_#
Mean of each sample (row) computed during fit.
- Type:
ndarray of shape (n_samples, 1)
- std_#
Standard deviation of each sample computed during fit.
- Type:
ndarray of shape (n_samples, 1)
- class spectoprep.preprocessing.scatter.MultiplicativeScatterCorrection[source]#
Bases:
BaseEstimator,TransformerMixinMultiplicative Scatter Correction (MSC) for spectroscopic data.
MSC performs a linear regression of each spectrum on a reference spectrum (usually the mean spectrum) and corrects using the estimated coefficients.
- mean_reference#
Reference spectrum (mean of all spectra by default).
- Type:
ndarray of shape (n_features,)
- class spectoprep.preprocessing.scatter.ExtendedMultiplicativeScatterCorrection(order=2)[source]#
Bases:
BaseEstimator,TransformerMixinExtended Multiplicative Scatter Correction (EMSC) for spectroscopic data.
EMSC extends the MSC method by incorporating polynomial terms to account for more complex spectral variations.
- Parameters:
order (int, default=2) – Order of the polynomial used in the correction.
- reference_spectrum#
Reference spectrum (mean of training spectra).
- Type:
ndarray of shape (n_features,)
- class spectoprep.preprocessing.scatter.LocalizedSNV(window_size=11)[source]#
Bases:
BaseEstimator,TransformerMixinLocalized Standard Normal Variate (LSNV) using a sliding window.
LSNV applies the SNV transformation using a local window around each wavelength point rather than the entire spectrum.
- Parameters:
window_size (int, default=11) – Size of the sliding window. Must be odd.
- class spectoprep.preprocessing.scatter.RobustNormalVariate(lower_percentile=25, upper_percentile=75)[source]#
Bases:
BaseEstimator,TransformerMixinRobust Normal Variate (RNV) Preprocessing.
RNV is a robust version of SNV that uses percentiles instead of mean and standard deviation to reduce the influence of outliers.
- Parameters:
Normalization and scaling#
Normalization methods for spectroscopic data.
- class spectoprep.preprocessing.norml.Normalization(method='minmax', feature_range=(0, 1))[source]#
Bases:
BaseEstimator,TransformerMixinGeneral normalization transformer that supports different methods.
- Parameters:
- min_#
Minimum values of each sample (for minmax scaling).
- Type:
ndarray of shape (n_samples, 1)
- max_#
Maximum values of each sample (for minmax scaling).
- Type:
ndarray of shape (n_samples, 1)
- mean_#
Mean values of each sample (for zscore scaling).
- Type:
ndarray of shape (n_samples, 1)
- std_#
Standard deviation of each sample (for zscore scaling).
- Type:
ndarray of shape (n_samples, 1)
- class spectoprep.preprocessing.norml.Autoscaling[source]#
Bases:
BaseEstimator,TransformerMixinAutoscaling (column-wise standardization).
Centers and scales data to unit variance along columns (features).
- mean_#
Mean value for each feature.
- Type:
ndarray of shape (n_features,)
- std_#
Standard deviation for each feature.
- Type:
ndarray of shape (n_features,)
- class spectoprep.preprocessing.norml.MeanCentering[source]#
Bases:
BaseEstimator,TransformerMixinMean Centering transformation.
Centers data by subtracting the column means, without scaling.
- mean_#
Mean value for each feature.
- Type:
ndarray of shape (n_features,)
- class spectoprep.preprocessing.norml.GlobalScaler(factor=1.0, mean=False, std=False)[source]#
Bases:
BaseEstimator,TransformerMixinApplies global scaling to spectra by a constant factor with optional mean centering and standardization.
- Parameters:
- class spectoprep.preprocessing.norml.RowStandardizer[source]#
Bases:
BaseEstimator,TransformerMixinStandardizes each row independently (i.e. across columns).
- class spectoprep.preprocessing.norml.ColumnStandardizer[source]#
Bases:
BaseEstimator,TransformerMixinStandardizes columns using StandardScaler fitted on the training set.