LSST Applications g0b6bd0c080+a72a5dd7e6,g1182afd7b4+2a019aa3bb,g17e5ecfddb+2b8207f7de,g1d67935e3f+06cf436103,g38293774b4+ac198e9f13,g396055baef+6a2097e274,g3b44f30a73+6611e0205b,g480783c3b1+98f8679e14,g48ccf36440+89c08d0516,g4b93dc025c+98f8679e14,g5c4744a4d9+a302e8c7f0,g613e996a0d+e1c447f2e0,g6c8d09e9e7+25247a063c,g7271f0639c+98f8679e14,g7a9cd813b8+124095ede6,g9d27549199+a302e8c7f0,ga1cf026fa3+ac198e9f13,ga32aa97882+7403ac30ac,ga786bb30fb+7a139211af,gaa63f70f4e+9994eb9896,gabf319e997+ade567573c,gba47b54d5d+94dc90c3ea,gbec6a3398f+06cf436103,gc6308e37c7+07dd123edb,gc655b1545f+ade567573c,gcc9029db3c+ab229f5caf,gd01420fc67+06cf436103,gd877ba84e5+06cf436103,gdb4cecd868+6f279b5b48,ge2d134c3d5+cc4dbb2e3f,ge448b5faa6+86d1ceac1d,gecc7e12556+98f8679e14,gf3ee170dca+25247a063c,gf4ac96e456+ade567573c,gf9f5ea5b4d+ac198e9f13,gff490e6085+8c2580be5c,w.2022.27
LSST Data Management Base Package
fgcmCalibrateTractTable.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"""Class for running fgcmcal on a single tract using sourceTable_visit tables.
24"""
25import numpy as np
26
27import lsst.pipe.base as pipeBase
28from lsst.pipe.base import connectionTypes
29from lsst.meas.algorithms import ReferenceObjectLoader, LoadReferenceObjectsConfig
30import lsst.afw.table as afwTable
31
32from .fgcmBuildStarsTable import FgcmBuildStarsTableTask
33from .fgcmCalibrateTractBase import (FgcmCalibrateTractConfigBase,
34 FgcmCalibrateTractBaseTask)
35from .utilities import lookupStaticCalibrations
36
37__all__ = ['FgcmCalibrateTractTableConfig', 'FgcmCalibrateTractTableTask']
38
39
40class FgcmCalibrateTractTableConnections(pipeBase.PipelineTaskConnections,
41 dimensions=("instrument",
42 "tract",)):
43 camera = connectionTypes.PrerequisiteInput(
44 doc="Camera instrument",
45 name="camera",
46 storageClass="Camera",
47 dimensions=("instrument",),
48 lookupFunction=lookupStaticCalibrations,
49 isCalibration=True,
50 )
51
52 fgcmLookUpTable = connectionTypes.PrerequisiteInput(
53 doc=("Atmosphere + instrument look-up-table for FGCM throughput and "
54 "chromatic corrections."),
55 name="fgcmLookUpTable",
56 storageClass="Catalog",
57 dimensions=("instrument",),
58 deferLoad=True,
59 )
60
61 sourceSchema = connectionTypes.InitInput(
62 doc="Schema for source catalogs",
63 name="src_schema",
64 storageClass="SourceCatalog",
65 )
66
67 refCat = connectionTypes.PrerequisiteInput(
68 doc="Reference catalog to use for photometric calibration",
69 name="cal_ref_cat",
70 storageClass="SimpleCatalog",
71 dimensions=("skypix",),
72 deferLoad=True,
73 multiple=True,
74 )
75
76 source_catalogs = connectionTypes.Input(
77 doc="Source table in parquet format, per visit",
78 name="sourceTable_visit",
79 storageClass="DataFrame",
80 dimensions=("instrument", "visit"),
81 deferLoad=True,
82 multiple=True,
83 )
84
85 visitSummary = connectionTypes.Input(
86 doc="Per-visit summary statistics table",
87 name="visitSummary",
88 storageClass="ExposureCatalog",
89 dimensions=("instrument", "visit"),
90 deferLoad=True,
91 multiple=True,
92 )
93
94 background = connectionTypes.Input(
95 doc="Calexp background model",
96 name="calexpBackground",
97 storageClass="Background",
98 dimensions=("instrument", "visit", "detector"),
99 deferLoad=True,
100 multiple=True,
101 )
102
103 fgcmPhotoCalib = connectionTypes.Output(
104 doc="Per-tract, per-visit photoCalib exposure catalogs produced from fgcm calibration",
105 name="fgcmPhotoCalibTractCatalog",
106 storageClass="ExposureCatalog",
107 dimensions=("instrument", "tract", "visit",),
108 multiple=True,
109 )
110
111 fgcmTransmissionAtmosphere = connectionTypes.Output(
112 doc="Per-visit atmosphere transmission files produced from fgcm calibration",
113 name="transmission_atmosphere_fgcm_tract",
114 storageClass="TransmissionCurve",
115 dimensions=("instrument", "tract", "visit",),
116 multiple=True,
117 )
118
119 fgcmRepeatability = connectionTypes.Output(
120 doc="Per-band raw repeatability numbers in the fgcm tract calibration",
121 name="fgcmRawRepeatability",
122 storageClass="Catalog",
123 dimensions=("instrument", "tract",),
124 multiple=False,
125 )
126
127 def __init__(self, *, config=None):
128 super().__init__(config=config)
129
130 # The ref_dataset_name will be deprecated with Gen2
131 loaderName = config.fgcmBuildStars.fgcmLoadReferenceCatalog.refObjLoader.ref_dataset_name
132 if config.connections.refCat != loaderName:
133 raise ValueError("connections.refCat must be the same as "
134 "config.fgcmBuildStars.fgcmLoadReferenceCatalog.refObjLoader.ref_dataset_name")
135 if config.fgcmOutputProducts.doReferenceCalibration:
136 loaderName = config.fgcmOutputProducts.refObjLoader.ref_dataset_name
137 if config.connections.refCat != loaderName:
138 raise ValueError("connections.refCat must be the same as "
139 "config.fgcmOutputProducts.refObjLoader.ref_dataset_name")
140
141 if not config.fgcmBuildStars.doModelErrorsWithBackground:
142 self.inputs.remove("background")
143
144 if not config.fgcmOutputProducts.doAtmosphereOutput:
145 self.prerequisiteInputs.remove("fgcmAtmosphereParameters")
146 if not config.fgcmOutputProducts.doZeropointOutput:
147 self.prerequisiteInputs.remove("fgcmZeropoints")
148
149
151 pipelineConnections=FgcmCalibrateTractTableConnections):
152 """Config for FgcmCalibrateTractTable task"""
153 def setDefaults(self):
154 super().setDefaults()
155
156 # For the Table version of CalibrateTract, use the associated
157 # Table version of the BuildStars task.
158 self.fgcmBuildStarsfgcmBuildStars.retarget(FgcmBuildStarsTableTask)
159 # For tract mode, we set a very high effective density cut.
160 self.fgcmBuildStarsfgcmBuildStars.densityCutMaxPerPixel = 10000
161
162
164 """
165 Calibrate a single tract using fgcmcal, using sourceTable_visit (parquet)
166 input catalogs.
167 """
168 ConfigClass = FgcmCalibrateTractTableConfig
169 _DefaultName = "fgcmCalibrateTractTable"
170
171 canMultiprocess = False
172
173 def __init__(self, initInputs=None, **kwargs):
174 super().__init__(initInputs=initInputs, **kwargs)
175 if initInputs is not None:
176 self.sourceSchemasourceSchema = initInputs["sourceSchema"].schema
177
178 def runQuantum(self, butlerQC, inputRefs, outputRefs):
179 handleDict = butlerQC.get(inputRefs)
180
181 self.log.info("Running with %d sourceTable_visit handles", (len(handleDict['source_catalogs'])))
182
183 # Run the build stars tasks
184 tract = butlerQC.quantum.dataId['tract']
185
186 handleDict['sourceSchema'] = self.sourceSchemasourceSchema
187
188 sourceTableHandles = handleDict['source_catalogs']
189 sourceTableHandleDict = {sourceTableHandle.dataId['visit']: sourceTableHandle for
190 sourceTableHandle in sourceTableHandles}
191
192 visitSummaryHandles = handleDict['visitSummary']
193 visitSummaryHandleDict = {visitSummaryHandle.dataId['visit']: visitSummaryHandle for
194 visitSummaryHandle in visitSummaryHandles}
195
196 handleDict['sourceTableHandleDict'] = sourceTableHandleDict
197 handleDict['visitSummaryHandleDict'] = visitSummaryHandleDict
198
199 # And the outputs
200 if self.config.fgcmOutputProducts.doZeropointOutput:
201 photoCalibRefDict = {photoCalibRef.dataId.byName()['visit']:
202 photoCalibRef for photoCalibRef in outputRefs.fgcmPhotoCalib}
203 handleDict['fgcmPhotoCalibs'] = photoCalibRefDict
204
205 if self.config.fgcmOutputProducts.doAtmosphereOutput:
206 atmRefDict = {atmRef.dataId.byName()['visit']: atmRef for
207 atmRef in outputRefs.fgcmTransmissionAtmosphere}
208 handleDict['fgcmTransmissionAtmospheres'] = atmRefDict
209
210 if self.config.fgcmBuildStars.doReferenceMatches:
211 refConfig = LoadReferenceObjectsConfig()
212 refConfig.filterMap = self.config.fgcmBuildStars.fgcmLoadReferenceCatalog.filterMap
213 loader = ReferenceObjectLoader(dataIds=[ref.datasetRef.dataId
214 for ref in inputRefs.refCat],
215 refCats=butlerQC.get(inputRefs.refCat),
216 config=refConfig,
217 log=self.log)
218 buildStarsRefObjLoader = loader
219 else:
220 buildStarsRefObjLoader = None
221
222 if self.config.fgcmOutputProducts.doReferenceCalibration:
223 refConfig = self.config.fgcmOutputProducts.refObjLoader
224 loader = ReferenceObjectLoader(dataIds=[ref.datasetRef.dataId
225 for ref in inputRefs.refCat],
226 refCats=butlerQC.get(inputRefs.refCat),
227 config=refConfig,
228 log=self.log)
229 self.fgcmOutputProducts.refObjLoader = loader
230
231 struct = self.runrun(handleDict, tract,
232 buildStarsRefObjLoader=buildStarsRefObjLoader)
233
234 if struct.photoCalibCatalogs is not None:
235 self.log.info("Outputting photoCalib catalogs.")
236 for visit, expCatalog in struct.photoCalibCatalogs:
237 butlerQC.put(expCatalog, photoCalibRefDict[visit])
238 self.log.info("Done outputting photoCalib catalogs.")
239
240 if struct.atmospheres is not None:
241 self.log.info("Outputting atmosphere transmission files.")
242 for visit, atm in struct.atmospheres:
243 butlerQC.put(atm, atmRefDict[visit])
244 self.log.info("Done outputting atmosphere files.")
245
246 # Turn raw repeatability into simple catalog for persistence
247 schema = afwTable.Schema()
248 schema.addField('rawRepeatability', type=np.float64,
249 doc="Per-band raw repeatability in FGCM calibration.")
250 repeatabilityCat = afwTable.BaseCatalog(schema)
251 repeatabilityCat.resize(len(struct.repeatability))
252 repeatabilityCat['rawRepeatability'][:] = struct.repeatability
253
254 butlerQC.put(repeatabilityCat, outputRefs.fgcmRepeatability)
255
256 return
Defines the fields and offsets for a table.
Definition: Schema.h:51
def run(self, handleDict, tract, buildStarsRefObjLoader=None, returnCatalogs=True)
Fit spatial kernel using approximate fluxes for candidates, and solving a linear system of equations.