32 from .selectImages
import WcsSelectImagesTask, SelectStruct
33 from .coaddInputRecorder
import CoaddInputRecorderTask
34 from .scaleVariance
import ScaleVarianceTask
37 from lsst.meas.mosaic
import applyMosaicResults
39 applyMosaicResults =
None 41 __all__ = [
"CoaddBaseTask",
"getSkyInfo"]
45 """!Configuration parameters for CoaddBaseTask 47 \anchor CoaddBaseConfig_ 49 \brief Configuration parameters shared between MakeCoaddTempExp and AssembleCoadd 51 coaddName = pexConfig.Field(
52 doc=
"Coadd name: typically one of deep or goodSeeing.",
56 select = pexConfig.ConfigurableField(
57 doc=
"Image selection subtask.",
58 target=WcsSelectImagesTask,
60 badMaskPlanes = pexConfig.ListField(
62 doc=
"Mask planes that, if set, the associated pixel should not be included in the coaddTempExp.",
65 inputRecorder = pexConfig.ConfigurableField(
66 doc=
"Subtask that helps fill CoaddInputs catalogs added to the final Exposure",
67 target=CoaddInputRecorderTask
69 doPsfMatch = pexConfig.Field(
71 doc=
"Match to modelPsf? Deprecated. Sets makePsfMatched=True, makeDirect=False",
74 modelPsf = measAlg.GaussianPsfFactory.makeField(doc=
"Model Psf factory")
75 doApplyUberCal = pexConfig.Field(
77 doc=
"Apply meas_mosaic ubercal results to input calexps?",
80 matchingKernelSize = pexConfig.Field(
82 doc=
"Size in pixels of matching kernel. Must be odd.",
84 check=
lambda x: x % 2 == 1
92 return pipeBase.TaskRunner.getTargetList(parsedCmd, selectDataList=parsedCmd.selectId.dataList,
97 """!Base class for coaddition. 99 Subclasses must specify _DefaultName 101 ConfigClass = CoaddBaseConfig
102 RunnerClass = CoaddTaskRunner
105 pipeBase.Task.__init__(self, *args, **kwargs)
106 self.makeSubtask(
"select")
107 self.makeSubtask(
"inputRecorder")
111 \brief Select exposures to coadd 113 Get the corners of the bbox supplied in skyInfo using \ref afwGeom.Box2D and convert the pixel 114 positions of the bbox corners to sky coordinates using \ref skyInfo.wcs.pixelToSky. Use the 115 \ref WcsSelectImagesTask_ "WcsSelectImagesTask" to select exposures that lie inside the patch 116 indicated by the dataRef. 118 \param[in] patchRef data reference for sky map patch. Must include keys "tract", "patch", 119 plus the camera-specific filter key (e.g. "filter" or "band") 120 \param[in] skyInfo geometry for the patch; output from getSkyInfo 121 \return a list of science exposures to coadd, as butler data references 125 cornerPosList = afwGeom.Box2D(skyInfo.bbox).getCorners()
126 coordList = [skyInfo.wcs.pixelToSky(pos)
for pos
in cornerPosList]
127 return self.select.runDataRef(patchRef, coordList, selectDataList=selectDataList).dataRefList
131 \brief Use \ref getSkyinfo to return the skyMap, tract and patch information, wcs and the outer bbox 134 \param[in] patchRef data reference for sky map. Must include keys "tract" and "patch" 136 \return pipe_base Struct containing: 138 - tractInfo: information for chosen tract of sky map 139 - patchInfo: information about chosen patch of tract 141 - bbox: outer bbox of patch, as an afwGeom Box2I 143 return getSkyInfo(coaddName=self.config.coaddName, patchRef=patchRef)
146 """!Return one "calexp" calibrated exposure 148 @param[in] dataRef a sensor-level data reference 149 @param[in] bgSubtracted return calexp with background subtracted? If False get the 150 calexp's background background model and add it to the calexp. 151 @return calibrated exposure 153 If config.doApplyUberCal, meas_mosaic calibrations will be applied to 154 the returned exposure using applyMosaicResults. 156 exposure = dataRef.get(
"calexp", immediate=
True)
158 background = dataRef.get(
"calexpBackground", immediate=
True)
159 mi = exposure.getMaskedImage()
160 mi += background.getImage()
162 if not self.config.doApplyUberCal:
164 if applyMosaicResults
is None:
166 "Cannot use improved calibrations for %s because meas_mosaic could not be imported." 174 """Return coadd name for given warpType and task config 179 Either 'direct' or 'psfMatched' 183 CoaddDatasetName : `string` 185 suffix =
"" if warpType ==
"direct" else warpType[0].upper() + warpType[1:]
186 return self.config.coaddName +
"Coadd" + suffix
189 """Return warp name for given warpType and task config 194 Either 'direct' or 'psfMatched' 198 WarpDatasetName : `string` 200 return self.config.coaddName +
"Coadd_" + warpType +
"Warp" 203 def _makeArgumentParser(cls):
204 """Create an argument parser 206 parser = pipeBase.ArgumentParser(name=cls._DefaultName)
207 parser.add_id_argument(
"--id",
"deepCoadd", help=
"data ID, e.g. --id tract=12345 patch=1,2",
208 ContainerClass=CoaddDataIdContainer)
209 parser.add_id_argument(
"--selectId",
"calexp", help=
"data ID, e.g. --selectId visit=6789 ccd=0..9",
210 ContainerClass=SelectDataIdContainer)
213 def _getConfigName(self):
214 """Return the name of the config dataset 216 return "%s_%s_config" % (self.config.coaddName, self._DefaultName)
218 def _getMetadataName(self):
219 """Return the name of the metadata dataset 221 return "%s_%s_metadata" % (self.config.coaddName, self._DefaultName)
225 \brief Convenience method to provide the bitmask from the mask plane names 227 return afwImage.Mask.getPlaneBitMask(self.config.badMaskPlanes)
232 \brief A dataId container for inputs to be selected. 234 Read the header (including the size and Wcs) for all specified 235 inputs and pass those along, ultimately for the SelectImagesTask. 236 This is most useful when used with multiprocessing, as input headers are 241 """Add a dataList containing useful information for selecting images""" 244 for ref
in self.refList:
246 md = ref.get(
"calexp_md", immediate=
True)
247 wcs = afwGeom.makeSkyWcs(md)
248 data =
SelectStruct(dataRef=ref, wcs=wcs, bbox=afwImage.bboxFromMetadata(md))
249 except FitsError
as e:
250 namespace.log.warn(
"Unable to construct Wcs from %s" % (ref.dataId))
257 \brief Return the SkyMap, tract and patch information, wcs, and outer bbox of the patch to be coadded. 259 \param[in] coaddName coadd name; typically one of deep or goodSeeing 260 \param[in] patchRef data reference for sky map. Must include keys "tract" and "patch" 262 \return pipe_base Struct containing: 264 - tractInfo: information for chosen tract of sky map 265 - patchInfo: information about chosen patch of tract 267 - bbox: outer bbox of patch, as an afwGeom Box2I 269 skyMap = patchRef.get(coaddName +
"Coadd_skyMap")
270 tractId = patchRef.dataId[
"tract"]
271 tractInfo = skyMap[tractId]
274 patchIndex = tuple(int(i)
for i
in patchRef.dataId[
"patch"].split(
","))
275 patchInfo = tractInfo.getPatchInfo(patchIndex)
277 return pipeBase.Struct(
281 wcs=tractInfo.getWcs(),
282 bbox=patchInfo.getOuterBBox(),
288 \brief Scale the variance in a maskedImage 290 The variance plane in a convolved or warped image (or a coadd derived 291 from warped images) does not accurately reflect the noise properties of 292 the image because variance has been lost to covariance. This function 293 attempts to correct for this by scaling the variance plane to match 294 the observed variance in the image. This is not perfect (because we're 295 not tracking the covariance) but it's simple and is often good enough. 297 \deprecated Use the ScaleVarianceTask instead. 299 @param maskedImage MaskedImage to operate on; variance will be scaled 300 @param maskPlanes List of mask planes for pixels to reject 301 @param log Log for reporting the renormalization factor; or None 302 @return renormalisation factor 304 config = ScaleVarianceTask.ConfigClass()
305 config.maskPlanes = maskPlanes
307 return task.run(maskedImage)
def getCoaddDatasetName(self, warpType="direct")
def makeDataRefList(self, namespace)
Base class for coaddition.
Configuration parameters for CoaddBaseTask.
A dataId container for inputs to be selected.
def __init__(self, args, kwargs)
def getSkyInfo(self, patchRef)
Use getSkyinfo to return the skyMap, tract and patch information, wcs and the outer bbox of the patch...
def getTempExpDatasetName(self, warpType="direct")
def getBadPixelMask(self)
Convenience method to provide the bitmask from the mask plane names.
def getTargetList(parsedCmd, kwargs)
def selectExposures(self, patchRef, skyInfo=None, selectDataList=[])
Select exposures to coadd.
def getCalExp(self, dataRef, bgSubtracted)
Return one "calexp" calibrated exposure.
def scaleVariance(maskedImage, maskPlanes, log=None)
Scale the variance in a maskedImage.
def getSkyInfo(coaddName, patchRef)
Return the SkyMap, tract and patch information, wcs, and outer bbox of the patch to be coadded...