LSST Applications g0b6bd0c080+a72a5dd7e6,g1182afd7b4+2a019aa3bb,g17e5ecfddb+2b8207f7de,g1d67935e3f+06cf436103,g38293774b4+ac198e9f13,g396055baef+6a2097e274,g3b44f30a73+6611e0205b,g480783c3b1+98f8679e14,g48ccf36440+89c08d0516,g4b93dc025c+98f8679e14,g5c4744a4d9+a302e8c7f0,g613e996a0d+e1c447f2e0,g6c8d09e9e7+25247a063c,g7271f0639c+98f8679e14,g7a9cd813b8+124095ede6,g9d27549199+a302e8c7f0,ga1cf026fa3+ac198e9f13,ga32aa97882+7403ac30ac,ga786bb30fb+7a139211af,gaa63f70f4e+9994eb9896,gabf319e997+ade567573c,gba47b54d5d+94dc90c3ea,gbec6a3398f+06cf436103,gc6308e37c7+07dd123edb,gc655b1545f+ade567573c,gcc9029db3c+ab229f5caf,gd01420fc67+06cf436103,gd877ba84e5+06cf436103,gdb4cecd868+6f279b5b48,ge2d134c3d5+cc4dbb2e3f,ge448b5faa6+86d1ceac1d,gecc7e12556+98f8679e14,gf3ee170dca+25247a063c,gf4ac96e456+ade567573c,gf9f5ea5b4d+ac198e9f13,gff490e6085+8c2580be5c,w.2022.27
LSST Data Management Base Package
Classes | Functions | Variables
lsst.ip.diffim.getTemplate Namespace Reference

Classes

class  GetCalexpAsTemplateConfig
 
class  GetCalexpAsTemplateTask
 
class  GetCoaddAsTemplateConfig
 
class  GetCoaddAsTemplateTask
 
class  GetDcrTemplateConnections
 
class  GetMultiTractCoaddTemplateConfig
 
class  GetMultiTractCoaddTemplateTask
 
class  GetTemplateConnections
 

Functions

def run (self, coaddExposures, bbox, wcs, dataIds, **kwargs)
 
def checkPatchList (self, patchList)
 
def getDcrModel (self, patchList, coaddRefs, visitInfo)
 

Variables

 detectorPolygon = geom.Box2D(inputs['bbox'])
 
int overlappingArea = 0
 
list coaddExposureList = []
 
list dataIds = []
 
 dataId = coaddRef.dataId
 
 patchWcs = inputs['skyMap'][dataId['tract']].getWcs()
 
 patchBBox = inputs['skyMap'][dataId['tract']][dataId['patch']].getOuterBBox()
 
 patchCorners = patchWcs.pixelToSky(geom.Box2D(patchBBox).getCorners())
 
 patchPolygon = afwGeom.Polygon(inputs['wcs'].skyToPixel(patchCorners))
 
 coaddExposures = self.getDcrModel(patchList, inputs['dcrCoadds'], inputs['visitInfo'])
 
list coaddExposureRefList = []
 
 patchList = dict()
 

Function Documentation

◆ checkPatchList()

def lsst.ip.diffim.getTemplate.checkPatchList (   self,
  patchList 
)
Check that all of the DcrModel subfilters are present for each patch.

Parameters
----------
patchList : `dict`
    Dict of the patches containing valid data for each tract

Raises
------
RuntimeError
    If the number of exposures found for a patch does not match the number of subfilters.

Definition at line 823 of file getTemplate.py.

823 def checkPatchList(self, patchList):
824 """Check that all of the DcrModel subfilters are present for each patch.
825
826 Parameters
827 ----------
828 patchList : `dict`
829 Dict of the patches containing valid data for each tract
830
831 Raises
832 ------
833 RuntimeError
834 If the number of exposures found for a patch does not match the number of subfilters.
835 """
836 for tract in patchList:
837 for patch in set(patchList[tract]):
838 if patchList[tract].count(patch) != self.config.numSubfilters:
839 raise RuntimeError("Invalid number of DcrModel subfilters found: %d vs %d expected",
840 patchList[tract].count(patch), self.config.numSubfilters)
841
daf::base::PropertySet * set
Definition: fits.cc:912
def checkPatchList(self, patchList)
Definition: getTemplate.py:823

