FTIR Model Training And Prediction Pipeline
xpectra is a reusable pipeline for microplastic FTIR classification, built around three preprocessing routes:
norm:combined_norm_data.csv.xzderiv1:combined_norm_deriv1_data.csv.xzderiv2:combined_norm_deriv2_data.csv.xz
The preprocessing defaults, reproduced by xpectra-process-raw, are: wavelet denoising, aspls baseline correction, atmospheric interpolation with zero, spectral_moments normalization, and Savitzky-Golay derivatives with window_length=15, polyorder=3.
When installed from PyPI, the reusable workflows are available as command-line tools:
xpectra-process-raw --out-dir processed_data
xpectra-train --routes all
xpectra-predict path/to/raw_spectra.csv --output predictions.csv
xpectra-study --list
The notebook reproduction drivers are grouped under xpectra-study. Install the optional
study dependencies for the heavier workflows:
python -m pip install "xpectra[study]"
Process Raw Data
Regenerate the three route files (.csv.xz) consumed by the study workflows. --out-dir
defaults to processed_data/; pass --dry-run to build and verify without writing:
xpectra-process-raw # writes to processed_data/
xpectra-process-raw --out-dir some/other/dir
xpectra-process-raw --dry-run # build + verify only, no files written
Reproduce Notebook Results
List the available study workflows:
xpectra-study --list
Run one workflow:
xpectra-study loso
xpectra-study nb2-corrected
xpectra-study nb2-figures
xpectra-study contrastive
xpectra-study nb3-analysis
xpectra-study nb3-figures
xpectra-study nb4-analysis
xpectra-study nb4-figures
xpectra-study report
Preprocessing route
The study workflows and the nb2/nb3/nb4 analysis and figure commands accept
--route {norm,deriv1,deriv2} (default norm). Every result table, figure, and cached
embedding is written with the route as a filename prefix (for example
norm_deep_ssl_loso.csv, deriv1_figure3_main_contrastive_transfer.png), so runs on
different routes never overwrite one another:
xpectra-study deep-ssl --route norm
xpectra-study deep-ssl --route deriv1
The classical sweeps (calibrate, loso, ood, ssl) instead carry a route column and
cover all three routes in a single unprefixed file.
The corrected Notebook 2 workflow reuses current nb2-corrected-v3 result tables by
default. To deliberately rerun the complete nested analysis, use
xpectra-nb2-corrected --force. Publication figures can be regenerated with
xpectra-nb2-figures (also --route-aware).
The Notebook 3 publication workflow uses the cached contrastive encoder and
embeddings from xpectra-study contrastive. Generate its canonical diagnostic
tables with xpectra-nb3-analysis, then build the main and supplementary figure
sets with xpectra-nb3-figures.
Notebook 4 validates robust field-spectrum clusters against polymer identity,
carbonyl index, environmental status, and source-study provenance. Generate its
canonical tables with xpectra-nb4-analysis and the publication figure sets
with xpectra-nb4-figures.
Train And Save Models
Train all 41 Xpectrass models for all three routes:
xpectra-train --routes all
Train selected models only:
xpectra-train \
--routes norm deriv1 deriv2 \
--model "XGBoost (100)" \
--model "Random Forest (100)"
Saved artifacts are written to:
models/
norm/<model>.joblib
deriv1/<model>.joblib
deriv2/<model>.joblib
training_summary.csv
Each artifact contains the fitted estimator, StandardScaler, LabelEncoder, class names, preprocessing settings, and exact training wavenumber order.
Predict From Raw CSV
Predict through all saved route artifacts:
xpectra-predict path/to/raw_spectra.csv \
--routes all \
--models-dir models \
--output predictions.csv
Use only selected models:
xpectra-predict path/to/raw_spectra.csv \
--routes norm deriv1 \
--model "XGBoost (100)" \
--output predictions.csv
If your CSV is already normalized, skip raw denoise/baseline/normalization and only interpolate/derive:
xpectra-predict path/to/normalized_spectra.csv \
--input-stage normalized \
--routes all \
--output predictions.csv
If your CSV is already route-ready on the expected wavenumber grid:
xpectra-predict path/to/route_ready.csv \
--input-stage route \
--routes norm \
--output predictions.csv
Override Preprocessing
The prediction CLI lets you override the preprocessing defaults:
xpectra-predict path/to/raw_spectra.csv \
--denoising-method wavelet \
--baseline-method aspls \
--normalization-method spectral_moments \
--interpolate-method zero
For absorbance-like inputs that should skip Xpectrass auto-conversion:
xpectra-predict path/to/raw_spectra.csv \
--force-absorbance
For spectra stored on a 0-100 absorbance-like scale:
xpectra-predict path/to/raw_spectra.csv \
--force-absorbance \
--absorbance-scale-factor 100
Metadata
Release files for xpectra 0.1.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| xpectra-0.1.1.tar.gz | 16.0 MB | Without provenance | Details for xpectra-0.1.1.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| xpectra-0.1.1-py3-none-any.whl | Python 3 | none | any | Details for xpectra-0.1.1-py3-none-any.whl |
Total release size: 32.0 MB
Release files / xpectra-0.1.1.tar.gz
| Download URL | xpectra-0.1.1.tar.gz |
|---|---|
| Size | 16.0 MB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
cd05c34750d432dec31c50da352289021acee90df15756ed67115d61637a340e
|
|
BLAKE2b-256 checksum How to use checksums |
1e4f8c95bfcc15ccb5742a2de5b2ad433540c2d7a9b7ba2809356e9a4a745ca7
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.13.9
|
Release files / xpectra-0.1.1-py3-none-any.whl
| Download URL | xpectra-0.1.1-py3-none-any.whl |
|---|---|
| Size | 16.0 MB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
e09e6112aac1bb5f79754be76b48614dbabf1488a9b1e4382d31703c8a807c16
|
|
BLAKE2b-256 checksum How to use checksums |
e0cd6c5d3d2270a1d718ce800b233fc26d05121168b8bb1b04f924bcd1513cac
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.13.9
|
Security for xpectra 0.1.1
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.