Skip to content

Commit

Permalink
detection: fix restoration of tempWideBackground
Browse files Browse the repository at this point in the history
We weren't restoring the original image because we didn't have a copy
of it.
  • Loading branch information
PaulPrice committed Feb 22, 2018
1 parent a29ab7a commit 3a37cf4
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 1 deletion.
2 changes: 1 addition & 1 deletion python/lsst/meas/algorithms/detection.py
Original file line number Diff line number Diff line change
Expand Up @@ -899,7 +899,7 @@ def tempWideBackgroundContext(self, exposure):
doTempWideBackground = self.config.doTempWideBackground
if doTempWideBackground:
self.log.info("Applying temporary wide background subtraction")
original = exposure.maskedImage.image.array[:]
original = exposure.maskedImage.image.array[:].copy()
self.tempWideBackground.run(exposure).background
# Remove NO_DATA regions (e.g., edge of the field-of-view); these can cause detections after
# subtraction because of extrapolation of the background model into areas with no constraints.
Expand Down
32 changes: 32 additions & 0 deletions tests/test_detection.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,11 @@
from __future__ import absolute_import, division, print_function
from builtins import range
import unittest
import numpy as np

import lsst.afw.geom as afwGeom
import lsst.afw.table as afwTable
import lsst.afw.image as afwImage
from lsst.meas.algorithms import SourceDetectionTask
from lsst.meas.algorithms.testUtils import plantSources
import lsst.utils.tests
Expand Down Expand Up @@ -98,6 +100,36 @@ def makeCoordList(self, bbox, numX, numY, minCounts, maxCounts, sigma):
counts += dCounts
return coordList

def testTempBackgrounds(self):
"""Test that the temporary backgrounds we remove are properly restored"""
bbox = afwGeom.Box2I(afwGeom.Point2I(12345, 67890), afwGeom.Extent2I(128, 127))
original = afwImage.ExposureF(bbox)
rng = np.random.RandomState(123)
original.image.array[:] = rng.normal(size=original.image.array.shape)
original.mask.set(0)
original.variance.set(1.0)

def checkExposure(original, doTempLocalBackground, doTempWideBackground):
config = SourceDetectionTask.ConfigClass()
config.reEstimateBackground = False
config.thresholdType = "pixel_stdev"
config.doTempLocalBackground = doTempLocalBackground
config.doTempWideBackground = doTempWideBackground
schema = afwTable.SourceTable.makeMinimalSchema()
task = SourceDetectionTask(config=config, schema=schema)

exposure = original.clone()
task.detectFootprints(exposure, sigma=3.21)

self.assertFloatsEqual(exposure.image.array, original.image.array)
# Mask is permitted to vary: DETECTED bit gets set
self.assertFloatsEqual(exposure.variance.array, original.variance.array)

checkExposure(original, False, False)
checkExposure(original, True, False)
checkExposure(original, False, True)
checkExposure(original, True, True)


class TestMemory(lsst.utils.tests.MemoryTestCase):
pass
Expand Down

0 comments on commit 3a37cf4

Please sign in to comment.