Skip to content

Commit b97240b

Browse files
committed
Introduce new summary value for normalized sky background range
1 parent 7ac00fb commit b97240b

File tree

1 file changed

+28
-4
lines changed

1 file changed

+28
-4
lines changed

python/lsst/pipe/tasks/computeExposureSummaryStats.py

Lines changed: 28 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -522,7 +522,11 @@ def update_background_stats(self, summary, background):
522522
Parameters
523523
----------
524524
summary : `lsst.afw.image.ExposureSummaryStats`
525-
Summary object to update in-place.
525+
Summary object to update in-place. This method adds/updates the
526+
following fields:
527+
- `skyBg`: Median sky background value across background models.
528+
- `skyBgNormRange`: Normalized range (max - min / median) of the
529+
combined sky background, used to quantify spatial variation.
526530
background : `lsst.afw.math.BackgroundList` or `None`
527531
Background model. If `None`, all fields that depend on the
528532
background will be reset (generally to NaN).
@@ -535,11 +539,31 @@ def update_background_stats(self, summary, background):
535539
as well.
536540
"""
537541
if background is not None:
538-
bgStats = (bg[0].getStatsImage().getImage().array
539-
for bg in background)
540-
summary.skyBg = float(sum(np.median(bg[np.isfinite(bg)]) for bg in bgStats))
542+
bgStats = []
543+
for bg in background:
544+
statsImageF = bg[0].getStatsImage().getImage()
545+
bgArray = statsImageF.array
546+
bgArray[~np.isfinite(bgArray)] = np.nan
547+
bgStats.append(bgArray)
548+
summary.skyBg = float(sum(np.nanmedian(bg) for bg in bgStats))
549+
shapes = [arr.shape for arr in bgStats]
550+
if len(set(shapes)) != 1:
551+
raise RuntimeError(
552+
f"BackgroundList images from background models have different shapes: {shapes}"
553+
)
554+
skyBgSumImage = np.sum(np.stack(bgStats), axis=0)
555+
556+
median = np.nanmedian(skyBgSumImage)
557+
if median != 0 and np.isfinite(median):
558+
summary.skyBgNormRange = float(
559+
(np.nanmax(skyBgSumImage) - np.nanmin(skyBgSumImage)) / median
560+
)
561+
else:
562+
summary.skyBgNormRange = float("nan")
541563
else:
542564
summary.skyBg = float("nan")
565+
summary.skyBgNormRange = float("nan")
566+
breakpoint()
543567

544568
def update_masked_image_stats(self, summary, masked_image):
545569
"""Compute summary-statistic fields that depend on the masked image

0 commit comments

Comments
 (0)