Skip to content

Conversation

@laurenam
Copy link
Contributor

No description provided.

@laurenam laurenam changed the title DM-53418: Further robustly to pedestal background subtraction in calibrateImage DM-53418: Further robustify the pedestal background subtraction in calibrateImage Nov 30, 2025
@laurenam laurenam requested a review from erykoff November 30, 2025 22:39
@laurenam laurenam force-pushed the tickets/DM-53418 branch 3 times, most recently from bb4b5b6 to fd4adfa Compare December 1, 2025 23:36
# start an iteration with a small bin size, then double it on each
# iteration until the relative or absolute change criterion is met.
# If those are never achieved, the iteration stops when the bin size
# gets bigger than the exposure's bounding box.
Copy link
Contributor

Choose a reason for hiding this comment

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

I think this comment should be moved up to line 2036?

self.log.info("Initial pedestal binSize = %d pixels", pedestalBackgroundConfig.binSize)
inPedestalIteration = True
cumulativePedestalLevel = 0.0
relativeStoppingCriterion = 0.05 # Relative change in cumulative pedestal value.
Copy link
Contributor

Choose a reason for hiding this comment

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

This should have a longer comment (above it): "When the cumulative pedestal value changes by less than 5% from one bin size to the next we assume we are converged"

inPedestalIteration = True
cumulativePedestalLevel = 0.0
relativeStoppingCriterion = 0.05 # Relative change in cumulative pedestal value.
absoluteStoppingCriterion = 0.5 # Absolute change in cumulative pedestal value.
Copy link
Contributor

Choose a reason for hiding this comment

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

This should have a longer comment (above it): "When the cumulative pedestal value changes by less than 0.5 counts (electrons or adu) from one bin size to the next, we assume we are converged".

Meanwhile, is this the right convergence amount? Seems larger than I would naively expect, but you've run the numbers.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah, in all my testing, any smaller than this and it just started bouncing around at each iteration (which is what this is trying to avoid).

pedestalBackgroundLevel, cumulativePedestalLevel,
relativeDelta, absoluteDelta)
if (relativeDelta > relativeStoppingCriterion
and absoluteDelta > absoluteStoppingCriterion):
Copy link
Contributor

Choose a reason for hiding this comment

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

I think this logic as it is written is hard to parse. Would it be clearer if it was (somewhat):

if relativeDelta < relativeStoppingCriterion or absoluteDelta < absoluteStoppingCriterion:
    # We are converged
    inPedestalIteration = False
else:
    # We have not yet converged; grow the bin size if possible.
    if binsize < blah:
        binsize = newbinsize
        log.info
        # (No need to set this to True again)
    else:
        # We have reached the maximum binsize.
        log.warning
        inPedestalIteration = False

This adds an extra safeguard on the pedestal background measurement by
adding an iteration on the measurement, increasing (doubling) the bin size
at each stage.  The bin size starts very small and there is at least one
iteration.  The stopping criterion is if either the change in the cumulative
pedestal between the current and subsequent level is less than 5% of the
current measured (cumulative) pedestal (relative change) or 0.5 "counts"
(absolute change) or if the bin size has reached a value greater than the
size of the exposure's bounding box.
@laurenam laurenam merged commit 4a40236 into main Dec 2, 2025
4 checks passed
@laurenam laurenam deleted the tickets/DM-53418 branch December 2, 2025 21:29
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