Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Subsampling BACKUP giants #772

Merged
merged 9 commits into from Nov 21, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
8 changes: 8 additions & 0 deletions doc/changes.rst
Expand Up @@ -39,11 +39,19 @@ desitarget Change Log
* Update targetmask and cuts for backup program [`PR #766`_]:
* Matches description in backup program document.
* Also use the ops/tiles-specstatus.ecsv tile file for SV [`PR #765`_].
* Fix a few variable name typos in the target selection code [`PR #770`_].
All of those likely never were triggered in production.
* Add another MWS backup object type BACKUP_GIANT_LOP. The default
BACKUP_GIANT category is now downsampled with galactic latitude to
avoid having large densities [`PR #772`_].
* Change backup target priorities to be between 15-30 to be able to place
new object types in between [`PR #772`_].

.. _`PR #765`: https://github.com/desihub/desitarget/pull/765
.. _`PR #766`: https://github.com/desihub/desitarget/pull/766
.. _`PR #768`: https://github.com/desihub/desitarget/pull/768
.. _`PR #770`: https://github.com/desihub/desitarget/pull/770
.. _`PR #772`: https://github.com/desihub/desitarget/pull/772
.. _`PR #773`: https://github.com/desihub/desitarget/pull/773

1.3.0 (2021-09-20)
Expand Down
81 changes: 65 additions & 16 deletions py/desitarget/cuts.py
Expand Up @@ -104,7 +104,7 @@ def random_fraction_of_trues(fraction, bool_array):
If a scalar is passed, then a scalar is returned.
"""
# ADM check that the input fraction was between 0 and 1.
if not 0 <= fraction <= 1:
if not np.all((0 <= fraction) & (fraction <= 1)):
msg = "fraction must be between 0 and 1, not {}".format(fraction)
log.critical(msg)
raise ValueError(msg)
Expand Down Expand Up @@ -337,6 +337,38 @@ def isGAIA_STD(ra=None, dec=None, galb=None, gaiaaen=None, pmra=None, pmdec=None

return std_faint, std_bright, std_wd

def backupGiantDownsample(l, b):
"""
Return the downsampling factor as a function of l,b

Parameters
----------
l: array
Galactic longitude
b: array
Galactic latitude

