Skip to content

Commit

Permalink
Switch from lsst.geom to lsst.sphgeom
Browse files Browse the repository at this point in the history
Use lsst.sphgeom.ConvexPolygon.convexHull
instead of lsst.geom.convexHull
  • Loading branch information
r-owen committed May 9, 2018
1 parent 6bb3a06 commit b00605b
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 15 deletions.
14 changes: 8 additions & 6 deletions python/lsst/pipe/tasks/makeDiscreteSkyMap.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
#
import sys
import traceback
import lsst.geom
import lsst.sphgeom

import lsst.afw.image as afwImage
import lsst.afw.geom as afwGeom
Expand Down Expand Up @@ -148,11 +148,11 @@ def run(self, butler, dataRefList):
# nb: don't need to worry about xy0 because Exposure saves Wcs with CRPIX shifted by (-x0, -y0).
boxI = afwImage.bboxFromMetadata(md)
boxD = afwGeom.Box2D(boxI)
points.extend(tuple(wcs.pixelToSky(corner).getVector()) for corner in boxD.getCorners())
points.extend(wcs.pixelToSky(corner).getVector() for corner in boxD.getCorners())
if len(points) == 0:
raise RuntimeError("No data found from which to compute convex hull")
self.log.info("Computing spherical convex hull")
polygon = lsst.geom.convexHull(points)
polygon = lsst.sphgeom.ConvexPolygon.convexHull(points)
if polygon is None:
raise RuntimeError(
"Failed to compute convex hull of the vertices of all calexp bounding boxes; "
Expand All @@ -174,9 +174,11 @@ def run(self, butler, dataRefList):
skyMapConfig.decList.extend(oldSkyMap.config.decList)
skyMapConfig.radiusList.extend(oldSkyMap.config.radiusList)
skyMapConfig.update(**self.config.skyMap.toDict())
skyMapConfig.raList.append(circle.center[0])
skyMapConfig.decList.append(circle.center[1])
skyMapConfig.radiusList.append(circle.radius + self.config.borderSize)
circleCenter = lsst.sphgeom.LonLat(circle.getCenter())
skyMapConfig.raList.append(circleCenter[0].asDegrees())
skyMapConfig.decList.append(circleCenter[1].asDegrees())
circleRadiusDeg = circle.getOpeningAngle().asDegrees()
skyMapConfig.radiusList.append(circleRadiusDeg + self.config.borderSize)
skyMap = DiscreteSkyMap(skyMapConfig)

for tractInfo in skyMap:
Expand Down
14 changes: 6 additions & 8 deletions python/lsst/pipe/tasks/selectImages.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
# see <http://www.lsstcorp.org/LegalNotices/>.
#
import numpy as np
import lsst.sphgeom
import lsst.pex.config as pexConfig
import lsst.pex.exceptions as pexExceptions
import lsst.afw.geom as afwGeom
Expand Down Expand Up @@ -172,27 +173,24 @@ class WcsSelectImagesTask(BaseSelectImagesTask):
def runDataRef(self, dataRef, coordList, makeDataRefList=True, selectDataList=[]):
"""Select images in the selectDataList that overlap the patch
We use the "convexHull" function in the geom package to define
We use the "convexHull" method of lsst.sphgeom.ConvexPolygon to define
polygons on the celestial sphere, and test the polygon of the
patch for overlap with the polygon of the image.
We use "convexHull" instead of generating a SphericalConvexPolygon
directly because the standard for the inputs to SphericalConvexPolygon
We use "convexHull" instead of generating a ConvexPolygon
directly because the standard for the inputs to ConvexPolygon
are pretty high and we don't want to be responsible for reaching them.
If "convexHull" is found to be too slow, we can revise this.
@param dataRef: Data reference for coadd/tempExp (with tract, patch)
@param coordList: List of ICRS coordinates (lsst.afw.geom.SpherePoint) specifying boundary of patch
@param makeDataRefList: Construct a list of data references?
@param selectDataList: List of SelectStruct, to consider for selection
"""
from lsst.geom import convexHull

dataRefList = []
exposureInfoList = []

patchVertices = [coord.getVector() for coord in coordList]
patchPoly = convexHull(patchVertices)
patchPoly = lsst.sphgeom.ConvexPolygon.convexHull(patchVertices)

for data in selectDataList:
dataRef = data.dataRef
Expand All @@ -206,7 +204,7 @@ def runDataRef(self, dataRef, coordList, makeDataRefList=True, selectDataList=[]
self.log.debug("WCS error in testing calexp %s (%s): deselecting", dataRef.dataId, e)
continue

imagePoly = convexHull([coord.getVector() for coord in imageCorners])
imagePoly = lsst.sphgeom.ConvexPolygon.convexHull([coord.getVector() for coord in imageCorners])
if imagePoly is None:
self.log.debug("Unable to create polygon from image %s: deselecting", dataRef.dataId)
continue
Expand Down
2 changes: 1 addition & 1 deletion ups/pipe_tasks.table
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ setupOptional(ip_diffim)
setupOptional(coadd_utils)
setupOptional(coadd_chisquared)
setupOptional(skymap)
setupOptional(geom)
setupOptional(sphgeom)

setupOptional(obs_test) # for unit tests
setupOptional(matplotlib)
Expand Down

0 comments on commit b00605b

Please sign in to comment.