Skip to content

Commit

Permalink
Merge pull request #941 from lsst/tickets/DM-44623
Browse files Browse the repository at this point in the history
DM-44623: Attach shrunk validPolygons to PSF-matched warps
  • Loading branch information
arunkannawadi authored Jun 25, 2024
2 parents 0532501 + 4839b26 commit 8b7d742
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 1 deletion.
6 changes: 6 additions & 0 deletions python/lsst/pipe/tasks/makeWarp.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
from lsst.skymap import BaseSkyMap
from lsst.utils.timer import timeMethod
from .coaddBase import CoaddBaseTask, makeSkyInfo, reorderAndPadList
from .make_psf_matched_warp import growValidPolygons
from .warpAndPsfMatch import WarpAndPsfMatchTask
from collections.abc import Iterable

Expand Down Expand Up @@ -388,6 +389,11 @@ def run(self, calExpList, ccdIdList, skyInfo, visitId=0, dataIdList=None, **kwar
warps[warpType].setPsf(
CoaddPsf(inputRecorder[warpType].coaddInputs.ccds, skyInfo.wcs,
self.config.coaddPsf.makeControl()))
else: # warpType == "psfMached"
growValidPolygons(
inputRecorder[warpType].coaddInputs,
-self.config.warpAndPsfMatch.psfMatch.kernel.active.kernelSize // 2,
)
else:
if not self.config.doWriteEmptyWarps:
# No good pixels. Exposure still empty.
Expand Down
44 changes: 43 additions & 1 deletion python/lsst/pipe/tasks/make_psf_matched_warp.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,12 @@

from __future__ import annotations

__all__ = ("MakePsfMatchedWarpConfig", "MakePsfMatchedWarpConnections", "MakePsfMatchedWarpTask",)
__all__ = (
"growValidPolygons",
"MakePsfMatchedWarpConfig",
"MakePsfMatchedWarpConnections",
"MakePsfMatchedWarpTask",
)

from typing import TYPE_CHECKING

Expand Down Expand Up @@ -204,4 +209,41 @@ def run(self, direct_warp: Exposure):

self.log.info("Total number of good pixels = %d", total_good_pixels)

growValidPolygons(
exposure_psf_matched.info.getCoaddInputs(),
-self.config.psfMatch.kernel.active.kernelSize // 2
)

return Struct(psf_matched_warp=exposure_psf_matched)


# Note that this is implemented as a free-floating function to enable reuse in
# makeWarp.py without creating any relationships between the two classes.
# This may be converted to a method after makeWarp.py is removed altogether.
def growValidPolygons(coaddInputs, growBy: int) -> None:
"""Grow coaddInputs' ccds' ValidPolygons in place.
Either modify each ccd's validPolygon in place, or if CoaddInputs
does not have a validPolygon, create one from its bbox.
Parameters
----------
coaddInputs : `lsst.afw.image.coaddInputs`
CoaddInputs object containing the ccds to grow the valid polygons of.
growBy : `int`
The value to grow the valid polygons by.
Notes
-----
Negative values for ``growBy`` can shrink the polygons.
"""
for ccd in coaddInputs.ccds:
polyOrig = ccd.getValidPolygon()
validPolyBBox = polyOrig.getBBox() if polyOrig else ccd.getBBox()
validPolyBBox.grow(growBy)
if polyOrig:
validPolygon = polyOrig.intersectionSingle(validPolyBBox)
else:
validPolygon = Polygon(geom.Box2D(validPolyBBox))

ccd.validPolygon = validPolygon

0 comments on commit 8b7d742

Please sign in to comment.