Getting started
What you get back
GSPICE returns read-only container objects whose array fields have explicit shapes and physical units. A value without a unit is a count, a mask, or a dimensionless ratio. In the shapes below, nspec is the
number of spectra and npix is the number of pixels.
gspice.fit() returns a
gspice.Model and a mask:
model, clipped = gspice.fit(flux, ivar)The mask clipped has the shape (nspec, npix). It is True at each pixel that fit left
out of its final estimate. It is also True at every pixel of a spectrum that fit did
not use.
A model has one mean and one covariance for each
S/N bin. There is one bin unless you call
fit(..., snr_bins=n). The mean and the covariance are in
scaled units, not flux units.
Continuum normalization explains the
scaling.
| Field | Type and shape | Holds |
|---|---|---|
mean | array (nbin, npix) | The mean of each bin, in scaled units |
cov | tuple of nbin arrays (npix, npix), or of LowRank | The covariance of each bin, in scaled units squared |
n_train | tuple of nbin integers | The number of training spectra of each bin |
edges | tuple of nbin − 1 floats | The signal-to-noise ratios (S/N) between the bins |
center | float or None | The constant center in flux units, or None for a mean-centered model |
noise | bool | True for a noise-aware model |
weighted | bool | True if fit had unequal weights |
blocks | Blocks or None | The block thresholds of fit_blocks, or None without them |
A noise-aware model, from
fit(..., noise=True), has one bin. Its mean is in flux units, and its cov is the
covariance of the flux without noise, in flux².
Blocks
Section titled “Blocks”gspice.fit_blocks() returns a copy of the
model whose blocks is a gspice.Blocks.
gspice.repair() reads it.
| Field | Type and shape | Holds |
|---|---|---|
starts | array of int64 (nblock,) | The first pixel of each block |
width | int | The number of pixels of each block |
nguard | int | The half-width of the guard window around each block, in pixels |
thresholds | array (nbin, nblock) | The threshold of each bin and block |
Prediction
Section titled “Prediction”gspice.pixelwise() predicts each pixel from
the pixels outside a guard window
around it. It returns a gspice.Prediction.
| Field | Shape | Holds |
|---|---|---|
flux | (nspec, npix) | The prediction of each pixel, in flux units |
var | (nspec, npix) | Its variance, which includes the noise, in flux² |
z | (nspec, npix) | The input flux minus the prediction, divided by √var; NaN at bad pixels |
Repaired
Section titled “Repaired”gspice.infill() and
gspice.repair() return a
gspice.Repaired. The
replaced pixels hold their
prediction. The ignored pixels are
neither replaced nor used to predict the others.
| Field | Shape | Holds |
|---|---|---|
flux | (nspec, npix) | The prediction at the replaced pixels, and the input flux elsewhere, in flux units |
var | (nspec, npix) | In flux²: the variance of the prediction at the replaced pixels, which includes the noise; 1/ivar at the other good pixels; inf at the other bad pixels |
replaced | (nspec, npix), bool | The replaced pixels |
ignored | (nspec, npix), bool | The ignored pixels |
chi2 | (nspec,) | The χ² of the input values at the replaced pixels that are good in the input; 0 if there are none |
dof | (nspec,), int64 | The number of those pixels |
fs | (nspec,) | The finite-sample factor of chi2 |
draws | (nspec, npix), or None | One random draw at the replaced pixels, and the input flux elsewhere, in flux units |
blocks | (nspec, nblock), bool, or None | The blocks that repair flagged in each spectrum |
Three fields depend on the call:
drawsis None unless you passrng, anumpy.random.Generator.blocksis None for a result ofinfill, and ofrepair(..., blockwise=False).Repaired.covariance(s)returns the replaced pixels of spectrumsand their covariance, in flux². It needs a call withcovariance=True.
S/N bin
A range of S/N with its own mean and covariance (fit(snr_bins=...)), with the index
.
scaled units
Flux multiplied by , the square root of the mean inverse variance of the good
pixels of the spectrum. The noise of a spectrum with equal ivar at every pixel then
has the variance 1.
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.
guard window
The pixels within nguard of a predicted pixel or block. A prediction does not
condition on them, and reports only the predicted pixels among them.
replaced pixel
A pixel of the set , whose value an infill replaces by its conditional mean.
ignored pixel
A pixel in that is not replaced: it is not conditioned on, and keeps its input
value. repair reports its ignored pixels as .
finite-sample factor
: the factor by which the error of an estimated mean and covariance widens the residuals of a held-out spectrum, (Held-out uncertainty).