fit_slit_by_basis_images
- jwst.wfss_contam.wavefit.fit_slit_by_basis_images(observed_slit, simul_slit, l2_alpha=0.0, rejection_threshold=0.1)[source]
Fit a linear combination of dispersed basis images to the observed slit.
The constant (degree-0) term is
simul_slit.data(the flat-spectrum simulation). Higher-degree terms are taken from thefluxmodel_1,fluxmodel_2, … attributes ofsimul_slit. These are the grism-frame images produced by passing polynomial flux models throughdisperse().The fit solves:
observed ≈ c_0 * data + c_1 * fluxmodel_1 + c_2 * fluxmodel_2 + ...
via inverse-variance-weighted least squares on valid pixels, using the
errarray of the observed slit as pixel uncertainties. Whenl2_alpha > 0, L2 regularisation is applied to the weighted normal equations.- Parameters:
- observed_slit
SlitModel Observed 2-D spectral cutout.
- simul_slit
SlitModel Simulated slit with
dataand optionalfluxmodel_Nattributes.- l2_alphafloat, optional
L2 regularisation strength. Added to the diagonal of the weighted normal-equation matrix as
alpha * Ibefore solving, which penalizes large coefficients. A value of0(the default) turns off regularization. Typical useful values are in the range1e-3-1e1.- rejection_thresholdfloat, optional
If the fitted constant term coefficient
c_0deviates from 1 by more than this amount, the fit is rejected andNoneis returned. This fit rejection is necessary to avoid fits “blowing up” when a source is located in nonzero (pseudo-)background, either from a nearby bright source or because the background subtraction was imperfect. If None, no fits will be rejected.
- observed_slit
- Returns:
- coeffsndarray
Best-fit coefficients
[c_0, c_1, ...].
- Raises:
- SlitFitError
If there are fewer valid pixels than basis terms.