Concepts
Fitting
gspice.fit() clips outliers from the
training spectra in iterative passes, then
estimates the mean and covariance in the working units of
The model. Five kinds of model share this
function: the default, constant center, S/N bins, low rank, and noise-aware.
Training spectra
Section titled “Training spectra”A covariance of npix pixels has npix² entries, so it needs many spectra. fit skips a
spectrum with more than maxbadpix bad pixels
(64 by default) or with the weight 0. It also skips a spectrum whose pixels a clipping
pass masks completely. counts the spectra that a fit
uses.
With the scaled spectrum of The model, the model of S/N bin holds
over the spectra of the bin. With weights , both sums are weighted, and divides by instead of . The weights apply to the final fit only, and the clipping passes use unit weights.
A default model needs , and a good pixel in at least one spectrum at every pixel. Close to that minimum, can still fail the condition check of its precision matrix. What you get back lists the fields of the model.
Outlier clipping
Section titled “Outlier clipping”An artifact in a training spectrum adds a large deviation to the sums above, and so
widens the covariance at its pixels. fit therefore flags the
outliers of the training spectra in
clipping passes, with thresholds that
fall from pass to pass (paper Alg. 4). The figure follows one spectrum with a bad column
through the three default passes:
Pixels 0 to 99 of training spectrum 153, with a bad column at pixels 0 to 12
Pass 1: |z| > 20 flags pixels 0 to 1
Pass 2: |z| > 8 flags pixels 2 to 11
Pass 3: |z| > 6 flags pixels 12 to 13
- flux, then in-sample |z|
- threshold of the pass
- masked by earlier passes
- flagged by the pass
The panels show fit with its default passes on 4000 simulated spectra of 200 pixels, 30% of them with an artifact. Each pass fits a covariance without the masked pixels and computes |z| of every pixel, with nguard 20. The bad column widens the covariance of pass 1, so only its strongest pixels pass 20. Each refit is narrower, so the next pass finds more of the column. A flag also covers the pixel on each side.
Pass uses the threshold nsigma[n - 1], from nsigma=(20, 8, 6) by default, and the
mask , with the bad pixels. It runs four steps:
- Interpolate the pixels of , and scale each spectrum by over its pixels outside .
- Fit the covariance, with unit weights.
- Compute the pixelwise z-score of every pixel of these spectra, interpolated pixels
included, with
nguard. - Flag : each pixel with above the threshold, and its two neighbors.
With cumulative=True, the default, . The final covariance is
fitted on the last of these masks, with the weights. The returned mask is that final
mask, and True at every pixel of a spectrum that fit did not use.
cumulative=False uses the 2022 rule, , with the final
mask for passes. nsigma=() fits without
clipping.
The clipping ceiling
Section titled “The clipping ceiling”A pass can flag only the outliers that its z-scores can reach. These z-scores are in-sample: each spectrum helped to fit the covariance that predicts it, so an outlier widens the covariance that judges it. For a default model, the in-sample of an outlier of any amplitude approaches the clipping ceiling
in a spectrum of typical leverage. With a constant center, the ceiling is . No ceiling is derived for a low-rank model.
At , npix 2400 and nguard=20, , and the ceiling is
. A pass at 20 then flags no pixel. fit logs a
warning on the gspice logger for each pass whose threshold exceeds the ceiling.
A pass above the clipping ceiling
gives the remedies.
Constant center
Section titled “Constant center”A default model subtracts the mean of its training spectra. center=c subtracts a
constant in flux units instead, such as a continuum level:
. The model then estimates no mean. With unit weights, the
covariance is , and the model needs
.
S/N bins
Section titled “S/N bins”In scaled units, the noise of every spectrum has a variance near 1. The variation between the spectra scales with , so it grows with the S/N:
signal-to-noise ratio of the spectrum (log scale)
- variance of the noise-free flux
- variance of the noise
- edges of snr_bins=3
The steps show the variance between spectra at pixel 37, the core of a line, in scaled units squared, for 20000 simulated spectra of 100 pixels. Each step holds a tenth of the spectra by S/N. The noise variance stays near 0.711, while the variance of the noise-free flux grows from 20.03 to 2972.72. One covariance of all spectra mixes these. The vertical lines are the edges at S/N 37.8 and 59.4 that fit(..., snr_bins=3) puts between three bins of equal count.
Spectra of different S/N therefore have different covariances in scaled units, and one
covariance of all of them is a mixture. snr_bins fits one model for each
S/N bin.
The S/N of a spectrum is the median of
over its good pixels
(gspice.snr()). snr_bins=n puts the edges
between the bins at quantiles of the S/N, so that each bin holds about the same number
of spectra. A sequence gives the interior edges instead.
Each bin clips and fits on its own spectra. Bin of the model equals the model that
fit returns for the spectra of bin alone. At prediction, each spectrum goes to the
bin of its S/N, with the edges in Model.edges. Each bin needs the spectra of a model of
its kind, for example for a default bin. A small bin also has
a low clipping ceiling, so it flags fewer outliers.
Low-rank model
Section titled “Low-rank model”A covariance of npix pixels cannot be estimated from fewer than npix + 1 spectra. A
low-rank model asks for less. With
rank=K, the covariance is a gspice.LowRank:
with the leading eigenvectors and eigenvalues of the sample covariance , and the diagonal matrix with . So and have the same variance at every pixel, and the correlations between pixels come from the components alone. The clipping passes use the same rank.
A low-rank model needs , a positive -th eigenvalue and every , but no good pixel at every pixel. It suits a training set with fewer spectra than pixels. Other routes gives its precision matrix.
Noise-aware model
Section titled “Noise-aware model”A default model is a scaled model: its one covariance holds both the variation between the spectra and their noise. That fails where the noise differs from spectrum to spectrum in level or in shape. A noise-aware model separates the two.
noise=True estimates , the covariance of the
noise-free flux, in flux units, from
the ivar of each pixel. It clips with a scaled model first, as above. At prediction,
spectrum has the covariance
with at the good pixels and at the bad
pixels. is with its negative eigenvalues set to 0, which biases it
upward. The working vector is , in flux units, with the
mean of the training spectra, weighted by times the weights. rank=K also works here.
is unbiased element by element under four conditions:
- The spectra are independent, with a common mean and a common signal covariance.
- The noise has zero mean and the variance
1 / ivar. - The noise is uncorrelated between pixels and with the signal.
- The masks, weights and
ivardo not depend on the flux.
The outlier flags of the final mask break condition 4, and so does an ivar computed
from the flux.
A noise-aware model has one bin and no center. It needs two spectra good at every pixel, and its clipping passes need the spectra of a scaled model. Each spectrum has its own covariance, so each needs its own factorization (Cost).
What each model needs
Section titled “What each model needs”| Model | Arguments | Spectra needed | Prediction | Finite-sample factor |
|---|---|---|---|---|
| Default | none | one per bin | derived | |
| Constant center | center=c | one per bin | 1 | |
| S/N bins | snr_bins=n | per bin, as for its kind | one per bin | derived for default bins |
| Low rank | rank=K | one per bin | 1 | |
| Noise-aware | noise=True | two good spectra at each pixel, and those of a scaled model for clipping | one factorization per spectrum | 1 |
is the precision matrix of Numerics. A weighted model has no finite-sample factor either (Conditions). Choose a model compares the models on simulated spectra.
training spectra
The spectra that gspice.fit() estimates the
model from.
working units
The units of the working vector: scaled units, or flux units for a noise-aware model.
bad pixel
A pixel that the input marks: a nonzero mask or ivar == 0. GSPICE never reads
flux or ivar there, and never conditions on it, except in the pixelwise
prediction, which uses its interpolated value.
outlier
A pixel whose flux is many standard deviations from its prediction: a large .
clipping pass
One round of fit. It fits a covariance, computes the in-sample z-score of every
training pixel, and flags the pixels above a threshold, nsigma[n - 1] for pass .
in-sample
Computed on the training spectra of the model, as the z-scores of the clipping passes
of fit are.
clipping ceiling
The value that the in-sample of an outlier of any amplitude approaches in a clipping pass, in a spectrum of typical leverage. A pass whose threshold exceeds it flags few pixels, or none (Fitting).
S/N bin
A range of S/N with its own mean and covariance (fit(snr_bins=...)), with the index
.
S/N
The signal-to-noise ratio of a spectrum: the median of over its
good pixels (gspice.snr()).
low-rank model
A model whose covariance is : components and a
diagonal (fit(rank=K), gspice.LowRank).
scaled model
A model in scaled units, whose one covariance holds both the variation between spectra and the noise. Every model is a scaled model except a noise-aware model.
noise-aware model
A model of the noise-free flux, in flux units, whose prediction adds the noise of each
spectrum from its ivar (fit(noise=True)). Its opposite is a scaled model.
noise-free flux
The flux that a spectrum would have without noise, . gspice.simulate returns it
as truth.
precision matrix
The inverse of the covariance, . GSPICE computes the conditional distribution from its blocks and .