603 def run(self, coaddExposures, bbox, wcs):
604 """Warp coadds from multiple tracts to form a template for image diff.
606 Where the tracts overlap, the resulting template image is averaged.
607 The PSF on the template is created by combining the CoaddPsf on each
608 template image into a meta-CoaddPsf.
612 coaddExposures: list of DeferredDatasetHandle to `lsst.afw.image.Exposure`
613 Coadds to be mosaicked
614 bbox : `lsst.geom.Box2I`
615 Template Bounding box of the detector geometry onto which to
616 resample the coaddExposures
617 wcs : `lsst.afw.geom.SkyWcs`
618 Template WCS onto which to resample the coaddExposures
623 return a pipeBase.Struct:
624 - ``outputExposure`` : a template coadd exposure assembled out of patches
630 Raised if no patches overlatp the input detector bbox
634 tractsSchema = afwTable.ExposureTable.makeMinimalSchema()
635 tractKey = tractsSchema.addField(
'tract', type=np.int32, doc=
'Which tract')
636 patchKey = tractsSchema.addField(
'patch', type=np.int32, doc=
'Which patch')
637 weightKey = tractsSchema.addField(
'weight', type=float, doc=
'Weight for each tract, should be 1')
641 bbox.grow(self.config.templateBorderSize)
648 for coaddExposure
in coaddExposures:
649 coaddPatch = coaddExposure.get()
652 warped = self.warper.
warpExposure(finalWcs, coaddPatch, maxBBox=finalBBox)
655 if not np.any(np.isfinite(warped.image.array)):
656 self.log.
info(
"No overlap for warped %s. Skipping" % coaddExposure.ref.dataId)
659 exp = afwImage.ExposureF(finalBBox, finalWcs)
660 exp.maskedImage.set(np.nan, afwImage.Mask.getPlaneBitMask(
"NO_DATA"), np.nan)
661 exp.maskedImage.assign(warped.maskedImage, warped.getBBox())
663 maskedImageList.append(exp.maskedImage)
665 record = tractsCatalog.addNew()
666 record.setPsf(coaddPatch.getPsf())
667 record.setWcs(coaddPatch.getWcs())
668 record.setPhotoCalib(coaddPatch.getPhotoCalib())
669 record.setBBox(coaddPatch.getBBox())
671 record.set(tractKey, coaddExposure.ref.dataId[
'tract'])
672 record.set(patchKey, coaddExposure.ref.dataId[
'patch'])
673 record.set(weightKey, 1.)
676 if nPatchesFound == 0:
677 raise pipeBase.NoWorkFound(
"No patches found to overlap detector")
682 statsCtrl.setNanSafe(
True)
683 statsCtrl.setWeighted(
True)
684 statsCtrl.setCalcErrorFromInputVariance(
True)
686 templateExposure = afwImage.ExposureF(finalBBox, finalWcs)
687 templateExposure.maskedImage.set(np.nan, afwImage.Mask.getPlaneBitMask(
"NO_DATA"), np.nan)
688 xy0 = templateExposure.getXY0()
691 weightList, clipped=0, maskMap=[])
692 templateExposure.maskedImage.setXY0(xy0)
696 boolmask = templateExposure.mask.array & templateExposure.mask.getPlaneBitMask(
'NO_DATA') == 0
698 centerCoord = afwGeom.SpanSet.fromMask(maskx, 1).computeCentroid()
700 ctrl = self.config.coaddPsf.makeControl()
701 coaddPsf = CoaddPsf(tractsCatalog, finalWcs, centerCoord, ctrl.warpingKernelName, ctrl.cacheSize)
703 raise RuntimeError(
"CoaddPsf could not be constructed")
705 templateExposure.setPsf(coaddPsf)
706 templateExposure.setFilterLabel(coaddPatch.getFilterLabel())
707 templateExposure.setPhotoCalib(coaddPatch.getPhotoCalib())
708 return pipeBase.Struct(outputExposure=templateExposure)
Pass parameters to a Statistics object.
Custom catalog class for ExposureRecord/Table.
A floating-point coordinate rectangle geometry.
Property stringToStatisticsProperty(std::string const property)
Conversion function to switch a string to a Property (see Statistics.h)
std::shared_ptr< lsst::afw::image::Image< PixelT > > statisticsStack(std::vector< std::shared_ptr< lsst::afw::image::Image< PixelT >>> &images, Property flags, StatisticsControl const &sctrl=StatisticsControl(), std::vector< lsst::afw::image::VariancePixel > const &wvector=std::vector< lsst::afw::image::VariancePixel >(0))
A function to compute some statistics of a stack of Images.
int warpExposure(DestExposureT &destExposure, SrcExposureT const &srcExposure, WarpingControl const &control, typename DestExposureT::MaskedImageT::SinglePixel padValue=lsst::afw::math::edgePixel< typename DestExposureT::MaskedImageT >(typename lsst::afw::image::detail::image_traits< typename DestExposureT::MaskedImageT >::image_category()))
Warp (remap) one exposure to another.
def run(self, coaddExposures, bbox, wcs)