Library of functions to fit lines

This class is dedicated to fitting lines on observed spectra.

class LineFittingLibrary.LineFittingLibrary[source]

This class contains a variety of function to fit emission or absorption lines in galaxy spectra.

class LineFittingLibrary.LineFittingLibrary(dV=-9999.99)[source]
Loads the environement proper to fit lines :
  • Gaussian line model
  • Lorentzian line model
  • pseudoVoigt line model
  • conversion magnitude AB to flux : flambda to fnu
Parameters:dV – the default value (def: -9999.99)
fit_Line(wl, spec1d, err1d, a0, lineName='AL', fitWidth=20, DLC=20, p0_sigma=15.0, p0_flux=8e-17, p0_share=0.5, continuumSide='left', model='gaussian')[source]

fits a line profile to a spectrum around a fixed line position

Parameters:
  • wl – wavelength (array, Angstrom)
  • spec1d – flux observed in the broad band (array, f lambda)
  • err1d – error on the flux observed in the broad band (array, f lambda)
  • a0 – expected position of the peak of the line in the observed frame (redshifted). a0 is not fitted, it is given.
  • lineName – suffix characterizing the line in the headers of the output
  • DLC – wavelength extent to fit the continuum around the line. (def: 230 Angstrom)
  • p0_sigma – prior on the line width in A (def: 15 A)
  • p0_flux – prior on the line flux in erg/cm2/s/A (def: 8e-17)
  • p0_share – prior on the share of Gaussian and Lorentzian model. Only used if the line is fitted with a pseudoVoigt profile width (def: 0.5 no units)
  • continuumSide – “left” = bluewards of the line or “right” = redwards of the line
  • model – line model to be fitted : “gaussian”, “lorentz” or “pseudoVoigt”.
Returns :
  • array 1 with the parameters of the model
  • array 2 with the model (wavelength, flux model)
  • header corresponding to the array 1
fit_Line_OIIdoublet(wl, spec1d, err1d, a0=3726.0321735398957, lineName='OII', fitWidth=20, DLC=20, p0_sigma=4.0, p0_flux=1e-16, p0_share=0.58, model='gaussian')[source]

fits the [OII] doublet line profile

Parameters:
  • wl – wavelength (array, Angstrom)
  • spec1d – flux observed in the broad band (array, f lambda)
  • err1d – error on the flux observed in the broad band (array, f lambda)
  • a0 – expected position of the peak of the line in the observed frame (redshifted). 2 positions given.
  • lineName – suffix characterizing the line in the headers of the output
  • DLC – wavelength extent to fit the continuum around the line. (def: 230 Angstrom)
  • p0_sigma – prior on the line width in A (def: 15 A)
  • p0_flux – prior on the line flux in erg/cm2/s/A (def: 8e-17)
  • p0_share – prior on the share between the two [OII] lines. (def: 0.58)
  • continuumSide – “left” = bluewards of the line or “right” = redwards of the line
  • model – line model to be fitted : “gaussian”, “lorentz” or “pseudoVoigt”
Returns :
  • array 1 with the parameters of the model
  • array 2 with the model (wavelength, flux model)
  • header corresponding to the array 1
fit_Line_OIIdoublet_position(wl, spec1d, err1d, a0=3726.0321, lineName='O2_3728', fitWidth=20, DLC=20, p0_sigma=4.0, p0_flux=1e-16, p0_share=0.58, model='gaussian')[source]

fits the [OII] doublet line profile

Parameters:
  • wl – wavelength (array, Angstrom)
  • spec1d – flux observed in the broad band (array, f lambda)
  • err1d – error on the flux observed in the broad band (array, f lambda)
  • a0 – expected position of the peak of the line in the observed frame (redshifted). 2 positions given.
  • lineName – suffix characterizing the line in the headers of the output
  • DLC – wavelength extent to fit the continuum around the line. (def: 230 Angstrom)
  • p0_sigma – prior on the line width in A (def: 15 A)
  • p0_flux – prior on the line flux in erg/cm2/s/A (def: 8e-17)
  • p0_share – prior on the share between the two [OII] lines. (def: 0.58)
  • continuumSide – “left” = bluewards of the line or “right” = redwards of the line
  • model – line model to be fitted : “gaussian”, “lorentz” or “pseudoVoigt”
