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

Merged
merged 2 commits 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
20 changes: 8 additions & 12 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 All @@ -38,7 +38,7 @@
except ImportError:
applyMosaicResults = None

__all__ = ("PerTractCcdDataIdContainer", "ForcedPhotCcdConfig", "ForcedPhotCcdTask")
__all__ = ("PerTractCcdDataIdContainer", "ForcedPhotCcdConfig", "ForcedPhotCcdTask", "imageOverlapsTract")


class PerTractCcdDataIdContainer(lsst.pipe.base.DataIdContainer):
Expand Down Expand Up @@ -84,7 +84,7 @@ def makeDataRefList(self, namespace):
# Going with just the nearest tract. Since we're throwing all tracts for the visit
# together, this shouldn't be a problem unless the tracts are much smaller than a CCD.
tract = skymap.findTract(wcs.pixelToSky(box.getCenter()))
if overlapsTract(tract, wcs, box):
if imageOverlapsTract(tract, wcs, box):
visitTract[visit].add(tract.getId())
else:
self.refList.extend(ref for ref in namespace.butler.subset(self.datasetType, dataId=dataId))
Expand All @@ -102,31 +102,27 @@ def makeDataRefList(self, namespace):
log.info("Number of visits for each tract: %s", dict(tractCounter))


def overlapsTract(tract, imageWcs, imageBox):
def imageOverlapsTract(tract, imageWcs, imageBox):
"""Return whether the image (specified by Wcs and bounding box) overlaps the tract

@param tract: TractInfo specifying a tract
@param imageWcs: Wcs for image
@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