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-13790: Remove all use of the geom package #197

Merged
merged 1 commit into from
May 11, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What's wrong with circle.radius?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lsst.sphgeom.Circle does not support radius or getRadius; the equivalent method is getOpeningAngle(). Unfortunately the sphgeom pybind11 wrapper doesn't seem to use properties, as openingAngle would be nicer than getOpeningAngle(). We make small enough use of sphgeom that I figured we could live with that, but I am not happy about it.

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