Skip to content

DM-45990: Create initial_pvi background metric #1114

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
33 changes: 29 additions & 4 deletions python/lsst/pipe/tasks/computeExposureSummaryStats.py
Original file line number Diff line number Diff line change
Expand Up @@ -522,7 +522,11 @@ def update_background_stats(self, summary, background):
Parameters
----------
summary : `lsst.afw.image.ExposureSummaryStats`
Summary object to update in-place.
Summary object to update in-place. This method adds/updates the
following fields:
- `skyBg`: Median sky background value across background models.
- `skyBgNormRange`: Normalized range (max - min / median) of the
combined sky background, used to quantify spatial variation.
background : `lsst.afw.math.BackgroundList` or `None`
Background model. If `None`, all fields that depend on the
background will be reset (generally to NaN).
Expand All @@ -535,11 +539,32 @@ def update_background_stats(self, summary, background):
as well.
"""
if background is not None:
bgStats = (bg[0].getStatsImage().getImage().array
for bg in background)
summary.skyBg = float(sum(np.median(bg[np.isfinite(bg)]) for bg in bgStats))
bgStats = []
for bg in background:
statsImageF = bg[0].getStatsImage().getImage()
bgArray = statsImageF.array
bgArray[~np.isfinite(bgArray)] = np.nan
bgStats.append(bgArray)
summary.skyBg = float(sum(np.nanmedian(bg) for bg in bgStats))
shapes = [arr.shape for arr in bgStats]
if len(set(shapes)) != 1:
raise RuntimeError(
f"BackgroundList images from background models have different shapes: {shapes}"
f"bgStats: {bgStats}"
)
skyBgSumImage = np.sum(np.stack(bgStats), axis=0)

median = np.nanmedian(skyBgSumImage)
if median != 0 and np.isfinite(median):
summary.skyBgNormRange = float(
(np.nanmax(skyBgSumImage) - np.nanmin(skyBgSumImage)) / median
)
else:
summary.skyBgNormRange = float("nan")
else:
summary.skyBg = float("nan")
summary.skyBgNormRange = float("nan")
breakpoint()

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