Skip to content

Conversation

@laurenam
Copy link
Contributor

No description provided.

@laurenam laurenam requested a review from TallJimbo October 24, 2025 22:00
@laurenam laurenam force-pushed the tickets/DM-48966 branch 3 times, most recently from ec0e85f to 3df15ed Compare November 5, 2025 02:30
_DefaultName = "adaptiveThresholdDetection"

def __init__(self, *args, **kwargs):
pipeBase.Task.__init__(self, *args, **kwargs)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can just drop the whole __init__ definition; it's doing nothing here.

},
doc="Maximum number of peaks per band. If the current band for the exposure "
"is not included as a key in this dict, the value associated with the "
"\"fallback\" key will be used.",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of escaping quotes, Just use single-quotes, either inside or outside. That's why Python supports both.

pipeBase.Task.__init__(self, *args, **kwargs)

def run(self, table, exposure, initialThreshold=None, initialThresholdMultiplier=2.0,
doReEstimageBackgroud=True, backgroundToPhotometricRatio=None):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Typo: doReEstimageBackgroud

There's a commit on the u/jbosch/DM-48966 branch that you can probably cherry-pick to fix this.

return brightDetectedMask


class AdaptiveThresholdDetectionConfig(Config):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we want to move this task and its config to a new module; leaving it here just increases the confusion about "dynamic" vs. "adaptive" detection. There's a commit on the u/jbosch/DM-48966 branch that you can cherry-pick to do this.

adaptiveDetectionTask = SourceDetectionTask(config=adaptiveDetectionConfig)

maxNumNegFactor = 1.0
while inAdaptiveDetection:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This loop would be better rewritten as a for loop over the maximum iteration count range, with break statements replacing inAdaptiveDetection=False assignments (I don't think you need that variable at all). This was done on the u/jbosch/DM-48966 branch, too, but only after the changes to make the task substitutable for SourceDetectionTask (which we don't want to do after all), so I'm not sure it will cherry-pick; might be better to just use it as a reference.

This aims at adaptively adjusting the detection threshold for PSF
modelling such that a single pipeline run is able to accommodate a
large variety of "scenes" (from sparsely populated, through very
crowded fields, and possible extended nebulosity).

It can be turned off (i.e. revert to previous behaviour) by setting
the following configs in pipe_tasks's CalibrateImageTask:

-c calibrateImage:do_adaptive_threshold_detection=False
-c calibrateImage:psf_detection.reEstimateBackground=True
-c calibrateImage:star_detection.reEstimateBackground=True
It may be desirable to limit selected sources to only those with a certain
error budget on the centroids (e.g. for astrometric calibration sources).
Namely, allow for a minimum magnitude (maximum brightness) as well as a
maximum total number of loaded reference objects.  This can be useful for
memory considerations, particularly for very crowded fields.
It doesn't make sense to subtract a local background from sources that
were explicitly placed to represent areas of background.
This is desired for the dynamic detection (particulalry when dealing
with crowded fields).
If the detection mask ends up as a single, or few many-peaked footprints,
then all subsequent processing will fall over.  Impose a limit to the
maximum number of peaks in a given footprint for the detection mask.  If
this condition is not met, iteravely increase the detection threshold until
it does.  This is meant to be a no-op for most "typical" scenes and observing
conditions, but can help avoid a total downstream meltdown in certain cases
(e.g. very crowded regions).
@laurenam laurenam merged commit 228ff66 into main Nov 8, 2025
5 checks passed
@laurenam laurenam deleted the tickets/DM-48966 branch November 8, 2025 00:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants