petitRADTRANS.sbi.validation#

Pre-training data-sanity guards for SBI runs.

These catch a gross mismatch between the simulated training corpus and the observation before the (expensive) training loop – the failure mode where a units/scale bug or a stale/corrupt dataset leaves the training spectra orders of magnitude away from the observation. Without this guard that only surfaces as a post-training OOD score, after a multi-hour run has already been wasted.

This is deliberately an amplitude/scale check, complementary to (not a replacement for) the post-training per-wavelength OOD diagnostic. A prior predictive legitimately spans orders of magnitude in flux, so the comparison is done on each spectrum’s overall amplitude in log10 space: the question is purely “is the observation many orders of magnitude outside the simulated range?”.

Classes#

Functions#

check_observation_in_training_range(...)

Check the observation's flux scale lies within the training distribution.

Module Contents#

class petitRADTRANS.sbi.validation.ObservationScaleReport#

Result of check_observation_in_training_range().

log10_observation_scale: float#
log10_training_p1: float#
log10_training_p50: float#
log10_training_p99: float#
orders_outside: float#
max_orders_outside: float#
passed: bool#
petitRADTRANS.sbi.validation.check_observation_in_training_range(training_values: Any, observation_values: Any, *, max_orders_outside: float = 2.0, on_fail: str = 'raise', max_training_rows: int = 8192) ObservationScaleReport#

Check the observation’s flux scale lies within the training distribution.

For every simulated spectrum a robust amplitude (median absolute flux) is computed, and the [p1, p99] range of those amplitudes in log10 space defines the simulated scale band. The observation’s amplitude must lie within max_orders_outside decades of that band. A units/scale bug – e.g. training spectra at ~1e-20 while the observation is ~1e-15 – puts the observation ~3+ decades outside and is rejected here, before training, instead of only via the post-training OOD diagnostic.

Parameters#

training_values:

Simulated spectra, shape (n_samples, n_wavelengths) (raw flux scale, matching observation_values).

observation_values:

The observed spectrum, shape (n_wavelengths,).

max_orders_outside:

How many decades the observation amplitude may fall outside the simulated [p1, p99] band before the check fails.

on_fail:

"raise" (default) aborts with a descriptive error, "warn" prints a warning and continues, "off" disables the check (still returns a report).

max_training_rows:

Training rows are evenly subsampled to at most this many before computing statistics, keeping the check cheap on a multi-hundred-thousand-row split.

Returns#

ObservationScaleReport

The computed log10 scale statistics and pass/fail verdict.