specsrbench.data

Loading the tuned cache: one object, loaded once, shared by every figure.

Each of the six notebooks opened the cache itself, with its own load() helper and its own list of .npy names. The lists had to be kept in step by hand, and the error message when one drifted was FileNotFoundError naming a file that had simply been renamed.

Arrays load lazily and are held after first access, so building all six figures in one process reads the 267 MB cache once rather than six times.

Functions

load_cache([directory])

The cache at directory, reusing an already-loaded one if possible.

Classes

Cache([directory])

The arrays every figure reads, from one directory.

Exceptions

MissingCache

Raised with the command that regenerates what is missing.

class specsrbench.data.Cache(directory=None)[source]

Bases: object

The arrays every figure reads, from one directory.

Parameters:

directory (Path | str | None)

property wl_high: ndarray

The log constant-R grid, in microns (6,671 points, R=4000).

property wl_low: ndarray
property z: ndarray

Spectroscopic redshift of each held-out galaxy.

property sigma_pix: ndarray

The LSF the caches were actually deconvolved with, in pixels.

A copy of the derived kernel, written by the build so that nothing downstream has to infer which kernel produced the arrays beside it. eval_set.npz ships a different sigma_pix that does not describe the data; never read that one.

property n_spectra: int
property n_pixels: int
property arrays: dict[str, ndarray]

Every method’s reconstruction, keyed by canonical name.

In the target’s normalised (per-spectrum z-scored) units, which is what makes the MAE columns comparable across spectra of wildly different brightness.

property sr1: ndarray
property zhat: ndarray

The redshift head’s estimate, as SR2 conditioned on it.

property x_high: ndarray

The grating reference every method is scored against.

property x_low: ndarray

The prism input, cubic-interpolated onto the high-resolution grid.

property snr: dict[str, ndarray]

Per-line S/N, keyed {method_key}_{line_key} (9 x 4 = 36).

property fits: dict[str, ndarray]

Gaussian fit parameters, keyed {label}_{line}_{amp,sigma,sn}.

property valid: ndarray

Pixels where the grating reference is real, not padding.

property x_high_err: ndarray

Reference flux uncertainty, in the same normalised units as x_high.

Scaled by each spectrum’s own standard deviation, matching the z-score applied to the fluxes; the mean is not subtracted, because an uncertainty is a width and has no offset.

Invalid pixels arrive as NaN. They are marked in the raw product by a sentinel of 1.0 against fluxes of order 1e-21; left unmasked, that one value drives the mean normalised uncertainty to 3e18 instead of ~0.5. The masking happens at build time, and tests/test_cache_integrity.py asserts it here.

x_high_err_floored()[source]

(errors, floor, mean) with a 1st-percentile floor applied.

A handful of pixels carry an uncertainty of essentially zero, and dividing a residual by one of those produces an inf that swallows the mean. The floor is the 1st percentile of the finite positive values, computed on this cache rather than hard-coded.

Return type:

tuple[ndarray, float, float]

line_positions(i)[source]

(key, label, observed wavelength) for lines inside the grid.

Parameters:

i (int)

Return type:

list[tuple[str, str, float]]

summary()[source]
Return type:

str

specsrbench.data.load_cache(directory=None)[source]

The cache at directory, reusing an already-loaded one if possible.

Parameters:

directory (Path | str | None)

Return type:

Cache