mangadap.contrib.xjmc module

Implements an emission-line fitting function using pPXF.


License

Copyright © 2019, SDSS-IV/MaNGA Pipeline Group


mangadap.contrib.xjmc._combine_stellar_templates(templates, gas_template, wgts, component, vgrp=None, sgrp=None)[source]

Reconstruct the set of templates used to fit each spectrum.

Based on an initial fit to the spectra, construct a single optimal stellar template to use for each spectrum, and combine those with the existing gas templates. Each optimal stellar-continuum template is set to the zeroth component.

Warning

  • There can only be one stellar component per fit.

  • It is possible for some optimal stellar-continuum templates to be 0 everywhere. In this case, the template is excluded from the array selecting which templates to include in the fit; however, that template is assigned a component. These details are handled by _ppxf_component_setup().

Todo

Allow for different template construct modes? E.g., use all, use anything that was non-zero in the first fit, or use single optimal template (as done now).

Parameters:
  • templates (numpy.ndarray) – Templates library to use for fitting. Shape is (NTPLPIX,NTPL).

  • gas_template (numpy.ndarray) – Boolean vector that selects the gas templates. Shape is (NTPL,).

  • wgts (numpy.ndarray) – The best-fitting template weights for each template in each spectrum. Shape is (NSPEC,NTPL).

  • component (numpy.ndarray) – Integer vector identifying the kinematic component for each template. Shape is (NTPL,).

  • vgrp (array-like, optional) – The integer velocity group associated with each template. Shape is \((N_{\rm tpl},)\) , but can be None.

  • sgrp (array-like, optional) – The integer sigma group associated with each template. Shape is \((N_{\rm tpl},)\) , but can be None.

Returns:

