LSST Applications  21.0.0-172-gfb10e10a+18fedfabac,22.0.0+297cba6710,22.0.0+80564b0ff1,22.0.0+8d77f4f51a,22.0.0+a28f4c53b1,22.0.0+dcf3732eb2,22.0.1-1-g7d6de66+2a20fdde0d,22.0.1-1-g8e32f31+297cba6710,22.0.1-1-geca5380+7fa3b7d9b6,22.0.1-12-g44dc1dc+2a20fdde0d,22.0.1-15-g6a90155+515f58c32b,22.0.1-16-g9282f48+790f5f2caa,22.0.1-2-g92698f7+dcf3732eb2,22.0.1-2-ga9b0f51+7fa3b7d9b6,22.0.1-2-gd1925c9+bf4f0e694f,22.0.1-24-g1ad7a390+a9625a72a8,22.0.1-25-g5bf6245+3ad8ecd50b,22.0.1-25-gb120d7b+8b5510f75f,22.0.1-27-g97737f7+2a20fdde0d,22.0.1-32-gf62ce7b1+aa4237961e,22.0.1-4-g0b3f228+2a20fdde0d,22.0.1-4-g243d05b+871c1b8305,22.0.1-4-g3a563be+32dcf1063f,22.0.1-4-g44f2e3d+9e4ab0f4fa,22.0.1-42-gca6935d93+ba5e5ca3eb,22.0.1-5-g15c806e+85460ae5f3,22.0.1-5-g58711c4+611d128589,22.0.1-5-g75bb458+99c117b92f,22.0.1-6-g1c63a23+7fa3b7d9b6,22.0.1-6-g50866e6+84ff5a128b,22.0.1-6-g8d3140d+720564cf76,22.0.1-6-gd805d02+cc5644f571,22.0.1-8-ge5750ce+85460ae5f3,master-g6e05de7fdc+babf819c66,master-g99da0e417a+8d77f4f51a,w.2021.48
LSST Data Management Base Package
Classes | Functions | Variables
lsst.ip.diffim.getTemplate Namespace Reference

Classes

class  GetCoaddAsTemplateConfig
 
class  GetCoaddAsTemplateTask
 
class  GetCalexpAsTemplateConfig
 
class  GetCalexpAsTemplateTask
 
class  GetMultiTractCoaddTemplateConnections
 

Functions

def run (self, coaddExposures, bbox, wcs)
 

Variables

 detectorPolygon = geom.Box2D(inputs['bbox'])
 
int overlappingArea = 0
 
list coaddExposureList = []
 
 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))
 

Function Documentation

◆ run()

