Skip to content

Commit

Permalink
return kcorrect
Browse files Browse the repository at this point in the history
  • Loading branch information
Michael Blanton committed Jun 26, 2024
1 parent 3f807d5 commit dc1dc92
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 30 deletions.
7 changes: 6 additions & 1 deletion RELEASE_NOTES
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
-------------------------------------------------------------------------------
5.2.0
5.1.3

- Return kcorrect in kcorrect.kcorrect.Kcorrect.absmag() and absmag_mc()

-------------------------------------------------------------------------------
5.1.2

- Update LINCCC template
- Change absmag outputs to be -9999 when maggies<=0, instead of
Expand Down
81 changes: 52 additions & 29 deletions src/kcorrect/kcorrect.py
Original file line number Diff line number Diff line change
Expand Up @@ -463,7 +463,8 @@ def kcorrect(self, redshift=None, coeffs=None, band_shift=0.):
return(kcorrect)

def absmag(self, maggies=None, ivar=None, redshift=None, coeffs=None,
band_shift=0., distance=None, reconstruct=False, limit=False):
band_shift=0., distance=None, reconstruct=False, limit=False,
kcorrect=False):
"""Return absolute magnitude in output bands
Parameters
Expand Down Expand Up @@ -493,6 +494,9 @@ def absmag(self, maggies=None, ivar=None, redshift=None, coeffs=None,
limit : bool
if set, return absmag_limit
kcorrect : bool
if set, return kcorrect
Returns
-------
Expand All @@ -501,10 +505,12 @@ def absmag(self, maggies=None, ivar=None, redshift=None, coeffs=None,
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
kcorrect : ndarray of np.float32
[ngalaxy, nbands] K-corrections used (if kcorrect is True)
Notes
-----
Expand Down Expand Up @@ -596,16 +602,21 @@ def absmag(self, maggies=None, ivar=None, redshift=None, coeffs=None,
absmag_limit[gd] = lmags[gd] - dm - k[gd]
absmag_limit[bd] = - 9999.

if(reconstruct & limit):
return(absmag, absmag_reconstruct, absmag_limit)
return_list = [absmag]
if(reconstruct):
return(absmag, absmag_reconstruct)
return_list.append(absmag_reconstruct)
if(limit):
return(absmag, absmag_limit)
return(absmag)
return_list.append(absmag_limit)
if(kcorrect):
return_list.append(k)
if(len(return_list) == 1):
return(return_list[0])
else:
return(tuple(return_list))

def absmag_mc(self, maggies_mc=None, ivar=None, redshift=None,
coeffs_mc=None, band_shift=0., distance=None, reconstruct=False):
coeffs_mc=None, band_shift=0., distance=None, reconstruct=False,
kcorrect=False):
"""Return absolute magnitude in output bands for Monte Carlo results
Parameters
Expand All @@ -632,14 +643,20 @@ def absmag_mc(self, maggies_mc=None, ivar=None, redshift=None,
reconstruct : bool
if set, return absmag_reconstruct
kcorrect : bool
if set, return kcorrect
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)
[ngalaxy, nbands, mc] reconstructed AB absolute magnitude from SED fits (if reconstruct set)
kcorrect : ndarray of np.float32
[ngalaxy, nbands, mc] K-corrections used (if kcorrect is True)
Notes
-----
Expand All @@ -650,27 +667,33 @@ def absmag_mc(self, maggies_mc=None, ivar=None, redshift=None,
absmag_mc = np.zeros(maggies_mc.shape, dtype=np.float32)
if(reconstruct):
absmag_reconstruct_mc = np.zeros(maggies_mc.shape, dtype=np.float32)
for imc in np.arange(mc, dtype=np.int32):
tmp_absmag, tmp_absmag_reconstruct = self.absmag(redshift=redshift,
maggies=maggies_mc[..., imc],
ivar=ivar,
coeffs=coeffs_mc[..., imc],
band_shift=band_shift,
distance=distance,
reconstruct=reconstruct)
absmag_mc[..., imc] = tmp_absmag
absmag_reconstruct_mc[..., imc] = tmp_absmag_reconstruct
return(absmag_mc, absmag_reconstruct_mc)
if(kcorrect):
kcorrect_mc = np.zeros(maggies_mc.shape, dtype=np.float32)
for imc in np.arange(mc, dtype=np.int32):
out = self.absmag(redshift=redshift, maggies=maggies_mc[..., imc],
ivar=ivar, coeffs=coeffs_mc[..., imc], band_shift=band_shift,
distance=distance, reconstruct=reconstruct, kcorrect=kcorrect)
if((reconstruct is False) & (kcorrect is False)):
absmag_mc[..., imc] = out
else:
absmag_mc[..., imc] = out[0]
iout = 1
if(reconstruct):
absmag_reconstruct_mc[..., imc] = out[iout]
iout += 1
if(kcorrect):
kcorrect_mc[..., imc] = out[iout]
iout += 1

return_list = [absmag_mc]
if(reconstruct):
return_list.append(absmag_reconstruct_mc)
if(kcorrect):
return_list.append(kcorrect_mc)
if(len(return_list) == 1):
return(return_list[0])
else:
for imc in np.arange(mc, dtype=np.int32):
absmag_mc[..., imc] = self.absmag(redshift=redshift,
maggies=maggies_mc[..., imc],
ivar=ivar,
coeffs=coeffs_mc[..., imc],
band_shift=band_shift,
distance=distance,
reconstruct=reconstruct)
return(absmag_mc)
return(tuple(return_list))

raise RuntimeError("Should not reach this point")

Expand Down

0 comments on commit dc1dc92

Please sign in to comment.