Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

write out wave and flux extensions in truth.fits files #287

Merged
merged 2 commits into from
Mar 1, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions doc/changes.rst
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,18 @@ desitarget Change Log
0.19.1 (unreleased)
-------------------

* No changes yet.
* Fix bug whereby FLUX and WAVE weren't being written to truth.fits files [`PR
#287`_].

.. _`PR #287`: https://github.com/desihub/desitarget/pull/287

0.19.0 (2018-02-27)
-------------------

This release includes significant non-backwards compatible changes
to importing target mask bits and how mock spectra are generated.

* Major refactor of select_mock_targets code infrastructure[`PR #264`_].
* Major refactor of select_mock_targets code infrastructure [`PR #264`_].
* Restructure desi_mask, bgs_mask, etc. imports to fix readthedocs build
[`PR #282`_].
* Update RELEASE dictionary with 6000 (northern) for DR6 [`PR #281`_].
Expand Down
28 changes: 22 additions & 6 deletions py/desitarget/mock/build.py
Original file line number Diff line number Diff line change
Expand Up @@ -560,8 +560,8 @@ def targets_truth(params, healpixels=None, nside=None, output_dir='.',
nside, log, seed=healseed)

# Finally, write the results to disk.
write_targets_truth(targets, truth, skytargets, skytruth,
healpix, nside, log, output_dir,
write_targets_truth(targets, truth, trueflux, MakeMock.wave, skytargets,
skytruth, healpix, nside, log, output_dir,
seed=healseed)

def finish_catalog(targets, truth, skytargets, skytruth, healpix,
Expand Down Expand Up @@ -620,8 +620,9 @@ def finish_catalog(targets, truth, skytargets, skytruth, healpix,

return targets, truth, skytargets, skytruth

def write_targets_truth(targets, truth, skytargets, skytruth, healpix,
nside, log, output_dir, seed=None):
def write_targets_truth(targets, truth, trueflux, truewave, skytargets,
skytruth, healpix, nside, log, output_dir,
seed=None):
"""Writes all the final catalogs to disk.

Parameters
Expand All @@ -630,6 +631,10 @@ def write_targets_truth(targets, truth, skytargets, skytruth, healpix,
Final target catalog.
truth : :class:`astropy.table.Table`
Corresponding truth table for targets.
trueflux : :class:`numpy.ndarray`
Array [npixel, ntarget] of observed-frame spectra.
truewave : :class:`numpy.ndarray`
Wavelength array corresponding to trueflux.
skytargets : :class:`astropy.table.Table`
Sky targets.
skytruth : :class:`astropy.table.Table`
Expand Down Expand Up @@ -697,8 +702,8 @@ def write_targets_truth(targets, truth, skytargets, skytruth, healpix,
# Write out the dark- and bright-time standard stars.
for stdsuffix, stdbit in zip(('dark', 'bright'), ('STD_FSTAR', 'STD_BRIGHT')):
stdfile = mockio.findfile('standards-{}'.format(stdsuffix), nside, healpix, basedir=output_dir)
istd = (((targets['DESI_TARGET'] & desi_mask.mask(stdbit)) |
(targets['DESI_TARGET'] & desi_mask.mask('STD_WD')) ) != 0)
istd = ( (targets['DESI_TARGET'] & desi_mask.mask(stdbit)) |
(targets['DESI_TARGET'] & desi_mask.mask('STD_WD')) ) != 0

if np.count_nonzero(istd) > 0:
log.info('Writing {} {} standards to {}'.format(np.sum(istd), stdsuffix.upper(), stdfile))
Expand Down Expand Up @@ -726,6 +731,17 @@ def write_targets_truth(targets, truth, skytargets, skytruth, healpix,
hdu.header['EXTNAME'] = 'TRUTH'
hx.append(hdu)

if len(trueflux) > 0:
hdu = fits.ImageHDU(truewave.astype(np.float32),
name='WAVE', header=truthhdr)
hdu.header['BUNIT'] = 'Angstrom'
hdu.header['AIRORVAC'] = 'vac'
hx.append(hdu)

hdu = fits.ImageHDU(trueflux.astype(np.float32), name='FLUX')
hdu.header['BUNIT'] = '1e-17 erg/s/cm2/Angstrom'
hx.append(hdu)

try:
hx.writeto(truthfile+'.tmp', overwrite=True)
except:
Expand Down