@@ -492,15 +492,22 @@ def detectFootprints(self, exposure, doSmooth=True, sigma=None, clearMask=True,
492492
493493 self .display (exposure , results , middle )
494494
495+ # Re-do the background tweak after any temporary backgrounds have
496+ # been restored.
497+ #
498+ # But we want to keep any large-scale background (e.g., scattered
499+ # light from bright stars) from being selected for sky objects in
500+ # the calculation, so do another detection pass without either the
501+ # local or wide temporary background subtraction; the DETECTED
502+ # pixels will mark the area to ignore.
503+
504+ # The following if/else is to workaround the fact that it is
505+ # currently not possible to persist an empty BackgroundList, so
506+ # we instead set the value of the backround tweak to 0.0 if
507+ # doBackgroundTweak is False and call the tweakBackground function
508+ # regardless to get at least one background into the list (do we
509+ # need a TODO here?).
495510 if self .config .doBackgroundTweak :
496- # Re-do the background tweak after any temporary backgrounds have
497- # been restored.
498- #
499- # But we want to keep any large-scale background (e.g., scattered
500- # light from bright stars) from being selected for sky objects in
501- # the calculation, so do another detection pass without either the
502- # local or wide temporary background subtraction; the DETECTED
503- # pixels will mark the area to ignore.
504511 originalMask = maskedImage .mask .array .copy ()
505512 try :
506513 self .clearMask (exposure .mask )
@@ -511,7 +518,9 @@ def detectFootprints(self, exposure, doSmooth=True, sigma=None, clearMask=True,
511518 isBgTweak = True ).additive
512519 finally :
513520 maskedImage .mask .array [:] = originalMask
514- self .tweakBackground (exposure , bgLevel , results .background )
521+ else :
522+ bgLevel = 0.0
523+ self .tweakBackground (exposure , bgLevel , results .background )
515524
516525 return results
517526
@@ -532,7 +541,8 @@ def tweakBackground(self, exposure, bgLevel, bgList=None):
532541 bg : `lsst.afw.math.BackgroundMI`
533542 Constant background model.
534543 """
535- self .log .info ("Tweaking background by %f to match sky photometry" , bgLevel )
544+ if bgLevel != 0.0 :
545+ self .log .info ("Tweaking background by %f to match sky photometry" , bgLevel )
536546 exposure .image -= bgLevel
537547 bgStats = lsst .afw .image .MaskedImageF (1 , 1 )
538548 bgStats .set (bgLevel , 0 , bgLevel )
0 commit comments