Skip to content

Commit

Permalink
Improve overlapsTract and use sphgeom
Browse files Browse the repository at this point in the history
Improve overlapsTract as follows:
- Update to use sphgeom instead of geom
  (this was the only routine using geom).
  Note that convexHull can no longer return False,
  but it should never fail anyway (if we find it does
  fail we'll have to move the call into a try/except).
- Use new method skymap.TractInfo.getOuterSkyPolygon
- Call wcs.pixelToSky once on a list of points
  • Loading branch information
r-owen committed May 10, 2018
1 parent 32c2b40 commit 9f517b9
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 10 deletions.
14 changes: 5 additions & 9 deletions python/lsst/meas/base/forcedPhotCcd.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
import lsst.afw.geom
import lsst.afw.image
import lsst.afw.table
from lsst.geom import convexHull
import lsst.sphgeom

from .forcedPhotImage import ForcedPhotImageTask, ForcedPhotImageConfig

Expand Down Expand Up @@ -110,23 +110,19 @@ def overlapsTract(tract, imageWcs, imageBox):
@param imageBox: Bounding box for image
@return bool
"""
tractWcs = tract.getWcs()
tractCorners = [tractWcs.pixelToSky(lsst.afw.geom.Point2D(coord)).getVector() for
coord in tract.getBBox().getCorners()]
tractPoly = convexHull(tractCorners)
tractPoly = tract.getOuterSkyPolygon()

imagePixelCorners = lsst.afw.geom.Box2D(imageBox).getCorners()
try:
imageCorners = [imageWcs.pixelToSky(lsst.afw.geom.Point2D(pix)) for pix in imageBox.getCorners()]
imageSkyCorners = imageWcs.pixelToSky(imagePixelCorners)
except lsst.pex.exceptions.LsstCppException as e:
# Protecting ourselves from awful Wcs solutions in input images
if (not isinstance(e.message, lsst.pex.exceptions.DomainErrorException) and
not isinstance(e.message, lsst.pex.exceptions.RuntimeErrorException)):
raise
return False

imagePoly = convexHull([coord.getVector() for coord in imageCorners])
if imagePoly is None:
return False
imagePoly = lsst.sphgeom.ConvexPolygon.convexHull([coord.getVector() for coord in imageSkyCorners])
return tractPoly.intersects(imagePoly) # "intersects" also covers "contains" or "is contained by"


Expand Down
2 changes: 1 addition & 1 deletion ups/meas_base.table
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ setupRequired(utils)
setupRequired(afw)
setupRequired(coadd_utils)
setupRequired(daf_base)
setupRequired(geom)
setupRequired(sphgeom)
setupRequired(numpy)
setupRequired(pex_config)
setupRequired(pipe_base)
Expand Down

0 comments on commit 9f517b9

Please sign in to comment.