Skip to content

Commit

Permalink
Option to turn off commissioning QSO cuts to speed unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
geordie666 committed Jul 21, 2019
1 parent 45d9f7d commit 9563188
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 30 deletions.
5 changes: 3 additions & 2 deletions doc/changes.rst
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,9 @@ desitarget Change Log
0.31.2 (unreleased)
-------------------

* Deprecate ``BRIGHTSTARINBLOB`` use ``MASKBITS`` instead [`PR #521`_].
* Extra options/care when making/vetting bundling scripts [`PR #521`_].
* Use ``MASKBITS`` instead of ``BRIGHTSTARINBLOB`` [`PR #521`_]. Also:
* Extra options and checks when making and vetting bundling scripts.
* Option to turn off commissioning QSO cuts to speed unit tests.
* Add ELG/LRG/QSO/STD selection cuts for commissioning [`PR #519`_].
* Add full set of columns to supplemental skies file [`PR #518`_].
* Fix some corner cases when reading HEALPixel-split files [`PR #518`_].
Expand Down
47 changes: 29 additions & 18 deletions py/desitarget/cmx/cmx_cuts.py
Original file line number Diff line number Diff line change
Expand Up @@ -989,24 +989,27 @@ def isSTD_calspec(ra=None, dec=None, cmxdir=None, matchrad=1.,
return iscalspec


def apply_cuts(objects, cmxdir=None):
"""Perform commissioning (cmx) target selection on objects, return target mask arrays
def apply_cuts(objects, cmxdir=None, noqso=False):
"""Commissioning (cmx) target selection, return target mask arrays.
Parameters
----------
objects: numpy structured array with UPPERCASE columns needed for
target selection, OR a string tractor/sweep filename
cmxdir : :class:`str`, optional, defaults to :envvar:`CMX_DIR`
Directory in which to find commmissioning files to which to match, such as the
CALSPEC stars. If not specified, the cmx directory is taken to be the value of
the :envvar:`CMX_DIR` environment variable.
Directory to find commmissioning files to which to match, such
as the CALSPEC stars. If not specified, the cmx directory is
taken to be the value of :envvar:`CMX_DIR`.
noqso : :class:`boolean`, optional, defaults to ``False``
If passed, do not run the quasar selection. All QSO bits will be
set to zero. Intended use is to speed unit tests.
Returns
-------
:class:`~numpy.ndarray`
commissioning target selection bitmask flags for each object
commissioning target selection bitmask flags for each object.
See desitarget.cmx.cmx_targetmask.cmx_mask for the definition of each bit
See desitarget.cmx.cmx_targetmask.cmx_mask for bit definitions.
"""
# -Check if objects is a filename instead of the actual data
if isinstance(objects, str):
Expand Down Expand Up @@ -1132,11 +1135,15 @@ def apply_cuts(objects, cmxdir=None):
)

# ADM determine if an object is SV0_QSO.
sv0_qso = isSV0_QSO(
primary=primary, zflux=zflux, rflux=rflux, gflux=gflux,
w1flux=w1flux, w2flux=w2flux, objtype=objtype,
dchisq=dchisq, maskbits=maskbits
)
if noqso:
# ADM don't run quasar cuts if requested, for speed.
sv0_qso = ~primary
else:
sv0_qso = isSV0_QSO(
primary=primary, zflux=zflux, rflux=rflux, gflux=gflux,
w1flux=w1flux, w2flux=w2flux, objtype=objtype,
dchisq=dchisq, maskbits=maskbits
)

# ADM run the STD target types for both faint and bright.
# ADM Make sure to pass all of the needed columns! At one point we stopped
Expand Down Expand Up @@ -1177,19 +1184,22 @@ def apply_cuts(objects, cmxdir=None):
return cmx_target, priority_shift


def select_targets(infiles, numproc=4, cmxdir=None):
def select_targets(infiles, numproc=4, cmxdir=None, noqso=False):
"""Process input files in parallel to select commissioning (cmx) targets
Parameters
----------
infiles : :class:`list` or `str`
A list of input filenames (tractor or sweep files) OR a single filename.
List of input filenames (tractor/sweep files) OR one filename.
numproc : :class:`int`, optional, defaults to 4
The number of parallel processes to use.
cmxdir : :class:`str`, optional, defaults to :envvar:`CMX_DIR`
Directory in which to find commmissioning files to which to match, such as the
CALSPEC stars. If not specified, the cmx directory is taken to be the value of
the :envvar:`CMX_DIR` environment variable.
Directory to find commmissioning files to which to match, such
as the CALSPEC stars. If not specified, the cmx directory is
taken to be the value of :envvar:`CMX_DIR`.
noqso : :class:`boolean`, optional, defaults to ``False``
If passed, do not run the quasar selection. All QSO bits will be
set to zero. Intended use is to speed unit tests.
Returns
-------
Expand Down Expand Up @@ -1238,7 +1248,8 @@ def _finalize_targets(objects, cmx_target, priority_shift):
def _select_targets_file(filename):
'''Returns targets in filename that pass the cuts'''
objects = io.read_tractor(filename)
cmx_target, priority_shift = apply_cuts(objects, cmxdir=cmxdir)
cmx_target, priority_shift = apply_cuts(objects,
cmxdir=cmxdir, noqso=noqso)

return _finalize_targets(objects, cmx_target, priority_shift)

Expand Down
24 changes: 14 additions & 10 deletions py/desitarget/test/test_cmx.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,21 +29,23 @@ def setUpClass(cls):
def test_cuts_basic(self):
"""Test cuts work with either data or filenames
"""
# ADM test for tractor files
# ADM test for tractor files.
# ADM No QSO cuts for speed. This doesn't affect coverage.
cmx, pshift = cuts.apply_cuts(self.tractorfiles[0],
cmxdir=self.cmxdir)
cmxdir=self.cmxdir, noqso=True)
data = io.read_tractor(self.tractorfiles[0])
cmx2, pshift2 = cuts.apply_cuts(data,
cmxdir=self.cmxdir)
cmxdir=self.cmxdir, noqso=True)
self.assertTrue(np.all(cmx == cmx2))
self.assertTrue(np.all(pshift == pshift2))

