Skip to content
GSPICE

Concepts

Prediction

gspice.pixelwise() and gspice.infill() evaluate the conditional distribution of The model and return predictions in flux units, differing in how they partition the set GG of pixels that are not conditioned on.

To find outliers, you need a prediction of every pixel that does not use the pixel itself. pixelwise predicts each pixel ii from the pixels beyond its guard window g={i′:∣i′−i∣≤nguard}g = \{i' : |i' - i| \le \mathrm{nguard}\}, clipped at the ends of the spectrum:

  • pixel i, predicted
  • its guard window: not conditioned on
  • conditioning pixels O

The conditioning pixels OO are all the pixels outside gg. With PP the precision matrix of Numerics,

xi∣xO∼N ⁣(−(Pgg−1PgO xO)i,  (Pgg−1)ii).x_i \mid x_O \sim \mathcal{N}\!\left(-\big(P_{gg}^{-1} P_{gO}\, x_O\big)_i,\; \big(P_{gg}^{-1}\big)_{ii}\right) .

The other pixels of gg are marginalized.

The guard window keeps the neighbors of pixel ii out of its prediction, for two reasons. First, neighboring pixels are correlated through the line-spread function and the upstream processing. The prediction should come from the correlations of the spectra instead (Finkbeiner et al., 2025). Second, an artifact a few pixels wide also changes the neighbors of ii, and a prediction from them would follow the artifact.

The default nguard=20 is the paper’s choice, set by the size of the smoothing kernel of its continuum normalization. nguard >= npix - 1 gives the prior. The guard window measures the effect of nguard on simulated artifacts.

pixelwise conditions on the bad pixels through their interpolated values. Their z-score is NaN, and the variance omits the error of the interpolated values. Next to a long run of bad pixels, the z-scores of the good pixels are therefore not calibrated. An interpolated bad pixel beyond the guard window can also carry the flux of a good pixel inside it into the prediction.

The z-score of pixel ii of spectrum ss is

zsi=fsi−f^sivarsi,z_{si} = \frac{f_{si} - \hat f_{si}}{\sqrt{\mathrm{var}_{si}}} ,

with f^si\hat f_{si} and varsi\mathrm{var}_{si} the conditional mean and variance in flux units. gspice.Prediction holds the three arrays.

To replace pixels, you predict them from all the pixels that you trust. infill divides the pixels of each spectrum into four kinds:

  • replaced pixels M
  • ignored pixel: not conditioned on, keeps its value
  • bad pixel: never conditioned on
  • conditioning pixels O
  • the replaced pixels MM, given by replace, the bad pixels by default;
  • the ignored pixels, given by ignore, which are neither conditioned on nor replaced, such as a guard window around a range of pixels;
  • the bad pixels, which are never conditioned on;
  • the conditioning pixels OO, all the other pixels.

GG is the union of replace, ignore and the bad pixels:

xG∣xO∼N ⁣(−PGG−1PGO xO,  PGG−1).x_G \mid x_O \sim \mathcal{N}\!\left(-P_{GG}^{-1} P_{GO}\, x_O,\; P_{GG}^{-1}\right) .

A pixel in both replace and ignore is replaced. The pixels of GG outside MM keep their input values and are marginalized. Unlike pixelwise, infill never conditions on a bad pixel, and no value in GG enters the mean, so an outlier in GG cannot change it.

A draw is a random sample of xMx_M from this distribution. Fill known bad pixels shows the mean, the variance, the covariance and the draws, and when to use each. What you get back lists the fields of the result.

A prediction of several pixels needs one number that says whether the observed values agree with it. Repaired.chi2 compares the input values with their prediction at TT, the replaced pixels that are good in the input:

χ2=rTTCTT−1rT,\chi^2 = r_T^\mathsf{T} C_{TT}^{-1} r_T ,

with rTr_T the input values minus the conditional mean, and CTTC_{TT} their conditional covariance. A bad pixel has no input value to compare, so it is in MM but not in TT. Repaired.dof, the number of degrees of freedom, is ∣T∣|T|.

The χ² uses the full conditional covariance, so the correlated errors of neighboring pixels do not count twice. Suppose that the mean and the covariance were exact, and that the pixel sets did not depend on the data. Then χ2\chi^2 would follow the χ² distribution with ∣T∣|T| degrees of freedom, whose mean is ∣T∣|T|. A fitted model predicts a held-out spectrum less well: the mean of χ2/∣T∣\chi^2 / |T| is then the finite-sample factor of Held-out uncertainty, which Repaired.fs holds.