Skip to content

Commit

Permalink
Move growValidPolygons to coaddBase
Browse files Browse the repository at this point in the history
  • Loading branch information
arunkannawadi committed Dec 3, 2024
1 parent 9745ceb commit c6e2e9c
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 35 deletions.
35 changes: 35 additions & 0 deletions python/lsst/pipe/tasks/coaddBase.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import lsst.pipe.base as pipeBase
import lsst.geom as geom

from lsst.afw.geom import Polygon
from lsst.meas.algorithms import ScaleVarianceTask
from .selectImages import PsfWcsSelectImagesTask
from .coaddInputRecorder import CoaddInputRecorderTask
Expand Down Expand Up @@ -251,3 +252,37 @@ def subBBoxIter(bbox, subregionSize):
"colShift=%s, rowShift=%s" %
(bbox, subregionSize, colShift, rowShift))
yield subBBox


# Note that this is implemented as a free-floating function to enable reuse in
# lsst.pipe.tasks.makeWarp and in lsst.drp.tasks.make_psf_matched_warp
# without creating any relationships between the two classes.
# This may be converted to a method after makeWarp.py is removed altogether in
# DM-47916.
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
3 changes: 1 addition & 2 deletions python/lsst/pipe/tasks/makeWarp.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,7 @@
from lsst.meas.algorithms import CoaddPsf, CoaddPsfConfig, GaussianPsfFactory
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 .coaddBase import CoaddBaseTask, growValidPolygons, makeSkyInfo, reorderAndPadList
from .warpAndPsfMatch import WarpAndPsfMatchTask
from collections.abc import Iterable

Expand Down
34 changes: 1 addition & 33 deletions python/lsst/pipe/tasks/make_psf_matched_warp.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
from __future__ import annotations

__all__ = (
"growValidPolygons",
"MakePsfMatchedWarpConfig",
"MakePsfMatchedWarpConnections",
"MakePsfMatchedWarpTask",
Expand All @@ -46,7 +45,7 @@
Struct,
)
from lsst.pipe.base.connectionTypes import Input, Output
from lsst.pipe.tasks.coaddBase import makeSkyInfo
from lsst.pipe.tasks.ooaddBase import makeSkyInfo, growValidPolygons
from lsst.skymap import BaseSkyMap
from lsst.utils.timer import timeMethod

Expand Down Expand Up @@ -266,34 +265,3 @@ def run(self, direct_warp: Exposure, bbox: geom.Box2I):
else:
return Struct(psf_matched_warp=None)


# 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 c6e2e9c

Please sign in to comment.