Skip to content

Commit

Permalink
Merge pull request #303 from lsst/tickets/DM-20566-pipe_tasks
Browse files Browse the repository at this point in the history
DM-20566: Replace afwGeom with geom where appropriate
  • Loading branch information
timj committed Jul 18, 2019
2 parents 4840a28 + ef36e91 commit 24ce6f0
Show file tree
Hide file tree
Showing 31 changed files with 168 additions and 158 deletions.
6 changes: 3 additions & 3 deletions examples/runRepair.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
import sys

import lsst.afw.image as afwImage
import lsst.afw.geom as afwGeom
import lsst.geom as geom
import lsst.meas.algorithms as measAlg
from lsst.pipe.tasks.repair import RepairTask

Expand Down Expand Up @@ -65,12 +65,12 @@ def addDefects(exp, nBadCols=10):
for xi in numpy.random.randint(0, xsize, nBadCols):
yi = numpy.random.randint(0, ysize)
xi, yi = int(xi), int(yi)
bbox = afwGeom.Box2I(afwGeom.PointI(xi, 0), afwGeom.ExtentI(1, yi+1))
bbox = geom.Box2I(geom.PointI(xi, 0), geom.ExtentI(1, yi+1))
subIm = afwImage.ImageF(img, bbox)
subIm.set(1e7)
defectList.append(bbox)
# set a 15 pixel box of defects at the upper left corner to demonstrate fallbackValue
bbox = afwGeom.Box2I(afwGeom.PointI(0, ysize-15), afwGeom.ExtentI(15, 15))
bbox = geom.Box2I(geom.PointI(0, ysize-15), geom.ExtentI(15, 15))
subIm = afwImage.ImageF(img, bbox)
subIm.set(1e7)
defectList.append(bbox)
Expand Down
31 changes: 16 additions & 15 deletions python/lsst/pipe/tasks/assembleCoadd.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import warnings
import lsst.pex.config as pexConfig
import lsst.pex.exceptions as pexExceptions
import lsst.geom as geom
import lsst.afw.geom as afwGeom
import lsst.afw.image as afwImage
import lsst.afw.math as afwMath
Expand Down Expand Up @@ -789,7 +790,7 @@ def run(self, skyInfo, tempExpRefList, imageScalerList, weightList,
self.assembleMetadata(coaddExposure, tempExpRefList, weightList)
coaddMaskedImage = coaddExposure.getMaskedImage()
subregionSizeArr = self.config.subregionSize
subregionSize = afwGeom.Extent2I(subregionSizeArr[0], subregionSizeArr[1])
subregionSize = geom.Extent2I(subregionSizeArr[0], subregionSizeArr[1])
# if nImage is requested, create a zero one which can be passed to assembleSubregion
if self.config.doNImage:
nImage = afwImage.ImageU(skyInfo.bbox)
Expand Down Expand Up @@ -829,8 +830,8 @@ def assembleMetadata(self, coaddExposure, tempExpRefList, weightList):
# (and we need more than just the PropertySet that contains the header), which is not possible
# with the current butler (see #2777).
tempExpList = [tempExpRef.get(tempExpName + "_sub",
bbox=afwGeom.Box2I(coaddExposure.getBBox().getMin(),
afwGeom.Extent2I(1, 1)), immediate=True)
bbox=geom.Box2I(coaddExposure.getBBox().getMin(),
geom.Extent2I(1, 1)), immediate=True)
for tempExpRef in tempExpRefList]
numCcds = sum(len(tempExp.getInfo().getCoaddInputs().ccds) for tempExp in tempExpList)

