Skip to content

Commit

Permalink
Merge fe2db94 into e9d5ffe
Browse files Browse the repository at this point in the history
  • Loading branch information
geordie666 committed Mar 25, 2021
2 parents e9d5ffe + fe2db94 commit 49e7428
Show file tree
Hide file tree
Showing 12 changed files with 208 additions and 64 deletions.
7 changes: 7 additions & 0 deletions doc/changes.rst
Expand Up @@ -5,6 +5,12 @@ desitarget Change Log
0.53.1 (unreleased)
-------------------

* Some clean-up for the 1% Survey [`PR #691`_]. Includes:
* Don't allow ``BGS_FAINT`` targets to be observed in ``DARK``.
* Warn about primary targets that might be too bright.
* Have a single function for calculating UTC time stamps.
* Functionality to read ledgers strictly before a certain UTC time.
* Centralize and speed up routines to match arrays on ``TARGETID``.
* Update ToO Ledger with TOOID and HI/LO priority options [`PR #690`_]
* Add an ``sv3_cuts.py`` module and sv3 bitmask yaml file [`PR #689`_].
* Don't pass the DR when constructing MTL filenames [`PR #688`_].
Expand All @@ -16,6 +22,7 @@ desitarget Change Log
.. _`PR #688`: https://github.com/desihub/desitarget/pull/688
.. _`PR #689`: https://github.com/desihub/desitarget/pull/689
.. _`PR #690`: https://github.com/desihub/desitarget/pull/690
.. _`PR #691`: https://github.com/desihub/desitarget/pull/691

0.53.0 (2021-03-18)
-------------------
Expand Down
3 changes: 0 additions & 3 deletions py/desitarget/QA.py
Expand Up @@ -6,7 +6,6 @@
Module dealing with Quality Assurance tests for Target Selection
"""
from __future__ import (absolute_import, division)
from time import time
import numpy as np
import fitsio
Expand All @@ -22,8 +21,6 @@
from glob import glob, iglob
from scipy.optimize import leastsq
from scipy.spatial import ConvexHull
from astropy import units as u
from astropy.coordinates import SkyCoord
from desiutil import brick
from desiutil.log import get_logger
from desitarget.internal import sharedmem
Expand Down
5 changes: 2 additions & 3 deletions py/desitarget/brightmask.py
Expand Up @@ -19,9 +19,6 @@
import numpy as np
import numpy.lib.recfunctions as rfn

from astropy.coordinates import SkyCoord
from astropy import units as u

from matplotlib.patches import Polygon
from matplotlib.collections import PatchCollection

Expand Down Expand Up @@ -587,6 +584,8 @@ def is_in_bright_mask(targs, sourcemask, inonly=False):
used_near_mask = np.zeros(len(sourcemask), dtype=bool)

# ADM turn the mask and target coordinates into SkyCoord objects.
from astropy.coordinates import SkyCoord
from astropy import units as u
ctargs = SkyCoord(targs["RA"]*u.degree, targs["DEC"]*u.degree)
cmask = SkyCoord(sourcemask["RA"]*u.degree, sourcemask["DEC"]*u.degree)

Expand Down
6 changes: 3 additions & 3 deletions py/desitarget/data/targetmask.yaml
Expand Up @@ -54,16 +54,16 @@ desi_mask:

#- Bright Galaxy Survey
bgs_mask:
- [BGS_FAINT, 0, "BGS faint targets", {obsconditions: BRIGHT|GRAY|DARK}]
- [BGS_FAINT, 0, "BGS faint targets", {obsconditions: BRIGHT}]
- [BGS_BRIGHT, 1, "BGS bright targets", {obsconditions: BRIGHT}]
- [BGS_WISE, 2, "BGS wise targets", {obsconditions: BRIGHT}]
- [BGS_FAINT_HIP, 3, "BGS faint targets at bright priorty", {obsconditions: BRIGHT}]

#- BGS North vs. South selections
- [BGS_FAINT_NORTH, 8, "BGS faint cuts tuned for Bok/Mosaic", {obsconditions: BRIGHT|GRAY|DARK}]
- [BGS_FAINT_NORTH, 8, "BGS faint cuts tuned for Bok/Mosaic", {obsconditions: BRIGHT}]
- [BGS_BRIGHT_NORTH, 9, "BGS bright cuts tuned for Bok/Mosaic", {obsconditions: BRIGHT}]
- [BGS_WISE_NORTH, 10, "BGS WISE cuts tuned for Bok/Mosaic", {obsconditions: BRIGHT}]
- [BGS_FAINT_SOUTH, 16, "BGS faint cuts tuned for DECam", {obsconditions: BRIGHT|GRAY|DARK}]
- [BGS_FAINT_SOUTH, 16, "BGS faint cuts tuned for DECam", {obsconditions: BRIGHT}]
- [BGS_BRIGHT_SOUTH, 17, "BGS bright cuts tuned for DECam", {obsconditions: BRIGHT}]
- [BGS_WISE_SOUTH, 18, "BGS WISE cuts tuned for DECam", {obsconditions: BRIGHT}]

Expand Down
74 changes: 73 additions & 1 deletion py/desitarget/geomask.py
Expand Up @@ -4,9 +4,10 @@
desitarget.geomask
==================
Utility functions for geometry on the sky, masking, etc.
Utility functions for geometry on the sky, masking, matching, etc.
.. _`this post on Stack Overflow`: https://stackoverflow.com/questions/7392143/python-implementations-of-packing-algorithm
.. _`by way of Stack Overflow`: https://stackoverflow.com/a/32654989
"""
from __future__ import (absolute_import, division)
#
Expand All @@ -32,6 +33,77 @@
log = get_logger()


