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 doApplyExternalPhotoCalib = pexConfig.Field(
72 doc=(
"Whether to apply external photometric calibration via an "
73 "`lsst.afw.image.PhotoCalib` object. Uses the "
74 "`externalPhotoCalibName` field to determine which calibration "
77 useGlobalExternalPhotoCalib = pexConfig.Field(
80 doc=(
"When using doApplyExternalPhotoCalib, use 'global' calibrations "
81 "that are not run per-tract. When False, use per-tract photometric "
84 externalPhotoCalibName = pexConfig.ChoiceField(
87 doc=(
"Type of external PhotoCalib if `doApplyExternalPhotoCalib` is True. "
88 "This field is only used for Gen2 middleware."),
91 "jointcal":
"Use jointcal_photoCalib",
92 "fgcm":
"Use fgcm_photoCalib",
93 "fgcm_tract":
"Use fgcm_tract_photoCalib"
96 doApplyExternalSkyWcs = pexConfig.Field(
99 doc=(
"Whether to apply external astrometric calibration via an "
100 "`lsst.afw.geom.SkyWcs` object. Uses `externalSkyWcsName` "
101 "field to determine which calibration to load.")
103 useGlobalExternalSkyWcs = pexConfig.Field(
106 doc=(
"When using doApplyExternalSkyWcs, use 'global' calibrations "
107 "that are not run per-tract. When False, use per-tract wcs "
110 externalSkyWcsName = pexConfig.ChoiceField(
113 doc=(
"Type of external SkyWcs if `doApplyExternalSkyWcs` is True. "
114 "This field is only used for Gen2 middleware."),
117 "jointcal":
"Use jointcal_wcs"
120 includeCalibVar = pexConfig.Field(
122 doc=
"Add photometric calibration variance to warp variance plane.",
125 matchingKernelSize = pexConfig.Field(
127 doc=
"Size in pixels of matching kernel. Must be odd.",
129 check=
lambda x: x % 2 == 1
137 return pipeBase.TaskRunner.getTargetList(parsedCmd, selectDataList=parsedCmd.selectId.dataList,
142 """!Base class for coaddition.
144 Subclasses must specify _DefaultName
146 ConfigClass = CoaddBaseConfig
147 RunnerClass = CoaddTaskRunner
151 self.makeSubtask(
"select")
152 self.makeSubtask(
"inputRecorder")
156 @brief Select exposures to coadd
158 Get the corners of the bbox supplied in skyInfo using @ref geom.Box2D and convert the pixel
159 positions of the bbox corners to sky coordinates using @ref skyInfo.wcs.pixelToSky. Use the
160 @ref WcsSelectImagesTask_ "WcsSelectImagesTask" to select exposures that lie inside the patch
161 indicated by the dataRef.
163 @param[in] patchRef data reference for sky map patch. Must include keys "tract", "patch",
164 plus the camera-specific filter key (e.g. "filter" or "band")
165 @param[in] skyInfo geometry for the patch; output from getSkyInfo
166 @return a list of science exposures to coadd, as butler data references
170 cornerPosList =
geom.Box2D(skyInfo.bbox).getCorners()
171 coordList = [skyInfo.wcs.pixelToSky(pos)
for pos
in cornerPosList]
172 return self.select.runDataRef(patchRef, coordList, selectDataList=selectDataList).dataRefList
176 @brief Use @ref getSkyinfo to return the skyMap, tract and patch information, wcs and the outer bbox
179 @param[in] patchRef data reference for sky map. Must include keys "tract" and "patch"
181 @return pipe_base Struct containing:
183 - tractInfo: information for chosen tract of sky map
184 - patchInfo: information about chosen patch of tract
186 - bbox: outer bbox of patch, as an geom Box2I
188 return getSkyInfo(coaddName=self.config.coaddName, patchRef=patchRef)
191 """Return coadd name for given warpType and task config
196 Either 'direct' or 'psfMatched'
200 CoaddDatasetName : `string`
205 """Return warp name for given warpType and task config
210 Either 'direct' or 'psfMatched'
214 WarpDatasetName : `string`
216 return self.config.coaddName +
"Coadd_" + warpType +
"Warp"
219 def _makeArgumentParser(cls):
220 """Create an argument parser
222 parser = pipeBase.ArgumentParser(name=cls._DefaultName)
223 parser.add_id_argument(
"--id",
"deepCoadd", help=
"data ID, e.g. --id tract=12345 patch=1,2",
224 ContainerClass=CoaddDataIdContainer)
225 parser.add_id_argument(
"--selectId",
"calexp", help=
"data ID, e.g. --selectId visit=6789 ccd=0..9",
226 ContainerClass=SelectDataIdContainer)
229 def _getConfigName(self):
230 """Return the name of the config dataset
232 return "%s_%s_config" % (self.config.coaddName, self._DefaultName)
234 def _getMetadataName(self):
235 """Return the name of the metadata dataset
237 return "%s_%s_metadata" % (self.config.coaddName, self._DefaultName)
241 @brief Convenience method to provide the bitmask from the mask plane names
243 return afwImage.Mask.getPlaneBitMask(self.config.badMaskPlanes)
248 @brief A dataId container for inputs to be selected.
250 Read the header (including the size and Wcs) for all specified
251 inputs and pass those along, ultimately for the SelectImagesTask.
252 This is most useful when used with multiprocessing, as input headers are
257 """Add a dataList containing useful information for selecting images"""
260 for ref
in self.refList:
262 md = ref.get(
"calexp_md", immediate=
True)
266 namespace.log.warn(
"Unable to construct Wcs from %s" % (ref.dataId))
273 @brief Return the SkyMap, tract and patch information, wcs, and outer bbox of the patch to be coadded.
275 @param[in] coaddName coadd name; typically one of deep or goodSeeing
276 @param[in] patchRef data reference for sky map. Must include keys "tract" and "patch"
278 @return pipe_base Struct containing:
280 - tractInfo: information for chosen tract of sky map
281 - patchInfo: information about chosen patch of tract
283 - bbox: outer bbox of patch, as an geom Box2I
285 skyMap = patchRef.get(coaddName +
"Coadd_skyMap")
286 return makeSkyInfo(skyMap, patchRef.dataId[
"tract"], patchRef.dataId[
"patch"])
290 """Return SkyInfo Struct
292 Constructs SkyInfo used by coaddition tasks for multiple
297 skyMap : `lsst.skyMap.SkyMap`
299 patchId : str or int or tuple of int
300 Either Gen2-style comma delimited string (e.g. '4,5'),
301 tuple of integers (e.g (4, 5), Gen3-style integer.
303 tractInfo = skyMap[tractId]
305 if isinstance(patchId, str)
and ',' in patchId:
307 patchIndex = tuple(int(i)
for i
in patchId.split(
","))
311 patchInfo = tractInfo.getPatchInfo(patchIndex)
313 return pipeBase.Struct(
317 wcs=tractInfo.getWcs(),
318 bbox=patchInfo.getOuterBBox(),
324 @brief Scale the variance in a maskedImage
326 The variance plane in a convolved or warped image (or a coadd derived
327 from warped images) does not accurately reflect the noise properties of
328 the image because variance has been lost to covariance. This function
329 attempts to correct for this by scaling the variance plane to match
330 the observed variance in the image. This is not perfect (because we're
331 not tracking the covariance) but it's simple and is often good enough.
333 @deprecated Use the ScaleVarianceTask instead.
335 @param maskedImage MaskedImage to operate on; variance will be scaled
336 @param maskPlanes List of mask planes for pixels to reject
337 @param log Log for reporting the renormalization factor; or None
338 @return renormalisation factor
340 config = ScaleVarianceTask.ConfigClass()
341 config.maskPlanes = maskPlanes
343 return task.run(maskedImage)
347 """Return coadd suffix for warpType
352 Either 'direct' or 'psfMatched'
356 CoaddSuffix : `string`
358 suffix =
"" if warpType ==
"direct" else warpType[0].upper() + warpType[1:]
363 """Match the order of one list to another, padding if necessary
368 List to be reordered and padded. Elements can be any type.
370 Iterable of values to be compared with outputKeys.
371 Length must match `inputList`
372 outputKeys : iterable
373 Iterable of values to be compared with inputKeys.
375 Any value to be inserted where inputKey not in outputKeys
380 Copy of inputList reordered per outputKeys and padded with `padWith`
381 so that the length matches length of outputKeys.
386 outputList.append(inputList[inputKeys.index(d)])
388 outputList.append(padWith)
A floating-point coordinate rectangle geometry.
Configuration parameters for CoaddBaseTask.
Base class for coaddition.
def getTempExpDatasetName(self, warpType="direct")
def selectExposures(self, patchRef, skyInfo=None, selectDataList=[])
Select exposures to coadd.
def __init__(self, **kwargs)
def getCoaddDatasetName(self, 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 getBadPixelMask(self)
Convenience method to provide the bitmask from the mask plane names.
def getTargetList(parsedCmd, **kwargs)
A dataId container for inputs to be selected.
def makeDataRefList(self, namespace)
std::shared_ptr< FrameSet > append(FrameSet const &first, FrameSet const &second)
Construct a FrameSet that performs two transformations in series.
std::shared_ptr< SkyWcs > makeSkyWcs(daf::base::PropertySet &metadata, bool strip=false)
Construct a SkyWcs from FITS keywords.
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)
Fit spatial kernel using approximate fluxes for candidates, and solving a linear system of equations.
def reorderAndPadList(inputList, inputKeys, outputKeys, padWith=None)
def makeCoaddSuffix(warpType="direct")
def makeSkyInfo(skyMap, tractId, patchId)
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.