Skip to content

Commit

Permalink
Use geom in preference to afwGeom
Browse files Browse the repository at this point in the history
  • Loading branch information
timj committed Jul 16, 2019
1 parent 62f7592 commit 098698b
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 26 deletions.
34 changes: 17 additions & 17 deletions tests/test_addToCoadd.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@

import lsst.utils
import lsst.utils.tests
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.afw.display.ds9 as ds9
Expand Down Expand Up @@ -80,7 +80,7 @@ def referenceAddToCoadd(coadd, weightMap, maskedImage, badPixelMask, weight):
- weight: relative weight of this maskedImage (a float)
Returns three items:
- overlapBBox: the overlap region relative to the parent (afwGeom.Box2I)
- overlapBBox: the overlap region relative to the parent (geom.Box2I)
- coaddArrayList: new coadd as a list of image, mask, variance numpy arrays
- weightMapArray: new weight map, as a numpy array
"""
Expand Down Expand Up @@ -124,7 +124,7 @@ def _testAddToCoaddImpl(self, useMask, uniformWeight=True):
"""Test coadd"""

trueImageValue = 10.0
imBBox = afwGeom.Box2I(afwGeom.Point2I(0, 0), afwGeom.Extent2I(10, 20))
imBBox = geom.Box2I(geom.Point2I(0, 0), geom.Extent2I(10, 20))
if useMask:
coadd = afwImage.MaskedImageF(imBBox)
weightMap = coadd.getImage().Factory(coadd.getBBox())
Expand All @@ -143,8 +143,8 @@ def _testAddToCoaddImpl(self, useMask, uniformWeight=True):
image = coadd.Factory(coadd.getDimensions())
image.set(badPixel)

subBBox = afwGeom.Box2I(afwGeom.Point2I(0, i),
image.getDimensions() - afwGeom.Extent2I(0, i))
subBBox = geom.Box2I(geom.Point2I(0, i),
image.getDimensions() - geom.Extent2I(0, i))
subImage = image.Factory(image, subBBox, afwImage.LOCAL)
subImage.set(truth)
del subImage
Expand Down Expand Up @@ -229,7 +229,7 @@ def referenceTest(self, coadd, weightMap, image, badPixelMask, weight):
def testMed(self):
"""Test addToCoadd by adding an image with known bad pixels using varying masks
"""
medBBox = afwGeom.Box2I(afwGeom.Point2I(130, 315), afwGeom.Extent2I(20, 21))
medBBox = geom.Box2I(geom.Point2I(130, 315), geom.Extent2I(20, 21))
medMIPath = os.path.join(AfwdataDir, MedMiSubpath)
maskedImage = afwImage.MaskedImageF(afwImage.MaskedImageF(medMIPath), medBBox)
coadd = afwImage.MaskedImageF(medBBox)
Expand All @@ -243,13 +243,13 @@ def testMultSizes(self):
"""Test addToCoadd by adding various subregions of the med image
to a coadd that's a slightly different shape
"""
bbox = afwGeom.Box2I(afwGeom.Point2I(130, 315), afwGeom.Extent2I(30, 31))
bbox = geom.Box2I(geom.Point2I(130, 315), geom.Extent2I(30, 31))
medMIPath = os.path.join(AfwdataDir, MedMiSubpath)
fullMaskedImage = afwImage.MaskedImageF(medMIPath)
maskedImage = afwImage.MaskedImageF(fullMaskedImage, bbox)
coaddBBox = afwGeom.Box2I(
maskedImage.getXY0() + afwGeom.Extent2I(-6, +4),
maskedImage.getDimensions() + afwGeom.Extent2I(10, -10))
coaddBBox = geom.Box2I(
maskedImage.getXY0() + geom.Extent2I(-6, +4),
maskedImage.getDimensions() + geom.Extent2I(10, -10))
coadd = afwImage.MaskedImageF(coaddBBox)
weightMap = afwImage.ImageF(coaddBBox)
badPixelMask = 0x0
Expand All @@ -259,30 +259,30 @@ def testMultSizes(self):
self.assertFalse(overlapBBox.isEmpty())

# add masked image that extends beyond coadd in x
bbox = afwGeom.Box2I(afwGeom.Point2I(120, 320), afwGeom.Extent2I(50, 10))
bbox = geom.Box2I(geom.Point2I(120, 320), geom.Extent2I(50, 10))
maskedImage = afwImage.MaskedImageF(fullMaskedImage, bbox)
overlapBBox = self.referenceTest(coadd, weightMap, maskedImage, badPixelMask, 0.5)
self.assertFalse(overlapBBox.isEmpty())

# add masked image that is fully within the coadd
bbox = afwGeom.Box2I(afwGeom.Point2I(130, 320), afwGeom.Extent2I(10, 10))
bbox = geom.Box2I(geom.Point2I(130, 320), geom.Extent2I(10, 10))
maskedImage = afwImage.MaskedImageF(fullMaskedImage, bbox)
overlapBBox = self.referenceTest(coadd, weightMap, maskedImage, badPixelMask, 0.5)
self.assertFalse(overlapBBox.isEmpty())

# add masked image that does not overlap coadd
bbox = afwGeom.Box2I(afwGeom.Point2I(0, 0), afwGeom.Extent2I(10, 10))
bbox = geom.Box2I(geom.Point2I(0, 0), geom.Extent2I(10, 10))
maskedImage = afwImage.MaskedImageF(fullMaskedImage, bbox)
overlapBBox = self.referenceTest(coadd, weightMap, maskedImage, badPixelMask, 0.5)
self.assertTrue(overlapBBox.isEmpty())

def testAssertions(self):
"""Test that addToCoadd requires coadd and weightMap to have the same dimensions and xy0"""
maskedImage = afwImage.MaskedImageF(afwGeom.Extent2I(10, 10))
coadd = afwImage.MaskedImageF(afwGeom.Extent2I(11, 11))
maskedImage = afwImage.MaskedImageF(geom.Extent2I(10, 10))
coadd = afwImage.MaskedImageF(geom.Extent2I(11, 11))
coadd.setXY0(5, 6)
for dw, dh in (1, 0), (0, 1), (-1, 0), (0, -1):
weightMapBBox = afwGeom.Box2I(coadd.getXY0(), coadd.getDimensions() + afwGeom.Extent2I(dw, dh))
weightMapBBox = geom.Box2I(coadd.getXY0(), coadd.getDimensions() + geom.Extent2I(dw, dh))
weightMap = afwImage.ImageF(weightMapBBox)
weightMap.setXY0(coadd.getXY0())
try:
Expand All @@ -291,7 +291,7 @@ def testAssertions(self):
except pexExcept.Exception:
pass
for dx0, dy0 in (1, 0), (0, 1), (-1, 0), (0, -1):
weightMapBBox = afwGeom.Box2I(coadd.getXY0() + afwGeom.Extent2I(dx0, dy0), coadd.getDimensions())
weightMapBBox = geom.Box2I(coadd.getXY0() + geom.Extent2I(dx0, dy0), coadd.getDimensions())
weightMap = afwImage.ImageF(weightMapBBox)
try:
coaddUtils.addToCoadd(coadd, weightMap, maskedImage, 0x0, 0.1)
Expand Down
14 changes: 7 additions & 7 deletions tests/test_copyGoodPixels.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
import numpy as np

import lsst.utils.tests
import lsst.afw.geom as afwGeom
import lsst.geom as geom
import lsst.afw.image as afwImage
import lsst.coadd.utils as coaddUtils
from lsst.log import Log
Expand Down Expand Up @@ -197,8 +197,8 @@ def basicImageTest(self, srcImage, destImage):

def testMaskedImage(self):
"""Test image version of copyGoodPixels"""
srcBBox = afwGeom.Box2I(afwGeom.Point2I(2, 17), afwGeom.Point2I(100, 101))
destBBox = afwGeom.Box2I(afwGeom.Point2I(13, 4), afwGeom.Point2I(95, 130))
srcBBox = geom.Box2I(geom.Point2I(2, 17), geom.Point2I(100, 101))
destBBox = geom.Box2I(geom.Point2I(13, 4), geom.Point2I(95, 130))
destXY0 = destBBox.getMin()

srcImage = self.getRandomMaskedImage(srcBBox)
Expand All @@ -209,15 +209,15 @@ def testMaskedImage(self):

for bboxStart in (destXY0, (50, 51)):
for bboxDim in ((25, 36), (200, 200)):
destViewBox = afwGeom.Box2I(afwGeom.Point2I(*bboxStart), afwGeom.Extent2I(*bboxDim))
destViewBox = geom.Box2I(geom.Point2I(*bboxStart), geom.Extent2I(*bboxDim))
destViewBox.clip(destBBox)
destView = destImage.Factory(destImage, destViewBox, afwImage.PARENT, False)
self.basicMaskedImageTest(srcImage, destView, badMask)

def testImage(self):
"""Test image version of copyGoodPixels"""
srcBBox = afwGeom.Box2I(afwGeom.Point2I(2, 17), afwGeom.Point2I(100, 101))
destBBox = afwGeom.Box2I(afwGeom.Point2I(13, 4), afwGeom.Point2I(95, 130))
srcBBox = geom.Box2I(geom.Point2I(2, 17), geom.Point2I(100, 101))
destBBox = geom.Box2I(geom.Point2I(13, 4), geom.Point2I(95, 130))
destXY0 = destBBox.getMin()

srcImage = self.getRandomImage(srcBBox)
Expand All @@ -228,7 +228,7 @@ def testImage(self):

for bboxStart in (destXY0, (50, 51)):
for bboxDim in ((25, 36), (200, 200)):
destViewBox = afwGeom.Box2I(afwGeom.Point2I(*bboxStart), afwGeom.Extent2I(*bboxDim))
destViewBox = geom.Box2I(geom.Point2I(*bboxStart), geom.Extent2I(*bboxDim))
destViewBox.clip(destBBox)
destView = destImage.Factory(destImage, destViewBox, afwImage.PARENT, False)
self.basicImageTest(srcImage, destView)
Expand Down
4 changes: 2 additions & 2 deletions tests/test_setCoaddEdgeBits.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
import numpy as np

import lsst.utils.tests
import lsst.afw.geom as afwGeom
import lsst.geom as geom
import lsst.afw.image as afwImage
import lsst.coadd.utils as coaddUtils
from lsst.log import Log
Expand All @@ -42,7 +42,7 @@ class SetCoaddEdgeBitsTestCase(lsst.utils.tests.TestCase):
def testRandomMap(self):
"""Test setCoaddEdgeBits using a random depth map
"""
imDim = afwGeom.Extent2I(50, 55)
imDim = geom.Extent2I(50, 55)
coaddMask = afwImage.Mask(imDim)

np.random.seed(12345)
Expand Down

0 comments on commit 098698b

Please sign in to comment.