LSST Applications 24.1.0,g0b6bd0c080+e62dec11b2,g17e5ecfddb+2f99ec5bff,g1d67935e3f+aeba7d5376,g33b6a96d52+e24369602a,g38293774b4+ac198e9f13,g396055baef+a9fc9fe987,g3b44f30a73+6ed7a0bf37,g45a0052f0b+d5a0214cf8,g48ccf36440+89c08d0516,g5c4744a4d9+9e5e24d318,g6c8d09e9e7+60190443eb,g8b9e2231ea+b61c7debcc,g9c8be92ad0+d5a0214cf8,g9d27549199+9e5e24d318,ga1cf026fa3+ac198e9f13,ga32aa97882+7403ac30ac,ga786bb30fb+8c170280cc,gaa63f70f4e+a45a85e39e,gabf319e997+a153293d79,gb22ebf5633+adf3385ca5,gbec6a3398f+aeba7d5376,gc75b51116a+846e1f9efd,gca4adeb000+d5a0214cf8,gd01420fc67+aeba7d5376,gd82bb2a289+52e0a19ca3,gd877ba84e5+aeba7d5376,gd95cd18b76+8a093cac5b,gdb4cecd868+a5301bf5a0,gecc7e12556+d5a0214cf8,gf14d0188e3+a153293d79,gf3ee170dca+60190443eb,gf4ac96e456+a153293d79,gf51b12da82+3612beda7c,gf8609944d8+9adb1d6802,gf9f5ea5b4d+ac198e9f13,gff490e6085+9d6cf01b2b
LSST Data Management Base Package
Loading...
Searching...
No Matches
getGen3CoaddExposureId.py
Go to the documentation of this file.
1# This file is part of coadd_utils.
2#
3# Developed for the LSST Data Management System.
4# This product includes software developed by the LSST Project
5# (https://www.lsst.org).
6# See the COPYRIGHT file at the top-level directory of this distribution
7# for details of code ownership.
8#
9# This program is free software: you can redistribute it and/or modify
10# it under the terms of the GNU General Public License as published by
11# the Free Software Foundation, either version 3 of the License, or
12# (at your option) any later version.
13#
14# This program is distributed in the hope that it will be useful,
15# but WITHOUT ANY WARRANTY; without even the implied warranty of
16# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17# GNU General Public License for more details.
18#
19# You should have received a copy of the GNU General Public License
20# along with this program. If not, see <https://www.gnu.org/licenses/>.
21
22__all__ = ["getGen3CoaddExposureId"]
23
24from lsst.daf.persistence import NoResults
25
26
27def getGen3CoaddExposureId(dataRef, coaddName="deep", includeBand=True, log=None):
28 """Return the coadd expId consistent with Gen3 implementation.
29
30 This is a temporary interface intended to aid with the migration from
31 Gen2 to Gen3 middleware. It will be removed with the Gen2 middleware.
32
33 Parameters
34 ----------
36 The data reference for the patch.
37 coaddName : `str`, optional
38 The prefix for the coadd name, e.g. "deep" for "deepCoadd"
39 includeBand : `bool`, optional
40 Whether to include band as part of the dataId packing.
41 log : `lsst.log.Log` or `None`, optional
42 Logger object for logging messages.
43
44 Returns
45 -------
46 expId : `int`
47 The integer id associated with `patchRef` that mimics that of Gen3.
48 """
49 tract = dataRef.dataId["tract"]
50 patch = dataRef.dataId["patch"]
51 filter = dataRef.dataId["filter"]
52 skyMap = dataRef.get(coaddName + "Coadd_skyMap")
53 tractInfo = skyMap[tract]
54 if includeBand:
55 try:
56 band = dataRef.get(coaddName + "Coadd_band")
57 if log is not None:
58 camera = dataRef.get("camera")
59 log.info("Filter %s has been assigned %s as the associated generic band for expId "
60 "computation.", filter, band)
61 except NoResults:
62 band = filter
63 if log is not None:
64 camera = dataRef.get("camera")
65 log.info("No %s mapping found for %s. Using filter %s in dataId as band",
66 coaddName + "Coadd_band", camera.getName(), band)
67 else:
68 band = None
69
70 # Note: the function skyMap.pack_data_id() requires Gen3-style
71 # dataId entries, namely the generic "band" rather than the
72 # "physical_filter", and the sequential patch id number rather
73 # than the comma separated string version.
74 for patchInfo in tractInfo:
75 patchIndexStr = str(patchInfo.getIndex()[0]) + "," + str(patchInfo.getIndex()[1])
76 if patchIndexStr == patch:
77 patchNumId = tractInfo.getSequentialPatchIndex(patchInfo)
78 break
79 try:
80 expId, maxBits = skyMap.pack_data_id(tract, patchNumId, band=band)
81 except Exception as e:
82 if log is not None:
83 log.warning("Setting exposureId to match Gen3 failed with: %s. Falling back to "
84 "Gen2 implementation.", e)
85 expId = int(dataRef.get(coaddName + "CoaddId"))
86 return expId
This static class includes a variety of methods for interacting with the the logging module.
Definition: Log.h:724