Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 14 additions & 10 deletions python/lsst/pipe/tasks/calibrateImage.py
Original file line number Diff line number Diff line change
Expand Up @@ -1932,18 +1932,18 @@ def _remeasure_star_background(self, result, background_to_photometric_ratio=Non
nPixToDilate -= 1

result.exposure.mask = dilatedMask
self.log.warning("detected_fraction_orig = %.3f detected_fraction_dilated = %.3f",
detected_fraction_orig, detected_fraction_dilated)
self.log.debug("detected_fraction_orig = %.3f; detected_fraction_dilated = %.3f",
detected_fraction_orig, detected_fraction_dilated)
n_above_max_per_amp = -99
highest_detected_fraction_per_amp = float("nan")

# Check the per-amplifier detection fractions.
n_above_max_per_amp, highest_detected_fraction_per_amp, no_zero_det_amps = \
self._compute_per_amp_fraction(result.exposure, detected_fraction_dilated,
detected_mask_planes, bad_mask_planes)
self.log.warning("Dilated mask: n_above_max_per_amp = %d, "
"highest_detected_fraction_per_amp = %.3f",
n_above_max_per_amp, highest_detected_fraction_per_amp)
self.log.debug("Dilated mask: n_above_max_per_amp = %d; "
"highest_detected_fraction_per_amp = %.3f",
n_above_max_per_amp, highest_detected_fraction_per_amp)

bgIgnoreMasksToAdd = ["SAT", "SUSPECT", "SPIKE"]
detected_fraction = 1.0
Expand Down Expand Up @@ -2029,7 +2029,7 @@ def _remeasure_star_background(self, result, background_to_photometric_ratio=Non
bad_mask_planes)
self.log.info("nIter = %d, thresh = %.2f: Fraction of pixels marked as DETECTED or "
"DETECTED_NEGATIVE in star_background_detection = %.3f "
"(max is %.3f; min is %.3f) nFootprint = %d (current min is %d)",
"(max is %.3f; min is %.3f); nFootprint = %d (current min is %d)",
nIter, starBackgroundDetectionConfig.thresholdValue,
detected_fraction, maxDetFracForFinalBg, minDetFracForFinalBg,
nFootprintTemp, minFootprints)
Expand All @@ -2052,9 +2052,13 @@ def _remeasure_star_background(self, result, background_to_photometric_ratio=Non
or detected_fraction < 0.85*maxDetFracForFinalBg):
break
else:
self.log.warning("Making small tweak....")
starBackgroundDetectionConfig.thresholdValue = 1.05*currentThresh
self.log.warning("n_above_max_per_amp = %d (abs max is %d)", n_above_max_per_amp, int(0.75*n_amp))
self.log.debug("Number of amplifiers with detected fraction above the maximum "
"(%.2f) excedes the maximum allowed (%d >= %d). Making a small "
"tweak to the threshold (from %.2f to %.2f) and rerunning.",
maxDetFracForFinalBg, n_above_max_per_amp, int(0.75*n_amp),
currentThresh, starBackgroundDetectionConfig.thresholdValue)
self.log.debug("n_above_max_per_amp = %d (abs max is %d)", n_above_max_per_amp, int(0.75*n_amp))
Copy link
Member

Choose a reason for hiding this comment

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

Should this still warn when the absolute max is exceeded? I see there's a warning on maxDetFracForFinalBg, I can't tell whether this is related.

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, this "maximum" is not an absolute criterion in the usual sense. It is a deciding factor for the "making a small tweak" branch, so I added this info into that debug message (I'm not sure a user -- other than myself -- would really be able to glean much meaning out of it as an info after the fact, and hopefully the maxDetFracForFinalBg warning will do the talking.)


detected_fraction = self._compute_mask_fraction(result.exposure.mask, detected_mask_planes,
bad_mask_planes)
Expand All @@ -2066,7 +2070,7 @@ def _remeasure_star_background(self, result, background_to_photometric_ratio=Non
result.exposure.mask = dilatedMask
self.log.warning("Final fraction of pixels marked as DETECTED or DETECTED_NEGATIVE "
"was too large in star_background_detection = %.3f (max = %.3f). "
"Reverting to dilated mask from PSF detection...",
"Reverting to dilated mask from PSF detection.",
detected_fraction, maxDetFracForFinalBg)
self.metadata['adaptive_threshold_value'] = float("nan")
star_background = self.star_background.run(
Expand Down Expand Up @@ -2102,7 +2106,7 @@ def _remeasure_star_background(self, result, background_to_photometric_ratio=Non
detected_mask_planes,
bad_mask_planes)
result.exposure.mask = dilatedMask
self.log.debug("detected_fraction_orig = %.3f detected_fraction_dilated = %.3f",
self.log.debug("detected_fraction_orig = %.3f; detected_fraction_dilated = %.3f",
detected_fraction_orig, detected_fraction_dilated)

bbox = result.exposure.getBBox()
Expand Down