mangadap.proc.spectralfitting module¶
Implements a few base classes used during spectral fitting procedures.
Revision history¶
14 Apr 2016: Implementation begun by K. Westfall (KBW)19 Apr 2016: (KBW) First version26 Apr 2016: (KBW) Moved PPXFFit to a separate file (ppxffit.py)03 Nov 2016: (KBW) Added USETPL column to stellar kinematics output table.25 Oct 2017: (KBW) Added PLY columns to emissionline database02 Feb 2018: (KBW) Addedselect_binned_spectra_to_fit()
.15 Mar 2018: (KBW) Equivalenth width now measured at the velocity of each line if a redshift is not provided. Seemeasure_equivalent_width()
.
Copyright © 2019, SDSSIV/MaNGA Pipeline Group

class
mangadap.proc.spectralfitting.
CompositionFit
(fit_method, bitmask, par=None)[source]¶ Bases:
mangadap.proc.spectralfitting.SpectralFitting
Base class for fitting the spectral composition.

class
mangadap.proc.spectralfitting.
EmissionLineFit
(fit_method, bitmask=None, par=None)[source]¶ Bases:
mangadap.proc.spectralfitting.SpectralFitting
Base class for fitting emission lines.

static
_per_emission_line_dtype
(neml, nkin, mask_dtype)[source]¶ Construct the record array data type for the output fits extension.

static
check_and_prep_input
(wave, flux, ivar=None, mask=None, sres=None, continuum=None, redshift=None, dispersion=None, default_dispersion=100.0)[source]¶ Check the input used for emissionline measurements.
inverse variance is converted to 1sigma error
mask must be a boolean array.
sres can be a single vector, but will be returned as an array with a size that matches flux.
output all converted to masked arrays with at least two dimensions

static
check_emission_line_database
(emldb, wave=None, check_par=True)[source]¶ Check the emissionline database. Modes are checked by
mangadap.par.emissionlinedb.EmissionLinePar
, and the indices are checked to be unique bymangadap.par.emissionlinedb.EmissionLineDB
. The type of the object must be
mangadap.par.emissionlinedb.EmissionLineDB
 The provided profile type of each line must be a defined class.
 At least one line must have
mode='f'
 All tied lines must be tied to a line with a correctly specified index.
 Warnings will be provided for any line with a centroid that falls outside of the provided wavelength range.
 The database must provide at least one valid line.
Parameters:  emldb (
mangadap.par.emissionlinedb.EmissionLineDB
) – Emissionline database.  wave (arraylike) – Wavelength vector.
 check_par (
bool
, optional) – Validate the provided parameters.
Raises: TypeError
– Raised if the provided object is not an instance ofmangadap.par.emissionlinedb.EmissionLineDB
.ValueError
– Raised if any line has a mode of x or if the database does not provide a valid definition for any templates.NameError
– Raised if a defined profile type is not known.
 The type of the object must be

