kcorrect.kcorrect
Module Contents
Classes
K-correction object |
|
K-correction object for SDSS data |
|
K-correction object for GALEX, SDSS, 2MASS data |
- class Kcorrect(filename=None, responses=None, templates=None, responses_out=None, responses_map=None, redshift_range=[0.0, 2.0], nredshift=4000, abcorrect=False, cosmo=None)[source]
Bases:
kcorrect.fitter.FitterK-correction object
- Parameters:
abcorrect (bool) – correct maggies to AB (default False)
filename (str) – input file to define kcorrect object (overrides responses, responses_out, responses_map, templates, redshift_range, nredshift, abcorrect)
responses (list of str) – names of input responses to base SED on
templates (list of kcorrect.template.SED) – templates to use (if None uses v4 default template set)
responses_out (list of str) – output responses for K-corrections (default to “responses”)
responses_map (list of str) – input responses to use for K-corrections (default to “responses”)
redshift_range (list of np.float32) – minimum and maximum redshifts (default [0., 2.])
nredshift (int or np.int32) – number of redshifts in interpolation grid (default 4000)
cosmo (astropy.cosmology.FLRW-like object) – object with distmod() method (default Planck18)
- abcorrect
correct maggies to AB
- Type:
bool
- Amatrix
interpolation function for each template and input response
- Type:
scipy.interpolate.interp1d object
- AmatrixOut
interpolation function for each template and output response
- Type:
scipy.interpolate.interp1d object
- cosmo
object with luminosity_distance() method
- Type:
astropy.cosmology.FLRW-like object
- imap
for each responses_map element, its corresponding index in responses
- Type:
ndarray of np.int32
- nredshift
number of redshifts in interpolation grid
- Type:
int or np.int32
- redshift_range
minimum and maximum redshifts
- Type:
list of np.float32
- redshifts
redshifts in grid
- Type:
ndarray of np.float32
- responses
[Nin] names of input responses to use
- Type:
list of str
- responses_map
[Nout] input responses to use for K-corrections
- Type:
list of str
- responses_out
[Nout] output responses for K-corrections
- Type:
list of str
- templates
templates to use
- Type:
kcorrect.template.Template object
Notes
K-corrections are magnitude shifts to account for the difference in the observed bandpass R and a desired output bandpass Q, denoted K_QR (see Blanton & Roweis 2007). The default behavior finds the K-corrections between each input bandpass with itself, i.e. K_QQ.
In detail:
“responses” corresponds to the observed bandpasses R.
“responses_out” corresponds to the observed bandpasses Q; it defaults to “responses”.
“responses_map” is the same length as “responses_out” and defines which bandpasses in “responses” to use for each output bandpass in “responses_out”. It defaults to “responses”.
Amatrix accepts a redshift as its argument and returns a matrix of shape [nresponses, ntemplates]. This matrix can be dotted into a set of coefficients for each template, and the result will be the observed bandpass maggies at the desired redshift for an SED corresponding to the coefficients. A ValueError results if the input redshift is outside redshift_range.
AmatrixOut is similar but returns a [nresponses_out, ntemplates] matrix for the output bandpasses.
Once defined, a Kcorrect object can be output to a FITS file with the method tofits(), and reimported with fromfits(). The filename parameter expects this format.
- derived(redshift=None, coeffs=None, band_shift=0.0, distance=None)[source]
Return derived quantities based on coefficients
- Parameters:
redshift (ndarray of np.float32, or np.float32) – [ngalaxy] redshift
coeffs (ndarray of np.float32) – [ngalaxy, ntemplates] coefficients for each template for each object
band_shift (np.float32) – band shift to apply for output response
distance (ndarray of np.float32 or np.float32) – [ngalaxy] luminosity distance in Mpc
- Returns:
derived – dictionary with derived quantities (see below)
- Return type:
dict()
Notes
If distance is not specified, then it is derived from the redshift assuming the cosmology in the cosmo attribute.
The derived dictionary contains the following keys with the associated quantities:
- ‘mremain’ndarray of np.float32, or np.float32
[ngalaxy] current stellar mass in solar masses
- ‘intsfh’ndarray of np.float32, or np.float32
[ngalaxy] current stellar mass in solar masses
- ‘mtol’ndarray of np.float32, or np.float32
[ngalaxy] mass-to-light ratio in each output band
- ‘b50’ndarray of np.float32, or np.float32
[ngalaxy] current (< 50 Myr) over past star formation
- ‘b300’ndarray of np.float32, or np.float32
[ngalaxy] current (< 300 Myr) over past star formation
- ‘b1000’ndarray of np.float32, or np.float32
[ngalaxy] current (< 1 Gyr) over past star formation
- ‘metallicity’ :
[ngalaxy] metallicity in current stars
All of these quantities should be taken with extreme caution and not accepted literally. After all, they are just the result of a template fit to a few bandpasses.
For the default template set, see Moustakas et al. (2013) for a comparison of the masses with other estimators.
For responses where solar_magnitude is not defined, mtol is in per maggy units (not per solar luminosity)
- derived_mc(redshift=None, coeffs_mc=None, band_shift=0.0, distance=None)[source]
Return derived quantities based on coefficients
- Parameters:
redshift (ndarray of np.float32, or np.float32) – [ngalaxy] redshift
coeffs_mc (ndarray of np.float32) – [ngalaxy, ntemplates, mc] coefficients for each template for each object
band_shift (np.float32) – band shift to apply for output response
distance (ndarray of np.float32 or np.float32) – [ngalaxy] luminosity distance in Mpc
- Returns:
derived – dictionary with derived quantities (see below)
- Return type:
dict()
Notes
Relies on repeated calls to the kcorrect.kcorrect.Kcorrect.derived() method.
The derived dictionary contains the following keys with the associated quantities:
- ‘mremain’ndarray of np.float32, or np.float32
[ngalaxy, mc] current stellar mass in solar masses
- ‘intsfh’ndarray of np.float32, or np.float32
[ngalaxy, mc] current stellar mass in solar masses
- ‘mtol’ndarray of np.float32, or np.float32
[ngalaxy, mc] mass-to-light ratio in each output band
- ‘b50’ndarray of np.float32, or np.float32
[ngalaxy] current (< 50 Myr) over past star formation
- ‘b300’ndarray of np.float32, or np.float32
[ngalaxy, mc] current (< 300 Myr) over past star formation
- ‘b1000’ndarray of np.float32, or np.float32
[ngalaxy, mc] current (< 1 Gyr) over past star formation
- ‘metallicity’ :
[ngalaxy, mc] metallicity in current stars
- reconstruct_out(redshift=None, coeffs=None, band_shift=0.0)[source]
Reconstruct output maggies associated with coefficients
- Parameters:
redshift (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 output band
- Return type:
ndarray of np.float32
- kcorrect(redshift=None, coeffs=None, band_shift=0.0)[source]
Return K-correction in all bands
- Parameters:
redshift (ndarray of np.float32, or np.float32) – redshift for K-correction
coeffs (ndarray of np.float32) – coefficients for each template for each object
band_shift (np.float32) – shift to apply for output responses
- Returns:
kcorrect – K-correction from input to output magnitudes
- Return type:
ndarray of np.float32
- absmag(maggies=None, ivar=None, redshift=None, coeffs=None, band_shift=0.0, distance=None, reconstruct=False, limit=False)[source]
Return absolute magnitude in output bands
- Parameters:
redshift (ndarray of np.float32, or np.float32) – [ngalaxy] redshift(s) for K-correction
maggies (ndarray of np.float32) – [ngalaxy, nbands] fluxes of each band in maggies
ivar (ndarray of np.float32) – [ngalaxy, nbands] inverse variance of each band
coeffs (ndarray of np.float32) – [ngalaxy, ntemplates] coefficients for each template for each object
band_shift (np.float32) – shift to apply for output responses
distance (ndarray of np.float32 or np.float32) – [ngalaxy] distance in Mpc (or None)
reconstruct (bool) – if set, return absmag_reconstruct
limit (bool) – if set, return absmag_limit
- Returns:
absmag (ndarray of np.float32) – [ngalaxy, nbands] AB absolute magnitude in each band for each object
absmag_reconstruct (ndarray of np.float32) – [ngalaxy, nbands] reconstructed AB absolute magnitude from SED fit (if reconstruct set)
absmag_limit (ndarray of np.float32) – [ngalaxy, nbands] 1-sigma bright limit on absolute mag from error
Notes
If distance is None, the distance is derived from the redshift using the cosmo attribute.
Depends on having run fit_coeffs on a consistent set of maggies and ivars.
Determines the distance modulus with the object’s “cosmo.distmod()” method. By default this is the Planck18 cosmology.
Returns the K-corrected absolute magnitude (or -9999 if there ivar=0, magggies are negative, or there is no valid value)
The “reconstructed” absolute magnitude is calculated from the kcorrect nonnegative fit instead of being a K-correction of the data. These values are -9999 if there is no valid value (usually meaning all of the coefficients input are zero).
The absolute magnitude “limit” is set to the 1-sigma limit from the error in each band (using the K-correction from the real fit). It is returned for every object with ivar != 0 and positive coefficients, and is -9999 otherwise.
If abcorrect is True, calls to_ab() method on input maggies to convert to AB.
- absmag_mc(maggies_mc=None, ivar=None, redshift=None, coeffs_mc=None, band_shift=0.0, distance=None, reconstruct=False)[source]
Return absolute magnitude in output bands for Monte Carlo results
- Parameters:
redshift (ndarray of np.float32, or np.float32) – [ngalaxy] redshift(s) for K-correction
maggies_mc (ndarray of np.float32) – [ngalaxy, nbands, mc] fluxes of each band in maggies
ivar (ndarray of np.float32) – [ngalaxy, nbands] inverse variance of each band
coeffs_mc (ndarray of np.float32) – [ngalaxy, ntemplates, mc] coefficients for each template for each object
band_shift (np.float32) – shift to apply for output responses
distance (ndarray of np.float32 or np.float32) – [ngalaxy] distance in Mpc (or None)
reconstruct (bool) – if set, return absmag_reconstruct
- Returns:
absmag (ndarray of np.float32) – [ngalaxy, nbands, mc] AB absolute magnitude in each band for each object
absmag_reconstruct (ndarray of np.float32) – [ngalaxy, nbands] reconstructed AB absolute magnitude from SED fits (if reconstruct set)
Notes
Relies on multiple calls to kcorrect.kcorrect.Kcorrect.absmag() method.
- tofits(filename=None)[source]
Output calculated information to FITS
- Parameters:
filename (str) – name of output file
Notes
Overwrites file if it already exists.
Stores HDUs:
DATA : single row table with: ‘nredshift’, ‘redshift_range’, ‘abcorrect’
REDSHIFTS : redshift grid
RESPONSES : array of input response names
RESPONSES_OUT : array of output response names
RESPONSES_MAP : array of response mapping
A : A-matrix data
AOUT : A-matrix output data
- class KcorrectSDSS(responses=['sdss_u0', 'sdss_g0', 'sdss_r0', 'sdss_i0', 'sdss_z0'], templates=None, responses_out=None, responses_map=None, redshift_range=[0.0, 2.0], nredshift=4000, abcorrect=True, cosmo=None)[source]
Bases:
KcorrectK-correction object for SDSS data
- Parameters:
abcorrect (bool) – correct maggies to AB (default True)
templates (list of kcorrect.template.SED) – templates to use (if None uses v4 default template set)
responses (list of str) – names of input responses to base SED on (default to SDSS ugriz)
responses_out (list of str) – output responses for K-corrections (default to “responses”)
responses_map (list of str) – input responses to use for K-corrections (default to “responses”)
redshift_range (list of np.float32) – minimum and maximum redshifts (default [0., 2.])
nredshift (int or np.int32) – number of redshifts in interpolation grid (default 4000)
cosmo (astropy.cosmology.FLRW-like object) – object with distmod() method (default Planck18)
- abcorrect
correct maggies to AB
- Type:
bool
- Amatrix
interpolation function for each template and input response
- Type:
scipy.interpolate.interp1d object
- AmatrixOut
interpolation function for each template and output response
- Type:
scipy.interpolate.interp1d object
- cosmo
object with luminosity_distance() method
- Type:
astropy.cosmology.FLRW-like object
- imap
for each responses_map element, its corresponding index in responses
- Type:
ndarray of np.int32
- nredshift
number of redshifts in interpolation grid
- Type:
int or np.int32
- redshift_range
minimum and maximum redshifts
- Type:
list of np.float32
- redshifts
redshifts in grid
- Type:
ndarray of np.float32
- responses
[Nin] names of input responses to use
- Type:
list of str
- responses_map
[Nout] input responses to use for K-corrections
- Type:
list of str
- responses_out
[Nout] output responses for K-corrections
- Type:
list of str
- templates
templates to use
- Type:
kcorrect.template.Template object
Notes
The ‘responses’ input defaults to [‘sdss_u0’, ‘sdss_g0’, ‘sdss_r0’, ‘sdss_i0’, ‘sdss_z0’]
This class provides the method fit_coeffs_asinh() to use SDSS-style asinh magnitudes (these are the magnitudes that the SDSS imaging reports).
If abcorrect is True, the to_ab() method is applied to the maggies input for absmag() and fit_coeffs() and fit_coeffs_asinh(), which adjusts from the SDSS system to the AB system.
- 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
Calls kcorrect.utils.sdss_ab_correct(), which does the following:
Uses the AB conversions produced by D. Eisenstein, in his message sdss-calib/1152
u(AB,2.5m) = u(database, 2.5m) - 0.036 g(AB,2.5m) = g(database, 2.5m) + 0.012 r(AB,2.5m) = r(database, 2.5m) + 0.010 i(AB,2.5m) = i(database, 2.5m) + 0.028 z(AB,2.5m) = z(database, 2.5m) + 0.040
fit_coeffs() and absmag() call this on their inputs if abcorrect is True.
- fit_coeffs_asinh(redshift=None, mag=None, mag_err=None, extinction=None)[source]
Fit coefficients to asinh mags
- Parameters:
redshift (np.float32 or ndarray of np.float32) – [N] or scalar redshift(s)
mag (ndarray of np.float32) – [N, 5] or [5] asinh magnitudes of each SDSS band
mag_err (ndarray of np.float32) – [N, 5] or [5] inverse variance of each band
extinction (ndarray of np.float32) – [N, 5] or [5] Galactic extinction in each band
- Returns:
coeffs – coefficients for each template
- Return type:
ndarray of np.float32
Notes
Converts mag, mag_err, and extinction to extinction-corrected maggies and ivar, and then (if abcorrect is True) calls to_ab() method to create AB maggies and ivar.
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.
- class KcorrectGST(responses=['galex_FUV', 'galex_NUV', 'sdss_u0', 'sdss_g0', 'sdss_r0', 'sdss_i0', 'sdss_z0', 'twomass_J', 'twomass_H', 'twomass_Ks'], templates=None, responses_out=None, responses_map=None, redshift_range=[0.0, 2.0], nredshift=4000, abcorrect=False, cosmo=None)[source]
Bases:
KcorrectK-correction object for GALEX, SDSS, 2MASS data
- Parameters:
abcorrect (bool) – correct maggies to AB (default True)
templates (list of kcorrect.template.SED) – templates to use (if None uses v4 default template set)
responses (list of str) – names of input responses to base SED on (default to FNugrizJHK)
responses_out (list of str) – output responses for K-corrections (default to “responses”)
responses_map (list of str) – input responses to use for K-corrections (default to “responses”)
redshift_range (list of np.float32) – minimum and maximum redshifts (default [0., 2.])
nredshift (int or np.int32) – number of redshifts in interpolation grid (default 4000)
cosmo (astropy.cosmology.FLRW-like object) – object with distmod() method (default Planck18)
- abcorrect
correct maggies to AB
- Type:
bool
- Amatrix
interpolation function for each template and input response
- Type:
scipy.interpolate.interp1d object
- AmatrixOut
interpolation function for each template and output response
- Type:
scipy.interpolate.interp1d object
- cosmo
object with luminosity_distance() method
- Type:
astropy.cosmology.FLRW-like object
- imap
for each responses_map element, its corresponding index in responses
- Type:
ndarray of np.int32
- nredshift
number of redshifts in interpolation grid
- Type:
int or np.int32
- redshift_range
minimum and maximum redshifts
- Type:
list of np.float32
- redshifts
redshifts in grid
- Type:
ndarray of np.float32
- responses
[Nin] names of input responses to use
- Type:
list of str
- responses_map
[Nout] input responses to use for K-corrections
- Type:
list of str
- responses_out
[Nout] output responses for K-corrections
- Type:
list of str
- templates
templates to use
- Type:
kcorrect.template.Template object
Notes
The ‘responses’ input defaults to [‘galex_FUV’, ‘galex_NUV’, ‘sdss_u0’, ‘sdss_g0’, ‘sdss_r0’, ‘sdss_i0’, ‘sdss_z0’, ‘twomass_J’, ‘twomass_H’, ‘twomass_Ks’]
abcorrect is by default False and the input maggies are assumed to be AB. If abcorrect is set to True, the to_ab() method is applied to the maggies input for absmag() and fit_coeffs() and fit_coeffs_asinh(), which adjusts from the SDSS system to the AB system. However, there is no change applied to the 2MASS or or GALEX inputs.
- to_ab(maggies=None, ivar=None)[source]
Convert FNugrizJHK 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
Leaves FN and JHK alone, and fixes ugriz with kcorrect.utils.sdss_ab_correct(), which does the following:
Uses the AB conversions produced by D. Eisenstein, in his message sdss-calib/1152
u(AB,2.5m) = u(database, 2.5m) - 0.036 g(AB,2.5m) = g(database, 2.5m) + 0.012 r(AB,2.5m) = r(database, 2.5m) + 0.010 i(AB,2.5m) = i(database, 2.5m) + 0.028 z(AB,2.5m) = z(database, 2.5m) + 0.040
fit_coeffs() and absmag() call this on their inputs if abcorrect is True.