Returns
-------
frac: array
The fraction of objects to select
"""
p = [6.9529434, 0.18786695, -2.6621607, -3.05095354, 8.10060927]

# this is approximately log density
ldens = p[0] + p[1] * np.cos(np.deg2rad(l)) + p[2] * np.log10(
np.abs(np.abs(b) + p[3] * np.cos(np.deg2rad(l)) + p[4]))

# this just maps x -> x when x<th
# and then x-> (1+alpha)*(x-th)+th when x>th
# The purpose is that in high density regions, it gives a
# high envelope
mapper = lambda x, alpha, th: (x * (x < th) + ((1 + alpha) * (x - th) + th) * (x > th))

subsamp = np.minimum(100 / 10**mapper(ldens, .1, .0), 1)
return subsamp



def isBACKUP(ra=None, dec=None,
gaiagmag=None, gaiabmag=None, gaiarmag=None,
Expand Down Expand Up @@ -393,41 +425,55 @@ def isBACKUP(ra=None, dec=None,
isbackupbright = primary.copy()
isbackupfaint = primary.copy()
isbackupveryfaint = primary.copy()
isbackupgiant = primary.copy()
is_backup_giant = primary.copy()
is_backup_lowp_giant = primary.copy()

# ADM determine which sources are close to the Galaxy.
in_gal = is_in_Galaxy([ra, dec], radec=True)

# APC bright targets are 11.2 + 0.6(BP-RP) < G < 16.
isbackupbright &= gaiagmag >= 11.2 + 0.6*bprp
isbackupbright &= gaiagmag >= 11.2 + 0.6 * bprp
isbackupbright &= gaiagmag < 16.0

# APC giant targets are min(17.5 + 0.6 (BP-RP), 19) < G < 16
giant_sel = (gaiagmag >= 16.0)
giant_sel &= gaiagmag < np.minimum(17.5 + 0.6 * bprp, 19)
# APC Giant candidates have low parallax
is_gaiagiant = parallax < (3 * parallaxerr + 0.1)
giant_sel &= parallax < (3 * parallaxerr + 0.1)

# APC giant targets are min(17.5 + 0.6(BP-RP), 19) < G < 16
isbackupgiant &= gaiagmag >= 16.0
isbackupgiant &= gaiagmag < np.minimum(17.5 + 0.6*bprp, 19)
# APC and are likely giants
isbackupgiant &= is_gaiagiant
# less contaminated giant selection
giant_hp_sel = giant_sel & (parallax < (2 * parallaxerr + 0.1))

# APC and are likely giants
gal = SkyCoord(ra*u.degree, dec*u.degree).galactic
l, b = gal.l.to_value(u.degree), gal.b.to_value(u.degree)

lowlat_fraction = backupGiantDownsample(l, b)
giant_hpsub_sel = random_fraction_of_trues(lowlat_fraction, giant_hp_sel)
# Subsampled subset of high priority giants
is_backup_giant &= giant_hpsub_sel
is_backup_lowp_giant &= (giant_sel & (~giant_hpsub_sel))
# do not select low priority distant giants in the galactic plane
is_backup_lowp_giant &= (~in_gal)

# APC faint targets are 16 < G < 18
isbackupfaint &= gaiagmag >= 16.0
isbackupfaint &= gaiagmag < 18.0
# APC and are not halo giant candidates
isbackupfaint &= ~is_gaiagiant
isbackupfaint &= (~is_backup_giant) & (~is_backup_lowp_giant)
# ADM and are "far from" the Galaxy.
isbackupfaint &= ~in_gal

# ADM very faint targets are 18. < G < 19.
isbackupveryfaint &= gaiagmag >= 18.
isbackupveryfaint &= gaiagmag < 19
# APC and are not halo giant candidates
isbackupveryfaint &= ~is_gaiagiant
isbackupveryfaint &= ~is_backup_giant
isbackupveryfaint &= ~is_backup_lowp_giant
# ADM and are "far from" the Galaxy.
isbackupveryfaint &= ~in_gal

return isbackupbright, isbackupfaint, isbackupveryfaint, isbackupgiant
return (isbackupbright, isbackupfaint, isbackupveryfaint,
is_backup_giant, is_backup_lowp_giant)


def isLRG(gflux=None, rflux=None, zflux=None, w1flux=None, w2flux=None,
Expand Down Expand Up @@ -2741,15 +2787,17 @@ def apply_cuts_gaia(numproc=4, survey='main', nside=None, pixlist=None,
# ADM determine if an object is a BACKUP target.
primary = np.ones_like(gaiaobjs, dtype=bool)
if survey == 'main':
backup_bright, backup_faint, backup_very_faint, backup_giant = targcuts.isBACKUP(
(backup_bright, backup_faint, backup_very_faint, backup_hip_giant,
backup_lowp_giant) = targcuts.isBACKUP(
ra=ra, dec=dec, gaiagmag=gaiagmag,
gaiabmag=gaiabmag, gaiarmag=gaiarmag,
parallax=parallax, parallaxerr=parallaxerr,
primary=primary)
else:
backup_bright, backup_faint, backup_very_faint = targcuts.isBACKUP(
(backup_bright, backup_faint, backup_very_faint) = targcuts.isBACKUP(
ra=ra, dec=dec, gaiagmag=gaiagmag,
primary=primary)


# ADM determine if a target is a Gaia-only standard.
primary = np.ones_like(gaiaobjs, dtype=bool)
Expand All @@ -2766,7 +2814,8 @@ def apply_cuts_gaia(numproc=4, survey='main', nside=None, pixlist=None,
mws_target |= backup_faint * mws_mask.BACKUP_FAINT
mws_target |= backup_very_faint * mws_mask.BACKUP_VERY_FAINT
if survey == 'main':
mws_target |= backup_giant * mws_mask.BACKUP_GIANT
mws_target |= backup_hip_giant * mws_mask.BACKUP_GIANT
mws_target |= backup_lowp_giant * mws_mask.BACKUP_GIANT_LOP
mws_target |= std_faint * mws_mask.GAIA_STD_FAINT
mws_target |= std_bright * mws_mask.GAIA_STD_BRIGHT
mws_target |= std_wd * mws_mask.GAIA_STD_WD
Expand Down
11 changes: 7 additions & 4 deletions py/desitarget/data/targetmask.yaml
Expand Up @@ -114,6 +114,7 @@ mws_mask:
- [GAIA_STD_BRIGHT, 35, "Standard stars for BRIGHT conditions", {obsconditions: BRIGHT|BACKUP|TWILIGHT12|TWILIGHT18}]

# ADM back-up targets for poor conditions and as filler.
- [BACKUP_GIANT_LOP, 58, "Giant candidate backup targets", {obsconditions: BACKUP|TWILIGHT12|TWILIGHT18}]
- [BACKUP_GIANT, 59, "Giant candidate backup targets", {obsconditions: BACKUP|TWILIGHT12|TWILIGHT18}]
- [BACKUP_BRIGHT, 60, "Bright backup Gaia targets", {obsconditions: BACKUP|TWILIGHT12|TWILIGHT18}]
- [BACKUP_FAINT, 61, "Fainter backup Gaia targets", {obsconditions: BACKUP|TWILIGHT12|TWILIGHT18}]
Expand Down Expand Up @@ -351,10 +352,11 @@ priorities:
MWS_FAINT_RED_SOUTH: SAME_AS_MWS_BROAD_NORTH

# ADM backup targets.
BACKUP_BRIGHT: {UNOBS: 9, MORE_ZGOOD: 2, MORE_ZWARN: 2, DONE: 2, OBS: 1, DONOTOBSERVE: 0, MORE_MIDZQSO: 0}
BACKUP_GIANT: {UNOBS: 8, MORE_ZGOOD: 2, MORE_ZWARN: 2, DONE: 2, OBS: 1, DONOTOBSERVE: 0, MORE_MIDZQSO: 0}
BACKUP_FAINT: {UNOBS: 7, MORE_ZGOOD: 2, MORE_ZWARN: 2, DONE: 2, OBS: 1, DONOTOBSERVE: 0, MORE_MIDZQSO: 0}
BACKUP_VERY_FAINT: {UNOBS: 6, MORE_ZGOOD: 2, MORE_ZWARN: 2, DONE: 2, OBS: 1, DONOTOBSERVE: 0, MORE_MIDZQSO: 0}
BACKUP_GIANT: {UNOBS: 35, MORE_ZGOOD: 2, MORE_ZWARN: 2, DONE: 2, OBS: 1, DONOTOBSERVE: 0, MORE_MIDZQSO: 0}
BACKUP_BRIGHT: {UNOBS: 30, MORE_ZGOOD: 2, MORE_ZWARN: 2, DONE: 2, OBS: 1, DONOTOBSERVE: 0, MORE_MIDZQSO: 0}
BACKUP_GIANT_LOP: {UNOBS: 25, MORE_ZGOOD: 2, MORE_ZWARN: 2, DONE: 2, OBS: 1, DONOTOBSERVE: 0, MORE_MIDZQSO: 0}
BACKUP_FAINT: {UNOBS: 20, MORE_ZGOOD: 2, MORE_ZWARN: 2, DONE: 2, OBS: 1, DONOTOBSERVE: 0, MORE_MIDZQSO: 0}
BACKUP_VERY_FAINT: {UNOBS: 15, MORE_ZGOOD: 2, MORE_ZWARN: 2, DONE: 2, OBS: 1, DONOTOBSERVE: 0, MORE_MIDZQSO: 0}

# ADM Standards are special; priorities don't apply.
GAIA_STD_FAINT: -1
Expand Down Expand Up @@ -502,6 +504,7 @@ numobs:
# ADM backup targets.
BACKUP_BRIGHT: 2
BACKUP_GIANT: 2
BACKUP_GIANT_LOP: 2
BACKUP_FAINT: 2
BACKUP_VERY_FAINT: 2

Expand Down