LSST Applications g0265f82a02+0e5473021a,g02d81e74bb+0dd8ce4237,g1470d8bcf6+3ea6592b6f,g2079a07aa2+86d27d4dc4,g2305ad1205+5ca4c0b359,g295015adf3+d10818ec9d,g2a9a014e59+6f9be1b9cd,g2bbee38e9b+0e5473021a,g337abbeb29+0e5473021a,g3ddfee87b4+703ba97ebf,g487adcacf7+4fa16da234,g50ff169b8f+96c6868917,g52b1c1532d+585e252eca,g591dd9f2cf+ffa42b374e,g5a732f18d5+53520f316c,g64a986408d+0dd8ce4237,g858d7b2824+0dd8ce4237,g8a8a8dda67+585e252eca,g99cad8db69+d39438377f,g9ddcbc5298+9a081db1e4,ga1e77700b3+15fc3df1f7,ga8c6da7877+f1d96605c8,gb0e22166c9+60f28cb32d,gb6a65358fc+0e5473021a,gba4ed39666+c2a2e4ac27,gbb8dafda3b+e5339d463f,gc120e1dc64+da31e9920e,gc28159a63d+0e5473021a,gcf0d15dbbd+703ba97ebf,gdaeeff99f8+f9a426f77a,ge6526c86ff+889fc9d533,ge79ae78c31+0e5473021a,gee10cc3b42+585e252eca,gf18bd8381d+7268b93478,gff1a9f87cc+0dd8ce4237,w.2024.16
LSST Data Management Base Package
Loading...
Searching...
No Matches
Classes | Functions | Variables
lsst.ip.diffim.getTemplate Namespace Reference

Classes

class  GetDcrTemplateConnections
 
class  GetTemplateConnections
 

Functions

 run (self, coaddExposures, bbox, wcs, dataIds, physical_filter=None, **kwargs)
 
 checkPatchList (self, patchList)
 
 getDcrModel (self, patchList, coaddRefs, visitInfo)
 
 _selectDataRef (coaddRef, tract, patch)
 

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())
 
 inputsWcs = inputs['wcs']
 
 patchPolygon = afwGeom.Polygon(inputsWcs.skyToPixel(patchCorners))
 
 coaddExposures = self.getDcrModel(patchList, inputs['dcrCoadds'], inputs['visitInfo'])
 
list coaddExposureRefList = []
 
 patchList = dict()
 

Function Documentation

◆ _selectDataRef()

lsst.ip.diffim.getTemplate._selectDataRef ( coaddRef,
tract,
patch )
protected

Definition at line 494 of file getTemplate.py.

494def _selectDataRef(coaddRef, tract, patch):
495 condition = (coaddRef.dataId['tract'] == tract) & (coaddRef.dataId['patch'] == patch)
496 return condition

◆ checkPatchList()

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 441 of file getTemplate.py.

441 def checkPatchList(self, patchList):
442 """Check that all of the DcrModel subfilters are present for each
443 patch.
444
445 Parameters
446 ----------
447 patchList : `dict`
448 Dict of the patches containing valid data for each tract.
449
450 Raises
451 ------
452 RuntimeError
453 If the number of exposures found for a patch does not match the
454 number of subfilters.
455 """
456 for tract in patchList:
457 for patch in set(patchList[tract]):
458 if patchList[tract].count(patch) != self.config.numSubfilters:
459 raise RuntimeError("Invalid number of DcrModel subfilters found: %d vs %d expected",
460 patchList[tract].count(patch), self.config.numSubfilters)
461
daf::base::PropertySet * set
Definition fits.cc:931

