jwspecfit.redshift
Strong-line redshift fitting via brute-force grid evaluation.
This module implements fit_redshift(), which determines the redshift
of a JWST NIRSpec spectrum by jointly fitting the amplitudes of a curated
set of strong emission lines on a dense grid of trial redshifts. The
algorithm is deliberately exhaustive (no early stopping), it gracefully
skips lines that fall outside the spectrum’s wavelength range at the
trial redshift, and it returns both a per-peak credible interval and a
ranked list of secondary peaks so that aliasing failures are visible.
The per-z score is the chi^2 of a non-negative joint line fit plus a
low-order polynomial continuum, computed via a single
scipy.optimize.lsq_linear() call with mixed bounds.
Functions
|
Fit the redshift of spec by joint strong-line fitting on a z grid. |
Classes
|
A single local minimum of the chi^2(z) curve, refined and ranked. |
|
Output of |
- class jwspecfit.redshift.Peak(z, prob, dchi2, ci68, ci95, n_lines_used, lines_used)[source]
Bases:
objectA single local minimum of the chi^2(z) curve, refined and ranked.
- Parameters:
- class jwspecfit.redshift.RedshiftResult(z_best, z_ci68, z_ci95, peaks, is_decisive, z_grid_coarse, chi2_coarse, P_z_coarse, z_grid_fine, chi2_fine, P_z_fine, lines_used, grating, spec)[source]
Bases:
objectOutput of
fit_redshift().- Parameters:
- jwspecfit.redshift.fit_redshift(spec, *, lines=None, z_min=0.0, z_max=20.0, dz_coarse=None, prior=None, n_peaks=5, refine_dchi2=9.0, continuum_order=3, nonneg=True, min_lines_in_range=2, verbose=True)[source]
Fit the redshift of spec by joint strong-line fitting on a z grid.
- Parameters:
spec (Spectrum) – Input spectrum. Must have valid wave_um, flux_ujy, err_ujy.
lines (list of str, optional) – Line names (keys of
REST_LINES_A) to include. Defaults toDEFAULT_LINES.z_min (float) – Bounds of the redshift search (default 0 to 20).
z_max (float) – Bounds of the redshift search (default 0 to 20).
dz_coarse (float, optional) – Coarse-grid step. Defaults to a value tied to the spectral resolving power (see
_default_dz_coarse()).prior (None | (lo, hi) | list[(lo, hi)] | callable) – Optional non-Gaussian prior over z.
Nonemeans flat.n_peaks (int) – Minimum number of peaks to refine and return.
refine_dchi2 (float) – All local minima within this Δχ² of the global minimum are refined, in addition to the top n_peaks.
continuum_order (int) – Order of the Legendre-polynomial continuum that is added to the per-z linear fit. Default 3.
nonneg (bool) – If True, line amplitudes are constrained to be non-negative (emission only). Strongly recommended.
min_lines_in_range (int) – Trial redshifts where fewer than this many default lines fall inside the spectrum get the continuum-only chi^2 baseline.
verbose (bool) – If True, log a few timing milestones at INFO level.
- Return type: