hispecdrp.primitives.line_fitting.fit_lines
Functions
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Fit a Gaussian profile to an absorption or emission line plus polynomial background to data. |
|
Classes
|
- class GaussianLineFitResult(amplitude: 'float', amplitude_err: 'float', mu: 'float', mu_err: 'float', fwhm: 'float', fwhm_err: 'float', background_coeffs: 'np.ndarray', background_coeffs_err: 'np.ndarray', redchi2: 'float', pcov: 'np.ndarray | None' = None)[source]
Bases:
object- to_row()[source]
- _gauss_absorption_jac(params, x, y, yerr)[source]
- _gauss_absorption_model(params, x)[source]
- _gauss_absorption_residuals(params, x, y, yerr)[source]
- _gauss_emission_jac(params, x, y, yerr)[source]
- _gauss_emission_model(params, x)[source]
- _gauss_emission_residuals(params, x, y, yerr)[source]
- _gaussian(x, amp, mu, fwhm)[source]
- fit_line_gauss(x, y, y_err=None, dq=None, fwhm_bounds=None, mu_guess=None, mu_bounds=None, background_poly_deg=0, absorption=False)[source]
Fit a Gaussian profile to an absorption or emission line plus polynomial background to data.
For
absorption=Falsethe model isamplitude * gaussian + background(a peak above the continuum). Forabsorption=Truethe model isbackground - amplitude * gaussian(a dip below the continuum). In both casesamplitude >= 0is the line strength (depth for absorption); the continuum is carried by the background polynomial.- Parameters:
x (np.ndarray) – X-axis values (e.g., pixel positions, wavelengths, or a velocity grid).
y (np.ndarray) – Flux values.
y_err (np.ndarray | None) – Uncertainties on y.
dq (np.ndarray | None) – Data quality mask for data.
fwhm_bounds (tuple | None) – Bounds on the FWHM parameter.
mu_guess (float | None) – Initial guess for line center.
mu_bounds (tuple | None) – Bounds on line center relative to mu_guess.
background_poly_deg (int) – Degree of the polynomial background model. For absorption a continuum is required, so this must be >= 0 (degree 0 = flat continuum).
absorption (bool) – Whether to fit an absorption line (True) or emission line (False).
- Returns:
GaussianLineFitResult – Result of the Gaussian line fit.
amplitudeis always the (positive) line strength;background_coeffsis the continuum.
- fit_lines_gauss(x, y, y_err, dq, line_centers, fwhm_bounds=None, mu_bounds=None, min_fit_window=None, max_fit_window=None, background_poly_deg=0, absorption=False)[source]
- polyval1d(coeffs, x)[source]
Evaluate a polynomial with given coefficients at specified points using the Horner method.
- Parameters:
coeffs (np.ndarray) – Coefficients of the polynomial, ordered from lowest degree to highest (NOTE: numpy is reversed).
x (np.ndarray) – Points at which to evaluate the polynomial.