Skip to content

Commit

Permalink
Merge c1f8de5 into e5af080
Browse files Browse the repository at this point in the history
  • Loading branch information
geordie666 committed Aug 15, 2018
2 parents e5af080 + c1f8de5 commit b480a1a
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 44 deletions.
6 changes: 4 additions & 2 deletions doc/changes.rst
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ desitarget Change Log
0.23.1 (unreleased)
-------------------

* Set ``NUMOBS`` for LRGs in MTL using target bits instead of magnitude [`PR #345`_].
* Update GFA targets [`PR #342`_]:
* Handle reading Gaia from sweeps as well as matching. Default to *not* matching.
* Makes Gaia matching radius stricter to return only the best Gaia objects.
Expand All @@ -13,16 +14,17 @@ desitarget Change Log
* Add Gaia epoch to the GFA file header (still needs passed from the sweeps).

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

0.23.0 (2018-08-09)
-------------------

Includes non-backwards compatible changes to standard star bit names.

* STD/STD_FSTAR -> STD_FAINT, with corresponding fixes for mocks [`PR #341`_].
* Match sweeps to Gaia and write new sweeps with Gaia columns [`PR #340`_]:
* Also add BRIGHTSTARINBLOB (if available) to target output files.
* Also add ``BRIGHTSTARINBLOB`` (if available) to target output files.
* And include a flag to call STD star cuts function without Gaia columns.
* STD/STD_FSTAR -> STD_FAINT, with corresponding fixes for mocks [`PR #341`_].