◆ getDcrModel()

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` [`lsst.daf.butler.DeferredDatasetHandle`]
    Data references to `~lsst.afw.image.Exposure` representing
    DcrModels that overlap the detector.
visitInfo : `lsst.afw.image.VisitInfo`
    Metadata for the science image.

Returns
-------
coaddExposureList : `list` [`lsst.afw.image.Exposure`]
    Coadd exposures that overlap the detector.

Definition at line 462 of file getTemplate.py.

462 def getDcrModel(self, patchList, coaddRefs, visitInfo):
463 """Build DCR-matched coadds from a list of exposure references.
464
465 Parameters
466 ----------
467 patchList : `dict`
468 Dict of the patches containing valid data for each tract.
469 coaddRefs : `list` [`lsst.daf.butler.DeferredDatasetHandle`]
470 Data references to `~lsst.afw.image.Exposure` representing
471 DcrModels that overlap the detector.
472 visitInfo : `lsst.afw.image.VisitInfo`
473 Metadata for the science image.
474
475 Returns
476 -------
477 coaddExposureList : `list` [`lsst.afw.image.Exposure`]
478 Coadd exposures that overlap the detector.
479 """
480 coaddExposureList = []
481 for tract in patchList:
482 for patch in set(patchList[tract]):
483 coaddRefList = [coaddRef for coaddRef in coaddRefs
484 if _selectDataRef(coaddRef, tract, patch)]
485
486 dcrModel = DcrModel.fromQuantum(coaddRefList,
487 self.config.effectiveWavelength,
488 self.config.bandwidth,
489 self.config.numSubfilters)
490 coaddExposureList.append(dcrModel.buildMatchedExposure(visitInfo=visitInfo))
491 return coaddExposureList
492
493

◆ run()

lsst.ip.diffim.getTemplate.run ( self,
coaddExposures,
bbox,
wcs,
dataIds,
physical_filter = None,
** 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` [`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` [`lsst.daf.butler.DataCoordinate`]
    Record of the tract and patch of each coaddExposure.
physical_filter : `str`, optional
    The physical filter of the science image.
**kwargs
    Any additional keyword parameters.

Returns
-------
result : `lsst.pipe.base.Struct`
   A struct with attributes:

   ``template``
       A template coadd exposure assembled out of patches
       (`lsst.afw.image.ExposureF`).

Raises
------
NoWorkFound
    If no coadds are found with sufficient un-masked pixels.
RuntimeError
    If the PSF of the template can't be calculated.

Definition at line 190 of file getTemplate.py.

190 def run(self, coaddExposures, bbox, wcs, dataIds, physical_filter=None, **kwargs):
191 """Warp coadds from multiple tracts to form a template for image diff.
192
193 Where the tracts overlap, the resulting template image is averaged.
194 The PSF on the template is created by combining the CoaddPsf on each
195 template image into a meta-CoaddPsf.
196
197 Parameters
198 ----------
199 coaddExposures : `list` [`lsst.afw.image.Exposure`]
200 Coadds to be mosaicked.
201 bbox : `lsst.geom.Box2I`
202 Template Bounding box of the detector geometry onto which to
203 resample the ``coaddExposures``.
204 wcs : `lsst.afw.geom.SkyWcs`
205 Template WCS onto which to resample the ``coaddExposures``.
206 dataIds : `list` [`lsst.daf.butler.DataCoordinate`]
207 Record of the tract and patch of each coaddExposure.
208 physical_filter : `str`, optional
209 The physical filter of the science image.
210 **kwargs
211 Any additional keyword parameters.
212
213 Returns
214 -------
215 result : `lsst.pipe.base.Struct`
216 A struct with attributes:
217
218 ``template``
219 A template coadd exposure assembled out of patches
220 (`lsst.afw.image.ExposureF`).
221
222 Raises
223 ------
224 NoWorkFound
225 If no coadds are found with sufficient un-masked pixels.
226 RuntimeError
227 If the PSF of the template can't be calculated.
228 """
229 # Table for CoaddPSF
230 tractsSchema = afwTable.ExposureTable.makeMinimalSchema()
231 tractKey = tractsSchema.addField('tract', type=np.int32, doc='Which tract')
232 patchKey = tractsSchema.addField('patch', type=np.int32, doc='Which patch')
233 weightKey = tractsSchema.addField('weight', type=float, doc='Weight for each tract, should be 1')
234 tractsCatalog = afwTable.ExposureCatalog(tractsSchema)
235
236 finalWcs = wcs
237 bbox.grow(self.config.templateBorderSize)
238 finalBBox = bbox
239
240 nPatchesFound = 0
241 maskedImageList = []
242 weightList = []
243
244 for coaddExposure, dataId in zip(coaddExposures, dataIds):
245
246 # warp to detector WCS
247 warped = self.warper.warpExposure(finalWcs, coaddExposure, maxBBox=finalBBox)
248
249 # Check if warped image is viable
250 if not np.any(np.isfinite(warped.image.array)):
251 self.log.info("No overlap for warped %s. Skipping" % dataId)
252 continue
253
254 exp = afwImage.ExposureF(finalBBox, finalWcs)
255 exp.maskedImage.set(np.nan, afwImage.Mask.getPlaneBitMask("NO_DATA"), np.nan)
256 exp.maskedImage.assign(warped.maskedImage, warped.getBBox())
257
258 maskedImageList.append(exp.maskedImage)
259 weightList.append(1)
260 record = tractsCatalog.addNew()
261 record.setPsf(coaddExposure.getPsf())
262 record.setWcs(coaddExposure.getWcs())
263 record.setPhotoCalib(coaddExposure.getPhotoCalib())
264 record.setBBox(coaddExposure.getBBox())
265 record.setValidPolygon(afwGeom.Polygon(geom.Box2D(coaddExposure.getBBox()).getCorners()))
266 record.set(tractKey, dataId['tract'])
267 record.set(patchKey, dataId['patch'])
268 record.set(weightKey, 1.)
269 nPatchesFound += 1
270
271 if nPatchesFound == 0:
272 raise pipeBase.NoWorkFound("No patches found to overlap detector")
273
274 # Combine images from individual patches together
275 statsFlags = afwMath.stringToStatisticsProperty('MEAN')
276 statsCtrl = afwMath.StatisticsControl()
277 statsCtrl.setNanSafe(True)
278 statsCtrl.setWeighted(True)
279 statsCtrl.setCalcErrorMosaicMode(True)
280
281 templateExposure = afwImage.ExposureF(finalBBox, finalWcs)
282 templateExposure.maskedImage.set(np.nan, afwImage.Mask.getPlaneBitMask("NO_DATA"), np.nan)
283 xy0 = templateExposure.getXY0()
284 # Do not mask any values
285 templateExposure.maskedImage = afwMath.statisticsStack(maskedImageList, statsFlags, statsCtrl,
286 weightList, clipped=0, maskMap=[])
287 templateExposure.maskedImage.setXY0(xy0)
288
289 # CoaddPsf centroid not only must overlap image, but must overlap the
290 # part of image with data. Use centroid of region with data.
291 boolmask = templateExposure.mask.array & templateExposure.mask.getPlaneBitMask('NO_DATA') == 0
292 maskx = afwImage.makeMaskFromArray(boolmask.astype(afwImage.MaskPixel))
293 centerCoord = afwGeom.SpanSet.fromMask(maskx, 1).computeCentroid()
294
295 ctrl = self.config.coaddPsf.makeControl()
296 coaddPsf = CoaddPsf(tractsCatalog, finalWcs, centerCoord, ctrl.warpingKernelName, ctrl.cacheSize)
297 if coaddPsf is None:
298 raise RuntimeError("CoaddPsf could not be constructed")
299
300 templateExposure.setPsf(coaddPsf)
301 # Coadds do not have a physical filter, so fetch it from the butler to prevent downstream warnings.
302 if physical_filter is None:
303 filterLabel = coaddExposure.getFilter()
304 else:
305 filterLabel = afwImage.FilterLabel(dataId['band'], physical_filter)
306 templateExposure.setFilter(filterLabel)
307 templateExposure.setPhotoCalib(coaddExposure.getPhotoCalib())
308 return pipeBase.Struct(template=templateExposure)
309
310
Cartesian polygons.
Definition Polygon.h:59
A group of labels for a filter in an exposure or coadd.
Definition FilterLabel.h:58
Pass parameters to a Statistics object.
Definition Statistics.h:83
Custom catalog class for ExposureRecord/Table.
Definition Exposure.h:311
A floating-point coordinate rectangle geometry.
Definition Box.h:413
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)

Variable Documentation

◆ coaddExposureList

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

Definition at line 164 of file getTemplate.py.

◆ coaddExposureRefList

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

Definition at line 412 of file getTemplate.py.

◆ coaddExposures

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

Definition at line 186 of file getTemplate.py.

◆ dataId

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

Definition at line 167 of file getTemplate.py.

◆ dataIds

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

Definition at line 165 of file getTemplate.py.

◆ detectorPolygon

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

Definition at line 162 of file getTemplate.py.

◆ inputsWcs

lsst.ip.diffim.getTemplate.inputsWcs = inputs['wcs']

Definition at line 171 of file getTemplate.py.

◆ overlappingArea

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

Definition at line 163 of file getTemplate.py.

◆ patchBBox

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

Definition at line 169 of file getTemplate.py.

◆ patchCorners

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

Definition at line 170 of file getTemplate.py.

◆ patchList

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

Definition at line 414 of file getTemplate.py.

◆ patchPolygon

lsst.ip.diffim.getTemplate.patchPolygon = afwGeom.Polygon(inputsWcs.skyToPixel(patchCorners))

Definition at line 173 of file getTemplate.py.

◆ patchWcs

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

Definition at line 168 of file getTemplate.py.