30 from .selectImages
import WcsSelectImagesTask, SelectStruct
31 from .coaddInputRecorder
import CoaddInputRecorderTask
32 from .scaleVariance
import ScaleVarianceTask
35 from lsst.meas.mosaic
import applyMosaicResults
37 applyMosaicResults =
None 39 __all__ = [
"CoaddBaseTask",
"getSkyInfo"]
43 """!Configuration parameters for CoaddBaseTask 45 @anchor CoaddBaseConfig_ 47 @brief Configuration parameters shared between MakeCoaddTempExp and AssembleCoadd 49 coaddName = pexConfig.Field(
50 doc=
"Coadd name: typically one of deep or goodSeeing.",
54 select = pexConfig.ConfigurableField(
55 doc=
"Image selection subtask.",
56 target=WcsSelectImagesTask,
58 badMaskPlanes = pexConfig.ListField(
60 doc=
"Mask planes that, if set, the associated pixel should not be included in the coaddTempExp.",
63 inputRecorder = pexConfig.ConfigurableField(
64 doc=
"Subtask that helps fill CoaddInputs catalogs added to the final Exposure",
65 target=CoaddInputRecorderTask
67 doPsfMatch = pexConfig.Field(
69 doc=
"Match to modelPsf? Deprecated. Sets makePsfMatched=True, makeDirect=False",
72 modelPsf = measAlg.GaussianPsfFactory.makeField(doc=
"Model Psf factory")
73 doApplyUberCal = pexConfig.Field(
75 doc=
"Apply meas_mosaic ubercal results to input calexps?",
78 matchingKernelSize = pexConfig.Field(
80 doc=
"Size in pixels of matching kernel. Must be odd.",
82 check=
lambda x: x % 2 == 1
90 return pipeBase.TaskRunner.getTargetList(parsedCmd, selectDataList=parsedCmd.selectId.dataList,
95 """!Base class for coaddition. 97 Subclasses must specify _DefaultName 99 ConfigClass = CoaddBaseConfig
100 RunnerClass = CoaddTaskRunner
103 pipeBase.Task.__init__(self, *args, **kwargs)
104 self.makeSubtask(
"select")
105 self.makeSubtask(
"inputRecorder")
109 @brief Select exposures to coadd 111 Get the corners of the bbox supplied in skyInfo using @ref afwGeom.Box2D and convert the pixel 112 positions of the bbox corners to sky coordinates using @ref skyInfo.wcs.pixelToSky. Use the 113 @ref WcsSelectImagesTask_ "WcsSelectImagesTask" to select exposures that lie inside the patch 114 indicated by the dataRef. 116 @param[in] patchRef data reference for sky map patch. Must include keys "tract", "patch", 117 plus the camera-specific filter key (e.g. "filter" or "band") 118 @param[in] skyInfo geometry for the patch; output from getSkyInfo 119 @return a list of science exposures to coadd, as butler data references 123 cornerPosList = afwGeom.Box2D(skyInfo.bbox).getCorners()
124 coordList = [skyInfo.wcs.pixelToSky(pos)
for pos
in cornerPosList]
125 return self.select.runDataRef(patchRef, coordList, selectDataList=selectDataList).dataRefList
129 @brief Use @ref getSkyinfo to return the skyMap, tract and patch information, wcs and the outer bbox 132 @param[in] patchRef data reference for sky map. Must include keys "tract" and "patch" 134 @return pipe_base Struct containing: 136 - tractInfo: information for chosen tract of sky map 137 - patchInfo: information about chosen patch of tract 139 - bbox: outer bbox of patch, as an afwGeom Box2I 141 return getSkyInfo(coaddName=self.config.coaddName, patchRef=patchRef)
144 """!Return one "calexp" calibrated exposure 146 @param[in] dataRef a sensor-level data reference 147 @param[in] bgSubtracted return calexp with background subtracted? If False get the 148 calexp's background background model and add it to the calexp. 149 @return calibrated exposure 151 If config.doApplyUberCal, meas_mosaic calibrations will be applied to 152 the returned exposure using applyMosaicResults. 154 exposure = dataRef.get(
"calexp", immediate=
True)
156 background = dataRef.get(
"calexpBackground", immediate=
True)
157 mi = exposure.getMaskedImage()
158 mi += background.getImage()
160 if not self.config.doApplyUberCal:
162 if applyMosaicResults
is None:
164 "Cannot use improved calibrations for %s because meas_mosaic could not be imported." 172 """Return coadd name for given warpType and task config 177 Either 'direct' or 'psfMatched' 181 CoaddDatasetName : `string` 183 suffix =
"" if warpType ==
"direct" else warpType[0].upper() + warpType[1:]
184 return self.config.coaddName +
"Coadd" + suffix
187 """Return warp name for given warpType and task config 192 Either 'direct' or 'psfMatched' 196 WarpDatasetName : `string` 198 return self.config.coaddName +
"Coadd_" + warpType +
"Warp" 201 def _makeArgumentParser(cls):
202 """Create an argument parser 204 parser = pipeBase.ArgumentParser(name=cls._DefaultName)
205 parser.add_id_argument(
"--id",
"deepCoadd", help=
"data ID, e.g. --id tract=12345 patch=1,2",
206 ContainerClass=CoaddDataIdContainer)
207 parser.add_id_argument(
"--selectId",
"calexp", help=
"data ID, e.g. --selectId visit=6789 ccd=0..9",
208 ContainerClass=SelectDataIdContainer)
211 def _getConfigName(self):
212 """Return the name of the config dataset 214 return "%s_%s_config" % (self.config.coaddName, self._DefaultName)
216 def _getMetadataName(self):
217 """Return the name of the metadata dataset 219 return "%s_%s_metadata" % (self.config.coaddName, self._DefaultName)
223 @brief Convenience method to provide the bitmask from the mask plane names 225 return afwImage.Mask.getPlaneBitMask(self.config.badMaskPlanes)
230 @brief A dataId container for inputs to be selected. 232 Read the header (including the size and Wcs) for all specified 233 inputs and pass those along, ultimately for the SelectImagesTask. 234 This is most useful when used with multiprocessing, as input headers are 239 """Add a dataList containing useful information for selecting images""" 242 for ref
in self.refList:
244 md = ref.get(
"calexp_md", immediate=
True)
245 wcs = afwGeom.makeSkyWcs(md)
246 data =
SelectStruct(dataRef=ref, wcs=wcs, bbox=afwImage.bboxFromMetadata(md))
247 except FitsError
as e:
248 namespace.log.warn(
"Unable to construct Wcs from %s" % (ref.dataId))
255 @brief Return the SkyMap, tract and patch information, wcs, and outer bbox of the patch to be coadded. 257 @param[in] coaddName coadd name; typically one of deep or goodSeeing 258 @param[in] patchRef data reference for sky map. Must include keys "tract" and "patch" 260 @return pipe_base Struct containing: 262 - tractInfo: information for chosen tract of sky map 263 - patchInfo: information about chosen patch of tract 265 - bbox: outer bbox of patch, as an afwGeom Box2I 267 skyMap = patchRef.get(coaddName +
"Coadd_skyMap")
268 tractId = patchRef.dataId[
"tract"]
269 tractInfo = skyMap[tractId]
272 patchIndex = tuple(int(i)
for i
in patchRef.dataId[
"patch"].split(
","))
273 patchInfo = tractInfo.getPatchInfo(patchIndex)
275 return pipeBase.Struct(
279 wcs=tractInfo.getWcs(),
280 bbox=patchInfo.getOuterBBox(),
286 @brief Scale the variance in a maskedImage 288 The variance plane in a convolved or warped image (or a coadd derived 289 from warped images) does not accurately reflect the noise properties of 290 the image because variance has been lost to covariance. This function 291 attempts to correct for this by scaling the variance plane to match 292 the observed variance in the image. This is not perfect (because we're 293 not tracking the covariance) but it's simple and is often good enough. 295 @deprecated Use the ScaleVarianceTask instead. 297 @param maskedImage MaskedImage to operate on; variance will be scaled 298 @param maskPlanes List of mask planes for pixels to reject 299 @param log Log for reporting the renormalization factor; or None 300 @return renormalisation factor 302 config = ScaleVarianceTask.ConfigClass()
303 config.maskPlanes = maskPlanes
305 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...