◆ getDcrModel()

def lsst.ip.diffim.getTemplate.getDcrModel (   self,
  patchList,
  coaddRefs,
  visitInfo 
)
Build DCR-matched coadds from a list of exposure references.

Parameters
----------
patchList : `dict`
    Dict of the patches containing valid data for each tract
coaddRefs : `list` of elements of type
            `lsst.daf.butler.DeferredDatasetHandle` of
            `lsst.afw.image.Exposure`
    Data references to DcrModels that overlap the detector.
visitInfo : `lsst.afw.image.VisitInfo`
    Metadata for the science image.

Returns
-------
`list` of elements of type `lsst.afw.image.Exposure`
        Coadd exposures that overlap the detector.

Definition at line 842 of file getTemplate.py.

842 def getDcrModel(self, patchList, coaddRefs, visitInfo):
843 """Build DCR-matched coadds from a list of exposure references.
844
845 Parameters
846 ----------
847 patchList : `dict`
848 Dict of the patches containing valid data for each tract
849 coaddRefs : `list` of elements of type
850 `lsst.daf.butler.DeferredDatasetHandle` of
852 Data references to DcrModels that overlap the detector.
853 visitInfo : `lsst.afw.image.VisitInfo`
854 Metadata for the science image.
855
856 Returns
857 -------
858 `list` of elements of type `lsst.afw.image.Exposure`
859 Coadd exposures that overlap the detector.
860 """
861 coaddExposureList = []
862 for tract in patchList:
863 for patch in set(patchList[tract]):
864 coaddRefList = [coaddRef for coaddRef in coaddRefs
865 if _selectDataRef(coaddRef, tract, patch)]
866
867 dcrModel = DcrModel.fromQuantum(coaddRefList,
868 self.config.effectiveWavelength,
869 self.config.bandwidth,
870 self.config.numSubfilters)
871 coaddExposureList.append(dcrModel.buildMatchedExposure(visitInfo=visitInfo))
872 return coaddExposureList
873
874
A class to contain the data, WCS, and other information needed to describe an image of the sky.
Definition: Exposure.h:72
Information about a single exposure of an imaging camera.
Definition: VisitInfo.h:68
def getDcrModel(self, patchList, coaddRefs, visitInfo)
Definition: getTemplate.py:842

◆ run()

def lsst.ip.diffim.getTemplate.run (   self,
  coaddExposures,
  bbox,
  wcs,
  dataIds,
**  kwargs 
)
Warp coadds from multiple tracts to form a template for image diff.

Where the tracts overlap, the resulting template image is averaged.
The PSF on the template is created by combining the CoaddPsf on each
template image into a meta-CoaddPsf.

Parameters
----------
coaddExposures : `list` of `lsst.afw.image.Exposure`
    Coadds to be mosaicked
bbox : `lsst.geom.Box2I`
    Template Bounding box of the detector geometry onto which to
    resample the coaddExposures
wcs : `lsst.afw.geom.SkyWcs`
    Template WCS onto which to resample the coaddExposures
dataIds : `list` of `lsst.daf.butler.DataCoordinate`
    Record of the tract and patch of each coaddExposure.
**kwargs
    Any additional keyword parameters.

Returns
-------
result : `lsst.pipe.base.Struct` containing
    - ``outputExposure`` : a template coadd exposure assembled out of patches

Definition at line 596 of file getTemplate.py.

