from uhina.loading import OSSLLoader
from sklearn.pipeline import Pipeline
from matplotlib import pyplot as plt
import fastcore.all as fc
Preprocessing
Utility functions to preprocess spectra.
SNV
SNV ()
Creates scikit-learn SNV custom transformer
TakeDerivative
TakeDerivative (window_length=11, polyorder=1, deriv=1)
*Creates scikit-learn derivation custom transformer
Args: window_length: int, optional Specify savgol filter smoothing window length
polyorder: int, optional
Specify order of the polynom used to interpolate derived signal
deriv: int, optional
Specify derivation degree
Returns: scikit-learn custom transformer*
Usage example:
= fc.load_pickle('./files/spectrum-and-all.pkl')
X, y, wavenumbers, smp_idx, ds_name, ds_label
#| eval: false
= Pipeline([
pipe 'SNV', SNV()),
('Derivative', TakeDerivative())
(
])
# Preprocess spectra
= pipe.fit_transform(X)
X_trans
# Plot first preprocessed spectrum
= plt.subplots(figsize=(12, 2))
fig, ax 0, :], lw=1)
ax.plot(wavenumbers, X_trans['Wavenumber ($cm^{-1}$)')
ax.set_xlabel('Absorbance')
ax.set_ylabel('Preprocessed Soil MIR Spectrum: SNV and 1st Derivative')
ax.set_title(True)
ax.grid( ax.invert_xaxis()