LSST Applications  21.0.0-172-gfb10e10a+18fedfabac,22.0.0+297cba6710,22.0.0+80564b0ff1,22.0.0+8d77f4f51a,22.0.0+a28f4c53b1,22.0.0+dcf3732eb2,22.0.1-1-g7d6de66+2a20fdde0d,22.0.1-1-g8e32f31+297cba6710,22.0.1-1-geca5380+7fa3b7d9b6,22.0.1-12-g44dc1dc+2a20fdde0d,22.0.1-15-g6a90155+515f58c32b,22.0.1-16-g9282f48+790f5f2caa,22.0.1-2-g92698f7+dcf3732eb2,22.0.1-2-ga9b0f51+7fa3b7d9b6,22.0.1-2-gd1925c9+bf4f0e694f,22.0.1-24-g1ad7a390+a9625a72a8,22.0.1-25-g5bf6245+3ad8ecd50b,22.0.1-25-gb120d7b+8b5510f75f,22.0.1-27-g97737f7+2a20fdde0d,22.0.1-32-gf62ce7b1+aa4237961e,22.0.1-4-g0b3f228+2a20fdde0d,22.0.1-4-g243d05b+871c1b8305,22.0.1-4-g3a563be+32dcf1063f,22.0.1-4-g44f2e3d+9e4ab0f4fa,22.0.1-42-gca6935d93+ba5e5ca3eb,22.0.1-5-g15c806e+85460ae5f3,22.0.1-5-g58711c4+611d128589,22.0.1-5-g75bb458+99c117b92f,22.0.1-6-g1c63a23+7fa3b7d9b6,22.0.1-6-g50866e6+84ff5a128b,22.0.1-6-g8d3140d+720564cf76,22.0.1-6-gd805d02+cc5644f571,22.0.1-8-ge5750ce+85460ae5f3,master-g6e05de7fdc+babf819c66,master-g99da0e417a+8d77f4f51a,w.2021.48
LSST Data Management Base Package
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
26 import lsst.pipe.base as pipeBase
27 from lsst.pipe.base import connectionTypes
28 import lsst.afw.table as afwTable
29 import lsst.daf.base as dafBase
30 import lsst.utils as utils
31 
32 
33 __all__ = ['PhotoCalibConsolidateGen2Gen3Config',
34  'PhotoCalibConsolidateGen2Gen3Connections',
35  'PhotoCalibConsolidateGen2Gen3Task',
36  'SkyWcsConsolidateGen2Gen3Config',
37  'SkyWcsConsolidateGen2Gen3Connections',
38  'SkyWcsConsolidateGen2Gen3Task']
39 
40 
41 class 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 
59 class PhotoCalibConsolidateGen2Gen3Config(pipeBase.PipelineTaskConfig,
60  pipelineConnections=PhotoCalibConsolidateGen2Gen3Connections):
61  def validate(self):
62  super().validate()
63 
64 
65 class 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 
105 class 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 
124 class SkyWcsConsolidateGen2Gen3Config(pipeBase.PipelineTaskConfig,
125  pipelineConnections=SkyWcsConsolidateGen2Gen3Connections):
126  def validate(self):
127  super().validate()
128 
129 
130 class 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)
Custom catalog class for ExposureRecord/Table.
Definition: Exposure.h:311
Class for storing ordered metadata with comments.
Definition: PropertyList.h:68