.. _`PR #340`: https://github.com/desihub/desitarget/pull/340
.. _`PR #341`: https://github.com/desihub/desitarget/pull/341
Expand Down
42 changes: 23 additions & 19 deletions py/desitarget/targets.py
Original file line number Diff line number Diff line change
Expand Up @@ -420,18 +420,20 @@ def calc_numobs(targets):
Args:
targets: numpy structured array or astropy Table of targets, including
columns DESI_TARGET, DECAM_FLUX, and DECAM_MW_TRANSMISSION
columns `DESI_TARGET`, `BGS_TARGET` or `MWS_TARGET`
Returns:
array of integers of requested number of observations
Notes:
if ZFLUX or (DECAM_FLUX and DECAM_MW_TRANSMISSION) are in targets,
then LRG numobs depends upon zmag, else defaults to 2
This is NUMOBS desired before any spectroscopic observations; i.e.
This is `NUMOBS` desired before any spectroscopic observations; i.e.
it does *not* take redshift into consideration (which is relevant
for interpreting low-z vs high-z QSOs)
"""
#ADM set up the default logger
from desiutil.log import get_logger
log = get_logger()

# Default is one observation
nobs = np.ones(len(targets), dtype='i4')

Expand All @@ -449,24 +451,26 @@ def calc_numobs(targets):
if n_no_target_class > 0:
raise ValueError('WARNING: {:d} rows in targets.calc_numobs have no target class'.format(n_no_target_class))

#- LRGs get 1, 2, or 3 observations depending upon magnitude
zflux = None
if 'ZFLUX' in targets.dtype.names:
zflux = targets['ZFLUX']
elif 'DECAM_FLUX' in targets.dtype.names:
if 'DECAM_MW_TRANSMISSION' in targets.dtype.names:
zflux = targets['DECAM_FLUX'][:,4] / targets['DECAM_MW_TRANSMISSION'][:,4]
else:
zflux = targets['DECAM_FLUX'][:,4]

#- LRGs get 1, 2, or (perhaps) 3 observations depending upon magnitude
#ADM set this using the LRG_1PASS/2PASS and maybe even 3PASS bits
islrg = (targets['DESI_TARGET'] & desi_mask.LRG) != 0
if zflux is not None:
lrg2 = islrg & (zflux < 10**((22.5-20.36)/2.5))
lrg3 = islrg & (zflux < 10**((22.5-20.56)/2.5))
#ADM default to 2 passes for LRGs
nobs[islrg] = 2
#ADM for redundancy in case the defaults change, explicitly set
#ADM NOBS for 1PASS and 2PASS LRGs
try:
lrg1 = (targets['DESI_TARGET'] & desi_mask.LRG_1PASS) != 0
lrg2 = (targets['DESI_TARGET'] & desi_mask.LRG_2PASS) != 0
nobs[lrg1] = 1
nobs[lrg2] = 2
except AttributeError:
log.error('per-pass LRG bits not set in {}'.format(desi_mask))
#ADM also reserve a setting for LRG_3PASS, but fail gracefully for now
try:
lrg3 = (targets['DESI_TARGET'] & desi_mask.LRG_3PASS) != 0
nobs[lrg3] = 3
else:
nobs[islrg] = 2
except AttributeError:
pass

#- TBD: flag QSOs for 4 obs ahead of time, or only after confirming
#- that they are redshift>2.15 (i.e. good for Lyman-alpha)?
Expand Down
34 changes: 11 additions & 23 deletions py/desitarget/test/test_numobs.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,8 @@ def setUp(self):
('BGS_TARGET',np.int64),
('MWS_TARGET',np.int64),
('NUMOBS',np.int32),
('DECAM_FLUX', '>f4', (6,)),
('DECAM_MW_TRANSMISSION', '>f4', (6,)),
]
self.targets = np.zeros(5, dtype=dtype)
self.targets['DECAM_MW_TRANSMISSION'] = 1.0
self.targets['DECAM_FLUX'][:,4] = 10**((22.5-np.linspace(20, 21, 5))/2.5)

def test_numobs(self):
t = self.targets
Expand All @@ -27,38 +23,30 @@ def test_numobs(self):
with self.assertRaises(ValueError):
calc_numobs(t)

#- ELGs and QSOs get one observation
#- ELGs and QSOs get one/four observations
t['DESI_TARGET'] = desi_mask.ELG
self.assertTrue(np.all(calc_numobs(t) == 1))
t['DESI_TARGET'] = desi_mask.QSO
self.assertTrue(np.all(calc_numobs(t) == 4))

#- LRG numobs depends upon zflux (DECAM_FLUX index 4)
t['DESI_TARGET'] = desi_mask.LRG
#ADM LRG NUMOBS is defined using per-pass target bits
#ADM the desi_mask.LRG reference tests the default, which
#ADM should correspond to 2 observations
t['DESI_TARGET'] = [desi_mask.LRG,
desi_mask.LRG_1PASS, desi_mask.LRG_2PASS,
desi_mask.LRG_1PASS, desi_mask.LRG_2PASS]
nobs = calc_numobs(t)
self.assertTrue(np.all(nobs == [1, 1, 2, 3, 3]))
self.assertTrue(np.all(nobs == [2, 1, 2, 1, 2]))

#- test astropy Table
t = Table(t)
nobs = calc_numobs(t)
self.assertTrue(np.all(nobs == [1, 1, 2, 3, 3]))

#- LRG numobs also works with ZFLUX instead of DECAM*
t['ZFLUX'] = t['DECAM_FLUX'][:,4] / t['DECAM_MW_TRANSMISSION'][:,4]
t.remove_column('DECAM_FLUX')
t.remove_column('DECAM_MW_TRANSMISSION')
nobs = calc_numobs(t)
self.assertTrue(np.all(nobs == [1, 1, 2, 3, 3]))
self.assertTrue(np.all(nobs == [2, 1, 2, 1, 2]))

#- this is true even if other targeting bits are set
t['DESI_TARGET'] |= desi_mask.mask('ELG|BGS_ANY')
nobs = calc_numobs(t)
self.assertTrue(np.all(nobs == [1, 1, 2, 3, 3]))

#- But if no *FLUX available, default to LRGs with 2 obs
t.remove_column('ZFLUX')
nobs = calc_numobs(t)
self.assertTrue(np.all(nobs == 2))

self.assertTrue(np.all(nobs == [2, 1, 2, 1, 2]))

if __name__ == '__main__':
unittest.main()

0 comments on commit b480a1a

Please sign in to comment.