@@ -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,35 @@ 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+ # TODO: refactor below to construct blank bg model
289+ im = refExposure .getMaskedImage ()
290+ blankIm = im .Factory (im , True ) # Don't do this
291+ blankIm .image .array *= 0
292+
293+ width = blankIm .getWidth ()
294+ height = blankIm .getHeight ()
295+ nx = width // self .config .binSize
296+ if width % self .config .binSize != 0 :
297+ nx += 1
298+ ny = height // self .config .binSize
299+ if height % self .config .binSize != 0 :
300+ ny += 1
301+
302+ bctrl = afwMath .BackgroundControl (nx , ny , self .sctrl , statsFlag )
303+ bctrl .setUndersampleStyle (self .config .undersampleStyle )
304+
305+ bkgd = afwMath .makeBackground (blankIm , bctrl )
306+
307+
283308 backgroundInfoList = []
284309 for ind , exp in enumerate (psfMatchedWarps ):
285310 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- )
311+ backgroundInfoStruct = afwMath .BackgroundList (bkgd ,)
293312 else :
294313 self .log .info ("Matching background of %s to %s" , exp .dataId , refMatchedWarp .dataId )
295314 toMatchExposure = exp .get ()
@@ -307,13 +326,7 @@ def run(self, psfMatchedWarps):
307326 backgroundInfoStruct .isReference = False
308327 except Exception as e :
309328 # 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- )
329+ backgroundInfoStruct = afwMath .BackgroundList (bkgd ,)
317330
318331 backgroundInfoList .append (backgroundInfoStruct )
319332
@@ -545,11 +558,14 @@ def matchBackgrounds(self, refExposure, sciExposure):
545558
546559 outBkgd = approx if self .config .usePolynomial else bkgd
547560
548- return pipeBase .Struct (
549- backgroundModel = outBkgd ,
550- fitRMS = rms ,
551- matchedMSE = mse ,
552- diffImVar = meanVar )
561+ # Type `Background` can't use a struct. Should fitRMS &c. be added to
562+ # a log instead of output?
563+ # return pipeBase.Struct(
564+ # backgroundModel=afwMath.BackgroundList(outBkgd),
565+ # fitRMS=rms,
566+ # matchedMSE=mse,
567+ # diffImVar=meanVar)
568+ return afwMath .BackgroundList (outBkgd ,)
553569
554570 def _fluxScale (self , exposure ):
555571 """Scales image to nJy flux using photometric calibration.
0 commit comments