22 import lsst.pex.config
as pexConfig
31 from .selectImages
import WcsSelectImagesTask, SelectStruct
32 from .coaddInputRecorder
import CoaddInputRecorderTask
33 from .scaleVariance
import ScaleVarianceTask
35 __all__ = [
"CoaddBaseTask",
"getSkyInfo",
"makeSkyInfo",
"makeCoaddSuffix"]
39 """!Configuration parameters for CoaddBaseTask 41 @anchor CoaddBaseConfig_ 43 @brief Configuration parameters shared between MakeCoaddTempExp and AssembleCoadd 45 coaddName = pexConfig.Field(
46 doc=
"Coadd name: typically one of deep or goodSeeing.",
50 select = pexConfig.ConfigurableField(
51 doc=
"Image selection subtask.",
52 target=WcsSelectImagesTask,
54 badMaskPlanes = pexConfig.ListField(
56 doc=
"Mask planes that, if set, the associated pixel should not be included in the coaddTempExp.",
59 inputRecorder = pexConfig.ConfigurableField(
60 doc=
"Subtask that helps fill CoaddInputs catalogs added to the final Exposure",
61 target=CoaddInputRecorderTask
63 doPsfMatch = pexConfig.Field(
65 doc=
"Match to modelPsf? Deprecated. Sets makePsfMatched=True, makeDirect=False",
68 modelPsf = measAlg.GaussianPsfFactory.makeField(doc=
"Model Psf factory")
69 doApplyUberCal = pexConfig.Field(
71 doc=
"Apply jointcal WCS and PhotoCalib results to input calexps?",
74 useMeasMosaic = pexConfig.Field(
76 doc=
"Use meas_mosaic's applyMosaicResultsExposure() to do the photometric " 77 "calibration/wcs update (deprecated).",
80 includeCalibVar = pexConfig.Field(
82 doc=
"Add photometric calibration variance to warp variance plane.",
85 matchingKernelSize = pexConfig.Field(
87 doc=
"Size in pixels of matching kernel. Must be odd.",
89 check=
lambda x: x % 2 == 1
97 return pipeBase.TaskRunner.getTargetList(parsedCmd, selectDataList=parsedCmd.selectId.dataList,
102 """!Base class for coaddition. 104 Subclasses must specify _DefaultName 106 ConfigClass = CoaddBaseConfig
107 RunnerClass = CoaddTaskRunner
111 self.makeSubtask(
"select")
112 self.makeSubtask(
"inputRecorder")
116 @brief Select exposures to coadd 118 Get the corners of the bbox supplied in skyInfo using @ref geom.Box2D and convert the pixel 119 positions of the bbox corners to sky coordinates using @ref skyInfo.wcs.pixelToSky. Use the 120 @ref WcsSelectImagesTask_ "WcsSelectImagesTask" to select exposures that lie inside the patch 121 indicated by the dataRef. 123 @param[in] patchRef data reference for sky map patch. Must include keys "tract", "patch", 124 plus the camera-specific filter key (e.g. "filter" or "band") 125 @param[in] skyInfo geometry for the patch; output from getSkyInfo 126 @return a list of science exposures to coadd, as butler data references 130 cornerPosList =
geom.Box2D(skyInfo.bbox).getCorners()
131 coordList = [skyInfo.wcs.pixelToSky(pos)
for pos
in cornerPosList]
132 return self.select.runDataRef(patchRef, coordList, selectDataList=selectDataList).dataRefList
136 @brief Use @ref getSkyinfo to return the skyMap, tract and patch information, wcs and the outer bbox 139 @param[in] patchRef data reference for sky map. Must include keys "tract" and "patch" 141 @return pipe_base Struct containing: 143 - tractInfo: information for chosen tract of sky map 144 - patchInfo: information about chosen patch of tract 146 - bbox: outer bbox of patch, as an geom Box2I 148 return getSkyInfo(coaddName=self.config.coaddName, patchRef=patchRef)
151 """Return coadd name for given warpType and task config 156 Either 'direct' or 'psfMatched' 160 CoaddDatasetName : `string` 165 """Return warp name for given warpType and task config 170 Either 'direct' or 'psfMatched' 174 WarpDatasetName : `string` 176 return self.config.coaddName +
"Coadd_" + warpType +
"Warp" 179 def _makeArgumentParser(cls):
180 """Create an argument parser 182 parser = pipeBase.ArgumentParser(name=cls._DefaultName)
183 parser.add_id_argument(
"--id",
"deepCoadd", help=
"data ID, e.g. --id tract=12345 patch=1,2",
184 ContainerClass=CoaddDataIdContainer)
185 parser.add_id_argument(
"--selectId",
"calexp", help=
"data ID, e.g. --selectId visit=6789 ccd=0..9",
186 ContainerClass=SelectDataIdContainer)
189 def _getConfigName(self):
190 """Return the name of the config dataset 192 return "%s_%s_config" % (self.config.coaddName, self._DefaultName)
194 def _getMetadataName(self):
195 """Return the name of the metadata dataset 197 return "%s_%s_metadata" % (self.config.coaddName, self._DefaultName)
201 @brief Convenience method to provide the bitmask from the mask plane names 203 return afwImage.Mask.getPlaneBitMask(self.config.badMaskPlanes)
208 @brief A dataId container for inputs to be selected. 210 Read the header (including the size and Wcs) for all specified 211 inputs and pass those along, ultimately for the SelectImagesTask. 212 This is most useful when used with multiprocessing, as input headers are 217 """Add a dataList containing useful information for selecting images""" 220 for ref
in self.refList:
222 md = ref.get(
"calexp_md", immediate=
True)
226 namespace.log.warn(
"Unable to construct Wcs from %s" % (ref.dataId))
233 @brief Return the SkyMap, tract and patch information, wcs, and outer bbox of the patch to be coadded. 235 @param[in] coaddName coadd name; typically one of deep or goodSeeing 236 @param[in] patchRef data reference for sky map. Must include keys "tract" and "patch" 238 @return pipe_base Struct containing: 240 - tractInfo: information for chosen tract of sky map 241 - patchInfo: information about chosen patch of tract 243 - bbox: outer bbox of patch, as an geom Box2I 245 skyMap = patchRef.get(coaddName +
"Coadd_skyMap")
246 return makeSkyInfo(skyMap, patchRef.dataId[
"tract"], patchRef.dataId[
"patch"])
250 """Return SkyInfo Struct 252 Constructs SkyInfo used by coaddition tasks for multiple 257 skyMap : `lsst.skyMap.SkyMap` 259 patchId : str or int or tuple of int 260 Either Gen2-style comma delimited string (e.g. '4,5'), 261 tuple of integers (e.g (4, 5), Gen3-style integer. 263 tractInfo = skyMap[tractId]
265 if isinstance(patchId, str)
and ',' in patchId:
267 patchIndex = tuple(int(i)
for i
in patchId.split(
","))
271 patchInfo = tractInfo.getPatchInfo(patchIndex)
273 return pipeBase.Struct(
277 wcs=tractInfo.getWcs(),
278 bbox=patchInfo.getOuterBBox(),
284 @brief Scale the variance in a maskedImage 286 The variance plane in a convolved or warped image (or a coadd derived 287 from warped images) does not accurately reflect the noise properties of 288 the image because variance has been lost to covariance. This function 289 attempts to correct for this by scaling the variance plane to match 290 the observed variance in the image. This is not perfect (because we're 291 not tracking the covariance) but it's simple and is often good enough. 293 @deprecated Use the ScaleVarianceTask instead. 295 @param maskedImage MaskedImage to operate on; variance will be scaled 296 @param maskPlanes List of mask planes for pixels to reject 297 @param log Log for reporting the renormalization factor; or None 298 @return renormalisation factor 300 config = ScaleVarianceTask.ConfigClass()
301 config.maskPlanes = maskPlanes
303 return task.run(maskedImage)
307 """Return coadd suffix for warpType 312 Either 'direct' or 'psfMatched' 316 CoaddSuffix : `string` 318 suffix =
"" if warpType ==
"direct" else warpType[0].upper() + warpType[1:]
def getCoaddDatasetName(self, warpType="direct")
def makeDataRefList(self, namespace)
Base class for coaddition.
A floating-point coordinate rectangle geometry.
Configuration parameters for CoaddBaseTask.
A dataId container for inputs to be selected.
def makeSkyInfo(skyMap, tractId, patchId)
std::shared_ptr< FrameSet > append(FrameSet const &first, FrameSet const &second)
Construct a FrameSet that performs two transformations in series.
Fit spatial kernel using approximate fluxes for candidates, and solving a linear system of equations...
def makeCoaddSuffix(warpType="direct")
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 __init__(self, kwargs)
def getTargetList(parsedCmd, kwargs)
def selectExposures(self, patchRef, skyInfo=None, selectDataList=[])
Select exposures to coadd.
std::shared_ptr< SkyWcs > makeSkyWcs(TransformPoint2ToPoint2 const &pixelsToFieldAngle, lsst::geom::Angle const &orientation, bool flipX, lsst::geom::SpherePoint const &boresight, std::string const &projection="TAN")
Construct a FITS SkyWcs from camera geometry.
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...
Backwards-compatibility support for depersisting the old Calib (FluxMag0/FluxMag0Err) objects...
lsst::geom::Box2I bboxFromMetadata(daf::base::PropertySet &metadata)
Determine the image bounding box from its metadata (FITS header)