Skip to content

Commit

Permalink
Merge pull request #537 from desihub/update_numobs
Browse files Browse the repository at this point in the history
handles tracer QSO inside mtl
  • Loading branch information
geordie666 committed Sep 20, 2019
2 parents 32e2780 + 093c5f3 commit 2a4a9b4
Show file tree
Hide file tree
Showing 5 changed files with 114 additions and 2 deletions.
2 changes: 2 additions & 0 deletions doc/changes.rst
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,12 @@ desitarget Change Log
* ...and bright-time targets observed in dark-time.
* Minor update to the ``MWS_BROAD`` class.
* Add info on versioning, main_cmx_or_sv to bitmask notebook [`PR #527`_]
* Uses ``SPECTYPE`` information from ``zcat`` to update NUMOBS_MORE for tracerqso vs. lyaqso [`PR #537`_].

.. _`PR #527`: https://github.com/desihub/desitarget/pull/527
.. _`PR #531`: https://github.com/desihub/desitarget/pull/531
.. _`PR #532`: https://github.com/desihub/desitarget/pull/532
.. _`PR #537`: https://github.com/desihub/desitarget/pull/537

0.32.0 (2019-08-07)
-------------------
Expand Down
11 changes: 10 additions & 1 deletion py/desitarget/mtl.py
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,16 @@ def make_mtl(targets, obscon, zcat=None, trim=False, scnd=None):
if (obsconditions.mask(obscon) & obsconditions.mask("BRIGHT")) != 0:
ii = targets_zmatcher[desi_target] & desi_mask.BGS_ANY > 0
ztargets['NUMOBS_MORE'][ii] = 1

if survey == 'main':
# If the object is confirmed to be a tracer QSO, then don't request more observations
if (obsconditions.mask(obscon) & obsconditions.mask("DARK")) != 0:
if zcat is not None:
ii = ztargets['SPECTYPE']=='QSO'
ii &= (ztargets['ZWARN'] == 0 )
ii &= (ztargets['Z']<2.1)
ii &= (ztargets['NUMOBS']>0)
ztargets['NUMOBS_MORE'][ii] = 0

# ADM assign priorities, note that only things in the zcat can have changed priorities.
# ADM anything else will be assigned PRIORITY_INIT, below.
priority = calc_priority(targets_zmatcher, ztargets, obscon)
Expand Down
1 change: 1 addition & 0 deletions py/desitarget/test/test_mtl.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ def setUp(self):
self.zcat['Z'] = [2.5, 1.0, 0.5, 1.0]
self.zcat['ZWARN'] = [0, 0, 0, 0]
self.zcat['NUMOBS'] = [1, 1, 1, 1]
self.zcat['SPECTYPE'] = ['QSO', 'QSO', 'GALAXY', 'GALAXY']

def reset_targets(self, prefix):
"""Add prefix to TARGET columns"""
Expand Down
99 changes: 99 additions & 0 deletions py/desitarget/test/test_mtl_multiple.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
# Licensed under a 3-clause BSD style license - see LICENSE.rst
# -*- coding: utf-8 -*-
"""Test desitarget.mtl.
"""
import os
import unittest
import numpy as np
from astropy.table import Table, join

from desitarget.targetmask import desi_mask as Mx
from desitarget.sv1.sv1_targetmask import desi_mask as MxSV
from desitarget.targetmask import obsconditions
from desitarget.mtl import make_mtl
from desitarget.targets import initial_priority_numobs, main_cmx_or_sv


class TestMTL(unittest.TestCase):

def setUp(self):
self.targets = Table()

# This is a dual identity case. In all cases the target is both QSO and ELG.
# The first case is a true QSO with lowz.
# The second case is a true QSO with highz.
# The third case is an ELG.

