LSST Applications  21.0.0-147-g0e635eb1+1acddb5be5,22.0.0+052faf71bd,22.0.0+1ea9a8b2b2,22.0.0+6312710a6c,22.0.0+729191ecac,22.0.0+7589c3a021,22.0.0+9f079a9461,22.0.1-1-g7d6de66+b8044ec9de,22.0.1-1-g87000a6+536b1ee016,22.0.1-1-g8e32f31+6312710a6c,22.0.1-10-gd060f87+016f7cdc03,22.0.1-12-g9c3108e+df145f6f68,22.0.1-16-g314fa6d+c825727ab8,22.0.1-19-g93a5c75+d23f2fb6d8,22.0.1-19-gb93eaa13+aab3ef7709,22.0.1-2-g8ef0a89+b8044ec9de,22.0.1-2-g92698f7+9f079a9461,22.0.1-2-ga9b0f51+052faf71bd,22.0.1-2-gac51dbf+052faf71bd,22.0.1-2-gb66926d+6312710a6c,22.0.1-2-gcb770ba+09e3807989,22.0.1-20-g32debb5+b8044ec9de,22.0.1-23-gc2439a9a+fb0756638e,22.0.1-3-g496fd5d+09117f784f,22.0.1-3-g59f966b+1e6ba2c031,22.0.1-3-g849a1b8+f8b568069f,22.0.1-3-gaaec9c0+c5c846a8b1,22.0.1-32-g5ddfab5d3+60ce4897b0,22.0.1-4-g037fbe1+64e601228d,22.0.1-4-g8623105+b8044ec9de,22.0.1-5-g096abc9+d18c45d440,22.0.1-5-g15c806e+57f5c03693,22.0.1-7-gba73697+57f5c03693,master-g6e05de7fdc+c1283a92b8,master-g72cdda8301+729191ecac,w.2021.39
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  xyTransform = afwGeom.makeWcsPairTransform(coaddPatch.getWcs(), finalWcs)
653  psfWarped = WarpedPsf(coaddPatch.getPsf(), xyTransform)
654  warped = self.warper.warpExposure(finalWcs, coaddPatch, maxBBox=finalBBox)
655 
656  # Check if warped image is viable
657  if not np.any(np.isfinite(warped.image.array)):
658  self.log.info("No overlap for warped %s. Skipping" % coaddExposure.ref.dataId)
659  continue
660 
661  warped.setPsf(psfWarped)
662 
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())
666 
667  maskedImageList.append(exp.maskedImage)
668  weightList.append(1)
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.)
677  nPatchesFound += 1
678 
679  if nPatchesFound == 0:
680  raise pipeBase.NoWorkFound("No patches found to overlap detector")
681 
682  # Combine images from individual patches together
683  statsFlags = afwMath.stringToStatisticsProperty('MEAN')
684  statsCtrl = afwMath.StatisticsControl()
685  statsCtrl.setNanSafe(True)
686  statsCtrl.setWeighted(True)
687  statsCtrl.setCalcErrorFromInputVariance(True)
688 
689  templateExposure = afwImage.ExposureF(finalBBox, finalWcs)
690  templateExposure.maskedImage.set(np.nan, afwImage.Mask.getPlaneBitMask("NO_DATA"), np.nan)
691  xy0 = templateExposure.getXY0()
692  # Do not mask any values
693  templateExposure.maskedImage = afwMath.statisticsStack(maskedImageList, statsFlags, statsCtrl,
694  weightList, clipped=0, maskMap=[])
695  templateExposure.maskedImage.setXY0(xy0)
696 
697  # CoaddPsf centroid not only must overlap image, but must overlap the part of
698  # image with data. Use centroid of region with data
699  boolmask = templateExposure.mask.array & templateExposure.mask.getPlaneBitMask('NO_DATA') == 0
700  maskx = afwImage.makeMaskFromArray(boolmask.astype(afwImage.MaskPixel))
701  centerCoord = afwGeom.SpanSet.fromMask(maskx, 1).computeCentroid()
702 
703  ctrl = self.config.coaddPsf.makeControl()
704  coaddPsf = CoaddPsf(tractsCatalog, finalWcs, centerCoord, ctrl.warpingKernelName, ctrl.cacheSize)
705  if coaddPsf is None:
706  raise RuntimeError("CoaddPsf could not be constructed")
707 
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.
Definition: Statistics.h:92
Custom catalog class for ExposureRecord/Table.
Definition: Exposure.h:311
std::shared_ptr< TransformPoint2ToPoint2 > makeWcsPairTransform(SkyWcs const &src, SkyWcs const &dst)
A Transform obtained by putting two SkyWcs objects "back to back".
Definition: SkyWcs.cc:146
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.