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
photoCalibConsolidateGen2Gen3.py
Go to the documentation of this file.
1# See COPYRIGHT file at the top of the source tree.
2#
3# This file is part of fgcmcal.
4#
5# Developed for the LSST Data Management System.
6# This product includes software developed by the LSST Project
7# (https://www.lsst.org).
8# See the COPYRIGHT file at the top-level directory of this distribution
9# for details of code ownership.
10#
11# This program is free software: you can redistribute it and/or modify
12# it under the terms of the GNU General Public License as published by
13# the Free Software Foundation, either version 3 of the License, or
14# (at your option) any later version.
15#
16# This program is distributed in the hope that it will be useful,
17# but WITHOUT ANY WARRANTY; without even the implied warranty of
18# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19# GNU General Public License for more details.
20#
21# You should have received a copy of the GNU General Public License
22# along with this program. If not, see <https://www.gnu.org/licenses/>.
23"""Convert gen2 to gen3 photocalib files.
24"""
25# import lsst.pex.config as pexConfig
26import lsst.pipe.base as pipeBase
27from lsst.pipe.base import connectionTypes
28import lsst.afw.table as afwTable
29import lsst.daf.base as dafBase
30import lsst.utils as utils
31
32
33__all__ = ['PhotoCalibConsolidateGen2Gen3Config',
34 'PhotoCalibConsolidateGen2Gen3Connections',
35 'PhotoCalibConsolidateGen2Gen3Task',
36 'SkyWcsConsolidateGen2Gen3Config',
37 'SkyWcsConsolidateGen2Gen3Connections',
38 'SkyWcsConsolidateGen2Gen3Task']
39
40
41class PhotoCalibConsolidateGen2Gen3Connections(pipeBase.PipelineTaskConnections,
42 dimensions=("instrument", "visit")):
43 photoCalibList = connectionTypes.Input(
44 doc="Per-detector photocalibs from fgcm",
45 name="fgcm_photoCalib",
46 storageClass="PhotoCalib",
47 dimensions=("instrument", "visit", "detector"),
48 deferLoad=True,
49 multiple=True,
50 )
51 photoCalibGlobalCatalog = connectionTypes.Output(
52 doc="Global per-visit photocalibs.",
53 name="fgcmPhotoCalibCatalog",
54 storageClass="ExposureCatalog",
55 dimensions=("instrument", "visit"),
56 )
57
58
59class PhotoCalibConsolidateGen2Gen3Config(pipeBase.PipelineTaskConfig,
60 pipelineConnections=PhotoCalibConsolidateGen2Gen3Connections):
61 def validate(self):
62 super().validate()
63
64
65class PhotoCalibConsolidateGen2Gen3Task(pipeBase.PipelineTask):
66 """Consolidate gen2 photocalibs into gen3 photocalibs."""
67 ConfigClass = PhotoCalibConsolidateGen2Gen3Config
68 _DefaultName = "photoCalibConsolidateGen2Gen3"
69
70 def __init__(self, butler=None, **kwargs):
71 super().__init__(**kwargs)
72
73 @utils.inheritDoc(pipeBase.PipelineTask)
74 def runQuantum(self, butlerQC, inputRefs, outputRefs):
75 visit = butlerQC.quantum.dataId['visit']
76
77 schema = afwTable.ExposureTable.makeMinimalSchema()
78 schema.addField('visit', type='L', doc='visit number')
79
80 metadata = dafBase.PropertyList()
81 metadata.add("COMMENT", "Catalog id is detector id, sorted")
82 metadata.add("COMMENT", "Only detectors with data have entries")
83
84 photoCalibCat = afwTable.ExposureCatalog(schema)
85 photoCalibCat.setMetadata(metadata)
86 photoCalibCat.reserve(len(inputRefs.photoCalibList))
87
88 photoCalibList = butlerQC.get(inputRefs.photoCalibList)
89 for dataRef in photoCalibList:
90 detector = dataRef.dataId['detector']
91 photoCalib = dataRef.get()
92 rec = photoCalibCat.addNew()
93 rec['id'] = detector
94 rec['visit'] = visit
95 rec.setPhotoCalib(photoCalib)
96
97 photoCalibCat.sort()
98
99 butlerQC.put(photoCalibCat, outputRefs.photoCalibGlobalCatalog)
100
101
102class SkyWcsConsolidateGen2Gen3Connections(pipeBase.PipelineTaskConnections,
103 dimensions=("instrument", "visit",
104 "skymap", "tract")):
105 skyWcsList = connectionTypes.Input(
106 doc="Per-tract, per-detector wcs calibrations.",
107 name="jointcal_wcs",
108 storageClass="Wcs",
109 dimensions=("instrument", "visit", "detector", "tract", "skymap"),
110 deferLoad=True,
111 multiple=True,
112 )
113 skyWcsTractCatalog = connectionTypes.Output(
114 doc="Per-tract, per-visit wcs calibrations.",
115 name="jointcalSkyWcsCatalog",
116 storageClass="ExposureCatalog",
117 dimensions=("instrument", "visit", "tract"),
118 )
119
120
121class SkyWcsConsolidateGen2Gen3Config(pipeBase.PipelineTaskConfig,
122 pipelineConnections=SkyWcsConsolidateGen2Gen3Connections):
123 def validate(self):
124 super().validate()
125
126
127class SkyWcsConsolidateGen2Gen3Task(pipeBase.PipelineTask):
128 """Consolidate gen2 skywcss into gen3 skywcss."""
129 ConfigClass = SkyWcsConsolidateGen2Gen3Config
130 _DefaultName = "skyWcsConsolidateGen2Gen3"
131
132 def __init__(self, butler=None, **kwargs):
133 super().__init__(**kwargs)
134
135 @utils.inheritDoc(pipeBase.PipelineTask)
136 def runQuantum(self, butlerQC, inputRefs, outputRefs):
137 visit = butlerQC.quantum.dataId['visit']
138
139 schema = afwTable.ExposureTable.makeMinimalSchema()
140 schema.addField('visit', type='L', doc='visit number')
141
142 metadata = dafBase.PropertyList()
143 metadata.add("COMMENT", "Catalog id is detector id, sorted")
144 metadata.add("COMMENT", "Only detectors with data have entries")
145
146 skyWcsCat = afwTable.ExposureCatalog(schema)
147 skyWcsCat.setMetadata(metadata)
148 skyWcsCat.reserve(len(inputRefs.skyWcsList))
149
150 skyWcsList = butlerQC.get(inputRefs.skyWcsList)
151 for dataRef in skyWcsList:
152 detector = dataRef.dataId['detector']
153 skyWcs = dataRef.get()
154 rec = skyWcsCat.addNew()
155 rec['id'] = detector
156 rec['visit'] = visit
157 rec.setWcs(skyWcs)
158
159 skyWcsCat.sort()
160
161 butlerQC.put(skyWcsCat, outputRefs.skyWcsTractCatalog)
Custom catalog class for ExposureRecord/Table.
Definition: Exposure.h:311
Class for storing ordered metadata with comments.
Definition: PropertyList.h:68