Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DM-13517: dynamicDetection: require sufficient sources for statistics #112

Merged
merged 1 commit into from
Apr 11, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
9 changes: 9 additions & 0 deletions python/lsst/meas/algorithms/dynamicDetection.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@ class DynamicDetectionConfig(SourceDetectionConfig):
skyObjects = ConfigurableField(target=SkyObjectsTask, doc="Generate sky objects")
doBackgroundTweak = Field(dtype=bool, default=True,
doc="Tweak background level so median PSF flux of sky objects is zero?")
minNumSources = Field(dtype=int, default=10,
doc="Minimum number of sky sources in statistical sample; "
"if below this number, we refuse to modify the threshold.")

def setDefaults(self):
SourceDetectionConfig.setDefaults(self)
Expand Down Expand Up @@ -117,6 +120,12 @@ def calculateThreshold(self, exposure, seed, sigma=None):

# Calculate new threshold
fluxes = catalog["base_PsfFlux_flux"]
good = ~catalog["base_PsfFlux_flag"]

if good.sum() < self.config.minNumSources:
self.log.warn("Insufficient good flux measurements (%d < %d) for dynamic threshold calculation",
good.sum(), self.config.minNumSources)
return Struct(multiplicative=1.0, additive=0.0)

bgMedian = np.median(fluxes/catalog["base_PsfFlux_area"])

Expand Down
4 changes: 4 additions & 0 deletions tests/test_dynamicDetection.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,10 @@ def testDynamic(self):
self.exposure.maskedImage.variance /= factor
self.check(1.0/np.sqrt(factor))

def testNoSources(self):
self.config.skyObjects.nSources = self.config.minNumSources - 1
self.check(1.0)


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