28 from .utilsLib
import addToCoadd, setCoaddEdgeBits
35 badMaskPlanes = pexConfig.ListField(
37 doc =
"mask planes that, if set, the associated pixel should not be included in the coadd",
38 default = (
"NO_DATA",
"SAT"),
43 """Coadd by weighted addition
45 This class may be subclassed to implement other coadd techniques.
46 Typically this is done by overriding addExposure.
48 ConfigClass = CoaddConfig
50 def __init__(self, bbox, wcs, badMaskPlanes, logName="coadd.utils.Coadd"):
53 @param[in] bbox: bounding box of coadd Exposure with respect to parent (lsst.afw.geom.Box2I):
54 coadd dimensions = bbox.getDimensions(); xy0 = bbox.getMin()
55 @param[in] wcs: WCS of coadd exposure (lsst.afw.math.Wcs)
56 @param[in] badMaskPlanes: mask planes to pay attention to when rejecting masked pixels.
57 Specify as a collection of names.
58 badMaskPlanes should always include "NO_DATA".
59 @param[in] logName: name by which messages are logged
61 self.
_log =
Log(Log.getDefaultLog(), logName)
65 self.
_coadd = afwImage.ExposureF(bbox, wcs)
70 self._statsControl.setNumSigmaClip(3.0)
71 self._statsControl.setNumIter(2)
75 def fromConfig(cls, bbox, wcs, config, logName="coadd.utils.Coadd"):
78 @param[in] bbox: bounding box of coadd Exposure with respect to parent (lsst.afw.geom.Box2I):
79 coadd dimensions = bbox.getDimensions(); xy0 = bbox.getMin()
80 @param[in] wcs: WCS of coadd exposure (lsst.afw.math.Wcs)
81 @param[in] config: coadd config; an instance of CoaddConfig
82 @param[in] logName: name by which messages are logged
87 badMaskPlanes = config.badMaskPlanes,
92 """Add an Exposure to the coadd
94 @param[in] exposure: Exposure to add to coadd; this should be:
95 - background-subtracted or background-matched to the other images being coadded
96 - psf-matched to the desired PSF model (optional)
97 - warped to match the coadd
98 - photometrically scaled to the desired flux magnitude
99 @param[in] weightFactor: extra weight factor for this exposure
102 - overlapBBox: region of overlap between exposure and coadd in parent coordinates (afwGeom.Box2I)
103 - weight: weight with which exposure was added to coadd; weight = weightFactor / clipped mean variance
105 Subclasses may override to preprocess the exposure or change the way it is added to the coadd.
107 maskedImage = exposure.getMaskedImage()
112 meanVar = statObj.getResult(afwMath.MEANCLIP)[0]
113 weight = weightFactor / float(meanVar)
114 if math.isnan(weight):
115 raise RuntimeError(
"Weight is NaN (weightFactor=%s; mean variance=%s)" % (weightFactor, meanVar))
118 filter = exposure.getFilter()
119 self._filterDict.setdefault(filter.getName(), filter)
121 self._log.log(Log.INFO,
"Add exposure to coadd with weight=%0.3g" % (weight,))
126 return overlapBBox, weight
129 """Get the coadd exposure for all exposures you have coadded so far
131 If all exposures in this coadd have the same-named filter then that filter is set in the coadd.
132 Otherwise the coadd will have the default unknown filter.
134 @warning: the Calib is not be set.
137 coaddMaskedImage = self._coadd.getMaskedImage()
138 scaledMaskedImage = coaddMaskedImage.Factory(coaddMaskedImage,
True)
148 scaledExposure.setFilter(self._filterDict.values()[0])
149 return scaledExposure
152 """Return a collection of all the filters seen so far in in addExposure
154 return self._filterDict.values()
157 """Return the bad pixel mask
162 """Return the bounding box of the coadd
167 """Return the wcs of the coadd
172 """Return the weight map for all exposures you have coadded so far
174 The weight map is a float Image of the same dimensions as the coadd; the value of each pixel
175 is the sum of the weights of all exposures that contributed to that pixel.
void setCoaddEdgeBits(lsst::afw::image::Mask< lsst::afw::image::MaskPixel > &coaddMask, lsst::afw::image::Image< WeightPixelT > const &weightMap)
set edge bits of coadd mask based on weight map
a place to record messages and descriptions of the state of processing.
Pass parameters to a Statistics objectA class to pass parameters which control how the stats are calc...
Statistics makeStatistics(afwImage::Mask< afwImage::MaskPixel > const &msk, int const flags, StatisticsControl const &sctrl)
Specialization to handle Masks.
lsst::afw::geom::Box2I addToCoadd(lsst::afw::image::Image< CoaddPixelT > &coadd, lsst::afw::image::Image< WeightPixelT > &weightMap, lsst::afw::image::Image< CoaddPixelT > const &image, WeightPixelT weight)
add good pixels from an image to a coadd and associated weight map
Exposure< ImagePixelT, MaskPixelT, VariancePixelT >::Ptr makeExposure(MaskedImage< ImagePixelT, MaskPixelT, VariancePixelT > &mimage, boost::shared_ptr< Wcs const > wcs=boost::shared_ptr< Wcs const >())