@@ -62,8 +62,8 @@ class MatchBackgroundsConnections(PipelineTaskConnections,
62
62
# This needs to be the models of each differential BG in warped coords
63
63
backgroundInfoList = cT .Output (
64
64
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" ),
67
67
storageClass = "Background" ,
68
68
multiple = True ,
69
69
)
@@ -280,16 +280,34 @@ def run(self, psfMatchedWarps):
280
280
281
281
self .log .info ("Matching %d Exposures" , numExp )
282
282
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
+
283
307
backgroundInfoList = []
284
308
for ind , exp in enumerate (psfMatchedWarps ):
285
309
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 ,)
293
311
else :
294
312
self .log .info ("Matching background of %s to %s" , exp .dataId , refMatchedWarp .dataId )
295
313
toMatchExposure = exp .get ()
@@ -307,13 +325,7 @@ def run(self, psfMatchedWarps):
307
325
backgroundInfoStruct .isReference = False
308
326
except Exception as e :
309
327
# 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 ,)
317
329
318
330
backgroundInfoList .append (backgroundInfoStruct )
319
331
@@ -545,11 +557,14 @@ def matchBackgrounds(self, refExposure, sciExposure):
545
557
546
558
outBkgd = approx if self .config .usePolynomial else bkgd
547
559
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 ,)
553
568
554
569
def _fluxScale (self , exposure ):
555
570
"""Scales image to nJy flux using photometric calibration.
0 commit comments