Expand Down Expand Up @@ -882,7 +883,7 @@ def assembleSubregion(self, coaddExposure, bbox, tempExpRefList, imageScalerList
----------
coaddExposure : `lsst.afw.image.Exposure`
The target exposure for the coadd.
bbox : `lsst.afw.geom.Box`
bbox : `lsst.geom.Box`
Sub-region to coadd.
tempExpRefList : `list`
List of data reference to tempExp.
Expand Down Expand Up @@ -1031,7 +1032,7 @@ def shrinkValidPolygons(self, coaddInputs):
if polyOrig:
validPolygon = polyOrig.intersectionSingle(validPolyBBox)
else:
validPolygon = afwGeom.polygon.Polygon(afwGeom.Box2D(validPolyBBox))
validPolygon = afwGeom.polygon.Polygon(geom.Box2D(validPolyBBox))
ccd.setValidPolygon(validPolygon)

def readBrightObjectMasks(self, dataRef):
Expand Down Expand Up @@ -1078,17 +1079,17 @@ def setBrightObjectMasks(self, exposure, dataId, brightObjectMasks):
plateScale = wcs.getPixelScale().asArcseconds()

for rec in brightObjectMasks:
center = afwGeom.PointI(wcs.skyToPixel(rec.getCoord()))
center = geom.PointI(wcs.skyToPixel(rec.getCoord()))
if rec["type"] == "box":
assert rec["angle"] == 0.0, ("Angle != 0 for mask object %s" % rec["id"])
width = rec["width"].asArcseconds()/plateScale # convert to pixels
height = rec["height"].asArcseconds()/plateScale # convert to pixels

halfSize = afwGeom.ExtentI(0.5*width, 0.5*height)
bbox = afwGeom.Box2I(center - halfSize, center + halfSize)
halfSize = geom.ExtentI(0.5*width, 0.5*height)
bbox = geom.Box2I(center - halfSize, center + halfSize)

bbox = afwGeom.BoxI(afwGeom.PointI(int(center[0] - 0.5*width), int(center[1] - 0.5*height)),
afwGeom.PointI(int(center[0] + 0.5*width), int(center[1] + 0.5*height)))
bbox = geom.BoxI(geom.PointI(int(center[0] - 0.5*width), int(center[1] - 0.5*height)),
geom.PointI(int(center[0] + 0.5*width), int(center[1] + 0.5*height)))
spans = afwGeom.SpanSet(bbox)
elif rec["type"] == "circle":
radius = int(rec["radius"].asArcseconds()/plateScale) # convert to pixels
Expand Down Expand Up @@ -1138,14 +1139,14 @@ def _subBBoxIter(bbox, subregionSize):
Parameters
----------
bbox : `lsst.afw.geom.Box2I`
bbox : `lsst.geom.Box2I`
Bounding box over which to iterate.
subregionSize: `lsst.afw.geom.Extent2I`
subregionSize: `lsst.geom.Extent2I`
Size of sub-bboxes.
Yields
------
subBBox : `lsst.afw.geom.Box2I`
subBBox : `lsst.geom.Box2I`
Next sub-bounding box of size ``subregionSize`` or smaller; each ``subBBox``
is contained within ``bbox``, so it may be smaller than ``subregionSize`` at
the edges of ``bbox``, but it will never be empty.
Expand All @@ -1157,7 +1158,7 @@ def _subBBoxIter(bbox, subregionSize):

for rowShift in range(0, bbox.getHeight(), subregionSize[1]):
for colShift in range(0, bbox.getWidth(), subregionSize[0]):
subBBox = afwGeom.Box2I(bbox.getMin() + afwGeom.Extent2I(colShift, rowShift), subregionSize)
subBBox = geom.Box2I(bbox.getMin() + geom.Extent2I(colShift, rowShift), subregionSize)
subBBox.clip(bbox)
if subBBox.isEmpty():
raise RuntimeError("Bug: empty bbox! bbox=%s, subregionSize=%s, "
Expand Down Expand Up @@ -1683,7 +1684,7 @@ def detectClipBig(self, clipList, clipFootprints, clipIndices, detectionFootprin
Mask value of clipped pixels.
maskDetValue
Mask value of detected pixels.
coaddBBox : `lsst.afw.geom.Box`
coaddBBox : `lsst.geom.Box`
BBox of the coadd and warps.
Returns
Expand Down
9 changes: 5 additions & 4 deletions python/lsst/pipe/tasks/coaddBase.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
# see <http://www.lsstcorp.org/LegalNotices/>.
#
import lsst.pex.config as pexConfig
import lsst.geom as geom
import lsst.afw.geom as afwGeom
import lsst.afw.image as afwImage
import lsst.pipe.base as pipeBase
Expand Down Expand Up @@ -114,7 +115,7 @@ def selectExposures(self, patchRef, skyInfo=None, selectDataList=[]):
"""!
@brief Select exposures to coadd
Get the corners of the bbox supplied in skyInfo using @ref afwGeom.Box2D and convert the pixel
Get the corners of the bbox supplied in skyInfo using @ref geom.Box2D and convert the pixel
positions of the bbox corners to sky coordinates using @ref skyInfo.wcs.pixelToSky. Use the
@ref WcsSelectImagesTask_ "WcsSelectImagesTask" to select exposures that lie inside the patch
indicated by the dataRef.
Expand All @@ -126,7 +127,7 @@ def selectExposures(self, patchRef, skyInfo=None, selectDataList=[]):
"""
if skyInfo is None:
skyInfo = self.getSkyInfo(patchRef)
cornerPosList = afwGeom.Box2D(skyInfo.bbox).getCorners()
cornerPosList = geom.Box2D(skyInfo.bbox).getCorners()
coordList = [skyInfo.wcs.pixelToSky(pos) for pos in cornerPosList]
return self.select.runDataRef(patchRef, coordList, selectDataList=selectDataList).dataRefList

Expand All @@ -142,7 +143,7 @@ def getSkyInfo(self, patchRef):
- tractInfo: information for chosen tract of sky map
- patchInfo: information about chosen patch of tract
- wcs: WCS of tract
- bbox: outer bbox of patch, as an afwGeom Box2I
- bbox: outer bbox of patch, as an geom Box2I
"""
return getSkyInfo(coaddName=self.config.coaddName, patchRef=patchRef)

Expand Down Expand Up @@ -240,7 +241,7 @@ def getSkyInfo(coaddName, patchRef):
- tractInfo: information for chosen tract of sky map
- patchInfo: information about chosen patch of tract
- wcs: WCS of tract
- bbox: outer bbox of patch, as an afwGeom Box2I
- bbox: outer bbox of patch, as an geom Box2I
"""
skyMap = patchRef.get(coaddName + "Coadd_skyMap")
return makeSkyInfo(skyMap, patchRef.dataId["tract"], patchRef.dataId["patch"])
Expand Down
20 changes: 10 additions & 10 deletions python/lsst/pipe/tasks/dcrAssembleCoadd.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
from math import ceil
import numpy as np
from scipy import ndimage
import lsst.afw.geom as afwGeom
import lsst.geom as geom
import lsst.afw.image as afwImage
import lsst.afw.table as afwTable
import lsst.coadd.utils as coaddUtils
Expand Down Expand Up @@ -481,7 +481,7 @@ def run(self, skyInfo, warpRefList, imageScalerList, weightList,
else:
dcrNImages = None

subregionSize = afwGeom.Extent2I(*self.config.subregionSize)
subregionSize = geom.Extent2I(*self.config.subregionSize)
nSubregions = (ceil(skyInfo.bbox.getHeight()/subregionSize[1]) *
ceil(skyInfo.bbox.getWidth()/subregionSize[0]))
subIter = 0
Expand All @@ -490,7 +490,7 @@ def run(self, skyInfo, warpRefList, imageScalerList, weightList,
subIter += 1
self.log.info("Computing coadd over patch %s subregion %s of %s: %s",
skyInfo.patchInfo.getIndex(), subIter, nSubregions, subBBox)
dcrBBox = afwGeom.Box2I(subBBox)
dcrBBox = geom.Box2I(subBBox)
dcrBBox.grow(self.bufferSize)
dcrBBox.clip(dcrModels.bbox)
modelWeights = self.calculateModelWeights(dcrModels, dcrBBox)
Expand Down Expand Up @@ -566,7 +566,7 @@ def calculateNImage(self, dcrModels, bbox, warpRefList, spanSetMaskList, statsCt
----------
dcrModels : `lsst.pipe.tasks.DcrModel`
Best fit model of the true sky after correcting chromatic effects.
bbox : `lsst.afw.geom.box.Box2I`
bbox : `lsst.geom.box.Box2I`
Bounding box of the patch to coadd.
warpRefList : `list` of `lsst.daf.persistence.ButlerDataRef`
The data references to the input warped exposures.
Expand Down Expand Up @@ -637,9 +637,9 @@ def dcrAssembleSubregion(self, dcrModels, subExposures, bbox, dcrBBox, warpRefLi
Best fit model of the true sky after correcting chromatic effects.
subExposures : `dict` of `lsst.afw.image.ExposureF`
The pre-loaded exposures for the current subregion.
bbox : `lsst.afw.geom.box.Box2I`
bbox : `lsst.geom.box.Box2I`
Bounding box of the subregion to coadd.
dcrBBox : `lsst.afw.geom.box.Box2I`
dcrBBox : `lsst.geom.box.Box2I`
Sub-region of the coadd which includes a buffer to allow for DCR.
warpRefList : `list` of `lsst.daf.persistence.ButlerDataRef`
The data references to the input warped exposures.
Expand Down Expand Up @@ -726,7 +726,7 @@ def newModelFromResidual(self, dcrModels, residualGeneratorList, dcrBBox, statsC
Current model of the true sky after correcting chromatic effects.
residualGeneratorList : `generator` of `numpy.ndarray`
The residual image for the next subfilter, shifted for DCR.
dcrBBox : `lsst.afw.geom.box.Box2I`
dcrBBox : `lsst.geom.box.Box2I`
Sub-region of the coadd which includes a buffer to allow for DCR.
statsCtrl : `lsst.afw.math.StatisticsControl`
Statistics control object for coadd
Expand Down Expand Up @@ -780,7 +780,7 @@ def calculateConvergence(self, dcrModels, subExposures, bbox, warpRefList, weigh
Best fit model of the true sky after correcting chromatic effects.
subExposures : `dict` of `lsst.afw.image.ExposureF`
The pre-loaded exposures for the current subregion.
bbox : `lsst.afw.geom.box.Box2I`
bbox : `lsst.geom.box.Box2I`
Sub-region to coadd
warpRefList : `list` of `lsst.daf.persistence.ButlerDataRef`
The data references to the input warped exposures.
Expand Down Expand Up @@ -1016,7 +1016,7 @@ def calculateModelWeights(self, dcrModels, dcrBBox):
----------
dcrModels : `lsst.pipe.tasks.DcrModel`
Best fit model of the true sky after correcting chromatic effects.
dcrBBox : `lsst.afw.geom.box.Box2I`
dcrBBox : `lsst.geom.box.Box2I`
Sub-region of the coadd which includes a buffer to allow for DCR.
Returns
Expand Down Expand Up @@ -1067,7 +1067,7 @@ def loadSubExposures(self, bbox, statsCtrl, warpRefList, imageScalerList, spanSe
Parameters
----------
bbox : `lsst.afw.geom.box.Box2I`
bbox : `lsst.geom.box.Box2I`
Sub-region to coadd
statsCtrl : `lsst.afw.math.StatisticsControl`
Statistics control object for coadd
Expand Down
12 changes: 6 additions & 6 deletions python/lsst/pipe/tasks/imageDifference.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
import lsst.pex.config as pexConfig
import lsst.pipe.base as pipeBase
import lsst.daf.base as dafBase
import lsst.afw.geom as afwGeom
import lsst.geom as geom
import lsst.afw.math as afwMath
import lsst.afw.table as afwTable
from lsst.meas.astrom import AstrometryConfig, AstrometryTask
Expand Down Expand Up @@ -426,7 +426,7 @@ def runDataRef(self, sensorRef, templateIdList=None):
# match exposure sources to template sources
mc = afwTable.MatchControl()
mc.findOnlyClosest = False
matches = afwTable.matchRaDec(templateSources, selectSources, 1.0*afwGeom.arcseconds,
matches = afwTable.matchRaDec(templateSources, selectSources, 1.0*geom.arcseconds,
mc)
else:
raise RuntimeError("doSelectSources=True and kernelSourcesFromRef=False,"
Expand Down Expand Up @@ -882,17 +882,17 @@ def __init__(self, **kwargs):
def fitAstrometry(self, templateSources, templateExposure, selectSources):
"""Fit the relative astrometry between templateSources and selectSources"""
if self.config.winter2013WcsShift > 0.0:
offset = afwGeom.Extent2D(self.config.winter2013WcsShift,
self.config.winter2013WcsShift)
offset = geom.Extent2D(self.config.winter2013WcsShift,
self.config.winter2013WcsShift)
cKey = templateSources[0].getTable().getCentroidKey()
for source in templateSources:
centroid = source.get(cKey)
source.set(cKey, centroid + offset)
elif self.config.winter2013WcsRms > 0.0:
cKey = templateSources[0].getTable().getCentroidKey()
for source in templateSources:
offset = afwGeom.Extent2D(self.config.winter2013WcsRms*numpy.random.normal(),
self.config.winter2013WcsRms*numpy.random.normal())
offset = geom.Extent2D(self.config.winter2013WcsRms*numpy.random.normal(),
self.config.winter2013WcsRms*numpy.random.normal())
centroid = source.get(cKey)
source.set(cKey, centroid + offset)

Expand Down
20 changes: 10 additions & 10 deletions python/lsst/pipe/tasks/insertFakes.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
import galsim
from astropy.table import Table

import lsst.afw.geom as afwGeom
import lsst.geom as geom
import lsst.afw.image as afwImage
import lsst.afw.math as afwMath
import lsst.pex.config as pexConfig
Expand Down Expand Up @@ -264,7 +264,7 @@ def run(self, fakeCat, image, wcs, photoCalib):
The catalog of fake sources to be input
image : `lsst.afw.image.exposure.exposure.ExposureF`
The image into which the fake sources should be added
wcs : `lsst.afw.geom.skyWcs.skyWcs.SkyWcs`
wcs : `lsst.afw.geom.SkyWcs`
WCS to use to add fake sources
photoCalib : `lsst.afw.image.photoCalib.PhotoCalib`
Photometric calibration to be used to calibrate the fake sources
Expand Down Expand Up @@ -320,7 +320,7 @@ def addPixCoords(self, fakeCat, wcs):
----------
fakeCat : `pandas.core.frame.DataFrame`
The catalog of fake sources to be input
wcs : `lsst.afw.geom.skyWcs.skyWcs.SkyWcs`
wcs : `lsst.afw.geom.SkyWcs`
WCS to use to add fake sources
Returns
Expand Down Expand Up @@ -353,7 +353,7 @@ def trimFakeCat(self, fakeCat, image, wcs):
The catalog of fake sources to be input
image : `lsst.afw.image.exposure.exposure.ExposureF`
The image into which the fake sources should be added
wcs : `lsst.afw.geom.skyWcs.skyWcs.SkyWcs`
wcs : `lsst.afw.geom.SkyWcs`
WCS to use to add fake sources
Returns
Expand Down Expand Up @@ -392,7 +392,7 @@ def mkFakeGalsimGalaxies(self, fakeCat, band, photoCalib, pixelScale, psf, image
-------
galImages : `list`
A list of tuples of `lsst.afw.image.exposure.exposure.ExposureF` and
`lsst.afw.geom.Point2D` of their locations.
`lsst.geom.Point2D` of their locations.
Notes
-----
Expand All @@ -411,7 +411,7 @@ def mkFakeGalsimGalaxies(self, fakeCat, band, photoCalib, pixelScale, psf, image
self.log.info("Making %d fake galaxy images" % len(fakeCat))

for (index, row) in fakeCat.iterrows():
xy = afwGeom.Point2D(row["x"], row["y"])
xy = geom.Point2D(row["x"], row["y"])

try:
# Due to the different radii used for calibration and measurement a correction factor is
Expand Down Expand Up @@ -470,16 +470,16 @@ def mkFakeStars(self, fakeCat, band, photoCalib, psf, image):
Returns
-------
starImages : `list`
A list of tuples of `lsst.afw.image.image.image.ImageF` of fake stars and
`lsst.afw.geom.Point2D` of their locations.
A list of tuples of `lsst.afw.image.ImageF` of fake stars and
`lsst.geom.Point2D` of their locations.
"""

starImages = []

self.log.info("Making %d fake star images" % len(fakeCat))

for (index, row) in fakeCat.iterrows():
xy = afwGeom.Point2D(row["x"], row["y"])
xy = geom.Point2D(row["x"], row["y"])

try:
# Due to the different radii used for calibration and measurement a correction factor is
Expand Down Expand Up @@ -531,7 +531,7 @@ def addFakeSources(self, image, fakeImages, sourceType):
image : `lsst.afw.image.exposure.exposure.ExposureF`
The image into which the fake sources should be added
fakeImages : `list`
A list of tuples of `lsst.afw.image.image.image.ImageF` and `lsst.afw.geom.Point2D,
A list of tuples of `lsst.afw.image.ImageF` and `lsst.geom.Point2D,
the images and the locations they are to be inserted at.
sourceType : `str`
The type (star/galaxy) of fake sources input
Expand Down

0 comments on commit 24ce6f0

Please sign in to comment.