xpectra

Calibration, OOD abstention, semi-supervised learning, and weathering analysis for microplastic FTIR classification

Release 0.1.1 · maintained by Data Analysis Team at KaziLab.se · <xpectra@kazilab.se>


xpectra is a reusable pipeline and analysis toolkit for reliable polymer identification from FTIR spectra. It targets the failure mode that ordinary microplastic classifiers hide: models trained on pristine reference plastics and validated on a random split of a single dataset report high accuracy, then fail silently on weathered, environmental particles measured on a different instrument. xpectra quantifies that generalization gap and provides the tools that make predictions trustworthy in deployment:

  • Honest validation — leave-one-study-out (LOSO), not random-split, so the score reflects transfer to an unseen instrument.

  • Probability calibration — leakage-safe temperature / isotonic scaling with expected calibration error (ECE) and reliability diagrams.

  • Out-of-distribution detection & abstention — max-softmax, entropy, energy, Mahalanobis, kNN-distance, and spectral-angle scorers with a calibrated abstention threshold.

  • Semi-supervised learning — self-training and label spreading over unlabeled field spectra.

  • Weathering analysis — the carbonyl index and its cross-instrument confounds.

  • A reproducible study layer — the full published analyses (deep models, contrastive representations, external-data augmentation, degradation clustering) as one-command workflows.

Three preprocessing routes

Every workflow runs over one of three preprocessing routes, produced once by xpectra-process-raw:

Route

File

Content

norm

combined_norm_data.csv.xz

spectral_moments-normalized spectra

deriv1

combined_norm_deriv1_data.csv.xz

first Savitzky–Golay derivative

deriv2

combined_norm_deriv2_data.csv.xz

second Savitzky–Golay derivative

Getting started

Project

Citation & contact

If you use xpectra in academic work, please cite the package and the underlying reference datasets (see Study reproduction workflows). For questions, contact the Data Analysis Team at KaziLab.se at <xpectra@kazilab.se>.