596 def run(self, coaddExposures, bbox, wcs, dataIds, **kwargs):
597 """Warp coadds from multiple tracts to form a template for image diff.
598
599 Where the tracts overlap, the resulting template image is averaged.
600 The PSF on the template is created by combining the CoaddPsf on each
601 template image into a meta-CoaddPsf.
602
603 Parameters
604 ----------
605 coaddExposures : `list` of `lsst.afw.image.Exposure`
606 Coadds to be mosaicked
607 bbox : `lsst.geom.Box2I`
608 Template Bounding box of the detector geometry onto which to
609 resample the coaddExposures
611 Template WCS onto which to resample the coaddExposures
612 dataIds : `list` of `lsst.daf.butler.DataCoordinate`
613 Record of the tract and patch of each coaddExposure.
614 **kwargs
615 Any additional keyword parameters.
616
617 Returns
618 -------
619 result : `lsst.pipe.base.Struct` containing
620 - ``outputExposure`` : a template coadd exposure assembled out of patches
621 """
622 # Table for CoaddPSF
623 tractsSchema = afwTable.ExposureTable.makeMinimalSchema()
624 tractKey = tractsSchema.addField('tract', type=np.int32, doc='Which tract')
625 patchKey = tractsSchema.addField('patch', type=np.int32, doc='Which patch')
626 weightKey = tractsSchema.addField('weight', type=float, doc='Weight for each tract, should be 1')
627 tractsCatalog = afwTable.ExposureCatalog(tractsSchema)
628
629 finalWcs = wcs
630 bbox.grow(self.config.templateBorderSize)
631 finalBBox = bbox
632
633 nPatchesFound = 0
634 maskedImageList = []
635 weightList = []
636
637 for coaddExposure, dataId in zip(coaddExposures, dataIds):
638
639 # warp to detector WCS
640 warped = self.warper.warpExposure(finalWcs, coaddExposure, maxBBox=finalBBox)
641
642 # Check if warped image is viable
643 if not np.any(np.isfinite(warped.image.array)):
644 self.log.info("No overlap for warped %s. Skipping" % dataId)
645 continue
646
647 exp = afwImage.ExposureF(finalBBox, finalWcs)
648 exp.maskedImage.set(np.nan, afwImage.Mask.getPlaneBitMask("NO_DATA"), np.nan)
649 exp.maskedImage.assign(warped.maskedImage, warped.getBBox())
650
651 maskedImageList.append(exp.maskedImage)
652 weightList.append(1)
653 record = tractsCatalog.addNew()
654 record.setPsf(coaddExposure.getPsf())
655 record.setWcs(coaddExposure.getWcs())
656 record.setPhotoCalib(coaddExposure.getPhotoCalib())
657 record.setBBox(coaddExposure.getBBox())
658 record.setValidPolygon(afwGeom.Polygon(geom.Box2D(coaddExposure.getBBox()).getCorners()))
659 record.set(tractKey, dataId['tract'])
660 record.set(patchKey, dataId['patch'])
661 record.set(weightKey, 1.)
662 nPatchesFound += 1
663
664 if nPatchesFound == 0:
665 raise pipeBase.NoWorkFound("No patches found to overlap detector")
666
667 # Combine images from individual patches together
668 statsFlags = afwMath.stringToStatisticsProperty('MEAN')
669 statsCtrl = afwMath.StatisticsControl()
670 statsCtrl.setNanSafe(True)
671 statsCtrl.setWeighted(True)
672 statsCtrl.setCalcErrorFromInputVariance(True)
673
674 templateExposure = afwImage.ExposureF(finalBBox, finalWcs)
675 templateExposure.maskedImage.set(np.nan, afwImage.Mask.getPlaneBitMask("NO_DATA"), np.nan)
676 xy0 = templateExposure.getXY0()
677 # Do not mask any values
678 templateExposure.maskedImage = afwMath.statisticsStack(maskedImageList, statsFlags, statsCtrl,
679 weightList, clipped=0, maskMap=[])
680 templateExposure.maskedImage.setXY0(xy0)
681
682 # CoaddPsf centroid not only must overlap image, but must overlap the part of
683 # image with data. Use centroid of region with data
684 boolmask = templateExposure.mask.array & templateExposure.mask.getPlaneBitMask('NO_DATA') == 0
685 maskx = afwImage.makeMaskFromArray(boolmask.astype(afwImage.MaskPixel))
686 centerCoord = afwGeom.SpanSet.fromMask(maskx, 1).computeCentroid()
687
688 ctrl = self.config.coaddPsf.makeControl()
689 coaddPsf = CoaddPsf(tractsCatalog, finalWcs, centerCoord, ctrl.warpingKernelName, ctrl.cacheSize)
690 if coaddPsf is None:
691 raise RuntimeError("CoaddPsf could not be constructed")
692
693 templateExposure.setPsf(coaddPsf)
694 templateExposure.setFilter(coaddExposure.getFilter())
695 templateExposure.setPhotoCalib(coaddExposure.getPhotoCalib())
696 return pipeBase.Struct(outputExposure=templateExposure)
697
698
A 2-dimensional celestial WCS that transform pixels to ICRS RA/Dec, using the LSST standard for pixel...
Definition: SkyWcs.h:117
Cartesian polygons.
Definition: Polygon.h:59
Pass parameters to a Statistics object.
Definition: Statistics.h:92
Custom catalog class for ExposureRecord/Table.
Definition: Exposure.h:311
A floating-point coordinate rectangle geometry.
Definition: Box.h:413
An integer coordinate rectangle.
Definition: Box.h:55
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.
Property stringToStatisticsProperty(std::string const property)
Conversion function to switch a string to a Property (see Statistics.h)
Definition: Statistics.cc:738
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, dataIds, **kwargs)
Definition: getTemplate.py:596

