kcorrect.fitter
Classes
Nonnegative SED fitting object |
Module Contents
- class Fitter(responses=None, templates=None, redshift_range=[0.0, 1.0], nredshift=2000, abcorrect=False)[source]
Bases:
objectNonnegative SED fitting object
- Parameters:
abcorrect (bool) – correct maggies to AB (default False)
responses (list of str) – names of responses to use
templates (kcorrect.template.Template object) – templates to use
redshift_range (list of np.float32) – minimum and maximum redshifts (default [0., 1.])
nredshift (int or np.int32) – number of redshifts in interpolation grid
- Amatrix[source]
interpolator to produce A matrix (set to None until set_Amatrix called)
- Type:
scipy.interpolate.interp1d object
- to_ab(maggies=None, ivar=None)[source]
Convert input maggies to AB
- Parameters:
maggies (ndarray of np.float32) – array of fluxes in standard SDSS system
ivar (ndarray of np.float32) – inverse variances in standard SDSS system (optional)
- Returns:
ab_maggies (ndarray of np.float32) – array of fluxes converted to AB
ab_ivar (ndarray of np.float32) – inverse variances converted to AB (if ivar input)
Notes
This method just returns maggies and/or ivar unchanged, as for this object we expect AB maggies on input.
fit_coeffs() calls this on its inputs.
- _fit_coeffs(redshift=None, maggies=None, ivar=None, mc=0)[source]
Fit coefficients to single object
- Parameters:
redshift (np.float32) – redshift
maggies (ndarray of np.float32) – fluxes of each band in AB maggies
ivar (ndarray of np.float32) – inverse variance of each band
mc (int) – if greater than 0, generate Monte Carlo of coefficients
- Returns:
coeffs (ndarray of np.float32) – [ntemplates] coefficients for each template
coeffs_mc (ndarray of np.float32) – [ntemplates, mc] coefficients for each MC for each template
maggies_mc (ndarray of np.float32) – [len(maggies), mc] maggies for each MC
Notes
This recasts the A and b matrices as np.float64 before sending them to scipy.optimize.nnls(). This is necessitated by a change in the algorithm for NNLS in SciPy 1.12.0 and later, which is apparently less numerically robust than the original algorithm.
- _process_inputs(redshift=None, maggies=None, ivar=None, coeffs=None)[source]
Returns whether input should be an array, and casts everything right
- Parameters:
redshift (a quantity or ndarray) – input redshift defining whether we have an array or scalar
maggies (a quantity or ndarray, or None) – input maggies
ivar (a quantity or ndarray, or None) – input ivar
coeffs (a quantity or ndarray, or None) – input coeffs
- Returns:
array (bool) – True if it is an array
n (int) – number of redshifts (1 if not an array)
redshift (np.float32 or [n] ndarray thereof) – redshift to use
maggies (ndarray of np.float32 or None) – AB maggies to use
ivar (ndarray of np.float32 or None) – ivar to use
coeffs (ndarray of np.float32 or None) – coeffs to use
Notes
Uses redshift to determine whether we should treat the calculation as an array or scalar. Then checks the appropriate sizes (based on the number of responses and the number of seds in the object). If maggies, ivar, or coeffs are None, then the corresponding output is None.
Applies this class’s to_ab() function on maggies and ivar to convert to return AB maggies.
- fit_coeffs(redshift=None, maggies=None, ivar=None, mc=0)[source]
Fit coefficients
- Parameters:
redshift (np.float32 or ndarray of np.float32) – redshift(s)
maggies (ndarray of np.float32) – fluxes of each band in AB maggies
ivar (ndarray of np.float32) – inverse variance of each band
mc (int) – if greater than 1, generate Monte Carlo of coefficients
- Returns:
coeffs (ndarray of np.float32) – coefficients for each template
coeffs_mc (ndarray of np.float32) – [ntemplates, mc] coefficients for each MC for each template
maggies_mc (ndarray of np.float32) – [nbands, mc] Monte Carlo maggies
Notes
maggies are assumed to be Galactic-extinction corrected already.
Calls this class’s to_ab() method on input maggies.
If redshift is an array, even with just one element, coeffs is returned as an [nredshift, ntemplate] array.
Otherwise coeffs is returned as an [ntemplate] array.
Occasionally the optimizer will report “NNLS quitting on iteration count.” This indicates that the default number of iterations for scipy.optimize.nnls was not enough. Under these conditions, this code tries a much larger number of iterations. If that still fails, you will receive a traceback.
- _reconstruct(Amatrix=None, redshift=None, coeffs=None, band_shift=0.0)[source]
Reconstruct maggies associated with coefficients
- Parameters:
Amatrix (scipy.interpolate.interp1d) – interpolator to use for Amatrix
redshift (np.float32) – redshift
coeffs (ndarray of np.float32) – coefficients
band_shift (np.float32) – blueshift to apply to reconstructed bandpasses
- Returns:
maggies – maggies in each band
- Return type:
ndarray of np.float32
Notes
Amatrix should be an interpolator over redshift that returns an array that is number of responses by number of templates.
- reconstruct(redshift=None, coeffs=None, band_shift=0.0)[source]
Reconstruct AB maggies associated with coefficients
- Parameters:
redshift (np.float32 or ndarray of np.float32) – redshift
coeffs (ndarray of np.float32) – coefficients
band_shift (np.float32) – blueshift to apply to reconstructed bandpasses
- Returns:
maggies – AB maggies in each band
- Return type:
ndarray of np.float32
Notes
Returns AB maggies, but note that if to_ab() is non-trivial, these may not be directly comparable to the input maggies.