mangadap.proc.elric module¶
Implements an emissionline profile fitting class.
Warning
Although it may still be possible to use Elric
, it is
currently not actively used by the surveylevel operation of the
MaNGA DAP. See instead mangadap.proc.sasuke.Sasuke
.
Revision history¶
26 Apr 2016: Original implementation by K. Westfall (KBW)13 Jul 2016: (KBW) Include log_bounds determining whether or not a returned parameters is near its boundary.19 Jul 2016: (KBW) Changed file name19 Oct 2016: (KBW) AddedElric.reset_continuum_mask_window()
function to deal with the subtraction of the continuum over the fully viable spectral range, and ignoring small spectral regions ignored during the stellar continuum fit. Changed the initial creation of the continuum mask to include the emission line regions to avoid any polynomial extrapolation errors, in case the emission line happens to fall exactly at the edge of the valid spectral range.08 Nov 2016: (KBW) Moved theStellarContinuumModel.reset_continuum_mask_window()
function fromElric
to be a member ofStellarContinuumModel
.24 May 2017: (KBW) Moved _check_db tomangadap.proc.spectralfitting.EmissionLineFit.check_emission_line_database()
and moved fill_equivalent_width tomangadap.proc.spectralfitting.EmissionLineFit.measure_equivalent_width()
. Moved _per_fitting_window_dtype from EmissionLineFit toElric
.24 Aug 2017: (KBW) Use newmangadap.proc.util.sample_growth()
instead of old residual_growth function.02 Feb 2018: (KBW) Adjust for change tomangadap.proc.stellarcontinuummodel.StellarContinuumModel.fill_to_match()
.
Copyright © 2019, SDSSIV/MaNGA Pipeline Group

class
mangadap.proc.elric.
Elric
(bitmask, wave=None, flux=None, emission_lines=None, error=None, mask=None, stellar_continuum=None, base_order=1, window_buffer=25, guess_redshift=None, guess_dispersion=None, default_dispersion=20.0, run_fit=False, loggers=None, quiet=False)[source]¶ Bases:
mangadap.proc.spectralfitting.EmissionLineFit
ELRIC: EmissionLine Regression and Inference Class
https://en.wikipedia.org/wiki/Edward_Elric
Use LineProfileFit to fit the emissionline properties in a set of spectra.
Todo
 Implement some scheme to penalize multicomponent fits at low S/N

_assess_and_save_fit
(i, j, model_fit_par, model_eml_par)[source]¶ Assess the result of the LineProfileFit results.
 (DONE) Check the success failure
 (DONE) Calculate the chi2, rchi2, rms, fractional_rms, residuals, fractional_residuals
 (DONE) Compare the fit parameters to the bounds
 Check the chisquare and residuals?
 Check the velocity offset wrt the input
 For multiple lines, check the order of the lines matches the guess parameters
 For multiple component lines, check the ordering of the subcomponents

static
_correct_subeml_par
(restwave_0, restwave_k, par, err=None)[source]¶ Correct the parameters fit assuming a rest wavelength of restwave_0, when it’s actually restwave_k. Input parameters are expected to be flux, velocity, velocity dispersion.

static
_is_near_bound
(par, lbnd, ubnd, logbounded, rtol=0.01, atol=0.0001)[source]¶ Determine of any of the parameters within start and start+npar are “near” an imposed boundary.

_parse_emission_line_models
()[source]¶ Parse the input emissionline file into a set of windows — the number of windows is \(N_{\rm win}\)) — that are fit for each spectrum.

static
_per_fitting_window_dtype
(nwin, max_npar, mask_dtype)[source]¶ Construct the record array data type for the output fits extension.

static
_set_profile_ties
(base_profiles, base_restwave, base_fixed_par, tied_profiles, tied_restwave, tied_fixed_par, mode, flux)[source]¶

fit
(wave, flux, emission_lines, ivar=None, mask=None, sres=None, continuum=None, base_order=1, window_buffer=25, guess_redshift=None, guess_dispersion=None, loggers=None, quiet=False)[source]¶ The flux array is expected to have size Nspec x Nwave.
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.

