Command-line interface

xpectra installs ten console scripts. Four are the everyday pipeline; the rest reproduce the published study (see Study reproduction workflows).

Command

Purpose

xpectra-process-raw

Build the three route files from the bundled sources

xpectra-train

Train and save models per route

xpectra-predict

Predict polymer class for new spectra

xpectra-study

Run a named reproduction workflow

xpectra-nb2-corrected / xpectra-nb2-figures

Corrected deep-model reanalysis + figures

xpectra-nb3-analysis / xpectra-nb3-figures

Contrastive-representation diagnostics + figures

xpectra-nb4-analysis / xpectra-nb4-figures

Degradation-clustering diagnostics + figures

xpectra-process-raw

Regenerate the three route files (.csv.xz). --out-dir defaults to processed_data/.

xpectra-process-raw                     # write to processed_data/
xpectra-process-raw --out-dir some/dir  # write elsewhere
xpectra-process-raw --dry-run           # build + verify, write nothing
xpectra-process-raw --keep-duplicates   # retain within-study duplicate spectra
xpectra-process-raw --no-external       # skip the external augmentation datasets

Deduplication happens here, at source, so the normalized and derivative matrices are duplicate-free for every downstream consumer.

xpectra-train

Train the model panel and save artifacts per route.

xpectra-train --routes all
xpectra-train --routes norm deriv1 --model "XGBoost (100)" --model "Random Forest (100)"

Artifacts are written to models/<route>/<model>.joblib, each bundling the fitted estimator, StandardScaler, LabelEncoder, class names, preprocessing settings, and the exact training wavenumber order. A models/training_summary.csv collates the run.

xpectra-predict

Predict from a CSV of spectra through the saved route artifacts.

xpectra-predict path/to/raw_spectra.csv --routes all --output predictions.csv

The --input-stage flag controls how much preprocessing to apply, matching the state of your input:

--input-stage

Input is…

Pipeline applied

raw (default)

raw instrument spectra

denoise → baseline → normalize → interpolate → derive

normalized

already normalized

interpolate → derive only

route

already route-ready on the grid

none

Preprocessing can be overridden for raw inputs:

xpectra-predict path/to/raw_spectra.csv \
  --denoising-method wavelet --baseline-method aspls \
  --normalization-method spectral_moments --interpolate-method zero

# absorbance-like inputs stored on a 0–100 scale
xpectra-predict path/to/raw_spectra.csv --force-absorbance --absorbance-scale-factor 100

xpectra-study

List and run the reproduction workflows. Each accepts --route {norm,deriv1,deriv2} where applicable (see Study reproduction workflows).

xpectra-study --list
xpectra-study loso
xpectra-study deep-ssl --route norm