fit_lines¶
- pyplatefit.fit_lines(wave, data, std, redshift, *, unit_wave=None, unit_data=None, vac=False, lines=None, line_ratios=None, major_lines=False, fit_all=False, lsf=None, trimm_spec=True, find_lya_vel_offset=True, dble_lyafit=False, mcmc_lya=False, mcmc_all=False, fit_lws=None, minpars={}, mcmcpars={})¶
Fit lines from a set of arrays (wave, data, std) using lmfit.
This function uses lmfit to perform fit of know lines in a spectrum with a given redshift, to compute the flux and flux uncertainty of each line covered by the spectrum. It must be used on a continuum subtracted spectrum.
The fit are performed by line families, each family is defined by a unique velocity offset and velocity dispersion, plus a list of emission lines. All lines are assumed to be gaussian except for lyman-alpha where an asymetric gaussian model is used.
All the emission lines known by
linelist.get_lines
are searched for, unless a list of line names or a table of lines is provided with thelines
parameter. Iftrim_spectrum
is set to true (default), the fit is done keeping only the parts of the spectrum around the expected lines.It is possible to add constraints in the ratio of some lines (for instance for doublets). These constraints are given in the line_ratios parameter and are expressed as a list of tuples (line_1 name, line_2 name, line_2 flux / line_1 flux minimum, flux ratio maximum). For instance, to constraint doublet fluxes and discriminate between single lines and doublets in MUSE-UDF, we used:
line_ratios = [(“CIII1907”, “CIII1909”, 0.6, 1.2), (“OII3726”, “OII3729”, 1.0, 2.0)]
That stands for:
0.6 <= OII3729 / OII3726 <= 1.2 1.0 <= CIII1909 / CIII1907 <= 2.0
If the units of the wavelength and data axis are provided, the function will try to determine the unit of the computed fluxes.
The table of the lines found in the spectrum are given in the table lines. The columns are:
FAMILY: the line family name (eg balmer)
LINE: The name of the line
LBDA_REST: The rest-frame position of the line in vacuum
DNAME: The display name for the line (set to None for close doublets)
VEL: The velocity offset in km/s with respect to the initial redshift (rest frame)
VEL_ERR: The error in velocity offset in km/s
Z: The fitted redshift in vacuum of the line (note for lyman-alpha the line peak is used)
Z_ERR: The error in fitted redshift of the line.
Z_INIT: The initial redshift
VDISP: The fitted velocity dispersion in km/s (rest frame)
VDISP_ERR: The error in fitted velocity dispersion
VDINST: The instrumental velocity dispersion in km/s
FLUX: Flux in the line. The unit depends on the units of the spectrum.
FLUX_ERR: The fitting uncertainty on the flux value.
SNR: the SNR of the line
SKEW: The skewness parameter of the asymetric line (for Lyman-alpha line only).
SKEW_ERR: The uncertainty on the skewness (for Lyman-alpha line only).
SEP: The fitted lya rest frame peak separation (in km/s) (for the double lyman-alpha fit only)
SEP_ERR: The error in fitted lya rest frame peak separation (in km/s) (for the double lyman-alpha fit only)
LBDA_OBS: The fitted position the line peak in the observed frame
PEAK_OBS: The fitted peak of the line in the observed frame
LBDA_LEFT: The wavelength at the left of the peak with 0.5*peak value
LBDA_RIGHT: The wavelength at the rigth of the peak with 0.5*peak value
FWHM_OBS: The full width at half maximum of the line in the observed frame
NSTD: The log10 of the normalized standard deviation of the line fit
LBDA_LNSTD: The wavelength at the left of the range used for NSTD estimation
LBDA_RNSTD: The wavelength at the right of the range used for NSTD estimation
EQW: The restframe line equivalent width
EQW_ERR: The error in EQW
CONT_OBS: The continuum mean value in Observed frame
CONT: the continuum mean value in rest frame
CONT_ERR: the error in rest frame continuum
The redshift table is saved in the table ztable The columns are:
FAMILY: the line family name
VEL: the velocity offset with respect to the original z in km/s
VEL_ERR: the error in velocity offset
Z: the fitted redshift (in vacuum)
Z_ERR: the error in redshift
Z_INIT: The initial redshift
VDISP: The fitted velocity dispersion in km/s (rest frame)
VDISP_ERR: The error in fitted velocity dispersion
LINE: the emission line name with maximum SNR
SNRMAX: the maximum SNR
SNRSUM: the sum of SNR (all lines)
SNRSUM_CLIPPED: the sum of SNR (only lines above a MIN SNR (default 3))
NL: number of fitted lines
NL_CLIPPED: number of lines with SNR>SNR_MIN
NFEV: the number of function evaluation
RCHI2: the reduced Chi2 of the family lines fit
- Parameters:
- wavearray_like of
floats
The wavelength axis of the spectrum.
- dataarray_like of
floats
The data (flux) axis of the spectrum.
- stdarray_like of
floats
The standard deviation associated to the data. It can be set to None if it’s not available.
- redshift
float
Expected redshift of the spectrum.
- unit_wave
astropy.unit.Unit
, optional The unit of the wavelength axis.
- unit_data
astropy.unit.Unit
, optional The unit of the data axis.
- vacbool, optional
If True, vacuum wavelength are expected; else air wavelength are expected. Default: False.
- lines
list
ofstr
orastropy.table.Table
, optional To limit the searched for lines, it is possible to use this parameter to pass:
a list of line names as in MPDAF line list;
or an astropy table with the information on the lines to fit. The table must contain the following columns
LINE: the line name
FAMILY: the line family (balmer, forbidden, ism)
LBDA_REST: the rest frame wavelength in vacuum (Angstroem)
DOUBLET: the central wavelength if this is a multiplet (Angstroem)
RESONANT: bool, True if the line is resonant
ABS: bool, True if the line can be in absorption
EMI: bool, True if the line can be in emission
DNAME: the line display name (None if no display)
- line_ratios
list
of (str
,str
,float
,float
)tuples
orstring
List on line ratio constraints (line1 name, line2 name, line2/line1 minimum, line2/line1 maximum.
- major_linesbool, optional
If true, the fit is restricted to the major lines as defined in mpdaf line table (used only when lines is None, ) default: False
- fit_allbool, optional
if True, use same velocity offset and velocity dispersion for all lines except Lya if False, allow different velocity offsets and velocity disperions between balmer, forbidden and resonnant lines default: false
- lsf
function
, optional LSF function LSF to derive FWHM as function of wavelength, otherwise assume no LSF default: True
- trimm_specbool, optional
if True, mask unused wavelengths part default : True
- find_lya_vel_offset: boolean, optional
if True, compute a starting velocity offset for lya on the data [disabled for dble_lyafit]
- dble_lyafit
False
if True, use a double asymetric gaussian model for the lya line fit
- fit_lws
dictionary
with
some
defaultand
bounds
parameters
- minpars
dictionary
with
minimization
methodand
associate
parameters
- wavearray_like of
- Returns:
- result
Dictionary
lines (see above)
ztable (see above)
lmfit_{family} the ResultObject from lmfit for the given family
table_spec an astropy table with the following columns
RESTWL: restframe wavelength
FLUX: resframe data value
ERR: stddev of FLUX
LINEFIT: final fit value
INIT_FIT: init value for the full fit
{family}_INIT_FIT: initial value for the fit of the given family
{family}_FIT_LSQ: LSQ fit of the given family
- result
- Raises:
- NoLineError:
when none of the fitted line can be on the spectrum at the given redshift.