class
mangadap.proc.elric.
ElricFittingWindow
(nlines=None, db_indx=None, line_index=None, restwave=None, profile_set=None, fixed_par=None, bounds=None, log_bounds=None, output_model=None, tied_pairs=None, tied_funcs=None)[source]¶ Bases:
object
A utility class for the fitting windows used by Elric
The class can be instantiated as fully None.
Parameters:  nlines (int) – (Optional) The number of lines to be fit simultaneously.
 db_indx (numpy.ndarray) – (Optional) An array with the database index (0based) of each line to be fit.
 line_index (numpy.ndarray) – (Optional) An array with the index numbers, read from the database, of each line to be fit.
 restwave (numpy.ndarray) – (Optional) An array with the rest wavelengths of each line to be fit.
 profile_set (numpy.ndarray) – (Optional) An array with the profile objects that define the functional form of each line.
 fixed_par (numpy.ndarray) – (Optional) An array with the fixed parameters for all parameters in the model to be fit.
 bounds (numpy.ndarray) – (Optional) A twocolumn array with the lower (first column) and upper (second column) bounds for the fit parameters.
 log_bounds (numpy.ndarray) – (Optional) The range of the boundary should be considered as logarithmic when testing if a parameter is near its boundary.
 output_model (bool) – (Optional) Include the bestfitting model in the composite emissionline model for each spectrum. This is only flagged as true if ALL the emission lines in the fitting window are to be included according to the emissionline database.
 tied_pairs (numpy.ndarray) – (Optional) The series of
tied profiles (
TiedLineProfile
objects) that are used to tie parameters of the model.  tied_funcs (numpy.ndarray) – (Optional) The member functions
of the
TiedLineProfile
objects that should be called sequentially to tie model parameters.

class
mangadap.proc.elric.
ElricPar
(emission_lines=None, base_order=None, window_buffer=None, guess_redshift=None, guess_dispersion=None, minimum_snr=None, pixelmask=None, stellar_continuum=None)[source]¶ Bases:
mangadap.par.parset.KeywordParSet
Elric emissionline fitting parameters.
The defined parameters are:
Key Type Options Default Description emission_lines
EmissionLineDB base_order
int 1 window_buffer
int, float 25.0 guess_redshift
ndarray, list, int, float guess_dispersion
ndarray, list, int, float minimum_snr
int, float 0.0 pixelmask
SpectralPixelMask stellar_continuum
StellarContinuumModel

class
mangadap.proc.elric.
LineProfileFit
(x, y, profile_list, base_order=None, error=None, mask=None, par=None, fixed=None, bounds=None, run_fit=True, construct_covariance=True, verbose=0)[source]¶ Bases:
object
Simultaneously fit multiple line profiles. Currently only allows one to fit using an NCompLineProfile object. The fitting algorithm used is scipy.optimize.least_squares with fitting method ‘trf’ to allow for bounds.
Todo
For multicomponent lines, set the first normalization to be the normalization for the sum of all components, then force the normalization of the subcomponents to be ordered from highest to lowest and bounded from 0 to 1.
Parameters:  x (1D array) – Independent variable
 y (1D array) – Dependent variable
 profile_list (list of or individual
NCompLineProfile
) – The profile(s) to fit to the dependent variable.  base_order (int) – (Optional) The order of the Legendre polynomial to include in the model for the baseline trend in y below the fitted line profile(s).
 error (1D array) – (Optional) Error in the dependent variables. If not provided, no error weighting is performed during the fitting process, and the covariance will not be constructed.
 mask (1D array) – (Optional) Boolean array used to ignore values in y during the fit.
 par (1D array) – (Optional) Initial guess for model parameters. The number of parameters much match the expectation based on the provided list of profiles and the order of the baseline polynomial. If not provided, the parameters are initialized to 0.
 fixed (1D array) – (Optional) Flags used to fix parameters during the fit. The number of parameters much match the expectation based on the provided list of profiles and the order of the baseline polynomial. If not provided, all parameters are freely fit.
 bounds (2tuple) – (Optional) Tuple with two arraylike
