23"""Class for running fgcmcal on a single tract using sourceTable_visit tables.
32from .fgcmBuildStarsTable
import FgcmBuildStarsTableTask
33from .fgcmCalibrateTractBase
import (FgcmCalibrateTractConfigBase,
34 FgcmCalibrateTractBaseTask)
35from .utilities
import lookupStaticCalibrations
37__all__ = [
'FgcmCalibrateTractTableConfig',
'FgcmCalibrateTractTableTask']
41 dimensions=(
"instrument",
43 camera = connectionTypes.PrerequisiteInput(
44 doc=
"Camera instrument",
46 storageClass=
"Camera",
47 dimensions=(
"instrument",),
48 lookupFunction=lookupStaticCalibrations,
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",),
61 sourceSchema = connectionTypes.InitInput(
62 doc=
"Schema for source catalogs",
64 storageClass=
"SourceCatalog",
67 refCat = connectionTypes.PrerequisiteInput(
68 doc=
"Reference catalog to use for photometric calibration",
70 storageClass=
"SimpleCatalog",
71 dimensions=(
"skypix",),
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"),
85 visitSummary = connectionTypes.Input(
86 doc=
"Per-visit summary statistics table",
88 storageClass=
"ExposureCatalog",
89 dimensions=(
"instrument",
"visit"),
94 background = connectionTypes.Input(
95 doc=
"Calexp background model",
96 name=
"calexpBackground",
97 storageClass=
"Background",
98 dimensions=(
"instrument",
"visit",
"detector"),
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",),
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",),
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",),
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")
141 if not config.fgcmBuildStars.doModelErrorsWithBackground:
142 self.inputs.remove(
"background")
144 if not config.fgcmOutputProducts.doAtmosphereOutput:
145 self.prerequisiteInputs.remove(
"fgcmAtmosphereParameters")
146 if not config.fgcmOutputProducts.doZeropointOutput:
147 self.prerequisiteInputs.remove(
"fgcmZeropoints")
151 pipelineConnections=FgcmCalibrateTractTableConnections):
152 """Config for FgcmCalibrateTractTable task"""
158 self.
fgcmBuildStarsfgcmBuildStars.retarget(FgcmBuildStarsTableTask)
165 Calibrate a single tract using fgcmcal, using sourceTable_visit (parquet)
168 ConfigClass = FgcmCalibrateTractTableConfig
169 _DefaultName = "fgcmCalibrateTractTable"
171 canMultiprocess =
False
174 super().
__init__(initInputs=initInputs, **kwargs)
175 if initInputs
is not None:
179 handleDict = butlerQC.get(inputRefs)
181 self.log.
info(
"Running with %d sourceTable_visit handles", (len(handleDict[
'source_catalogs'])))
184 tract = butlerQC.quantum.dataId[
'tract']
186 handleDict[
'sourceSchema'] = self.
sourceSchemasourceSchema
188 sourceTableHandles = handleDict[
'source_catalogs']
189 sourceTableHandleDict = {sourceTableHandle.dataId[
'visit']: sourceTableHandle
for
190 sourceTableHandle
in sourceTableHandles}
192 visitSummaryHandles = handleDict[
'visitSummary']
193 visitSummaryHandleDict = {visitSummaryHandle.dataId[
'visit']: visitSummaryHandle
for
194 visitSummaryHandle
in visitSummaryHandles}
196 handleDict[
'sourceTableHandleDict'] = sourceTableHandleDict
197 handleDict[
'visitSummaryHandleDict'] = visitSummaryHandleDict
200 if self.config.fgcmOutputProducts.doZeropointOutput:
201 photoCalibRefDict = {photoCalibRef.dataId.byName()[
'visit']:
202 photoCalibRef
for photoCalibRef
in outputRefs.fgcmPhotoCalib}
203 handleDict[
'fgcmPhotoCalibs'] = photoCalibRefDict
205 if self.config.fgcmOutputProducts.doAtmosphereOutput:
206 atmRefDict = {atmRef.dataId.byName()[
'visit']: atmRef
for
207 atmRef
in outputRefs.fgcmTransmissionAtmosphere}
208 handleDict[
'fgcmTransmissionAtmospheres'] = atmRefDict
210 if self.config.fgcmBuildStars.doReferenceMatches:
212 refConfig.filterMap = self.config.fgcmBuildStars.fgcmLoadReferenceCatalog.filterMap
214 for ref
in inputRefs.refCat],
215 refCats=butlerQC.get(inputRefs.refCat),
218 buildStarsRefObjLoader = loader
220 buildStarsRefObjLoader =
None
222 if self.config.fgcmOutputProducts.doReferenceCalibration:
223 refConfig = self.config.fgcmOutputProducts.refObjLoader
225 for ref
in inputRefs.refCat],
226 refCats=butlerQC.get(inputRefs.refCat),
229 self.fgcmOutputProducts.refObjLoader = loader
231 struct = self.
runrun(handleDict, tract,
232 buildStarsRefObjLoader=buildStarsRefObjLoader)
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.")
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.")
248 schema.addField(
'rawRepeatability', type=np.float64,
249 doc=
"Per-band raw repeatability in FGCM calibration.")
251 repeatabilityCat.resize(len(struct.repeatability))
252 repeatabilityCat[
'rawRepeatability'][:] = struct.repeatability
254 butlerQC.put(repeatabilityCat, outputRefs.fgcmRepeatability)
Defines the fields and offsets for a table.
def run(self, handleDict, tract, buildStarsRefObjLoader=None, returnCatalogs=True)
def __init__(self, *config=None)
def __init__(self, initInputs=None, **kwargs)
def runQuantum(self, butlerQC, inputRefs, outputRefs)
Fit spatial kernel using approximate fluxes for candidates, and solving a linear system of equations.