Variable Documentation

◆ coaddExposureList

list lsst.ip.diffim.getTemplate.coaddExposureList = []

Definition at line 575 of file getTemplate.py.

◆ coaddExposureRefList

list lsst.ip.diffim.getTemplate.coaddExposureRefList = []

Definition at line 794 of file getTemplate.py.

◆ coaddExposures

lsst.ip.diffim.getTemplate.coaddExposures = self.getDcrModel(patchList, inputs['dcrCoadds'], inputs['visitInfo'])

Definition at line 593 of file getTemplate.py.

◆ dataId

lsst.ip.diffim.getTemplate.dataId = coaddRef.dataId

Definition at line 578 of file getTemplate.py.

◆ dataIds

list lsst.ip.diffim.getTemplate.dataIds = []

Definition at line 576 of file getTemplate.py.

◆ detectorPolygon

lsst.ip.diffim.getTemplate.detectorPolygon = geom.Box2D(inputs['bbox'])

Definition at line 573 of file getTemplate.py.

◆ overlappingArea

int lsst.ip.diffim.getTemplate.overlappingArea = 0

Definition at line 574 of file getTemplate.py.

◆ patchBBox

lsst.ip.diffim.getTemplate.patchBBox = inputs['skyMap'][dataId['tract']][dataId['patch']].getOuterBBox()

Definition at line 580 of file getTemplate.py.

◆ patchCorners

lsst.ip.diffim.getTemplate.patchCorners = patchWcs.pixelToSky(geom.Box2D(patchBBox).getCorners())

Definition at line 581 of file getTemplate.py.

◆ patchList

lsst.ip.diffim.getTemplate.patchList = dict()

Definition at line 796 of file getTemplate.py.

◆ patchPolygon

lsst.ip.diffim.getTemplate.patchPolygon = afwGeom.Polygon(inputs['wcs'].skyToPixel(patchCorners))

Definition at line 582 of file getTemplate.py.

◆ patchWcs

lsst.ip.diffim.getTemplate.patchWcs = inputs['skyMap'][dataId['tract']].getWcs()

Definition at line 579 of file getTemplate.py.