Skip to content

Commit be4be72

Browse files
committed
Simplify adaptive threshold iteration tracking.
This should not change the behavior at all.
1 parent 7a03e69 commit be4be72

File tree

1 file changed

+4
-16
lines changed

1 file changed

+4
-16
lines changed

python/lsst/meas/algorithms/adaptive_thresholds.py

Lines changed: 4 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -178,8 +178,6 @@ def run(self, table, exposure, **kwargs):
178178
maxNumPeak = self.config.maxNumPeakPerBand["fallback"]
179179

180180
# Set up and configure the adaptive detection task on first iteration.
181-
inAdaptiveDetection = True
182-
nAdaptiveDetIter = 0
183181
thresholdFactor = 1.0
184182
adaptiveDetectionConfig = self.config.baseline.copy()
185183
adaptiveDetectionConfig.thresholdPolarity = "both"
@@ -189,9 +187,8 @@ def run(self, table, exposure, **kwargs):
189187
adaptiveDetectionTask = SourceDetectionTask(config=adaptiveDetectionConfig)
190188

191189
maxNumNegFactor = 1.0
192-
while inAdaptiveDetection:
193-
inAdaptiveDetection = False
194-
nAdaptiveDetIter += 1
190+
# We use a 1-indexed iteration variable just to make logs intuitive.
191+
for nAdaptiveDetIter in range(1, self.config.maxAdaptiveDetIter + 1):
195192
detRes = adaptiveDetectionTask.run(table=table, exposure=exposure, doSmooth=True, **kwargs)
196193
sourceCat = detRes.sources
197194
nFootprint = len(sourceCat)
@@ -231,8 +228,7 @@ def run(self, table, exposure, **kwargs):
231228
"at iter: %d.",
232229
nIsolated, self.config.sufficientIsolated, fractionIsolated,
233230
self.config.sufficientFractionIsolated, nAdaptiveDetIter)
234-
inAdaptiveDetection = False
235-
continue
231+
break
236232

237233
if nFootprint == 0 or nPosPeak == 0:
238234
thresholdFactor = 0.25
@@ -243,7 +239,6 @@ def run(self, table, exposure, **kwargs):
243239
adaptiveDetectionConfig.thresholdValue = (
244240
thresholdFactor*adaptiveDetectionConfig.thresholdValue)
245241
adaptiveDetectionTask = SourceDetectionTask(config=adaptiveDetectionConfig)
246-
inAdaptiveDetection = False if nAdaptiveDetIter >= self.config.maxAdaptiveDetIter else True
247242
continue
248243

249244
if ((nPeak/nFootprint > self.config.maxPeakToFootRatio and nIsolated < self.config.minIsolated)
@@ -265,7 +260,6 @@ def run(self, table, exposure, **kwargs):
265260
adaptiveDetectionConfig.thresholdValue = (
266261
thresholdFactor*adaptiveDetectionConfig.thresholdValue)
267262
adaptiveDetectionTask = SourceDetectionTask(config=adaptiveDetectionConfig)
268-
inAdaptiveDetection = False if nAdaptiveDetIter >= self.config.maxAdaptiveDetIter else True
269263
continue
270264

271265
if (nPeak > maxNumPeak or nPeakPerSrcMax > maxNumPeakPerSrcMax
@@ -292,9 +286,6 @@ def run(self, table, exposure, **kwargs):
292286
adaptiveDetectionConfig.thresholdValue,
293287
adaptiveDetectionConfig.includeThresholdMultiplier)
294288
adaptiveDetectionTask = SourceDetectionTask(config=adaptiveDetectionConfig)
295-
inAdaptiveDetection = (
296-
False if nAdaptiveDetIter >= self.config.maxAdaptiveDetIter else True
297-
)
298289
continue
299290

300291
if nFootprint <= self.config.minFootprint:
@@ -310,11 +301,8 @@ def run(self, table, exposure, **kwargs):
310301
thresholdFactor*adaptiveDetectionConfig.thresholdValue
311302
)
312303
adaptiveDetectionTask = SourceDetectionTask(config=adaptiveDetectionConfig)
313-
inAdaptiveDetection = True
314304
else:
315-
inAdaptiveDetection = False
316-
if nAdaptiveDetIter >= self.config.maxAdaptiveDetIter:
317-
inAdaptiveDetection = False
305+
break
318306
# Final round of detection with positive polarity
319307
adaptiveDetectionConfig.thresholdPolarity = "positive"
320308
adaptiveDetectionTask = SourceDetectionTask(config=adaptiveDetectionConfig)

0 commit comments

Comments
 (0)