• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

desihub / desitarget / 10218914087

02 Aug 2024 04:31PM UTC coverage: 53.05%. Remained the same
10218914087

Pull #827

github

web-flow
Merge branch 'main' into ADM-col-gd1
Pull Request #827: Add GAIA_ prefix to PHOT_*_MEAN_MAG column names

0 of 2 new or added lines in 2 files covered. (0.0%)

2 existing lines in 1 file now uncovered.

7818 of 14737 relevant lines covered (53.05%)

0.53 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

0.0
/py/desitarget/streams/targets.py
1
"""
2
desitarget.streams.targets
3
==========================
4

5
Manipulate/add target bitmasks/priorities/numbers of observations for
6
stream targets.
7
"""
8
import numpy as np
×
9
import numpy.lib.recfunctions as rfn
×
10

11
from desitarget.targets import initial_priority_numobs, set_obsconditions, \
×
12
    encode_targetid
13
from desitarget.streams.utilities import errors_to_ivars
×
14

15
# ADM set up the DESI default logger.
16
from desiutil.log import get_logger
×
17
log = get_logger()
×
18

19

20
def finalize(targets, desi_target, bgs_target, mws_target, scnd_target):
×
21
    """Return new targets array with added/renamed columns
22

23
    Parameters
24
    ----------
25
    targets : :class:`~numpy.ndarray`
26
        numpy structured array of targets.
27
    desi_target : :class:`~numpy.ndarray`
28
        1D array of target selection bit flags.
29
    bgs_target : :class:`~numpy.ndarray`
30
        1D array of target selection bit flags.
31
    mws_target : :class:`~numpy.ndarray`
32
        1D array of target selection bit flags.
33
    scnd_target : :class:`~numpy.ndarray`
34
        1D array of target selection bit flags.
35

36
    Returns
37
    -------
38
    :class:`~numpy.ndarray`
39
       new targets structured array with the following additions:
40
          * renaming OBJID -> BRICK_OBJID (it is only unique within a brick).
41
          * renaming TYPE -> MORPHTYPE (used downstream in other contexts).
42
          * Adding new columns:
43
              - TARGETID: unique ID across all bricks or Gaia files.
44
              - DESI_TARGET: dark time survey target selection flags.
45
              - MWS_TARGET: bright time MWS target selection flags.
46
              - BGS_TARGET: bright time BGS target selection flags.
47
              - SCND_TARGET: stream secondary target selection flags.
48
              - PRIORITY_INIT: initial priority for observing target.
49
              - SUBPRIORITY: a placeholder column that is set to zero.
50
              - NUMOBS_INIT: initial number of observations for target.
51
              - OBSCONDITIONS: bitmask of observation conditions.
52

53
    Notes
54
    -----
55
        - SUBPRIORITY is the only column that isn't populated. This is
56
          because it's easier to populate it in a reproducible fashion
57
          when collecting targets rather than on a per-brick basis
58
          when this function is called. It's set to all zeros.
59
        - NUMOBS_INIT and PRIORITY_INIT are split into DARK/BRIGHT/BACKUP
60
          versions, as these surveys are effectively separate.
61
    """
62
    # ADM some straightforward checks that inputs are the same length.
63
    ntargets = len(targets)
×
64
    assert ntargets == len(desi_target)
×
65
    assert ntargets == len(bgs_target)
×
66
    assert ntargets == len(mws_target)
×
67
    assert ntargets == len(scnd_target)
×
68

69
    # ADM rename some columns for downstream code.
UNCOV
70
    targets = rfn.rename_fields(targets,
×
71
                                {'OBJID': 'BRICK_OBJID', 'TYPE': 'MORPHTYPE',
72
                                 'PHOT_G_MEAN_MAG': 'GAIA_PHOT_G_MEAN_MAG',
73
                                 'PHOT_BP_MEAN_MAG': 'GAIA_PHOT_BP_MEAN_MAG',
74
                                 'PHOT_RP_MEAN_MAG': 'GAIA_PHOT_RP_MEAN_MAG'}
75
                                )
76

77
    # ADM create the unique TARGETID.
UNCOV
78
    targetid = encode_targetid(objid=targets['BRICK_OBJID'],
×
79
                               brickid=targets['BRICKID'],
80
                               release=targets['RELEASE'])
81

82
    nodata = np.zeros(ntargets, dtype='int')-1
×
83
    subpriority = np.zeros(ntargets, dtype='float')
×
84

85
    # ADM the columns to write out and their values and formats.
86
    cols = ["TARGETID", "DESI_TARGET", "BGS_TARGET", "MWS_TARGET", "SCND_TARGET",
×
87
            "SUBPRIORITY", "OBSCONDITIONS"]
88
    vals = [targetid, desi_target, bgs_target, mws_target, scnd_target,
×
89
            subpriority, nodata]
90
    forms = [">i8", ">i8", ">i8", ">i8", ">i8", ">f8", ">i8"]
×
91

92
    # ADM set the initial PRIORITY and NUMOBS.
93
    # ADM populate bright/dark/backup separately.
94
    ender = ["_DARK", "_BRIGHT", "_BACKUP"]
×
95
    obscon = ["DARK|GRAY", "BRIGHT", "BACKUP"]
×
96
    for edr, oc in zip(ender, obscon):
×
97
        cols += ["{}_INIT{}".format(pn, edr) for pn in ["PRIORITY", "NUMOBS"]]
×
98
        vals += [nodata, nodata]
×
99
        forms += ['>i8', '>i8']
×
100

101
    # ADM write the output array.
102
    newdt = [dt for dt in zip(cols, forms)]
×
103
    done = np.array(np.zeros(len(targets)), dtype=targets.dtype.descr+newdt)
×
104
    for col in targets.dtype.names:
×
105
        done[col] = targets[col]
×
106
    for col, val in zip(cols, vals):
×
107
        done[col] = val
×
108

109
    # ADM add PRIORITY/NUMOBS columns.
110
    for edr, oc in zip(ender, obscon):
×
111
        pc, nc = "PRIORITY_INIT"+edr, "NUMOBS_INIT"+edr
×
112
        done[pc], done[nc] = initial_priority_numobs(done, obscon=oc, scnd=True)
×
113

114
    # ADM set the OBSCONDITIONS.
115
    done["OBSCONDITIONS"] = set_obsconditions(done, scnd=True)
×
116

117
    # ADM replace any NaNs with zeros.
NEW
118
    for col in ["GAIA_PHOT_G_MEAN_MAG", "GAIA_PHOT_BP_MEAN_MAG",
×
119
                "GAIA_PHOT_RP_MEAN_MAG", "PARALLAX", "PMRA", "PMDEC"]:
120
        ii = np.isnan(done[col])
×
121
        done[col][ii] = 0.
×
122

123
    # ADM change errors to IVARs.
124
    done = errors_to_ivars(
×
125
        done, colnames=["PARALLAX_ERROR", "PMRA_ERROR", "PMDEC_ERROR"])
126

127
    # ADM some final checks that the targets conform to expectations...
128
    # ADM check that each target has a unique ID.
129
    if len(done["TARGETID"]) != len(np.unique(done["TARGETID"])):
×
130
        msg = ("Targets are not unique. The code might need updated to read the "
×
131
               "sweep files one-by-one (as in desitarget.cuts.select_targets()) "
132
               "rather than caching each individual stream")
133
        log.critical(msg)
×
134

135
    return done
×
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc