@@ -138,6 +138,13 @@ def setDefaults(self):
138138class DcrAssembleCoaddTask (CompareWarpAssembleCoaddTask ):
139139 """Assemble DCR coadded images from a set of warps.
140140
141+ Attributes
142+ ----------
143+ bufferSize : `int`
144+ The number of pixels to grow each subregion by to allow for DCR.
145+ warpCtrl : `lsst.afw.math.WarpingControl`
146+ Configuration settings for warping an image
147+
141148 Notes
142149 -----
143150 As with AssembleCoaddTask, we want to assemble a coadded image from a set of
@@ -230,7 +237,7 @@ def runDataRef(self, dataRef, selectDataList=[]):
230237 def prepareDcrInputs (self , templateCoadd , tempExpRefList , weightList ):
231238 """Prepare the DCR coadd by iterating through the visitInfo of the input warps.
232239
233- Sets the properties ``filterInfo `` and ``bufferSize``.
240+ Sets the properties ``warpCtrl `` and ``bufferSize``.
234241
235242 Parameters
236243 ----------
@@ -358,10 +365,13 @@ def run(self, skyInfo, tempExpRefList, imageScalerList, weightList,
358365 for subBBox in self ._subBBoxIter (skyInfo .bbox , subregionSize ):
359366 modelIter = 0
360367 self .log .info ("Computing coadd over %s" , subBBox )
368+ dcrBBox = afwGeom .Box2I (subBBox )
369+ dcrBBox .grow (self .bufferSize )
370+ dcrBBox .clip (dcrModels .bbox )
361371 if self .config .useModelWeights :
362- modelWeights = self .calculateModelWeights (templateCoadd . maskedImage [ subBBox ] )
372+ modelWeights = self .calculateModelWeights (dcrModels , dcrBBox )
363373 else :
364- return 1.
374+ modelWeights = 1.
365375 convergenceMetric = self .calculateConvergence (dcrModels , subBBox , tempExpRefList ,
366376 imageScalerList , weightList , spanSetMaskList ,
367377 stats .ctrl )
@@ -372,7 +382,7 @@ def run(self, skyInfo, tempExpRefList, imageScalerList, weightList,
372382 while (convergenceCheck > self .config .convergenceThreshold or
373383 modelIter < self .config .minNumIter ):
374384 gain = self .calculateGain (modelIter )
375- self .dcrAssembleSubregion (dcrModels , subBBox , tempExpRefList , imageScalerList ,
385+ self .dcrAssembleSubregion (dcrModels , subBBox , dcrBBox , tempExpRefList , imageScalerList ,
376386 weightList , spanSetMaskList , stats .flags , stats .ctrl ,
377387 convergenceMetric , baseMask , subfilterVariance , gain ,
378388 modelWeights )
@@ -449,7 +459,7 @@ def calculateNImage(self, dcrModels, bbox, tempExpRefList, spanSetMaskList, stat
449459 dcrNImage .array [shiftedImage .mask .array & statsCtrl .getAndMask () == 0 ] += 1
450460 return dcrNImages
451461
452- def dcrAssembleSubregion (self , dcrModels , bbox , tempExpRefList , imageScalerList , weightList ,
462+ def dcrAssembleSubregion (self , dcrModels , bbox , dcrBBox , tempExpRefList , imageScalerList , weightList ,
453463 spanSetMaskList , statsFlags , statsCtrl , convergenceMetric ,
454464 baseMask , subfilterVariance , gain , modelWeights ):
455465 """Assemble the DCR coadd for a sub-region.
@@ -472,6 +482,8 @@ def dcrAssembleSubregion(self, dcrModels, bbox, tempExpRefList, imageScalerList,
472482 Best fit model of the true sky after correcting chromatic effects.
473483 bbox : `lsst.afw.geom.box.Box2I`
474484 Bounding box of the subregion to coadd.
485+ dcrBBox :`lsst.afw.geom.box.Box2I`
486+ Sub-region of the coadd which includes a buffer to allow for DCR.
475487 tempExpRefList : `list` of `lsst.daf.persistence.ButlerDataRef`
476488 The data references to the input warped exposures.
477489 imageScalerList : `list` of `lsst.pipe.task.ImageScaler`
@@ -496,20 +508,16 @@ def dcrAssembleSubregion(self, dcrModels, bbox, tempExpRefList, imageScalerList,
496508 A 2D array of weight values that tapers smoothly to zero away from detected sources.
497509 Set to a placeholder value of 1.0 if ``self.config.useModelWeights`` is False.
498510 """
499- bboxGrow = afwGeom .Box2I (bbox )
500- bboxGrow .grow (self .bufferSize )
501- bboxGrow .clip (dcrModels .bbox )
502-
503511 tempExpName = self .getTempExpDatasetName (self .warpType )
504512 residualGeneratorList = []
505513
506514 for tempExpRef , imageScaler , altMaskSpans in zip (tempExpRefList , imageScalerList , spanSetMaskList ):
507- exposure = tempExpRef .get (tempExpName + "_sub" , bbox = bboxGrow )
515+ exposure = tempExpRef .get (tempExpName + "_sub" , bbox = dcrBBox )
508516 visitInfo = exposure .getInfo ().getVisitInfo ()
509517 wcs = exposure .getInfo ().getWcs ()
510518 maskedImage = exposure .maskedImage
511519 templateImage = dcrModels .buildMatchedTemplate (warpCtrl = self .warpCtrl , visitInfo = visitInfo ,
512- bbox = bboxGrow , wcs = wcs , mask = baseMask ,
520+ bbox = dcrBBox , wcs = wcs , mask = baseMask ,
513521 splitSubfilters = self .config .splitSubfilters )
514522 imageScaler .scaleMaskedImage (maskedImage )
515523 if altMaskSpans is not None :
@@ -519,10 +527,10 @@ def dcrAssembleSubregion(self, dcrModels, bbox, tempExpRefList, imageScalerList,
519527 self .removeMaskPlanes (maskedImage )
520528 maskedImage -= templateImage
521529 maskedImage .image .array *= modelWeights
522- residualGeneratorList .append (self .dcrResiduals (maskedImage , visitInfo , bboxGrow , wcs ,
530+ residualGeneratorList .append (self .dcrResiduals (maskedImage , visitInfo , dcrBBox , wcs ,
523531 dcrModels .filter ))
524532
525- dcrSubModelOut = self .newModelFromResidual (dcrModels , residualGeneratorList , bboxGrow ,
533+ dcrSubModelOut = self .newModelFromResidual (dcrModels , residualGeneratorList , dcrBBox ,
526534 statsFlags , statsCtrl , weightList ,
527535 mask = baseMask , gain = gain )
528536 dcrModels .assign (dcrSubModelOut , bbox )
@@ -791,13 +799,15 @@ def calculateGain(self, modelIter):
791799 return max (self .config .baseGain , iterGain )
792800 return self .config .baseGain
793801
794- def calculateModelWeights (self , maskedImage ):
802+ def calculateModelWeights (self , dcrModels , dcrBBox ):
795803 """Build an array that smoothly tapers to 0 away from detected sources.
796804
797805 Parameters
798806 ----------
799- maskedImage : `numpy.ndarray`
800- The input masked image to calculate weights for.
807+ dcrModels : `lsst.pipe.tasks.DcrModel`
808+ Best fit model of the true sky after correcting chromatic effects.
809+ dcrBBox : `lsst.afw.geom.box.Box2I`
810+ Sub-region of the coadd which includes a buffer to allow for DCR.
801811
802812 Returns
803813 -------
@@ -812,9 +822,9 @@ def calculateModelWeights(self, maskedImage):
812822 """
813823 if self .config .modelWeightsWidth < 0 :
814824 raise ValueError ("modelWeightsWidth must not be negative if useModelWeights is set" )
815- convergeMask = maskedImage .mask .getPlaneBitMask (self .config .convergenceMaskPlanes )
816- convergeMaskPixels = maskedImage .mask .array & convergeMask > 0
817- weights = np .zeros_like (maskedImage .image .array )
825+ convergeMask = dcrModels .mask .getPlaneBitMask (self .config .convergenceMaskPlanes )
826+ convergeMaskPixels = dcrModels .mask .array & convergeMask > 0
827+ weights = np .zeros_like (dcrModels [ 0 ][ dcrBBox ] .image .array )
818828 weights [convergeMaskPixels ] = 1.
819829 weights = ndimage .filters .gaussian_filter (weights , self .config .modelWeightsWidth )
820830 weights /= np .max (weights )
0 commit comments