Returns :
  • array 1 with the parameters of the model
  • array 2 with the model (wavelength, flux model)
  • header corresponding to the array 1
fit_Line_OIIdoublet_position_C0noise(wl, spec1d, err1d, a0=3726.0321, lineName='O2_3728', fitWidth=20, DLC=20, p0_sigma=4.0, p0_flux=1e-16, p0_share=0.58, model='gaussian')[source]

fits the [OII] doublet line profile

Parameters:
  • wl – wavelength (array, Angstrom)
  • spec1d – flux observed in the broad band (array, f lambda)
  • err1d – error on the flux observed in the broad band (array, f lambda)
  • a0 – expected position of the peak of the line in the observed frame (redshifted). 2 positions given.
  • lineName – suffix characterizing the line in the headers of the output
  • DLC – wavelength extent to fit the continuum around the line. (def: 230 Angstrom)
  • p0_sigma – prior on the line width in A (def: 15 A)
  • p0_flux – prior on the line flux in erg/cm2/s/A (def: 8e-17)
  • p0_share – prior on the share between the two [OII] lines. (def: 0.58)
  • continuumSide – “left” = bluewards of the line or “right” = redwards of the line
  • model – line model to be fitted : “gaussian”, “lorentz” or “pseudoVoigt”
Returns :
  • array 1 with the parameters of the model
  • array 2 with the model (wavelength, flux model)
  • header corresponding to the array 1
fit_Line_position(wl, spec1d, err1d, a0=5007.0, lineName='AL', fitWidth=20, DLC=20, p0_sigma=15.0, p0_flux=8e-17, p0_share=0.5, continuumSide='left', model='gaussian')[source]

fits a line profile to a spectrum around a fixed line position

Parameters:
  • wl – wavelength (array, Angstrom)
  • spec1d – flux observed in the broad band (array, f lambda)
  • err1d – error on the flux observed in the broad band (array, f lambda)
  • a0 – expected position of the peak of the line in the observed frame (redshifted). a0 is not fitted, it is given.
  • lineName – suffix characterizing the line in the headers of the output
  • DLC – wavelength extent to fit the continuum around the line. (def: 230 Angstrom)
  • p0_sigma – prior on the line width in A (def: 15 A)
  • p0_flux – prior on the line flux in erg/cm2/s/A (def: 8e-17)
  • p0_share – prior on the share of Gaussian and Lorentzian model. Only used if the line is fitted with a pseudoVoigt profile width (def: 0.5 no units)
  • continuumSide – “left” = bluewards of the line or “right” = redwards of the line
  • model – line model to be fitted : “gaussian”, “lorentz” or “pseudoVoigt”.
Returns :
  • array 1 with the parameters of the model
  • array 2 with the model (wavelength, flux model)
  • header corresponding to the array 1
fit_Line_position_C0noise(wl, spec1d, err1d, a0=5007.0, lineName='AL', fitWidth=20, DLC=20, p0_sigma=15.0, p0_flux=8e-17, p0_share=0.5, continuumSide='left', model='gaussian')[source]

fits a line profile to a spectrum where the error model is takes the value of the continuum.

Parameters:
  • wl – wavelength (array, Angstrom)
  • spec1d – flux observed in the broad band (array, f lambda)
  • err1d – error on the flux observed in the broad band (array, f lambda)
  • a0 – expected position of the peak of the line in the observed frame (redshifted). a0 is fitted.
  • lineName – suffix characterizing the line in the headers of the output
  • fitWidth – width in Angstrom around the line where the fit is performed, default 20 Angstrom
  • continuumSide – “left” = bluewards of the line or “right” = redwards of the line
  • DLC – wavelength extent to fit the continuum around the line. (def: 230 Angstrom)
  • p0_sigma – prior on the line width in A (def: 15 A)
  • p0_flux – prior on the line flux in erg/cm2/s/A (def: 8e-17)
  • p0_share – prior on the share of Gaussian and Lorentzian model. Only used if the line is fitted with a pseudoVoigt profile width (def: 0.5 no units)
  • model – line model to be fitted : “gaussian”, “lorentz” or “pseudoVoigt”.
