1 from __future__
import division, absolute_import
32 from .selectImages
import WcsSelectImagesTask, SelectStruct
33 from .coaddInputRecorder
import CoaddInputRecorderTask
36 from lsst.meas.mosaic
import applyMosaicResults
38 applyMosaicResults =
None
40 __all__ = [
"CoaddBaseTask",
"getSkyInfo"]
43 """Config for CoaddBaseTask
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.",
57 default = (
"NO_DATA",),
59 inputRecorder = pexConfig.ConfigurableField(
60 doc =
"Subtask that helps fill CoaddInputs catalogs added to the final Exposure",
61 target = CoaddInputRecorderTask
63 doPsfMatch = pexConfig.Field(dtype=bool, doc=
"Match to modelPsf?", default=
False)
64 modelPsf = measAlg.GaussianPsfFactory.makeField(doc =
"Model Psf factory")
65 doApplyUberCal = pexConfig.Field(
67 doc =
"Apply meas_mosaic ubercal results to input calexps?",
74 return pipeBase.TaskRunner.getTargetList(parsedCmd, selectDataList=parsedCmd.selectId.dataList,
78 """Base class for coaddition.
80 Subclasses must specify _DefaultName
82 ConfigClass = CoaddBaseConfig
83 RunnerClass = CoaddTaskRunner
86 pipeBase.Task.__init__(self, *args, **kwargs)
87 self.makeSubtask(
"select")
88 self.makeSubtask(
"inputRecorder")
91 """!Select exposures to coadd
93 @param[in] patchRef data reference for sky map patch. Must include keys "tract", "patch",
94 plus the camera-specific filter key (e.g. "filter" or "band")
95 @param[in] skyInfo geometry for the patch; output from getSkyInfo
96 @return a list of science exposures to coadd, as butler data references
101 coordList = [skyInfo.wcs.pixelToSky(pos)
for pos
in cornerPosList]
102 return self.select.runDataRef(patchRef, coordList, selectDataList=selectDataList).dataRefList
105 """!Return SkyMap, tract and patch
107 @param[in] patchRef data reference for sky map. Must include keys "tract" and "patch"
109 @return pipe_base Struct containing:
111 - tractInfo: information for chosen tract of sky map
112 - patchInfo: information about chosen patch of tract
114 - bbox: outer bbox of patch, as an afwGeom Box2I
116 return getSkyInfo(coaddName=self.config.coaddName, patchRef=patchRef)
119 """!Return one "calexp" calibrated exposure
121 @param[in] dataRef a sensor-level data reference
122 @param[in] bgSubtracted return calexp with background subtracted? If False get the
123 calexp's background background model and add it to the calexp.
124 @return calibrated exposure
126 If config.doApplyUberCal, meas_mosaic calibrations will be applied to
127 the returned exposure using applyMosaicResults.
129 exposure = dataRef.get(
"calexp", immediate=
True)
131 background = dataRef.get(
"calexpBackground", immediate=
True)
132 mi = exposure.getMaskedImage()
133 mi += background.getImage()
135 if not self.config.doApplyUberCal:
137 if applyMosaicResults
is None:
139 "Cannot use improved calibrations for %s because meas_mosaic could not be imported."
147 return self.config.coaddName +
"Coadd"
150 return self.config.coaddName +
"Coadd_tempExp"
154 """Create an argument parser
156 parser = pipeBase.ArgumentParser(name=cls._DefaultName)
157 parser.add_id_argument(
"--id",
"deepCoadd", help=
"data ID, e.g. --id tract=12345 patch=1,2",
158 ContainerClass=CoaddDataIdContainer)
159 parser.add_id_argument(
"--selectId",
"calexp", help=
"data ID, e.g. --selectId visit=6789 ccd=0..9",
160 ContainerClass=SelectDataIdContainer)
164 """Return the name of the config dataset
166 return "%s_%s_config" % (self.config.coaddName, self._DefaultName)
169 """Return the name of the metadata dataset
171 return "%s_%s_metadata" % (self.config.coaddName, self._DefaultName)
174 """Convenience method to provide the bitmask from the mask plane names"""
175 return afwImage.MaskU.getPlaneBitMask(self.config.badMaskPlanes)
178 """!Write a coadd product through the butler
180 @param[in] dataRef data reference for coadd
181 @param[in,out] obj coadd product to write
182 @param[in] suffix suffix to apply to coadd dataset name
185 if suffix
is not None:
186 objName +=
"_" + suffix
187 self.log.info(
"Persisting %s" % objName)
188 dataRef.put(obj, objName)
191 """A dataId container for inputs to be selected.
193 Read the header (including the size and Wcs) for all specified
194 inputs and pass those along, ultimately for the SelectImagesTask.
195 This is most useful when used with multiprocessing, as input headers are
199 """Add a dataList containing useful information for selecting images"""
202 for ref
in self.refList:
204 md = ref.get(
"calexp_md", immediate=
True)
206 data = SelectStruct(dataRef=ref, wcs=wcs, dims=(md.get(
"NAXIS1"), md.get(
"NAXIS2")))
207 except FitsError
as e:
208 namespace.log.warn(
"Unable to construct Wcs from %s" % (ref.dataId))
210 self.dataList.append(data)
213 """!Return SkyMap, tract and patch
215 @param[in] coaddName coadd name; typically one of deep or goodSeeing
216 @param[in] patchRef data reference for sky map. Must include keys "tract" and "patch"
218 @return pipe_base Struct containing:
220 - tractInfo: information for chosen tract of sky map
221 - patchInfo: information about chosen patch of tract
223 - bbox: outer bbox of patch, as an afwGeom Box2I
225 skyMap = patchRef.get(coaddName +
"Coadd_skyMap")
226 tractId = patchRef.dataId[
"tract"]
227 tractInfo = skyMap[tractId]
230 patchIndex = tuple(int(i)
for i
in patchRef.dataId[
"patch"].split(
","))
231 patchInfo = tractInfo.getPatchInfo(patchIndex)
233 return pipeBase.Struct(
235 tractInfo = tractInfo,
236 patchInfo = patchInfo,
237 wcs = tractInfo.getWcs(),
238 bbox = patchInfo.getOuterBBox(),
def getTempExpDatasetName
def getCalExp
Return one "calexp" calibrated exposure.
def selectExposures
Select exposures to coadd.
Wcs::Ptr makeWcs(coord::Coord const &crval, geom::Point2D const &crpix, double CD11, double CD12, double CD21, double CD22)
Create a Wcs object from crval, crpix, CD, using CD elements (useful from python) ...
def writeCoaddOutput
Write a coadd product through the butler.
def getSkyInfo
Return SkyMap, tract and patch.
def getSkyInfo
Return SkyMap, tract and patch.
A floating-point coordinate rectangle geometry.