Skip to content
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

DM-46693: Add ability to re-apply bgModel1 in SkyCorrectionTask #989

Merged
merged 3 commits into from
Dec 20, 2024
Merged
Changes from 1 commit
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
Prev Previous commit
Next Next commit
Add skyFrameScale as a returned output
leeskelvin committed Dec 20, 2024

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
commit 6f0c8e1474530778575c65ebe3a98295a1c7a318
15 changes: 13 additions & 2 deletions python/lsst/pipe/tasks/skyCorrection.py
Original file line number Diff line number Diff line change
@@ -300,6 +300,8 @@ def run(self, calExps, calBkgs, skyFrames, camera):
Returns
-------
results : `Struct` containing:
skyFrameScale : `float`
Scale factor applied to the sky frame.
skyCorr : `list` [`lsst.afw.math.BackgroundList`]
Detector-level sky correction background lists.
calExpMosaic : `lsst.afw.image.ExposureF`
@@ -318,8 +320,9 @@ def run(self, calExps, calBkgs, skyFrames, camera):
initialBackgroundIndex = len(calBkgs[0]._backgrounds) - 1

# Subtract a scaled sky frame from all input exposures
skyFrameScale = None
if self.config.doSky:
self._subtractSkyFrame(calExps, skyFrames, calBkgs)
skyFrameScale = self._subtractSkyFrame(calExps, skyFrames, calBkgs)

# Adds full-fp bg back onto exposures, removes it from list
if self.config.undoBgModel1:
@@ -341,7 +344,9 @@ def run(self, calExps, calBkgs, skyFrames, camera):
skyCorrExtras, camera, self.config.binning, ids=calExpIds, refExps=calExps
)

return Struct(skyCorr=calBkgs, calExpMosaic=calExpMosaic, calBkgMosaic=calBkgMosaic)
return Struct(
skyFrameScale=skyFrameScale, skyCorr=calBkgs, calExpMosaic=calExpMosaic, calBkgMosaic=calBkgMosaic
)

def _restoreOriginalBackgroundRefineMask(self, calExps, calBkgs):
"""Restore original background to each calexp and invert the related
@@ -562,6 +567,11 @@ def _subtractSkyFrame(self, calExps, skyFrames, calBkgs):
Sky frame calibration data for the input detectors.
calBkgs : `list` [`lsst.afw.math.BackgroundList`]
Background lists associated with the input calibrated exposures.

Returns
-------
scale : `float`
Scale factor applied to the sky frame.
"""
skyFrameBgModels = []
scales = []
@@ -577,6 +587,7 @@ def _subtractSkyFrame(self, calExps, skyFrames, calBkgs):
# also updating the calBkg list in-place
self.sky.subtractSkyFrame(calExp.getMaskedImage(), skyFrameBgModel, scale, calBkg)
self.log.info("Sky frame subtracted with a scale factor of %.5f", scale)
return scale

def _binAndMosaic(self, exposures, camera, binning, ids=None, refExps=None):
"""Bin input exposures and mosaic across the entire focal plane.