elements giving the upper and lower bound for each
parameter. The length of each array element must match the
number of parameters. For an unbounded problem, set
bounds=None
, or use numpy.inf with an appropriate sign to disable bounds on all or some variables.  run_fit (bool) – (Optional) Flag to run the fit upon
instantiation of the object, which defaults to True. If set
to False, the object is initialized but the fit is not
executed, and can be executed later using
fit()
.  construct_covariance (bool) – (Optional) Flag to construct the covariance matrix based on the result object provided by scipy.optimize.least_squares, which defaults to True. If set to False, the covariance matrix is set to None.
 verbose (int) – (Optional) Verbosity level for scipy.optimize.least_squares; default is 0.

x
¶ Independent variable of length \(M\).
Type: numpy.ndarray

y
¶ Dependent variable to be fit of length \(M\).
Type: numpy.ndarray

err
¶ Error, \(\sigma\), in the dependent variable of length \(M\).
Type: numpy.ndarray

mask
¶ Flag to fit dependent variables of length \(M\).
Type: numpy.ndarray

nlines
¶ Number of lines being fit.
Type: int

base_order
¶ The order of the Legendre polynomial include in the model; see astropy.modeling.polynomial.Legendre1D.
Type: int

model
¶ The compound model being fit composed of the line profiles and the baseline (if a baseline is being fit). That is, this defines the function \(f(\mathbf{x}\mathbf{\theta})\), where \(\mathbf{x}\) is the dependent variable and \(\mathbf{\theta}\) is the list of variables. The fitting algorithm minimizes the (errorweighted) residuals to approximate \(y=f(\mathbf{x}\mathbf{\theta})\).
Type: astropy.modeling.models.CompoundModel

npar
¶ Total number of parameters in the model. The is the number of parameters per line and the number of parameters included in the baseline.
Type: int

nfitpar
¶ Number of free parameters, defined as \(N\).
Type: int

par
¶ Full list of model parameters, including those parameters that have been fixed.
Type: numpy.ndarray

fixed
¶ Flags to fit (False) or fix (True) a given parameter.
Type: numpy.ndarray

bounds
¶ Tuple with two arraylike elements giving the upper and lower bound for each parameter. For an unbounded problem, this is set to
bounds=(numpy.inf,numpy.inf)
.Type: 2tuple

result
¶ Object with the results from scipy.optimize.least_squares. The bestfitting parameters, \(\mathbf{\theta}\), is returned as
result.x
.Type: scipy.optimize.OptimizeResult

cov
¶ The formal covariance matrix for the fit. The scipy.optimize.OptimizeResult object provides the Jacobian of the model, an \(M \times N\) array with elements
\[J_{ij} = \left.\frac{\partial f_i}{\partial \theta_j}\right_{\mathbf{\theta}}\]at location in parameter space of the bestfitting model. This is used to construct the covariance matrix by taking the inverse of the curvature matrix:
\[\mathbf{\alpha}_{kl} = \left[\frac{1}{\sigma_{i}} J_{ik}\right]^{\rm T} \left[\frac{1}{\sigma_{i}} J_{il}\right].\]That is, \(\mathbf{C} = \mathbf{\alpha}^{1}\).
Type: numpy.ndarray
Raises: TypeError
– Raised if the provided profile objects are not instances ofNCompLineProfile
.ValueError
– Raised if any of the provided parameter arrays (par, fixed) are not onedimensional or the number of parameters is not as expected based on the number of profile and baseline parameters.
Todo
 Provide a better initialization for the parameters.
 Need to provide the bestfitting parameters and errors as full vectors, including the fixed parameters.

fit
(x, y, error=None, mask=None, construct_covariance=True, verbose=0)[source]¶ Fit the line profiles provided upon initialization to the data using scipy.optimize.least_squares.