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()
653 psfWarped = WarpedPsf(coaddPatch.getPsf(), xyTransform)
654 warped = self.warper.
warpExposure(finalWcs, coaddPatch, maxBBox=finalBBox)
657 if not np.any(np.isfinite(warped.image.array)):
658 self.log.
info(
"No overlap for warped %s. Skipping" % coaddExposure.ref.dataId)
661 warped.setPsf(psfWarped)
663 exp = afwImage.ExposureF(finalBBox, finalWcs)
664 exp.maskedImage.set(np.nan, afwImage.Mask.getPlaneBitMask(
"NO_DATA"), np.nan)
665 exp.maskedImage.assign(warped.maskedImage, warped.getBBox())
667 maskedImageList.append(exp.maskedImage)
669 record = tractsCatalog.addNew()
670 record.setPsf(psfWarped)
671 record.setWcs(finalWcs)
672 record.setPhotoCalib(coaddPatch.getPhotoCalib())
673 record.setBBox(warped.getBBox())
674 record.set(tractKey, coaddExposure.ref.dataId[
'tract'])
675 record.set(patchKey, coaddExposure.ref.dataId[
'patch'])
676 record.set(weightKey, 1.)
679 if nPatchesFound == 0:
680 raise pipeBase.NoWorkFound(
"No patches found to overlap detector")
685 statsCtrl.setNanSafe(
True)
686 statsCtrl.setWeighted(
True)
687 statsCtrl.setCalcErrorFromInputVariance(
True)
689 templateExposure = afwImage.ExposureF(finalBBox, finalWcs)
690 templateExposure.maskedImage.set(np.nan, afwImage.Mask.getPlaneBitMask(
"NO_DATA"), np.nan)
691 xy0 = templateExposure.getXY0()
694 weightList, clipped=0, maskMap=[])
695 templateExposure.maskedImage.setXY0(xy0)
699 boolmask = templateExposure.mask.array & templateExposure.mask.getPlaneBitMask(
'NO_DATA') == 0
701 centerCoord = afwGeom.SpanSet.fromMask(maskx, 1).computeCentroid()
703 ctrl = self.config.coaddPsf.makeControl()
704 coaddPsf = CoaddPsf(tractsCatalog, finalWcs, centerCoord, ctrl.warpingKernelName, ctrl.cacheSize)
706 raise RuntimeError(
"CoaddPsf could not be constructed")
708 templateExposure.setPsf(coaddPsf)
709 templateExposure.setFilterLabel(coaddPatch.getFilterLabel())
710 templateExposure.setPhotoCalib(coaddPatch.getPhotoCalib())
711 return pipeBase.Struct(outputExposure=templateExposure)
Pass parameters to a Statistics object.
Custom catalog class for ExposureRecord/Table.
std::shared_ptr< TransformPoint2ToPoint2 > makeWcsPairTransform(SkyWcs const &src, SkyWcs const &dst)
A Transform obtained by putting two SkyWcs objects "back to back".
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)