# ADM test for sweeps files
# ADM test for sweeps files.
# ADM No QSO cuts for speed. This doesn't affect coverage.
cmx, pshift = cuts.apply_cuts(self.sweepfiles[0],
cmxdir=self.cmxdir)
cmxdir=self.cmxdir, noqso=True)
data = io.read_tractor(self.sweepfiles[0])
cmx2, pshift2 = cuts.apply_cuts(data,
cmxdir=self.cmxdir)
cmxdir=self.cmxdir, noqso=True)
self.assertTrue(np.all(cmx == cmx2))
self.assertTrue(np.all(pshift == pshift2))

Expand Down Expand Up @@ -85,12 +87,13 @@ def test_select_targets(self):
"""Test select targets works with either data or filenames
"""
for filelist in [self.tractorfiles, self.sweepfiles]:
# ADM No QSO cuts for speed. This doesn't affect coverage.
targets = cuts.select_targets(filelist, numproc=1,
cmxdir=self.cmxdir)
cmxdir=self.cmxdir, noqso=True)
t1 = cuts.select_targets(filelist[0:1], numproc=1,
cmxdir=self.cmxdir)
cmxdir=self.cmxdir, noqso=True)
t2 = cuts.select_targets(filelist[0], numproc=1,
cmxdir=self.cmxdir)
cmxdir=self.cmxdir, noqso=True)
for col in t1.dtype.names:
try:
notNaN = ~np.isnan(t1[col])
Expand All @@ -110,8 +113,9 @@ def test_parallel_select(self):
"""
for nproc in [1, 2]:
for filelist in [self.tractorfiles, self.sweepfiles]:
# ADM No QSO cuts for speed. Doesn't affect coverage.
targets = cuts.select_targets(filelist, numproc=nproc,
cmxdir=self.cmxdir)
cmxdir=self.cmxdir, noqso=True)
self.assertTrue('CMX_TARGET' in targets.dtype.names)
self.assertEqual(len(targets), np.count_nonzero(targets['CMX_TARGET']))

Expand Down

0 comments on commit 9563188

Please sign in to comment.