Skip to contents

OSSL Data

Download the Open Soil Spectral Library from its official storage bucket into a user-local cache. autoSpectra never redistributes OSSL data.

ossl_cache_dir()
Default local cache directory for OSSL data
ossl_download()
Download all three OSSL components (VisNIR, MIR, soillab)
ossl_download_file()
Download one OSSL component file to the cache directory
ossl_join()
Join OSSL spectra with soil lab data for model training
ossl_l1_labels
Fancy display labels for OSSL L1 properties
ossl_l1_log_transform
Properties that Safanelli log1p-transforms before fitting
ossl_l1_properties
All OSSL Level-1 harmonized soil property variable names (34 targets)
ossl_load_raw()
Load a cached OSSL CSV (gzipped) as a data.table
ossl_mir_instruments
MIR instruments contributing to OSSL v1.2
ossl_mir_matrix()
Extract OSSL MIR spectra as a matrix aligned to the OSSL standard grid
ossl_prepare()
Convenience: load and join all OSSL data for a given sensor type
ossl_soillab()
Extract OSSL Level-1 soil lab data for a set of properties
ossl_visnir_instruments
VisNIR instruments contributing to OSSL v1.2
ossl_visnir_matrix()
Extract OSSL VisNIR spectra as a matrix aligned to the OSSL standard grid

Pre-trained Models

Download the published model families from Zenodo (one-time setup)

download_ossl_models()
Download pre-trained OSSL soilVAE models from Zenodo
models_available()
Check whether pre-trained models are available locally
audit_release_archive()
Audit a built release archive for redistributed OSSL training data

Prediction

Predict soil properties, with intervals and applicability domain

predict_soil()
Predict soil properties from a spectral data frame
predict_applicability()
Compute applicability-domain scores for new spectra
format_predictions()
Round predictions and rename columns to display labels
get_family()
Lookup a model family from the registry
family_matches()
Test whether a family matches a sensor type
property_label()
Get a display label for a soil property key

Preprocessing

Spectral preprocessing, resampling and coverage masks

preprocess_visnir()
Canonical Safanelli preprocessing for VisNIR (reflectance input)
preprocess_mir()
Canonical Safanelli preprocessing for MIR (absorbance input)
reflectance_to_absorbance()
Convert reflectance to absorbance
apply_pipeline()
Apply a spectral preprocessing pipeline
apply_sg_matrix()
Apply Savitzky-Golay filter row-wise to a spectral matrix
apply_snv()
Apply Standard Normal Variate (SNV) row-wise
apply_snv_masked()
Apply SNV using only the masked (covered) bands of each row
parse_sg()
Parse SG parameter string of the form "SG(m,p)", "SG(m,p,d)", etc.
sg_safe_params()
Compute safe SG parameters given available number of columns
resample_to_grid()
Resample a spectral matrix to a target wavelength grid via linear interpolation
get_wavelengths()
Extract wavelength/wavenumber positions from a data frame's column names
mask_from_coverage()
Build a coverage mask from a resampled spectral matrix
has_spectral_coverage()
Which rows carry any spectral signal at all

Target Transforms

log1p transform for skewed properties and its bounded inverse, which keeps predictions inside the calibration range

apply_target_transform()
Forward log1p transform for properties whose policy asks for it
invert_target_transform()
Invert the target transform without letting it explode
target_bounds()
Training-scale bounds used to keep a back-transform from extrapolating
metrics_original_scale()
Score predictions in original units, with the bounded back-transform

soilVAE Family

Masked, sensor-agnostic variational autoencoder

build_maskedVAE()
Build a masked soilVAE for sensor-agnostic prediction
train_maskedVAE()
Train a masked soilVAE for one soil property
build_soilVAE()
Build a standard soilVAE
train_soilVAE()
Train a (standard) soilVAE model for one soil property
load_soilVAE()
Load a saved soilVAE model and its scaler
spectral_dropout()
Random spectral-dropout augmentation for masked-VAE training
train_ossl_models()
Train soilVAE models for all properties of one model family using OSSL data

Cubist + PCA Family

Replication of Safanelli et al. (2025)

train_cubist_pca()
Train one Cubist + PCA(120) model for a single soil property
load_cubist_pca()
Load a saved Cubist + PCA bundle for a property
predict_cubist_pca()
Predict with a Cubist + PCA bundle

Applicability Domain

Q-statistic (Cubist) and latent-space Mahalanobis distance (soilVAE)

q_statistic()
Compute the Q-statistic for each row of a PCA residual matrix
q_statistic_ucl()
Upper Confidence Limit for the Q-statistic (Jackson-Mudholkar 1979)
predict_q_statistic()
Compute Q-statistic and in-domain flag for new spectra against a fitted PCA
mahalanobis_d2()
Squared Mahalanobis distance against a multivariate Gaussian (mu, Sigma)
mahalanobis_threshold()
Chi-squared threshold for the Mahalanobis test in latent space

Prediction Intervals

Conformal calibration

train_normalized_conformal()
Train a normalised-conformal calibration for a Cubist + PCA model
predict_with_pi()
Predict with prediction intervals using a normalised-conformal calibration
absolute_conformal()
Simple absolute-residual conformal calibration (used by the VAE family)

Validation

Cross-validation, including leave-one-dataset-out

cv_train_property()
Perform 10-fold CV with refitting for one (family, property) combination
random_kfold()
Build random 10-fold indices (Safanelli default)
stratified_kfold()
Build Leave-One-Dataset-Out (LODO) k-fold indices
split_idx()
Split indices into train / calibration / test sets
metrics_from_y()
Compute prediction metrics (RMSE, Bias, R², RPIQ, CCC)

In-Memory Model Cache

Load models once per session and reuse them without disk I/O

get_cached_model()
Retrieve a soilVAE model from the in-memory cache
preload_ossl_models()
Pre-load all soilVAE models for a family into memory
list_cached_models()
List models currently held in the in-memory cache
clear_model_cache()
Clear the in-memory model cache

Visualization

Plotting functions

plot_spectra()
Plot one or more spectra from a data frame
plot_mean_spectrum()
Plot a mean spectrum with +/-1 SD ribbon
plot_predictions()
Plot predicted vs observed values for a soil property
plot_applicability()
Plot applicability-domain scores

Registry

Model registry and metadata

model_registry
Official autoSpectra model family registry
ossl_l1_properties
All OSSL Level-1 harmonized soil property variable names (34 targets)
ossl_l1_labels
Fancy display labels for OSSL L1 properties
ossl_visnir_instruments
VisNIR instruments contributing to OSSL v1.2
ossl_mir_instruments
MIR instruments contributing to OSSL v1.2

Shiny App

Launch the interactive application

run_autoSpectra()
Launch the autoSpectra Shiny application

Utilities

Lower-level helpers used by the trainers

save_scaler()
Save a z-score scaler to RDS and JSON
save_metrics_json()
Save per-model metrics JSON (RMSE, R2, RPIQ, conformal quantiles, latent stats)
feature_minmax()
Compute per-band min/max feature range from a preprocessed matrix
dir_create()
Create a directory if it does not already exist
vneed()
Safe shiny::validate wrapper