@@ -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,35 @@ 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
+ # 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
+
283
308
backgroundInfoList = []
284
309
for ind , exp in enumerate (psfMatchedWarps ):
285
310
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 ,)
293
312
else :
294
313
self .log .info ("Matching background of %s to %s" , exp .dataId , refMatchedWarp .dataId )
295
314
toMatchExposure = exp .get ()
@@ -307,13 +326,7 @@ def run(self, psfMatchedWarps):
307
326
backgroundInfoStruct .isReference = False
308
327
except Exception as e :
309
328
# 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 ,)
317
330
318
331
backgroundInfoList .append (backgroundInfoStruct )
319
332
@@ -545,11 +558,14 @@ def matchBackgrounds(self, refExposure, sciExposure):
545
558
546
559
outBkgd = approx if self .config .usePolynomial else bkgd
547
560
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 ,)
553
569
554
570
def _fluxScale (self , exposure ):
555
571
"""Scales image to nJy flux using photometric calibration.
0 commit comments