Skip to content

Commit beacbdf

Browse files
committed
Slight hack for unpersistable empty BackgroundList
1 parent 3037bb8 commit beacbdf

File tree

1 file changed

+20
-10
lines changed

1 file changed

+20
-10
lines changed

python/lsst/meas/algorithms/dynamicDetection.py

Lines changed: 20 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -494,15 +494,22 @@ def detectFootprints(self, exposure, doSmooth=True, sigma=None, clearMask=True,
494494

495495
self.display(exposure, results, middle)
496496

497+
# Re-do the background tweak after any temporary backgrounds have
498+
# been restored.
499+
#
500+
# But we want to keep any large-scale background (e.g., scattered
501+
# light from bright stars) from being selected for sky objects in
502+
# the calculation, so do another detection pass without either the
503+
# local or wide temporary background subtraction; the DETECTED
504+
# pixels will mark the area to ignore.
505+
506+
# The following if/else is to workaround the fact that it is
507+
# currently not possible to persist an empty BackgroundList, so
508+
# we instead set the value of the backround tweak to 0.0 if
509+
# doBackgroundTweak is False and call the tweakBackground function
510+
# regardless to get at least one background into the list (do we
511+
# need a TODO here?).
497512
if self.config.doBackgroundTweak:
498-
# Re-do the background tweak after any temporary backgrounds have
499-
# been restored.
500-
#
501-
# But we want to keep any large-scale background (e.g., scattered
502-
# light from bright stars) from being selected for sky objects in
503-
# the calculation, so do another detection pass without either the
504-
# local or wide temporary background subtraction; the DETECTED
505-
# pixels will mark the area to ignore.
506513
originalMask = maskedImage.mask.array.copy()
507514
try:
508515
self.clearMask(exposure.mask)
@@ -513,7 +520,9 @@ def detectFootprints(self, exposure, doSmooth=True, sigma=None, clearMask=True,
513520
isBgTweak=True).additive
514521
finally:
515522
maskedImage.mask.array[:] = originalMask
516-
self.tweakBackground(exposure, bgLevel, results.background)
523+
else:
524+
bgLevel = 0.0
525+
self.tweakBackground(exposure, bgLevel, results.background)
517526

518527
return results
519528

@@ -534,7 +543,8 @@ def tweakBackground(self, exposure, bgLevel, bgList=None):
534543
bg : `lsst.afw.math.BackgroundMI`
535544
Constant background model.
536545
"""
537-
self.log.info("Tweaking background by %f to match sky photometry", bgLevel)
546+
if bgLevel != 0.0:
547+
self.log.info("Tweaking background by %f to match sky photometry", bgLevel)
538548
exposure.image -= bgLevel
539549
bgStats = lsst.afw.image.MaskedImageF(1, 1)
540550
bgStats.set(bgLevel, 0, bgLevel)

0 commit comments

Comments
 (0)