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 the fluxmodel_1, fluxmodel_2, … attributes of simul_slit. These are the grism-frame images produced by passing polynomial flux models through disperse().

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 err array of the observed slit as pixel uncertainties. When l2_alpha > 0, L2 regularisation is applied to the weighted normal equations.

Parameters:
observed_slitSlitModel

Observed 2-D spectral cutout.

simul_slitSlitModel

Simulated slit with data and optional fluxmodel_N attributes.

l2_alphafloat, optional

L2 regularisation strength. Added to the diagonal of the weighted normal-equation matrix as alpha * I before solving, which penalizes large coefficients. A value of 0 (the default) turns off regularization. Typical useful values are in the range 1e-3 - 1e1.

rejection_thresholdfloat, optional

If the fitted constant term coefficient c_0 deviates from 1 by more than this amount, the fit is rejected and None is 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.

Returns:
coeffsndarray

Best-fit coefficients [c_0, c_1, ...].

Raises:
SlitFitError

If there are fewer valid pixels than basis terms.