def lsst.ip.diffim.getTemplate.run (   self,
  coaddExposures,
  bbox,
  wcs 
)
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 DeferredDatasetHandle to `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

Returns
-------
result : `struct`
    return a pipeBase.Struct:
    - ``outputExposure`` : a template coadd exposure assembled out of patches


Raises
------
NoWorkFound
    Raised if no patches overlatp the input detector bbox

Definition at line 603 of file getTemplate.py.

603  def run(self, coaddExposures, bbox, wcs):
604  """Warp coadds from multiple tracts to form a template for image diff.
605 
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.
609 
610  Parameters
611  ----------
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
619 
620  Returns
621  -------
622  result : `struct`
623  return a pipeBase.Struct:
624  - ``outputExposure`` : a template coadd exposure assembled out of patches
625 
626 
627  Raises
628  ------
629  NoWorkFound
630  Raised if no patches overlatp the input detector bbox
631 
632  """
633  # Table for CoaddPSF
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')
638  tractsCatalog = afwTable.ExposureCatalog(tractsSchema)
639 
640  finalWcs = wcs
641  bbox.grow(self.config.templateBorderSize)
642  finalBBox = bbox
643 
644  nPatchesFound = 0
645  maskedImageList = []
646  weightList = []
647 
648  for coaddExposure in coaddExposures:
649  coaddPatch = coaddExposure.get()
650 
651  # warp to detector WCS
652  warped = self.warper.warpExposure(finalWcs, coaddPatch, maxBBox=finalBBox)
653 
654  # Check if warped image is viable
655  if not np.any(np.isfinite(warped.image.array)):
656  self.log.info("No overlap for warped %s. Skipping" % coaddExposure.ref.dataId)
657  continue
658 
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())
662 
663  maskedImageList.append(exp.maskedImage)
664  weightList.append(1)
665  record = tractsCatalog.addNew()
666  record.setPsf(coaddPatch.getPsf())
667  record.setWcs(coaddPatch.getWcs())
668  record.setPhotoCalib(coaddPatch.getPhotoCalib())
669  record.setBBox(coaddPatch.getBBox())
670  record.setValidPolygon(afwGeom.Polygon(geom.Box2D(coaddPatch.getBBox()).getCorners()))
671  record.set(tractKey, coaddExposure.ref.dataId['tract'])
672  record.set(patchKey, coaddExposure.ref.dataId['patch'])
673  record.set(weightKey, 1.)
674  nPatchesFound += 1
675 
676  if nPatchesFound == 0:
677  raise pipeBase.NoWorkFound("No patches found to overlap detector")
678 
679  # Combine images from individual patches together
680  statsFlags = afwMath.stringToStatisticsProperty('MEAN')
681  statsCtrl = afwMath.StatisticsControl()
682  statsCtrl.setNanSafe(True)
683  statsCtrl.setWeighted(True)
684  statsCtrl.setCalcErrorFromInputVariance(True)
685 
686  templateExposure = afwImage.ExposureF(finalBBox, finalWcs)
687  templateExposure.maskedImage.set(np.nan, afwImage.Mask.getPlaneBitMask("NO_DATA"), np.nan)
688  xy0 = templateExposure.getXY0()
689  # Do not mask any values
690  templateExposure.maskedImage = afwMath.statisticsStack(maskedImageList, statsFlags, statsCtrl,
691  weightList, clipped=0, maskMap=[])
692  templateExposure.maskedImage.setXY0(xy0)
693 
694  # CoaddPsf centroid not only must overlap image, but must overlap the part of
695  # image with data. Use centroid of region with data
696  boolmask = templateExposure.mask.array & templateExposure.mask.getPlaneBitMask('NO_DATA') == 0
697  maskx = afwImage.makeMaskFromArray(boolmask.astype(afwImage.MaskPixel))
698  centerCoord = afwGeom.SpanSet.fromMask(maskx, 1).computeCentroid()
699 
700  ctrl = self.config.coaddPsf.makeControl()
701  coaddPsf = CoaddPsf(tractsCatalog, finalWcs, centerCoord, ctrl.warpingKernelName, ctrl.cacheSize)
702  if coaddPsf is None:
703  raise RuntimeError("CoaddPsf could not be constructed")
704 
705  templateExposure.setPsf(coaddPsf)
706  templateExposure.setFilterLabel(coaddPatch.getFilterLabel())
707  templateExposure.setPhotoCalib(coaddPatch.getPhotoCalib())
708  return pipeBase.Struct(outputExposure=templateExposure)
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
Property stringToStatisticsProperty(std::string const property)
Conversion function to switch a string to a Property (see Statistics.h)
Definition: Statistics.cc:738
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)
Definition: getTemplate.py:603

Variable Documentation

◆ coaddExposureList

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

Definition at line 585 of file getTemplate.py.

◆ dataId

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

Definition at line 587 of file getTemplate.py.

◆ detectorPolygon

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

Definition at line 583 of file getTemplate.py.

◆ overlappingArea

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

Definition at line 584 of file getTemplate.py.

◆ patchBBox

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

Definition at line 589 of file getTemplate.py.

◆ patchCorners

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

Definition at line 590 of file getTemplate.py.

◆ patchPolygon

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

Definition at line 591 of file getTemplate.py.

◆ patchWcs

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

Definition at line 588 of file getTemplate.py.