lsst.coadd.utils g169eefeba3+0b70771f1a
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 ----------
35 dataRef : `lsst.daf.persistence.butlerSubset.ButlerDataRef`
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
def getGen3CoaddExposureId(dataRef, coaddName="deep", includeBand=True, log=None)