static
get_spectra_to_fit
(binned_spectra, pixelmask=None, select=None, error=False, original_spaxels=False)[source]¶ Get the spectra to fit during the emissionline fitting.
Parameters:  binned_spectra – (
mangadap.proc.spatiallybinnedspectra.SpatiallBinnedSpectra
): Object with the spectra to fit.  pixelmask – (
mangadap.util.pixelmask.SpectralPixelMask
, optional): Pixel mask to apply.  select (numpy.ndarray, optional) – Select specific spectra to return. Must have the correct shape; cf. original_spaxels.
 error (
bool
, optional) – Return \(1\sigma\) errors instead of inverse variance.  original_spaxels (
bool
, optional) – Instead of the binned spectra, use the drpf attribute of the binned_spectra object to return the original spaxels, corrected for Galactic extinction.
Returns:  The wavelength vector of the spectra,
 a masked numpy array with the flux data,
 (3) a masked numpy array with the error data (returned as either inverse variance or \(1\sigma\),
 (4) and an array with the spectral resolution for each spectrum, based on the internal binned spectra parameters.
Return type: Four objects are returned
 binned_spectra – (

static
instrumental_dispersion
(wave, sres, restwave, cz)[source]¶ Determine the instrumental dispersion for a set of rest wavelengths and velocities.
Parameters:  wave (numpy.ndarray) – Vector with the wavelengths of the spectrum.
 sres (numpy.ndarray) – Vector with the spectral resolution as a function of wavelength.
 restwave (float, numpy.ndarray) – Rest wavelengths for a set of measured lines.
 cz (float, numpy.ndarray) – Redshifts (in km/s) of each or all lines.
Returns:  The instrumental dispersions for each
provided line.
Return type: numpy.ndarray

static
line_metrics
(emission_lines, wave, flux, ferr, model_flux, model_eml_par, mask=None, model_mask=None, bitmask=None, window=15, fill_redshift=False)[source]¶ Calculate fitquality metrics near each emission line.
Todo
 Allow window to be defined in angstroms?
Parameters:  emission_lines (
mangadap.par.emissionlinedb.EmissionLineDB
) – Emissionline database use during the fit.  wave (numpy.ndarray) – Wavelength vector for object spectra. Shape is \((N_{\rm pix},)\).
 flux (numpy.ndarray) – Object spectra that have been fit. Can be provided as a numpy.ma.MaskedArray. Shape is \((N_{\rm spec},N_{\rm pix})\).
 ferr (numpy.ndarray) – \(1\sigma\) errors in the object spectra. Can be provided as a numpy.ma.MaskedArray. Shape is \((N_{\rm spec},N_{\rm pix})\).
 model_flux (numpy.ndarray) – Bestfitting model spectra. Can be provided as a numpy.ma.MaskedArray. Shape is (\(N_{\rm spec},N_{\rm pix}\)).
 model_eml_par (numpy.recarray) – A numpy record array with data type given by
_per_emission_line_dtype()
. UsesFLUX
,KIN
, andMASK
; and assigns results toLINE_*
columns.  mask (numpy.ndarray, optional) – A mask for the object spectra that have been fit. Added to mask attribute of flux if it is a numpy.ma.MaskedArray.
 model_mask (numpy.ndarray, optional) – A boolean numpy array with the mask for the model spectra. Added to mask attribute of model_flux if it is a numpy.ma.MaskedArray.
 bitmask (
mangadap.util.bitmask.BitMask
, optional) – The BitMask object used to interpret the MASK column in the model_eml_par object. If None, the MASK column is ignored.  window (
int
, optional) – The width of the window used to compute the metrics around each line in number of pixels.  fill_redshift (
bool
, optional) – Fill any masked velocity measurement to the masked median of the velocities for the unmasked lines in the same spectrum when constructing the redshifted bands. If False, the A/N measurement is masked.
Returns: Return the input model_eml_par after filling the LINE_PIXC, AMP, ANR, LINE_NSTAT, LINE_CHI2, LINE_RMS, and LINE_FRMS columns.
Return type: numpy.recarray
Raises: ValueError
– Raised if various checks of the input array sizes are incorrect.

static
measure_equivalent_width
(wave, flux, emission_lines, model_eml_par, mask=None, redshift=None, bitmask=None, checkdb=True)[source]¶ The flux array is expected to have size Nspec x Nwave.
Provided previous emissionline fits, this function adds the equivalent width measurements to the output database.
Errors currently do not include the errors in the continuum measurement; only the provided error in the flux.
Raises: ValueError
– Raised if the length of the spectra, errors, or mask does not match the length of the wavelength array; raised if the wavelength, redshift, or dispersion arrays are not 1D vectors; and raised if the number of redshifts or dispersions is not a single value or the same as the number of input spectra.

static
select_binned_spectra_to_fit
(binned_spectra, minimum_snr=0.0, stellar_continuum=None, debug=False)[source]¶ Select binned spectra for which to fit emission lines.
Todo
This could be based on the moment assessment of the emissionline S/N instead; for now just based on continuum S/N.
Parameters:  binned_spectra – (
mangadap.proc.spatiallybinnedspectra.SpatiallyBinnedSpectra
): Binned spectra to be fit.  minimum_snr (float) – The minimum S/N of the binned spectrum
to fit; see
mangadap.proc.spatiallybinnedspectra.SpatiallyBinnedSpectra.above_snr_limit()
.  stellar_continuum – (
mangadap.proc.stellarcontinuummodel.StellarContinuumModel
, optional): Stellarcontinuum models that have been fit to the binned spectra, if available. The current function will only return True for spectra that are both above the S/N limit and have good stellarcontinuum models.
Returns: Boolean vector with the spectra in the binned_spectra object to fit.
Return type: numpy.ndarray
 binned_spectra – (

static

class
mangadap.proc.spectralfitting.
SpectralFitting
(fit_type, bitmask=None, par=None)[source]¶ Bases:
object
Base class for spectral fitting.

class
mangadap.proc.spectralfitting.
StellarKinematicsFit
(fit_method, bitmask, par=None)[source]¶ Bases:
mangadap.proc.spectralfitting.SpectralFitting
Base class for fitting stellar kinematics.