specsr.linefit¶
Gaussian emission-line fitting, and the S/N derived from it.
Fits a Gaussian on a linear continuum in a window around each expected line and reports amplitude over continuum scatter. This is the measurement behind the paper’s S/N figure.
The continuum scatter is estimated from sidebands — an annulus around the line, excluding its core — rather than from the whole window. Using the window would fold the line itself into the noise estimate and depress the S/N of exactly the strong lines the figure is about.
Note what this quantity is and is not: it references only the spectrum being
measured, never the HR truth, so a high S/N means “a confident detection of
something”, not “the right line flux”. Establishing that a line is correct
needs the reference, which is why
specsr.plotting.plot_line_flux_comparison() exists alongside it.
Functions
|
Fit one line. |
|
Gaussian on a linear continuum. |
|
|
|
Robust scatter via MAD, NaN-aware. |
|
Per-line S/N for several spectrum sets over the same objects. |
- specsr.linefit.fit_line_sideband_weighted(x, y, mu0, *, fit_halfwin=0.25, core_halfwin=0.05, sb_gap=0.03, sb_width=0.12, sigma_bounds=(0.001, 0.12), mu_bounds_half=0.01, allow_negative_amp=True, maxfev=40000)[source]¶
Fit one line. Returns a dict of parameters, or
Noneif unfittable.Negative amplitudes are allowed by default: forcing positivity would turn a non-detection into a small positive bump and manufacture signal where there is none.
- specsr.linefit.line_snr_from_fit(fit)[source]¶
(amp/sigma_cont, amp/amp_err)from a fit, or(nan, nan).
- specsr.linefit.mad_sigma(y)[source]¶
Robust scatter via MAD, NaN-aware. NaN when there is too little data.
- specsr.linefit.measure_line_snr(wavelength, z, spectra, lines_rest_um, line_names=None, **fit_kw)[source]¶
Per-line S/N for several spectrum sets over the same objects.
- Parameters:
spectra –
{"LR": array, "SR": array, "HR": array, ...}, each(n, n_lambda).lines_rest_um – Rest wavelengths, microns. Redshifted per object with
z.
- Returns:
{f"{line}_sn_{kind}": array}with NaN where a line falls off the grid orthe fit fails — left as NaN rather than zero, since “not measurable” and
”measured as zero” are different statements.