def match_to(A, B):
"""Return indexes where B matches A, holding A in place.
Parameters
----------
A : :class:`~numpy.ndarray` or `list`
Array of integers to match TO.
B : :class:`~numpy.ndarray` or `list`
Array of integers matched to `A`
Returns
-------
:class:`~numpy.ndarray`
The integer indexes in A that B matches to.
Notes
-----
- Result should be such that for ii = match_to(A, B)
np.all(A[ii] == B) is True.
- We're looking up locations of B in A so B can be
a shorter array than A (provided the B->A matches are
unique) but A cannot be a shorter array than B.
"""
# ADM grab the integer matchers.
Aii, Bii = match(A, B)

# ADM return, restoring the original order.
return Aii[np.argsort(Bii)]


def match(A, B):
"""Return matching indexes for two arrays on a unique key.
Parameters
----------
A : :class:`~numpy.ndarray` or `list`
An array of integers.
B : :class:`~numpy.ndarray` or `list`
An array of integers.
Returns
-------
:class:`~numpy.ndarray`
The integer indexes in A to match to B.
:class:`~numpy.ndarray`
The integer indexes in B to match to A.
Notes
-----
- Result should be such that for Aii, Bii = match(A, B)
np.all(A[Aii] == B[Bii]) is True.
- Only works if there is a unique mapping from A->B, i.e
if A and B do NOT contain duplicates.
- h/t Anand Raichoor `by way of Stack Overflow`_.
"""
# AR sorting A,B
tmpA = np.sort(A)
tmpB = np.sort(B)

# AR create mask equivalent to np.in1d(A,B) and np.in1d(B,A) for unique elements
maskA = (
np.searchsorted(tmpB, tmpA, "right") - np.searchsorted(tmpB, tmpA, "left")
) == 1
maskB = (
np.searchsorted(tmpA, tmpB, "right") - np.searchsorted(tmpA, tmpB, "left")
) == 1

# AR to get back to original indexes
return np.argsort(A)[maskA], np.argsort(B)[maskB]


def get_imaging_maskbits(bitnamelist=None):
"""Return MASKBITS names and bits from the Legacy Surveys.
Expand Down

0 comments on commit 49e7428

Please sign in to comment.