self.type_A = np.array(['QSO', 'QSO', 'ELG'])
self.type_B = np.array(['ELG', 'ELG', 'QSO'])
self.priorities_A = np.array([Mx[t].priorities['UNOBS'] for t in self.type_A])
self.priorities_B = np.array([Mx[t].priorities['UNOBS'] for t in self.type_B])
self.priorities = np.maximum(self.priorities_A, self.priorities_B) # get the maximum between the two
self.targets['DESI_TARGET'] = np.array([Mx[t].mask for t in self.type_A]) | np.array([Mx[t].mask for t in self.type_B])
self.targets['BGS_TARGET'] = np.zeros(len(self.type_A), dtype=np.int64)
self.targets['MWS_TARGET'] = np.zeros(len(self.type_A), dtype=np.int64)

n = len(self.targets)
self.targets['ZFLUX'] = 10**((22.5-np.linspace(20, 22, n))/2.5)
self.targets['TARGETID'] = list(range(n))
pinit, ninit = initial_priority_numobs(self.targets)
self.targets["PRIORITY_INIT"] = pinit
self.targets["NUMOBS_INIT"] = ninit


# - reverse the order for zcat to make sure joins work
self.zcat = Table()
self.zcat['TARGETID'] = self.targets['TARGETID'][::-1]
self.zcat['Z'] = [1.0, 1.5, 2.5]
self.zcat['ZWARN'] = [0, 0, 0]
self.zcat['NUMOBS'] = [1, 1, 1]
self.zcat['SPECTYPE'] = ['QSO', 'QSO', 'GALAXY']

# priorities and numobs more after measuring redshifts
self.post_prio = [0 for t in self.type_A]
self.post_numobs_more = [0 for t in self.type_A]
self.post_prio[0] = Mx['QSO'].priorities['MORE_ZGOOD'] # highz QSO
self.post_prio[1] = Mx['QSO'].priorities['DONE'] # Lowz QSO, DONE
self.post_prio[2] = Mx['ELG'].priorities['DONE'] # ELG, DONE
self.post_numobs_more[0] = 3
self.post_numobs_more[1] = 0
self.post_numobs_more[2] = 0

def test_mtl(self):
"""Test output from MTL has the correct column names.
"""
# ADM loop through once each for the main survey, commissioning and SV.
#t = self.reset_targets(prefix)
mtl = make_mtl(self.targets, "GRAY|DARK")
goodkeys = sorted(set(self.targets.dtype.names) | set(['NUMOBS_MORE', 'PRIORITY', 'OBSCONDITIONS']))
mtlkeys = sorted(mtl.dtype.names)
self.assertEqual(mtlkeys, goodkeys)

def test_numobs(self):
"""Test priorities, numobs and obsconditions are set correctly with no zcat.
"""
# ADM loop through once for SV and once for the main survey.
mtl = make_mtl(self.targets, "GRAY|DARK")
mtl.sort(keys='TARGETID')
self.assertTrue(np.all(mtl['NUMOBS_MORE'] == [4, 4, 4]))
self.assertTrue(np.all(mtl['PRIORITY'] == self.priorities))

def test_zcat(self):
"""Test priorities, numobs and obsconditions are set correctly after zcat.
"""
# ADM loop through once for SV and once for the main survey.
mtl = make_mtl(self.targets, "DARK|GRAY", zcat=self.zcat, trim=False)
mtl.sort(keys='TARGETID')
self.assertTrue(np.all(mtl['PRIORITY'] == self.post_prio))
self.assertTrue(np.all(mtl['NUMOBS_MORE'] == self.post_numobs_more))

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


def test_suite():
"""Allows testing of only this module with the command:
python setup.py test -m desitarget.test.test_mtl
"""
return unittest.defaultTestLoader.loadTestsFromName(__name__)
3 changes: 2 additions & 1 deletion py/desitarget/test/test_priorities.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,12 @@ def setUp(self):
('Z', np.float32),
('ZWARN', np.float32),
('NUMOBS', np.float32),
('SPECTYPE', np.str)
]

n = 3

self.targets = Table(np.zeros(n, dtype=targdtype))
self.targets = Table(np.zeros(n, dtype=targdtype))
self.targets['TARGETID'] = list(range(n))

self.zcat = Table(np.zeros(n, dtype=zdtype))
Expand Down

0 comments on commit 2a4a9b4

Please sign in to comment.