@@ -62,8 +62,8 @@ class MatchBackgroundsConnections(PipelineTaskConnections,
6262 # This needs to be the models of each differential BG in warped coords
6363 backgroundInfoList = cT .Output (
6464 doc = "List of differential backgrounds, w/goodness of fit params" ,
65- name = "calexpBackground_diff " , # This needs to change
66- dimensions = ("visit " , "detector" , ),
65+ name = "psfMatchedWarpBackground_diff " , # This needs to change
66+ dimensions = ("tract " , "patch" , "skymap" , "visit" ),
6767 storageClass = "Background" ,
6868 multiple = True ,
6969 )
@@ -280,16 +280,34 @@ def run(self, psfMatchedWarps):
280280
281281 self .log .info ("Matching %d Exposures" , numExp )
282282
283+ # Creating a null BackgroundList object by fitting a blank image
284+ statsFlag = getattr (afwMath , self .config .gridStatistic )
285+ self .sctrl .setNumSigmaClip (self .config .numSigmaClip )
286+ self .sctrl .setNumIter (self .config .numIter )
287+
288+ im = refExposure .getMaskedImage ()
289+ blankIm = im .Factory (im , True )
290+ blankIm .image .array *= 0
291+
292+ width = blankIm .getWidth ()
293+ height = blankIm .getHeight ()
294+ nx = width // self .config .binSize
295+ if width % self .config .binSize != 0 :
296+ nx += 1
297+ ny = height // self .config .binSize
298+ if height % self .config .binSize != 0 :
299+ ny += 1
300+
301+ bctrl = afwMath .BackgroundControl (nx , ny , self .sctrl , statsFlag )
302+ bctrl .setUndersampleStyle (self .config .undersampleStyle )
303+
304+ bkgd = afwMath .makeBackground (blankIm , bctrl )
305+
306+
283307 backgroundInfoList = []
284308 for ind , exp in enumerate (psfMatchedWarps ):
285309 if ind in refIndSet :
286- backgroundInfoStruct = pipeBase .Struct (
287- isReference = True ,
288- backgroundModel = None ,
289- fitRMS = 0.0 ,
290- matchedMSE = None ,
291- diffImVar = None ,
292- )
310+ backgroundInfoStruct = afwMath .BackgroundList (bkgd ,)
293311 else :
294312 self .log .info ("Matching background of %s to %s" , exp .dataId , refMatchedWarp .dataId )
295313 toMatchExposure = exp .get ()
@@ -307,13 +325,7 @@ def run(self, psfMatchedWarps):
307325 backgroundInfoStruct .isReference = False
308326 except Exception as e :
309327 # self.log.warning("Failed to fit background %s: %s", toMatchRef.dataId, e)
310- backgroundInfoStruct = pipeBase .Struct (
311- isReference = False ,
312- backgroundModel = None ,
313- fitRMS = None ,
314- matchedMSE = None ,
315- diffImVar = None ,
316- )
328+ backgroundInfoStruct = afwMath .BackgroundList (bkgd ,)
317329
318330 backgroundInfoList .append (backgroundInfoStruct )
319331
@@ -545,11 +557,14 @@ def matchBackgrounds(self, refExposure, sciExposure):
545557
546558 outBkgd = approx if self .config .usePolynomial else bkgd
547559
548- return pipeBase .Struct (
549- backgroundModel = outBkgd ,
550- fitRMS = rms ,
551- matchedMSE = mse ,
552- diffImVar = meanVar )
560+ # Type `Background` can't use a struct. Should fitRMS &c. be added to
561+ # a log instead of output?
562+ # return pipeBase.Struct(
563+ # backgroundModel=afwMath.BackgroundList(outBkgd),
564+ # fitRMS=rms,
565+ # matchedMSE=mse,
566+ # diffImVar=meanVar)
567+ return afwMath .BackgroundList (outBkgd ,)
553568
554569 def _fluxScale (self , exposure ):
555570 """Scales image to nJy flux using photometric calibration.
0 commit comments