Skip to content

Commit

Permalink
Merge 66d4a71 into dc07802
Browse files Browse the repository at this point in the history
  • Loading branch information
sbailey committed Feb 27, 2019
2 parents dc07802 + 66d4a71 commit 30a39db
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 11 deletions.
16 changes: 6 additions & 10 deletions py/desitarget/mock/build.py
Expand Up @@ -935,7 +935,7 @@ def targets_truth(params, healpixels=None, nside=None, output_dir='.',
seed=healseed)

def finish_catalog(targets, truth, objtruth, skytargets, skytruth, healpix,
nside, log, seed=None, survey='main'):
nside, log, seed=None):
"""Add hpxpixel, brick_objid, targetid, subpriority, priority, and numobs to the
target catalog.
Expand All @@ -959,11 +959,7 @@ def finish_catalog(targets, truth, objtruth, skytargets, skytruth, healpix,
Logger object.
seed : :class:`int`, optional
Seed for the random number generation. Defaults to None.
survey : :class:`str`
Specifies which target masks yaml file to use. Options are `main`, `cmx`
and `sv` for the main survey, commissioning and SV, respectively.
Defaults to `main`.
Returns
-------
Updated versions of targets, truth, objtruth, skytargets, and skytruth.
Expand Down Expand Up @@ -1013,8 +1009,8 @@ def finish_catalog(targets, truth, objtruth, skytargets, skytruth, healpix,
log.warning('Mismatching TARGETIDs!')
raise ValueError

targets['PRIORITY_INIT'], targets['NUMOBS_INIT'] = initial_priority_numobs(
targets, survey=survey)
targets['PRIORITY_INIT'], targets['NUMOBS_INIT'] = \
initial_priority_numobs(targets)

# Rename TYPE --> MORPHTYPE
targets.rename_column('TYPE', 'MORPHTYPE')
Expand All @@ -1028,8 +1024,8 @@ def finish_catalog(targets, truth, objtruth, skytargets, skytruth, healpix,
skytargets['SUBPRIORITY'][:] = subpriority[nobj:]
skytruth['TARGETID'][:] = targetid[nobj:]

skytargets['PRIORITY_INIT'], skytargets['NUMOBS_INIT'] = initial_priority_numobs(
skytargets, survey=survey)
skytargets['PRIORITY_INIT'], skytargets['NUMOBS_INIT'] = \
initial_priority_numobs(skytargets)

# Rename TYPE --> MORPHTYPE
skytargets.rename_column('TYPE', 'MORPHTYPE')
Expand Down
49 changes: 48 additions & 1 deletion py/desitarget/test/test_mock_build.py
Expand Up @@ -3,19 +3,66 @@
"""Test desitarget.mock.build, but only add_mock_shapes_and_fluxes for now.
"""
import unittest
import tempfile
import os
import shutil
from pkg_resources import resource_filename
import numpy as np
from astropy.table import Table
import healpy as hp
import fitsio

import desimodel.footprint

from desitarget.mock.sky import random_sky
from desitarget.mock.build import targets_truth
from desitarget.targetmask import desi_mask, bgs_mask, mws_mask

class TestMockBuild(unittest.TestCase):

def setUp(self):
pass
self.outdir = tempfile.mkdtemp()

def tearDown(self):
if os.path.exists(self.outdir):
shutil.rmtree(self.outdir)

@unittest.skipUnless('DESITARGET_RUN_MOCK_UNITTEST' in os.environ, '$DESITARGET_RUN_MOCK_UNITTEST not set; skipping expensive mock tests')
def test_targets_truth(self):
configfile = resource_filename('desitarget.mock', 'data/select-mock-targets.yaml')

import yaml
with open(configfile) as fx:
params = yaml.load(fx)

for targettype in params['targets'].keys():
mockfile = params['targets'][targettype]['mockfile'].format(**os.environ)
self.assertTrue(os.path.exists(mockfile), 'Missing {}'.format(mockfile))

#- Test without spectra
targets_truth(params, healpixels=[99737,], nside=256, output_dir=self.outdir, no_spectra=True)
targetfile = self.outdir + '/997/99737/targets-256-99737.fits'
truthfile = self.outdir + '/997/99737/truth-256-99737.fits'
self.assertTrue(os.path.exists(targetfile))
self.assertTrue(os.path.exists(truthfile))

with fitsio.FITS(truthfile) as fx:
self.assertTrue('TRUTH' in fx)
#- WAVE is there, and FLUX is there but with strange shape (n,0)
# self.assertTrue('WAVE' not in fx)
# self.assertTrue('FLUX' not in fx)

#- Test with spectra
shutil.rmtree(self.outdir+'/997')

targets_truth(params, healpixels=[99737,], nside=256, output_dir=self.outdir, no_spectra=False)
self.assertTrue(os.path.exists(targetfile))
self.assertTrue(os.path.exists(truthfile))

with fitsio.FITS(truthfile) as fx:
self.assertTrue('TRUTH' in fx)
self.assertTrue('WAVE' in fx)
self.assertTrue('FLUX' in fx)

@unittest.skip('This test is deprecated, so skip for now.')
def test_shapes_and_fluxes(self):
Expand Down

0 comments on commit 30a39db

Please sign in to comment.