Seven arrays are returned:

  • (1) the weights of only the stellar templates used in constructing each optimal template [shape is (NSPEC,NTPL)];

  • (2) the optimal stellar templates for each spectrum with the gas templates appended [shape is (NSPEC+NGASTPL,NPIXTPL)];

  • (3) a boolean array that selects the gas templates [shape is (NSPEC+NGASTPL,);

  • (4) boolean array selecting which templates to use with each spectrum [shape is (NSPEC,NSPEC+NGASTPL)]

  • (5) integer array setting the component associated with each template [shape is (NSPEC+NGASTPL)].

  • (6) integer array setting the velocity group associated with each template [shape is (NSPEC+NGASTPL)].

  • (7) integer array setting the sigma group associated with each template [shape is (NSPEC+NGASTPL)].

Return type:

tuple

Raises:

ValueError – Raised if there is more than one stellar component.

mangadap.contrib.xjmc._fit_iteration(tpl_wave, templates, wave, flux, noise, velscale, start, moments, component, gas_template, tpl_to_use=None, reject_boxcar=101, velscale_ratio=None, degree=-1, mdegree=0, reddening=None, vgrp=None, sgrp=None, constr_kinem=None, mask=None, plot=False, quiet=True, sigma_rej=3.0, starting_spectrum=None, ppxf_faults='flag')[source]

Run a single fit+rejection iteration of pPXF for all input spectra with the provided set of constraints/options.

Parameters:
  • tpl_wave (numpy.ndarray) – Wavelength vector for the template library to fit to the object spectrum.

  • templates (numpy.ndarray) – Full template library. Shape is (NTPL,NTPLPIX).

  • wave (numpy.ndarray) – Wavelength vector. Shape is (NPIX,).

  • flux (numpy.ndarray) – Object spectra to fit. Shape is (NSPEC,NPIX).

  • noise (numpy.ndarray) – Error in the object spectra to fit. Shape is (NSPEC,NPIX).

  • velscale (float) – The pixel scale of the object spectra in km/s.

  • start (list) – The starting kinematics for each kinematic component. Length is NCOMP.

  • moments (numpy.ndarray) – Integer vector with the number of kinematic moments for each component. Shape is (NCOMP,).

  • component (numpy.ndarray) – Integer vector identifying the kinematic component for each template. Shape is (NTPL,).

  • gas_template (numpy.ndarray) – Boolean vector that selects the gas templates. Shape is (NTPL,).

  • tpl_to_use (numpy.ndarray, optional) – Boolean vector selecting templates to consider during the fit. Shape is (NTPL,). If None, all templates are used in the fit.

  • reject_boxcar (int, optional) – Size of the window for the rejection statistics. Should be an odd number and larger and 10. Default is 101. If None, no rejection iteration is performed.

  • velscale_ratio (int, optional) – The ratio between the object and template pixel scale.

  • degree (int, optional) – Order of the additive polynomial to include in the fit. Not included by default.

  • mdegree (int, optional) – Order of the multiplicative polynomial to fit. Not included by default.

  • reddening (float, optional) – Initial E(B-V) guess for reddening (uses ppxf-default Calzetti 2000 model). No attentuation fit by default.

  • vgrp (array-like, optional) – The integer velocity group associated with each template. Shape is \((N_{\rm tpl},)\).

  • sgrp (array-like, optional) – The integer sigma group associated with each template. Shape is \((N_{\rm tpl},)\).

  • constr_kinem (dict, optional) – A dictionary with the constraints to apply to the kinematics of each component; see constr_kinem in ppxf.

  • mask (numpy.ndarray, optional) – Boolean vector that selects the pixels in the object spectra to fit (i.e., mask=True for pixels to fit and mask=False for pixels to ignore). Shape is (NSPEC,NPIX). All pixels are fit by default.

  • vsyst (float, optional) – The pseudo velocity shift between the template and object spectra just due to the difference in the starting wavelength.

  • plot (bool, optional) – Show the pPXF fit plot at each iteration.

  • quiet (bool, optional) – Suppress output to the terminal.

  • sigma_rej (float, optional) – Sigma values used for the rejection.

  • starting_spectrum (int, optional) – Select a spectrum index to start the iteration. Only used for debugging! If None, starts with the first spectrum.

  • ppxf_faults (str, optional) –

    Dictates how exceptions raised by ppxf are treated. Allowed values are:

    • 'flag': Log the fault and continue. Any spectrum that faults is flagged as such in the last object returned by the method (see below).

    • 'raise': Re-raise the exception returned by ppxf.

Returns:

Twelve arrays are returned:

  • (1) The best-fitting model for each spectrum [shape is (NSPEC,NPIX)];

  • (2) the best-fitting emission-line-only model for each spectrum [shape is (NSPEC,NPIX)];

  • (3) a boolean array that is True for all spectral pixels included in the fit [shape is (NSPEC,NPIX)];

  • (4) the best-fitting weight for each template in each spectrum [shape is (NSPEC,NTPL)];

  • (5) the error in the best-fitting template weights [shape is (NSPEC,NTPL)];

  • (6) the coefficients of the additive polynomial for each spectrum [shape is (NSPEC,DEGREE+1)]; -(7) the coefficients of the multiplicative polynomial for each spectrum [shape is (NSPEC,MDEGREE)];

  • (8) the best-fitting reddening values for each spectrum [shape is (NSPEC,)];

  • (9) the input kinematics for each fit [shape is (NSPEC,sum(MOMENTS)];

  • (10) the best-fit kinematics for each fit [shape is (NSPEC,sum(MOMENTS)];

  • (11) the formal error in the best-fit kinematics for each fit [shape is (NSPEC,sum(MOMENTS)].

  • (12) a boolean array flagging spectra that caused ppxf to fault; True means the fit faulted, False means it was successful.

Return type:

tuple

mangadap.contrib.xjmc._good_templates(templates, gas_template, mask, start, velscale, velscale_ratio, vsyst)[source]

Determine which of the templates to use during the fit.

Good template are any stellar-continuum template and any gas template that is non-zero over the expected fitting range.

The details of this code should be pulled directly from ppxf for consistency.

Parameters:
  • templates (numpy.ndarray) – Templates library to use for fitting. Shape is (NTPLPIX,NTPL).

  • gas_template (numpy.ndarray) – Boolean vector that selects the gas templates. Shape is (NTPL,).

  • mask (numpy.ndarray) – Boolean vector that selects the pixels in the object spectrum to fit (i.e., mask=True for pixels to fit and mask=False for pixels to ignore). As in pPXF, the length is expected to be less than or equal to NTPLPIX in the template spectra.

  • start (list) – The starting kinematics for each kinematic component. Length is NCOMP.

  • velscale (float) – The pixel scale of the object spectrum to fit in km/s.

  • velscale_ratio (int, optional) – The ratio between the object and template pixel scale.

  • vsyst (float, optional) – The pseudo velocity shift between the template and object spectra just due to the difference in the starting wavelength.

Returns:

Boolean array flagging good templates, which means anything that is not a gas template and any gas template that has non-zero values in the fitting region.

Return type:

numpy.ndarray

mangadap.contrib.xjmc._ppxf_component_setup(component, gas_template, start, single_gas_component=False, gas_start=None)[source]

Setup the component, moment, and starting point arrays for a ppxf-fitting interation.

This primarily just sets all the gas components to a single component if requested. It also restructures the moment and starting point arrays as necessary to reflect this change.

..warning:

This function requires that all stellar components have
component numbers that are **less than** any gas components.
However, this **is not checked** by the function.
Parameters:
  • component (numpy.ndarray) – The full list of components for all templates. The total number of components is NCOMP.

  • gas_template (numpy.ndarray) – A boolean array identifying the gas templates.

  • start (list, numpy.ndarray) – The starting kinematics to use for each object spectrum. Shape is (NOBJ,); each element has shape (NCOMP,); each component element has shape (NMOM,), such that the number of moments can be different for each component. NCOMP and NMOM should be the same for all object spectra.

  • single_gas_component (bool, optional) – Flag to force all gas components to have the same kinematics.

  • gas_start (list, numpy.ndarray, optional) – The starting kinematics to use for the gas components. Shape must be (NOBJ,2).

Returns:

Three numpy arrays are returned:

  1. The list of down-selected and renumbered, if necessary, kinematic components,

  2. the down-selected and reordered, if necessary, number of moments to fit, and

  3. the down-selected and reordered starting guesses for each component.

Return type:

tuple

Raises:

ValueError – Raised if the provided gas starting kinematics is not correct.

mangadap.contrib.xjmc._reorder_solution(ppsol, pperr, component_map, moments, start=None, fill_value=-999.0)[source]

Provided the best-fitting parameters from a ppxf instance, restructure the parameters to account for components that were removed during the template validation.

Parameters:
  • ppsol (list) – The pPXF solution parameters

  • pperr (list) – The formal errors on the pPXF solution parameters

  • component_map (numpy.ndarray) – An integer vector mapping the input component number to the output component number; i.e., component_map[0] is the original component number for the downselected 0th component; length is NCOMP.

  • moments (list) – The number of moments for the original set of components; length is NCOMP.

  • start (list, optional) – The starting kinematics for the original set of components. If provided, the starting values are included in the output parameter object for components that were not included in the pPPXF fit; otherwise, the unfit components are given placeholder parameter values.

  • fill_value (float, optional) – The placeholder value to give parameters and errors for components not included in the pPXF fit.

Returns:

Two lists with the rearranged best-fitting parameters and errors.

Return type:

list

mangadap.contrib.xjmc._reset_components(c, valid)[source]

Down-select and appropriately reindex a set of ppxf kinematic components.

Parameters:
  • c (numpy.ndarray) – Integer array with the kinematic components assigned to each template. Shape is \((N_{\rm tpl},)\).

  • valid (numpy.ndarray) – Boolean array selecting the valid templates for component reassignment.

Returns:

Returns the down-selected and re-ordered set of components and an integer array with the mapping between the old and new components; i.e., see component_map in _reorder_solution().

Return type:

tuple

mangadap.contrib.xjmc._reset_kinematic_constraints(comp, valid, A, b)[source]

Down-select the kinematic constraints set for each component base on the boolean flagging of valid templates.

Parameters:
  • comp (numpy.ndarray) – Integer array with the kinematic components assigned to each template. Shape is \((N_{\rm tpl},)\).

  • valid (numpy.ndarray) – Boolean array selecting the valid templates for component reassignment.

  • A (numpy.ndarray) – Linear constraint matrix used by ppxf to impose constraints on the fitted kinematics; see the ppxf keyword argument constr_kinematics. Shape is \((N_{\rm constr},2 N_{\rm comp})\); i.e., each row of A constitutes an imposed constraint and each column pair provides the coefficient for each kinematic moment. This method currently only allows for 2 moments in the fit. Can be None.

  • b (numpy.ndarray) – Linear constraint vector used by ppxf to impose constraints one the fitted kinematics; see the ppxf keyword argument constr_kinematics. Shape is \((N_{\rm constr},)\). Can be None.

Returns:

Return the adjusted A and b objects after accounting for any components removed because their constituent templates were all invalid. If A or b are None, both objects are returned as None; otherwise, both are adjusted arrays. Note that if the arrays do not require adjustment (i.e., no components have been removed), the input A and b are returned, not a copy of these arrays.

Return type:

tuple

mangadap.contrib.xjmc._set_to_using_optimal_templates(nspec, ntpl, wgts, component, vgrp=None, sgrp=None)[source]
mangadap.contrib.xjmc._validate_templates_components(templates, gas_template, component, vgrp, sgrp, moments, mask, start, tpl_to_use, velscale, velscale_ratio=None, vsyst=0, constr_kinem=None)[source]

Check that templates are valid in the sense that they have non-zero components in valid pixel regions.

If all templates are valid, the returned data is identical to the input. If not, the returned data are restructured as necessary for running pPXF.

The start vector is used to set the guess offset (including vsyst) between the provided mask and the template. The tpl_to_use vector is used to set a tempate as invalid.

Parameters:
  • templates (numpy.ndarray) – Templates library to use for fitting. Shape is (NTPLPIX,NTPL).

  • gas_template (numpy.ndarray) – Boolean vector that selects the gas templates. Shape is (NTPL,).

  • component (numpy.ndarray) – Integer vector identifying the kinematic component for each template. Shape is (NTPL,).

  • vgrp (array-like) – The integer velocity group associated with each template. Shape is \((N_{\rm tpl},)\) , but can be None.

  • sgrp (array-like) – The integer sigma group associated with each template. Shape is \((N_{\rm tpl},)\) , but can be None.

  • moments (numpy.ndarray) – Integer vector with the number of kinematic moments for each component. Shape is (NCOMP,).

  • mask (numpy.ndarray) – Boolean vector that selects the pixels in the object spectrum to fit (i.e., mask=True for pixels to fit and mask=False for pixels to ignore). As in pPXF, the length is expected to be less than or equal to NTPLPIX in the template spectra.

  • start (list) – The starting kinematics for each kinematic component. Length is NCOMP.

  • tpl_to_use (numpy.ndarray) – In addition to removing unconstrained templates, this boolean vector selects that should even be considered in the fit. Shape is (NTPL,).

  • velscale (float) – The pixel scale of the object spectrum to fit in km/s.

  • velscale_ratio (int, optional) – The ratio between the object and template pixel scale.

  • vsyst (float, optional) – The pseudo velocity shift between the template and object spectra just due to the difference in the starting wavelength.

  • constr_kinem (dict, optional) – A dictionary with the constraints to apply to the kinematics of each component; see constr_kinem in ppxf.

Returns:

Eleven objects are returned. The number of new valid templates is listed as _NTPL:

  1. Boolean vector with which templates were valid (length is NTPL),

  2. the valid set of templates to pass to pPXF [shape is (NTPLPIX,_NTPL)],

  3. the boolean vector selecting gas templates (length is _NTPL),

  4. an integer vector mapping the input component number to the output component number (i.e., component_map[0] is the original component number for the downselected 0th component; length is _NCOMP),

  5. the new component number for the downselected templates (length is _NTPL),

  6. the new velocity group number for the downselected templates (length is _NTPL),

  7. the new sigma group number for the downselected templates (length is _NTPL),

  8. the number of moments for the new components (length is _NCOMP),

  9. the starting kinematics for each new component (length is _NCOMP),

  10. the parameter tying object reordered as necessary for the new component list, and

  11. the kinematics constraint dictionary for the down-selected set of templates.

Return type:

tuple

Raises:

ValueError – Raised if no templates are valid.

mangadap.contrib.xjmc.calculate_noise(residuals, width=101)[source]

Robust determination of the error spectrum as 1/2 of the interval enclosing 68% of the values in a given running window. Created by Michele Cappellari (23 September 2017)

Parameters:
  • residuals (numpy.ndarray) – Vector of residuals between the model and data

  • width (int, optional) – Size of the window for the statistics. Should be an odd number and larger and 10.

Returns:

Vector with the same size as the input residuals with half of the 68% confidence interval of the residuals within a box of size width centered at each position.

Return type:

numpy.ndarray

Raises:

ValueError – Raised if the width is not an odd number or if it is less than 11 elements.

mangadap.contrib.xjmc.emline_fitter_with_ppxf(tpl_wave, templates, wave, flux, noise, mask, velscale, velscale_ratio, inp_component, gas_template, inp_moments, inp_start, vgrp=None, sgrp=None, constr_kinem=None, degree=-1, mdegree=0, reddening=None, reject_boxcar=101, tpl_to_use=None, binid=None, flux_binned=None, noise_binned=None, mask_binned=None, x_binned=None, y_binned=None, x=None, y=None, plot=False, quiet=False, debug=False, sigma_rej=3.0, ppxf_faults='flag')[source]

Main calling function for simultaneously fitting stellar-continuum and nebular emission lines in many spectra using pPXF.

This is a generalization of a function originally provided by Xihan Ji and Michele Cappellari.

The function does not fit the stellar kinematics; these are fixed during the fit (as provided in inp_start) and should have resulted from a previous fit to the stellar-continuum alone; see e.g., PPXFFit. The number of stellar kinematic moments must have been the same for all spectra, and there can only be one stellar component.

The templates are expected to be an integer number of velscale_ratio in length; see check_templates().

The fitting procedure can be performed for a single set of spectra, or a set of spectra that are remapped from an input set of binned spectra. The latter operation is selected by providing the binned flux, error, and mask arrays. The individual spectra can be mapped to a binned spectrum using binned and unbinned on-sky coordinates or by providing the bin indices directly (see argument description below).

When the binned spectra are provided, the fitting procedure is as follows:

  • If a direct association of binned spectrum to remapped spectrum is not provided (via binid), the Cartesian coordinates are used to identify the closest association between binned and remapped spectra.

  • The binned spectra are fit with the stellar components fixed to the provided kinematics in the starting value array and with all the gas templates part of a single kinematic component. This first fit iteration includes any rejection iterations according to the provided boxcar width.

  • The fit to the binned spectrum is then used to set (1) the single optimal stellar template and (2) the initial guess for the gas kinematics to use for the subsequent fits to each remapped spectrum.

  • Each spectrum is fit for the first time with the stellar kinematics fixed to the result for the associated binned spectrum and, again, with all the gas templates free but part of the same kinematic component. This fit iteration includes any rejection iterations according to the provided boxcar width.

  • Finally the spectra are fit without any rejection iteration and allowing the gas templates to be associated with multiple kinematic components as requested by the user (using the vgrp, sgrp, and constr_kinem arguments).

When no binned spectra are provided, the procedure is virtually the same except the initial fit to the binned spectra is skipped. An initial fit to the spectra is performed to construct the optimal template, instead of basing the optimal template on the initial fit to the binned spectrum.

To tie the kinematics assigned to each template, you have to assign them to velocity and/or velocity dispersion (sigma) groups using vgrp and sgrp, respectively. These arrays are used to construct the ppxf tied argument, appropriate for each spectrum fit; see ppxf_tied_parameters(). To impose constraints on the component kinematics, use constr_kinem; see the ppxf documentation.

Each template is identified as a gas template using the provided gas_template argument.

Todo

  • Allow mask(s) to be optional

  • Skip the last step if the gas are already part of the same kinematic component as dictated by the input tying data.

Parameters:
  • tpl_wave (numpy.ndarray) – Wavelength array for the spectral templates. Shape is \((N_{\rm tpl, pix},)\).

  • templates (numpy.ndarray) – Templates library to use for fitting. Shape is \((N_{\rm tpl},N_{\rm tpl, pix})\).

  • wave (numpy.ndarray) – Wavelength vector. Shape is \((N_{\rm pix},)\).

  • flux (numpy.ndarray) – Object spectra to fit. Shape is \((N_{\rm spec},N_{\rm pix})\).

  • noise (numpy.ndarray) – Error in the object spectra to fit. Shape must match flux.

  • mask (numpy.ndarray) – Boolean vector that selects the pixels in the object spectra to fit (i.e., mask=True for pixels to fit and mask=False for pixels to ignore). Shape must match flux. All pixels are fit by default.

  • velscale (float) – The pixel scale of the object spectra in km/s.

  • velscale_ratio (int) – The ratio between the object and template pixel scale; must be an integer.

  • inp_component (numpy.ndarray) – Integer vector identifying the kinematic component for each template. Shape is \((N_{\rm tpl},)\). The unique components must be 0..:math:N_{rm comp}-1, without skipping any numbers.

  • gas_template (numpy.ndarray) – Boolean vector that selects the gas templates. Shape is \((N_{\rm tpl},)\).

  • inp_moments (numpy.ndarray) – Integer vector with the number of kinematic moments for each component. Shape is \((N_{\rm comp},)\). WARNING: These must currently all be 2.

  • inp_start (list, numpy.ndarray) – The starting kinematics to use for each spectrum. Shape is \((N_{\rm spec},)\); each element has shape \((N_{\rm comp},)\), and each component element has shape \((N_{\rm mom},)\). The object types allow each component to have its own number of moments, but each spectrum should have the same \((N_{\rm comp},)\) and \((N_{\rm mom},)\) for each component.

  • vgrp (array-like, optional) – The integer velocity group associated with each template. Shape is \((N_{\rm tpl},)\).

  • sgrp (array-like, optional) – The integer sigma group associated with each template. Shape is \((N_{\rm tpl},)\).

  • constr_kinem (dict, optional) – A dictionary with the constraints to apply to the kinematics of each component; see constr_kinem in ppxf.

  • degree (int, optional) – Order of the additive polynomial to include in the fit. Not included by default.

  • mdegree (int, optional) – Order of the multiplicative polynomial to fit. Not included by default.

  • reddening (float, optional) – Initial E(B-V) guess for reddening (uses ppxf-default Calzetti 2000 model). No attentuation fit by default.

  • reject_boxcar (int, optional) – Size of the window for the rejection statistics. Should be an odd number and larger than 10. Default is 101. If None, no rejection iterations are performed.

  • tpl_to_use (numpy.ndarray, optional) – Boolean vector selecting templates to consider during the fit. If None, all templates are used in the fit. If provided, the shape must be \((N_{\rm bin},N_{\rm tpl})\) when providing the binned data and \((N_{\rm spec},N_{\rm tpl})\) when no binned data are provided.

  • binid (numpy.ndarray, optional) – Bin index associated with each spectrum. Ignored if binned spectra are not provided. If binned spectra are provided, and this is None, coordinates must be provided and they are used to associate each bin with a binned spectrum just based by proximity. If provided, this associates each spectrum to the binned spectrum to use for the stellar kinematics. Shape is \((N_{\rm spec},)\).

  • flux_binned (numpy.ndarray, optional) – Binned spectra with previous fits to the stellar kinematics. See purpose above. Shape must be \((N_{\rm bin},N_{\rm pix})\).

  • noise_binned (numpy.ndarray, optional) – Error in the binned spectra. Shape must match flux_binned.

  • mask_binned (numpy.ndarray, optional) – Good-pixel mask for the binned spectra. Shape must match flux_binned.

  • x_binned (numpy.ndarray, optional) – On-sky bin x coordinate; shape is \((N_{\rm bin},)\).

  • y_binned (numpy.ndarray, optional) – On-sky bin y coordinate; shape is \((N_{\rm bin},)\).

  • x (numpy.ndarray, optional) – On-sky spectrum x coordinates; shape is \((N_{\rm spec},)\).

  • y (numpy.ndarray, optional) – On-sky spectrum y coordinates; shape is \((N_{\rm spec},)\).

  • plot (bool, optional) – Show the pPXF fit plot at each iteration.

  • quiet (bool, optional) – Suppress output to the terminal.

  • debug (bool, optional) – Run in debugging mode. Currently, all this does is perform the initial setup and then return empty vectors of the correct shape. No fits are performed.

  • ppxf_faults (str, optional) –

    Dictates how exceptions raised by ppxf are treated. Allowed values are:

    • 'flag': Log the fault and continue. Any spectrum that faults is flagged as such in the last object returned by the method (see below).

    • 'raise': Re-raise the exception returned by ppxf.

Returns:

The following arrays are returned:

  1. The best-fitting model for each spectrum. Shape is \((N_{\rm spec},N_{\rm pix})\).

  2. The best-fitting emission-line-only model for each spectrum. Shape is \((N_{\rm spec},N_{\rm pix})\).

  3. Boolean array that is True for all spectral pixels included in the fit spectrum. Shape is \((N_{\rm spec},N_{\rm pix})\).

  4. Best-fitting weight for each template in each spectrum. Shape is \((N_{\rm spec}, N_{\rm tpl})\).

  5. Error in the best-fitting template weights. Shape is \((N_{\rm spec}, N_{\rm tpl})\).

  6. Coefficients of the additive polynomial for each spectrum; None if not fit. Shape is \((N_{\rm spec}, d+1\), where \(d\) is degree.

  7. Coefficients of the multiplicative polynomial for each spectrum; None if not fit. Shape is \((N_{\rm spec}, m\), where \(m\) is mdegree.

  8. Best-fitting reddening values for each spectrum; None if not fit. Shape is \((N_{\rm spec},)\).

  9. Input kinematics for each fit. Shape is \((N_{\rm spec},\sum_i k_i)\), where \(k_i\) is the number of kinematic moments for component \(i\).

  10. Best-fit kinematics for each fit. Shape is \((N_{\rm spec},\sum_i k_i)\), where \(k_i\) is the number of kinematic moments for component \(i\).

  11. Formal error in the best-fit kinematics for each spectrum. Shape is \((N_{\rm spec},\sum_i k_i)\), where \(k_i\) is the number of kinematic moments for component \(i\).

Return type:

tuple

Raises:
  • NotImplementedError – Raised if the number of stellar components is larger than 1.

  • ValueError – Raised if: (1) only some of the necessary bin-remapping data has not been provided (see function description); (2) the template flag object does not have the correct shape; (3) the wavelength and flux vectors do not match; (4) any of the spectra are fully masked (i.e., there’s nothing to fit); or (5) the input list of kinematics does not have the correct length.

mangadap.contrib.xjmc.ppxf_tied_parameters(component, vgrp, sgrp, moments)[source]

Construct the object used to tie kinematic parameters in pPXF.

Note

The components and kinematics groups can potentially have redundant information. E.g., If all sigma groups also have tied velocities, they’ll be part of a component and will not required a tied parameter.

Warning

High-order moments are not currently tied, but this is straight-forward to add.

Parameters:
  • component (array-like) – The kinematic component assigned to each template. Shape is \((N_{\rm tpl},)\).

  • vgrp (array-like) – The velocity group assigned to each template. Shape is \((N_{\rm tpl},)\). Can be None for no groups.

  • sgrp (array-like) – The velocity-dispersion (sigma) group assigned to each template. Shape is \((N_{\rm tpl},)\). Can be None for no groups.

  • moments (array-like) – The number of moments assigned to each component. Can be negative for fixed parameters. Shape is \((N_{\rm comp},)\).

Returns:

The tied object to pass to ppxf. Will be None if both vgrp or sgrp are None or when the consolidation of the groups and components result in no tying being necessary.

Return type:

list

Raises:

ValueError – Raised if the components or the groups are not an uninterupted sequence from 0..N-1, if the moments are provided for each component, or the length of the vgrp or sgrp arrays do not match the input component array.

mangadap.contrib.xjmc.ppxf_vsyst(tpl_wave, obj_wave, velscale, velscale_ratio=None)[source]

Determine the pseudo velocity offset between the template and object spectra due to the difference in the starting wavelengths.

Calculation is independent of the base of the logarithm used the sampling of the spectra, but the wavelengths must be geometrically binned.

Todo

Compute velscale_ratio directly from the input?

Parameters:
  • tpl_wave (numpy.ndarray) – Wavelength vector for the template library to fit to the object spectrum.

  • obj_wave (numpy.ndarray) – Wavelength vector for the object spectrum to be fit.

  • velscale (float) – Velocity step per pixel in km/s for the object spectrum.

  • velscale_ratio (int, optional) – The integer ratio between the velocity scale of the pixel in the galaxy data to that of the template data. This is used only when constructing the template library. If None, assumes that the velocity scales are identical; i.e., velscale_ratio=None is identical to velscale_ratio=1.

Returns:

Velocity offset in km/s between the initial wavelengths of the template and object spectra.

Return type:

float