lsst.fgcmcal g34bb90edf1+d0506499b5
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 def _getMetadataName(self):
74 return None
75
76 @utils.inheritDoc(pipeBase.PipelineTask)
77 def runQuantum(self, butlerQC, inputRefs, outputRefs):
78 visit = butlerQC.quantum.dataId['visit']
79
80 schema = afwTable.ExposureTable.makeMinimalSchema()
81 schema.addField('visit', type='I', doc='visit number')
82
83 metadata = dafBase.PropertyList()
84 metadata.add("COMMENT", "Catalog id is detector id, sorted")
85 metadata.add("COMMENT", "Only detectors with data have entries")
86
87 photoCalibCat = afwTable.ExposureCatalog(schema)
88 photoCalibCat.setMetadata(metadata)
89 photoCalibCat.reserve(len(inputRefs.photoCalibList))
90
91 photoCalibList = butlerQC.get(inputRefs.photoCalibList)
92 for dataRef in photoCalibList:
93 detector = dataRef.dataId['detector']
94 photoCalib = dataRef.get()
95 rec = photoCalibCat.addNew()
96 rec['id'] = detector
97 rec['visit'] = visit
98 rec.setPhotoCalib(photoCalib)
99
100 photoCalibCat.sort()
101
102 butlerQC.put(photoCalibCat, outputRefs.photoCalibGlobalCatalog)
103
104
105class SkyWcsConsolidateGen2Gen3Connections(pipeBase.PipelineTaskConnections,
106 dimensions=("instrument", "visit",
107 "skymap", "tract")):
108 skyWcsList = connectionTypes.Input(
109 doc="Per-tract, per-detector wcs calibrations.",
110 name="jointcal_wcs",
111 storageClass="Wcs",
112 dimensions=("instrument", "visit", "detector", "tract", "skymap"),
113 deferLoad=True,
114 multiple=True,
115 )
116 skyWcsTractCatalog = connectionTypes.Output(
117 doc="Per-tract, per-visit wcs calibrations.",
118 name="jointcalSkyWcsCatalog",
119 storageClass="ExposureCatalog",
120 dimensions=("instrument", "visit", "tract"),
121 )
122
123
124class SkyWcsConsolidateGen2Gen3Config(pipeBase.PipelineTaskConfig,
125 pipelineConnections=SkyWcsConsolidateGen2Gen3Connections):
126 def validate(self):
127 super().validate()
128
129
130class SkyWcsConsolidateGen2Gen3Task(pipeBase.PipelineTask):
131 """Consolidate gen2 skywcss into gen3 skywcss."""
132 ConfigClass = SkyWcsConsolidateGen2Gen3Config
133 _DefaultName = "skyWcsConsolidateGen2Gen3"
134
135 def __init__(self, butler=None, **kwargs):
136 super().__init__(**kwargs)
137
138 def _getMetadataName(self):
139 return None
140
141 @utils.inheritDoc(pipeBase.PipelineTask)
142 def runQuantum(self, butlerQC, inputRefs, outputRefs):
143 visit = butlerQC.quantum.dataId['visit']
144
145 schema = afwTable.ExposureTable.makeMinimalSchema()
146 schema.addField('visit', type='I', doc='visit number')
147
148 metadata = dafBase.PropertyList()
149 metadata.add("COMMENT", "Catalog id is detector id, sorted")
150 metadata.add("COMMENT", "Only detectors with data have entries")
151
152 skyWcsCat = afwTable.ExposureCatalog(schema)
153 skyWcsCat.setMetadata(metadata)
154 skyWcsCat.reserve(len(inputRefs.skyWcsList))
155
156 skyWcsList = butlerQC.get(inputRefs.skyWcsList)
157 for dataRef in skyWcsList:
158 detector = dataRef.dataId['detector']
159 skyWcs = dataRef.get()
160 rec = skyWcsCat.addNew()
161 rec['id'] = detector
162 rec['visit'] = visit
163 rec.setWcs(skyWcs)
164
165 skyWcsCat.sort()
166
167 butlerQC.put(skyWcsCat, outputRefs.skyWcsTractCatalog)