mangadap.proc.spectralfitting module¶
Implements a few base classes used during spectral fitting procedures.
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
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)[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
At least one line must be fit independently
All tied lines must be tied to a line with a correctly specified index.
The database must provide at least one valid line to fit.
 Parameters
emldb (
mangadap.par.emissionlinedb.EmissionLineDB
) – Emissionline database.wave (arraylike) – Wavelength vector.
 Raises
TypeError – Raised if the provided object is not an instance of
mangadap.par.emissionlinedb.EmissionLineDB
.ValueError – Raised if there are no independently fitted lines, if there are no lines to fit, if there are no valid lines within the provided wavelength range, if the wavelength range is not provided as a 1D vector, or if the index to tie lines is not valid. (Warning: The latter does not catch lines with valid indices but where the tied line falls outside of the provided wavelength range.)

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 cube 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

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 (
EmissionLineFitDataTable
) – 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

static

class
mangadap.proc.spectralfitting.
EmissionLineFitDataTable
(neml=1, nkin=2, mask_dtype=<class 'numpy.int16'>, shape=None)[source]¶ Bases:
mangadap.util.datatable.DataTable
Primary data table with the results of the parameterized emissionline fit.
Table includes:
Key
Type
Description
BINID
int64
Bin ID number
BINID_INDEX
int64
0indexed number of bin
FIT_INDEX
int64
The index in the fit database associated with each emission line.
MASK
int16
Maskbit value for each emission line.
FLUX
float64
The bestfitting flux of the emission line.
FLUXERR
float64
The error in the bestfitting emissionline flux
KIN
float64
The bestfitting kinematics in each emission line
KINERR
float64
The error in the bestfitting emissionline kinematics
SIGMACORR
float64
Quadrature correction in the emissionline velocity dispersion
SIGMAINST
float64
Dispersion of the instrumental linespread function at the location of each emission line.
SIGMATPL
float64
Dispersion of the instrumental linespread function of the emissionline templates.
CONTAPLY
float64
The value of any additive polynomial included in the fit at the location of each emission line
CONTMPLY
float64
The value of any multiplicative polynomial included in the fit at the location of each emission line
CONTRFIT
float64
The value of any extinction curve included in the fit at the location of each emission line
LINE_PIXC
int64
The integer pixel nearest the center of each emission line.
AMP
float64
The bestfitting amplitude of the emission line.
ANR
float64
The amplitudetonoise ratio defined as the model amplitude divided by the median noise in the two (blue and red) sidebands defined for the emission line.
LINE_NSTAT
int64
The number of pixels included in the fit metric calculations (LINE_RMS, LINE_FRMS, LINE_CHI2) near each emission line.
LINE_RMS
float64
The rootmeansquare residual of the model fit near each emission line.
LINE_FRMS
float64
The rootmeansquare of the fractional residuals of the model fit near each emission line.
LINE_CHI2
float64
The chisquare of the model fit near each emission line.
BMED
float64
The median flux in the blue sideband of each emission line
RMED
float64
The median flux in the red sideband of each emission line
EWCONT
float64
The continuum value interpolated at the emissionline center (in the observed frame) used for the equivalent width measurement.
EW
float64
The equivalent width of each emission line
EWERR
float64
The error in the equivalent width of each emission line
 Parameters
neml (
int
) – Number of emission lines being fitnkin (
int
) – Number of kinematic parameters (e.g., 2 for V and sigma)mask_dtype (
type
) – The data type used for the maskbits (e.g., numpy.int16). Typically this would be set bymangadap.util.bitmask.BitMask.minimum_dtype()
.shape (
int
,tuple
, optional) – The shape of the initial array. If None, the data array will not be instantiated; useinit()
to initialize the data array after instantiation.

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.

class
mangadap.proc.spectralfitting.
StellarKinematicsFitDataTable
(ntpl=1, nadd=0, nmult=0, nkin=2, mask_dtype=<class 'numpy.int16'>, shape=None)[source]¶ Bases:
mangadap.util.datatable.DataTable
Class defining the data table to hold the stellar kinematics fit.
Table includes:
Key
Type
Description
BINID
int64
Bin ID number
BINID_INDEX
int64
0indexed number of bin
MASK
int16
Maskbit value
BEGPIX
int64
Index of the first pixel included in the fit
ENDPIX
int64
Index of the pixel just beyond the last pixel included in fit
NPIXTOT
int64
Total number of pixels in the spectrum to be fit.
NPIXFIT
int64
Number of pixels used by the fit.
TPLWGT
float64
Optimal weight of each template.
TPLWGTERR
float64
Nominal error in the weight of each template.
USETPL
bool_
Flag that each template was included in the fit.
ADDCOEF
float64
Coefficients of the additive polynomial, if included.
MULTCOEF
float64
Coefficients of the multiplicative polynomial, if included.
KININP
float64
Input guesses for the kinematics
KIN
float64
Bestfitting stellar kinematics
KINERR
float64
Errors in the bestfitting stellar kinematics
CHI2
float64
Chisquare figureofmerit for the fit
RCHI2
float64
Reduced chisquare figureofmerit for the fit
CHIGRW
float64
Value of the errornormalized residuals at 0, 68%, 95%, 99%, and 100% growth
RMS
float64
Rootmeansquare of the fit residuals.
RMSGRW
float64
Value of absolute value of the fit residuals at 0, 68%, 95%, 99%, and 100% growth
FRMS
float64
Rootmeansquare of the fractional residuals (i.e., residuals/model).
FRMSGRW
float64
Value of absolute value of the fractional residuals at 0, 68%, 95%, 99%, 100% growth
SIGMACORR_SRES
float64
Quadrature correction for the stellar velocity dispersion determined by the mean difference in spectral resolution between galaxy and template data.
SIGMACORR_EMP
float64
Quadrature correciton for the stellar velocity dispersion determined by fitting the optimal template to one resolution matched to the galaxy data.
 Parameters
ntpl (
int
) – Number of templates used to model the stellar continuum.nadd (
int
) – Number of coefficients in any additive polynomial included in the fit. Can be 0.nmult (
int
) – Number of coefficients in any multiplicative polynomial included in the fit. Can be 0.nkin (
int
) – Number of kinematic moments included in the fit. Note that the number of moments used as input guesses is always assumed to be 2.mask_dtype (
type
) – The data type used for the maskbits (e.g., numpy.int16). Typically this would be set bymangadap.util.bitmask.BitMask.minimum_dtype()
.shape (
int
,tuple
, optional) – The shape of the initial array. If None, the data array will not be instantiated; useinit()
to initialize the data array after instantiation.