22 from __future__
import absolute_import, division, print_function
33 from .selectImages
import WcsSelectImagesTask, SelectStruct
34 from .coaddInputRecorder
import CoaddInputRecorderTask
35 from .scaleVariance
import ScaleVarianceTask
38 from lsst.meas.mosaic
import applyMosaicResults
40 applyMosaicResults =
None 42 __all__ = [
"CoaddBaseTask",
"getSkyInfo"]
46 """!Configuration parameters for CoaddBaseTask 48 \anchor CoaddBaseConfig_ 50 \brief Configuration parameters shared between MakeCoaddTempExp and AssembleCoadd 52 coaddName = pexConfig.Field(
53 doc=
"Coadd name: typically one of deep or goodSeeing.",
57 select = pexConfig.ConfigurableField(
58 doc=
"Image selection subtask.",
59 target=WcsSelectImagesTask,
61 badMaskPlanes = pexConfig.ListField(
63 doc=
"Mask planes that, if set, the associated pixel should not be included in the coaddTempExp.",
66 inputRecorder = pexConfig.ConfigurableField(
67 doc=
"Subtask that helps fill CoaddInputs catalogs added to the final Exposure",
68 target=CoaddInputRecorderTask
70 doPsfMatch = pexConfig.Field(
72 doc=
"Match to modelPsf? Deprecated. Sets makePsfMatched=True, makeDirect=False",
75 modelPsf = measAlg.GaussianPsfFactory.makeField(doc=
"Model Psf factory")
76 doApplyUberCal = pexConfig.Field(
78 doc=
"Apply meas_mosaic ubercal results to input calexps?",
81 matchingKernelSize = pexConfig.Field(
83 doc=
"Size in pixels of matching kernel. Must be odd.",
85 check=
lambda x: x % 2 == 1
93 return pipeBase.TaskRunner.getTargetList(parsedCmd, selectDataList=parsedCmd.selectId.dataList,
98 """!Base class for coaddition. 100 Subclasses must specify _DefaultName 102 ConfigClass = CoaddBaseConfig
103 RunnerClass = CoaddTaskRunner
106 pipeBase.Task.__init__(self, *args, **kwargs)
107 self.makeSubtask(
"select")
108 self.makeSubtask(
"inputRecorder")
112 \brief Select exposures to coadd 114 Get the corners of the bbox supplied in skyInfo using \ref afwGeom.Box2D and convert the pixel 115 positions of the bbox corners to sky coordinates using \ref skyInfo.wcs.pixelToSky. Use the 116 \ref WcsSelectImagesTask_ "WcsSelectImagesTask" to select exposures that lie inside the patch 117 indicated by the dataRef. 119 \param[in] patchRef data reference for sky map patch. Must include keys "tract", "patch", 120 plus the camera-specific filter key (e.g. "filter" or "band") 121 \param[in] skyInfo geometry for the patch; output from getSkyInfo 122 \return a list of science exposures to coadd, as butler data references 126 cornerPosList = afwGeom.Box2D(skyInfo.bbox).getCorners()
127 coordList = [skyInfo.wcs.pixelToSky(pos)
for pos
in cornerPosList]
128 return self.select.runDataRef(patchRef, coordList, selectDataList=selectDataList).dataRefList
132 \brief Use \ref getSkyinfo to return the skyMap, tract and patch information, wcs and the outer bbox 135 \param[in] patchRef data reference for sky map. Must include keys "tract" and "patch" 137 \return pipe_base Struct containing: 139 - tractInfo: information for chosen tract of sky map 140 - patchInfo: information about chosen patch of tract 142 - bbox: outer bbox of patch, as an afwGeom Box2I 144 return getSkyInfo(coaddName=self.config.coaddName, patchRef=patchRef)
147 """!Return one "calexp" calibrated exposure 149 @param[in] dataRef a sensor-level data reference 150 @param[in] bgSubtracted return calexp with background subtracted? If False get the 151 calexp's background background model and add it to the calexp. 152 @return calibrated exposure 154 If config.doApplyUberCal, meas_mosaic calibrations will be applied to 155 the returned exposure using applyMosaicResults. 157 exposure = dataRef.get(
"calexp", immediate=
True)
159 background = dataRef.get(
"calexpBackground", immediate=
True)
160 mi = exposure.getMaskedImage()
161 mi += background.getImage()
163 if not self.config.doApplyUberCal:
165 if applyMosaicResults
is None:
167 "Cannot use improved calibrations for %s because meas_mosaic could not be imported." 175 """Return coadd name for given warpType and task config 180 Either 'direct' or 'psfMatched' 184 CoaddDatasetName : `string` 186 suffix =
"" if warpType ==
"direct" else warpType[0].upper() + warpType[1:]
187 return self.config.coaddName +
"Coadd" + suffix
190 """Return warp name for given warpType and task config 195 Either 'direct' or 'psfMatched' 199 WarpDatasetName : `string` 201 return self.config.coaddName +
"Coadd_" + warpType +
"Warp" 204 def _makeArgumentParser(cls):
205 """Create an argument parser 207 parser = pipeBase.ArgumentParser(name=cls._DefaultName)
208 parser.add_id_argument(
"--id",
"deepCoadd", help=
"data ID, e.g. --id tract=12345 patch=1,2",
209 ContainerClass=CoaddDataIdContainer)
210 parser.add_id_argument(
"--selectId",
"calexp", help=
"data ID, e.g. --selectId visit=6789 ccd=0..9",
211 ContainerClass=SelectDataIdContainer)
214 def _getConfigName(self):
215 """Return the name of the config dataset 217 return "%s_%s_config" % (self.config.coaddName, self._DefaultName)
219 def _getMetadataName(self):
220 """Return the name of the metadata dataset 222 return "%s_%s_metadata" % (self.config.coaddName, self._DefaultName)
226 \brief Convenience method to provide the bitmask from the mask plane names 228 return afwImage.Mask.getPlaneBitMask(self.config.badMaskPlanes)
233 \brief A dataId container for inputs to be selected. 235 Read the header (including the size and Wcs) for all specified 236 inputs and pass those along, ultimately for the SelectImagesTask. 237 This is most useful when used with multiprocessing, as input headers are 242 """Add a dataList containing useful information for selecting images""" 245 for ref
in self.refList:
247 md = ref.get(
"calexp_md", immediate=
True)
248 wcs = afwGeom.makeSkyWcs(md)
249 data =
SelectStruct(dataRef=ref, wcs=wcs, bbox=afwImage.bboxFromMetadata(md))
250 except FitsError
as e:
251 namespace.log.warn(
"Unable to construct Wcs from %s" % (ref.dataId))
258 \brief Return the SkyMap, tract and patch information, wcs, and outer bbox of the patch to be coadded. 260 \param[in] coaddName coadd name; typically one of deep or goodSeeing 261 \param[in] patchRef data reference for sky map. Must include keys "tract" and "patch" 263 \return pipe_base Struct containing: 265 - tractInfo: information for chosen tract of sky map 266 - patchInfo: information about chosen patch of tract 268 - bbox: outer bbox of patch, as an afwGeom Box2I 270 skyMap = patchRef.get(coaddName +
"Coadd_skyMap")
271 tractId = patchRef.dataId[
"tract"]
272 tractInfo = skyMap[tractId]
275 patchIndex = tuple(int(i)
for i
in patchRef.dataId[
"patch"].split(
","))
276 patchInfo = tractInfo.getPatchInfo(patchIndex)
278 return pipeBase.Struct(
282 wcs=tractInfo.getWcs(),
283 bbox=patchInfo.getOuterBBox(),
289 \brief Scale the variance in a maskedImage 291 The variance plane in a convolved or warped image (or a coadd derived 292 from warped images) does not accurately reflect the noise properties of 293 the image because variance has been lost to covariance. This function 294 attempts to correct for this by scaling the variance plane to match 295 the observed variance in the image. This is not perfect (because we're 296 not tracking the covariance) but it's simple and is often good enough. 298 \deprecated Use the ScaleVarianceTask instead. 300 @param maskedImage MaskedImage to operate on; variance will be scaled 301 @param maskPlanes List of mask planes for pixels to reject 302 @param log Log for reporting the renormalization factor; or None 303 @return renormalisation factor 305 config = ScaleVarianceTask.ConfigClass()
306 config.maskPlanes = maskPlanes
308 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...