Skip to content

Commit

Permalink
Merge pull request #707 from desihub/ADM-zcat-dchisq
Browse files Browse the repository at this point in the history
When making a zcat, update the ZWARN bit-mask using DELTACHI2 values
  • Loading branch information
geordie666 committed Apr 6, 2021
2 parents 3d031b3 + 37a6216 commit 3b79cb1
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 5 deletions.
6 changes: 5 additions & 1 deletion doc/changes.rst
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,11 @@ desitarget Change Log
0.57.1 (unreleased)
-------------------

* No changes yet.
* When making a zcat, update ``ZWARN`` using ``DELTACHI2`` [`PR #707`_]:
* Flag ``ZWARN`` for all targets with ``DELTACHI2 < 25``.
* Also flag ``BGS`` targets in bright-time with ``DELTACHI2 < 40``.

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

0.57.0 (2021-04-04)
-------------------
Expand Down
5 changes: 4 additions & 1 deletion py/desitarget/data/targetmask.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ targetid_mask:
- [RESERVED, 62, "RIGHTMOST bit for left over bit space (encompasses bit 62 inclusive)", {nbits: 1}]

# ADM ZWARN mask (bits that can be set to warn that a redshift is bad).
# ADM inherited from https://github.com/desihub/redrock/blob/8e33f642b6d8a762c4d71626fb3aca6377c976d4/py/redrock/zwarning.py
# ADM inherited from https://github.com/desihub/redrock/blob/master/py/redrock/zwarning.py
zwarn_mask:
- [SKY, 0, "sky fiber"]
- [LITTLE_COVERAGE, 1, "too little wavelength coverage"]
Expand All @@ -188,6 +188,9 @@ zwarn_mask:
- [BAD_TARGET, 8, "catastrophically bad targeting data"]
- [NODATA, 9, "No data for this fiber, e.g. because spectrograph was broken during this exposure (ivar=0 for all pixels)"]
- [BAD_MINFIT, 10, "Bad parabola fit to the chi2 minimum"]
- [LOW_DEL_CHI2, 16, "DELTACHI2 is lower than 25 for a DESI SV3 target"]
- [LOW_DEL_CHI2_BGS, 17, "DELTACHI2 is lower than 40 for a DESI SV3 BGS target in bright time"]


#- Priorities for each target bit
#- Numerically larger priorities are higher priority to be observed first.
Expand Down
27 changes: 24 additions & 3 deletions py/desitarget/mtl.py
Original file line number Diff line number Diff line change
Expand Up @@ -909,8 +909,8 @@ def tiles_to_be_processed(zcatdir, mtltilefn, obscon, survey):
return newtiles


def make_zcat_rr_backstop(zcatdir, tiles):
"""Make the simplest possible zcat using SV1-era redrock outputs.
def make_zcat_rr_backstop(zcatdir, tiles, obscon, survey):
"""Make a simple zcat using only redrock outputs.
Parameters
----------
Expand All @@ -920,6 +920,14 @@ def make_zcat_rr_backstop(zcatdir, tiles):
Numpy array of tiles to be processed. Must contain at least:
* TILEID - unique tile identifier.
* ZDATE - final night processed to complete the tile (YYYYMMDD).
obscon : :class:`str`
A string matching ONE obscondition in the desitarget bitmask yaml
file (i.e. `desitarget.targetmask.obsconditions`), e.g. "DARK".
Governs how ZWARN is updated using `DELTACHI2`.
survey : :class:`str`, optional, defaults to "main"
Used to update `ZWARN` using `DELTACHI2` for a given survey type.
Options are ``'main'`` and ``'svX``' (where X is 1, 2, 3 etc.)
for the main survey and different iterations of SV, respectively.
Returns
-------
Expand Down Expand Up @@ -987,6 +995,19 @@ def make_zcat_rr_backstop(zcatdir, tiles):
for col in set(zcat.dtype.names) - set(['RA', 'DEC', 'NUMOBS', 'ZTILEID']):
zcat[col] = zs[col]

# ADM Finally, flag the ZWARN bit if DELTACHI2 is too low.
if survey == "sv3":
from desitarget.sv3.sv3_targetmask import desi_mask
desi_target = fms[zid]["SV3_DESI_TARGET"]
# ADM set ZWARN flag for everything with DELTACHI2 < 25.
lodc2 = zs["DELTACHI2"] < 25
zcat["ZWARN"] |= lodc2*zwarn_mask["LOW_DEL_CHI2"]
if obscon == "BRIGHT":
lodc2 = zs["DELTACHI2"] < 40
bgs = desi_target & desi_mask["BGS_ANY"] != 0
lodc2bgs = bgs & lodc2
zcat["ZWARN"] |= lodc2bgs*zwarn_mask["LOW_DEL_CHI2_BGS"]

return zcat


Expand Down Expand Up @@ -1069,7 +1090,7 @@ def loop_ledger(obscon, survey='main', zcatdir=None, mtldir=None,

# ADM create the zcat: This will likely change, but for now let's
# ADM just use redrock.
zcat = make_zcat_rr_backstop(zcatdir, tiles)
zcat = make_zcat_rr_backstop(zcatdir, tiles, obscon, survey)

# ADM insist that for an MTL loop with real observations, the zcat
# ADM must conform to the data model. In particular, it must include
Expand Down

0 comments on commit 3b79cb1

Please sign in to comment.