30 __all__ = [
"CoaddInputRecorderTask"]
34 """Config for CoaddInputRecorderTask 36 The inputRecorder section of the various coadd tasks' configs should generally agree, 37 or the schemas created by earlier tasks (like MakeCoaddTempExpTask) will not contain 38 the fields filled by later tasks (like AssembleCoaddTask). 41 saveEmptyCcds = pexConfig.Field(
42 dtype=bool, default=
False, optional=
False,
43 doc=(
"Add records for CCDs we iterated over but did not add a coaddTempExp" 44 " due to a lack of unmasked pixels in the coadd footprint.")
46 saveErrorCcds = pexConfig.Field(
47 dtype=bool, default=
False, optional=
False,
48 doc=(
"Add records for CCDs we iterated over but did not add a coaddTempExp" 49 " due to an exception (often due to the calexp not being found on disk).")
51 saveVisitGoodPix = pexConfig.Field(
52 dtype=bool, default=
True, optional=
False,
53 doc=(
"Save the total number of good pixels in each coaddTempExp (redundant with a sum of" 54 " good pixels in associated CCDs)")
56 saveCcdWeights = pexConfig.Field(
57 dtype=bool, default=
True, optional=
False,
58 doc=(
"Save weights in the CCDs table as well as the visits table?" 59 " (This is necessary for easy construction of CoaddPsf, but otherwise duplicate information.)")
64 """A helper class for CoaddInputRecorderTask, managing the CoaddInputs object for that single 65 CoaddTempExp. This will contain a single 'visit' record for the CoaddTempExp and a number of 'ccd' 68 Should generally be created by calling CoaddInputRecorderTask.makeCoaddTempExp(). 74 @param task The CoaddInputRecorderTask that is utilising us 75 @param visitId Identifier (integer) for the visit 76 @param num Number of CCDs for this visit that overlap this 77 patch (for reserving memory) 88 """Add a 'ccd' record for a calexp just added to the CoaddTempExp 90 @param[in] calExp Calibrated exposure just added to the CoaddTempExp, or None in case of 91 failures that should nonetheless be tracked. Should be the original 92 calexp, in that it should contain the original Psf and Wcs, not the 93 warped and/or matched ones. 94 @param[in] ccdId A unique numeric ID for the Exposure. 95 @param[in] nGoodPix Number of good pixels this image will contribute to the CoaddTempExp. 96 If saveEmptyCcds is not set and this value is zero, no record will be 99 if nGoodPix == 0
and not self.
task.config.saveEmptyCcds:
105 record.setI(self.
task.ccdCcdKey, calExp.getDetector().getId())
107 self.
task.log.warn(
"Error getting detector serial number in visit %d; using -1" 109 record.setI(self.
task.ccdCcdKey, -1)
110 record.setI(self.
task.ccdGoodPixKey, nGoodPix)
111 if calExp
is not None:
113 if self.
task.config.saveCcdWeights:
114 record.setD(self.
task.ccdWeightKey, 1.0)
115 record.set(self.
task.ccdFilterKey, calExp.getFilter().getName())
117 def finish(self, coaddTempExp, nGoodPix=None):
118 """Finish creating the CoaddInputs for a CoaddTempExp. 120 @param[in,out] coaddTempExp Exposure object from which to obtain the PSF, WCS, and bounding 121 box for the entry in the 'visits' table. On return, the completed 122 CoaddInputs object will be attached to it. 123 @param[in] nGoodPix Total number of good pixels in the CoaddTempExp; ignored unless 124 saveVisitGoodPix is true. 127 if self.
task.config.saveVisitGoodPix:
129 coaddTempExp.getInfo().setCoaddInputs(self.
coaddInputs)
130 wcs = coaddTempExp.getWcs()
134 apCorrMap = makeCoaddApCorrMap(self.
coaddInputs.ccds, coaddTempExp.getBBox(afwImage.PARENT), wcs)
135 coaddTempExp.getInfo().setApCorrMap(apCorrMap)
137 def _setExposureInfoInRecord(self, exposure, record):
138 """Set exposure info and bbox in an ExposureTable record 140 @param[in] exposure exposure whose info is to be recorded 141 @param[in,out] record record of an ExposureTable to set 143 info = exposure.getInfo()
144 record.setPsf(info.getPsf())
145 record.setWcs(info.getWcs())
146 record.setCalib(info.getCalib())
147 record.setApCorrMap(info.getApCorrMap())
148 record.setValidPolygon(info.getValidPolygon())
149 record.setVisitInfo(info.getVisitInfo())
150 record.setBBox(exposure.getBBox())
151 record.setTransmissionCurve(info.getTransmissionCurve())
156 """Subtask that handles filling a CoaddInputs object for a coadd exposure, tracking the CCDs and 157 visits that went into a coadd. 159 The interface here is a little messy, but I think this is at least partly a product of a bit of 160 messiness in the coadd code it's plugged into. I hope #2590 might result in a better design. 163 ConfigClass = CoaddInputRecorderConfig
166 pipeBase.Task.__init__(self, *args, **kwargs)
168 if self.config.saveVisitGoodPix:
170 doc=
"Number of good pixels in the coaddTempExp")
172 doc=
"Weight for this visit in the coadd")
173 self.
ccdSchema = afwTable.ExposureTable.makeMinimalSchema()
174 self.
ccdCcdKey = self.
ccdSchema.addField(
"ccd", type=numpy.int32, doc=
"cameraGeom CCD serial number")
176 doc=
"Foreign key for the visits (coaddTempExp) catalog")
178 doc=
"Number of good pixels in this CCD")
179 if self.config.saveCcdWeights:
181 doc=
"Weight for this visit in the coadd")
183 doc=
"Filter associated with this visit.")
185 doc=
"Filter associated with this visit.")
188 """Return a CoaddTempExpInputRecorder instance to help with saving a CoaddTempExp's inputs. 190 The visitId may be any number that is unique for each CoaddTempExp that goes into a coadd, 191 but ideally should be something more meaningful that can be used to reconstruct a data ID. 196 """Create a CoaddInputs object with schemas defined by the task configuration""" 200 """Called by AssembleCoaddTask when adding (a subset of) a coaddTempExp to a coadd. The 201 base class impementation extracts the CoaddInputs from the coaddTempExp and appends 202 them to the given coaddInputs, filling in the weight column(s). 204 Note that the passed coaddTempExp may be a subimage, but that this method will only be 205 called for the first subimage 207 Returns the record for the visit to allow subclasses to fill in additional fields. 208 Warns and returns None if the inputRecorder catalogs for the coaddTempExp are not usable. 210 tempExpInputs = coaddTempExp.getInfo().getCoaddInputs()
211 if len(tempExpInputs.visits) != 1:
212 self.log.warn(
"CoaddInputs for coaddTempExp should have exactly one record in visits table " 213 "(found %d). CoaddInputs for this visit will not be saved." 214 % len(tempExpInputs.visits))
216 inputVisitRecord = tempExpInputs.visits[0]
217 outputVisitRecord = coaddInputs.visits.addNew()
218 outputVisitRecord.assign(inputVisitRecord)
220 outputVisitRecord.set(self.
visitFilterKey, coaddTempExp.getFilter().getName())
221 for inputCcdRecord
in tempExpInputs.ccds:
222 if inputCcdRecord.getL(self.
ccdVisitKey) != inputVisitRecord.getId():
223 self.log.warn(
"CoaddInputs for coaddTempExp with id %d contains CCDs with visit=%d. " 224 "CoaddInputs may be unreliable." 225 % (inputVisitRecord.getId(), inputCcdRecord.getL(self.
ccdVisitKey)))
226 outputCcdRecord = coaddInputs.ccds.addNew()
227 outputCcdRecord.assign(inputCcdRecord)
228 if self.config.saveCcdWeights:
230 outputCcdRecord.set(self.
ccdFilterKey, coaddTempExp.getFilter().getName())
231 return inputVisitRecord