Returns :
  • array 1 with the parameters of the model
  • array 2 with the model (wavelength, flux model)
  • header corresponding to the array 1
fit_recLine(wl, spec1d, err1d, a0, lineName='AL', fitWidth=20, DLC=20, p0_sigma=5.0, p0_flux=5e-17, continuumSide='left')[source]

fits a recombination line profile : emission and absorption modeled by Gaussians. Only for high SNR spectra.

Parameters:
  • wl – wavelength (array, Angstrom)
  • spec1d – flux observed in the broad band (array, f lambda)
  • err1d – error on the flux observed in the broad band (array, f lambda)
  • a0 – expected position of the peak of the line in the observed frame (redshifted)
  • lineName – suffix characterizing the line in the headers of the output
  • DLC – wavelength extent to fit the continuum around the line. (def: 230 Angstrom)
  • p0_sigma – prior on the line width in A (def: 15 A)
  • p0_flux – prior on the line flux in erg/cm2/s/A (def: 8e-17)
  • continuumSide – “left” = bluewards of the line or “right” = redwards of the line
Returns :
  • array 1 with the parameters of the model
  • array 2 with the model (wavelength, flux model)
  • header corresponding to the array 1
getFractionObsMag(mag, lambdaMag, filter, xmin, xmax, wl, fl, flErr)[source]

Computes the fraction of light captured by the spectrograph in a broad band by comparing the integrated flux in the broad band to the magnitude.

Parameters:
  • mag – magnitude AB (float, mag)
  • lambdaMag – mean wavelength covered by the magnitude AB (float, Angstrom)
  • fl – flux observed in the broad band (array, f lambda)
  • flErr – error on the flux observed in the broad band (array, f lambda)
  • filt – filter curve (interpolation 1d)
  • xmin – lower integration boundary (Angstrom)
  • xmax – higher integration boundary (Angstrom)
Returns :
  • fraction of light observed
  • error on the fraction of light observed
getFractionObsMed(mag, lambdaMag, fl, flErr)[source]

Computes the fraction of light captured by the spectrograph in a broad band by comparing the median flux in the broad band to the magnitude converted to flux at the mean wavelength of the broad band.

Parameters:
  • mag – magnitude AB (float, mag)
  • lambdaMag – mean wavelength covered by the magnitude AB (float, Angstrom)
  • fl – flux observed in the broad band (array, f lambda)
  • flErr – error on the flux observed in the broad band (array, f lambda)
Returns :
  • fraction of light observed
  • error on the fraction of light observed
integrateMAG(wl, spec1d, err1d, filt, xmin=5000.0, xmax=7500.0)[source]

Integrates a spectrum over a filter curve.

Parameters:
  • wl – wavelength (array)
  • spec1d – flux, f lambda convention (array)
  • err1d – flux error (array)
  • filt – filter curve (interpolation 1d)
  • xmin – lower integration boundary (Angstrom)
  • xmax – higher integration boundary (Angstrom)
returns :
  • integral of filter curve
  • integral of spec1d
  • integral of spec1d * filter curve
  • integral of (spec1d + err1d) * filter curve
  • integral of (spec1d - err1d) * filter curve
plotLineFit(wl, fl, flErr, lineModel, a0, datI, path_to_fig='plot.pdf', title=' - ', fitWidth=70.0, DLC=50, doublet=False)[source]

Plots a spectrum and the emission line model fitted.

Parameters:
  • wl – wavelength (array, Angstrom)
  • fl – flux observed in the broad band (array, f lambda)
  • flErr – error on the flux observed in the broad band (array, f lambda)
  • lineModel – model output by the line fitting functions (array, (2,N) wavelength and flux)
  • a0 – position of the peak of the line
  • path_to_fig – where you wish to save the figure