Skip to content

Commit e602337

Browse files
committed
Make thresholdScaling optional in dynamicDetection
1 parent 98d8905 commit e602337

1 file changed

Lines changed: 35 additions & 27 deletions

File tree

python/lsst/meas/algorithms/dynamicDetection.py

Lines changed: 35 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,8 @@ class DynamicDetectionConfig(SourceDetectionConfig):
3434
doc="Multiplier for the negative (relative to positive) polarity "
3535
"detections threshold to use for first pass (to find sky objects).")
3636
skyObjects = ConfigurableField(target=SkyObjectsTask, doc="Generate sky objects.")
37+
doThresholdScaling = Field(dtype=bool, default=True,
38+
doc="Scale the threshold level to get empirically measured S/N requested?")
3739
doBackgroundTweak = Field(dtype=bool, default=True,
3840
doc="Tweak background level so median PSF flux of sky objects is zero?")
3941
minFractionSources = Field(dtype=float, default=0.02,
@@ -376,36 +378,42 @@ def detectFootprints(self, exposure, doSmooth=True, sigma=None, clearMask=True,
376378
psf = self.getPsf(exposure, sigma=sigma)
377379
convolveResults = self.convolveImage(maskedImage, psf, doSmooth=doSmooth)
378380

379-
if self.config.doBrightPrelimDetection:
380-
brightDetectedMask = self._computeBrightDetectionMask(maskedImage, convolveResults)
381+
if self.config.doThresholdScaling:
382+
if self.config.doBrightPrelimDetection:
383+
brightDetectedMask = self._computeBrightDetectionMask(maskedImage, convolveResults)
384+
else:
385+
prelim = None
386+
factor = 1.0
387+
388+
# Seed needs to fit in a C++ 'int' so pybind doesn't choke on it.
389+
seed = (expId if expId is not None else int(maskedImage.image.array.sum())) % (2**31 - 1)
381390

382391
middle = convolveResults.middle
383392
sigma = convolveResults.sigma
384-
prelim = self.applyThreshold(
385-
middle, maskedImage.getBBox(), factor=self.config.prelimThresholdFactor,
386-
factorNeg=self.config.prelimNegMultiplier*self.config.prelimThresholdFactor
387-
)
388-
self.finalizeFootprints(
389-
maskedImage.mask, prelim, sigma, factor=self.config.prelimThresholdFactor,
390-
factorNeg=self.config.prelimNegMultiplier*self.config.prelimThresholdFactor
391-
)
392-
if self.config.doBrightPrelimDetection:
393-
# Combine prelim and bright detection masks for multiplier
394-
# determination.
395-
maskedImage.mask.array |= brightDetectedMask
396-
397-
# Calculate the proper threshold
398-
# seed needs to fit in a C++ 'int' so pybind doesn't choke on it
399-
seed = (expId if expId is not None else int(maskedImage.image.array.sum())) % (2**31 - 1)
400-
threshResults = self.calculateThreshold(exposure, seed, sigma=sigma)
401-
minMultiplicative = 0.5
402-
if threshResults.multiplicative < minMultiplicative:
403-
self.log.warning("threshResults.multiplicative = %.2f is less than minimum value (%.2f). "
404-
"Setting to %.2f.", threshResults.multiplicative, minMultiplicative,
405-
minMultiplicative)
406-
factor = max(minMultiplicative, threshResults.multiplicative)
407-
self.log.info("Modifying configured detection threshold by factor %.2f to %.2f",
408-
factor, factor*self.config.thresholdValue)
393+
if self.config.doThresholdScaling:
394+
prelim = self.applyThreshold(
395+
middle, maskedImage.getBBox(), factor=self.config.prelimThresholdFactor,
396+
factorNeg=self.config.prelimNegMultiplier*self.config.prelimThresholdFactor
397+
)
398+
self.finalizeFootprints(
399+
maskedImage.mask, prelim, sigma, factor=self.config.prelimThresholdFactor,
400+
factorNeg=self.config.prelimNegMultiplier*self.config.prelimThresholdFactor
401+
)
402+
if self.config.doBrightPrelimDetection:
403+
# Combine prelim and bright detection masks for multiplier
404+
# determination.
405+
maskedImage.mask.array |= brightDetectedMask
406+
407+
# Calculate the proper threshold
408+
threshResults = self.calculateThreshold(exposure, seed, sigma=sigma)
409+
minMultiplicative = 0.5
410+
if threshResults.multiplicative < minMultiplicative:
411+
self.log.warning("threshResults.multiplicative = %.2f is less than minimum value (%.2f). "
412+
"Setting to %.2f.", threshResults.multiplicative, minMultiplicative,
413+
minMultiplicative)
414+
factor = max(minMultiplicative, threshResults.multiplicative)
415+
self.log.info("Modifying configured detection threshold by factor %.2f to %.2f",
416+
factor, factor*self.config.thresholdValue)
409417

410418
growOverride = None
411419
inFinalize = True

0 commit comments

Comments
 (0)