def main(): # a 31x31 postage stamp image nx, ny = 31, 31 # move xy0 to simulate it being a shallow bbox'd sub-image xorig, yorig = 100, 300 xy0 = afwGeom.Point2I(xorig, yorig) psfSigma = 3.0 x0, y0 = xorig + nx / 2, yorig + ny / 2 p0 = afwGeom.Point2D(x0, y0) img = afwImage.ImageF(nx, ny, 0) img.setXY0(xy0) for i in range(ny): for j in range(nx): ic = i - (y0 - yorig) jc = j - (x0 - xorig) r = math.sqrt(ic * ic + jc * jc) img.set(j, i, 1.0 * math.exp(-r**2 / (2.0 * psfSigma**2))) # now warp it about the centroid using a linear transform linTran = afwGeom.LinearTransform().makeScaling( 1.2) # a simple scale-by-20% # extent a bit along x-dir linTran[0] *= 1.2 wimg = afwImage.ImageF(nx, ny, 0) # output 'warped' image wimg.setXY0(xy0) kernel = afwMath.LanczosWarpingKernel(5) # warping kernel afwMath.warpCenteredImage(wimg, img, kernel, linTran, p0) img.writeFits("img.fits") wimg.writeFits("wimg.fits")
def testTransform(self): transform = afwGeom.LinearTransform(np.array([[2.0, 0.0], [0.0, 2.0]])) spanSetPreScale = afwGeom.SpanSet.fromShape(2, afwGeom.Stencil.CIRCLE) spanSetPostScale = spanSetPreScale.transformedBy(transform) self.assertEqual(spanSetPostScale.getBBox().getMinX(), -4) self.assertEqual(spanSetPostScale.getBBox().getMinY(), -4)
def testTransform(self): dims = afwGeom.Extent2I(512, 512) bbox = afwGeom.Box2I(afwGeom.Point2I(0, 0), dims) radius = 5 offset = afwGeom.Extent2D(123, 456) crval = afwGeom.SpherePoint(0 * afwGeom.degrees, 0 * afwGeom.degrees) crpix = afwGeom.Point2D(0, 0) cdMatrix = np.array([1.0e-5, 0.0, 0.0, 1.0e-5]) cdMatrix.shape = (2, 2) source = afwGeom.makeSkyWcs(crval=crval, crpix=crpix, cdMatrix=cdMatrix) target = afwGeom.makeSkyWcs(crval=crval, crpix=crpix + offset, cdMatrix=cdMatrix) sourceSpanSet = afwGeom.SpanSet.fromShape(radius, afwGeom.Stencil.CIRCLE) sourceSpanSet = sourceSpanSet.shiftedBy(12, 34) fpSource = afwDetect.Footprint(sourceSpanSet, bbox) fpTarget = fpSource.transform(source, target, bbox) self.assertEqual(len(fpSource.getSpans()), len(fpTarget.getSpans())) self.assertEqual(fpSource.getArea(), fpTarget.getArea()) imSource = afwImage.ImageU(dims) fpSource.spans.setImage(imSource, 1) imTarget = afwImage.ImageU(dims) fpTarget.spans.setImage(imTarget, 1) subSource = imSource.Factory(imSource, fpSource.getBBox()) subTarget = imTarget.Factory(imTarget, fpTarget.getBBox()) self.assertTrue(np.all(subSource.getArray() == subTarget.getArray())) # make a bbox smaller than the target footprint bbox2 = afwGeom.Box2I(fpTarget.getBBox()) bbox2.grow(-1) fpTarget2 = fpSource.transform(source, target, bbox2) # this one clips fpTarget3 = fpSource.transform(source, target, bbox2, False) # this one doesn't self.assertTrue(bbox2.contains(fpTarget2.getBBox())) self.assertFalse(bbox2.contains(fpTarget3.getBBox())) self.assertNotEqual(fpTarget.getArea(), fpTarget2.getArea()) self.assertEqual(fpTarget.getArea(), fpTarget3.getArea()) # Test that peakCatalogs get Transformed correctly truthList = [(x, y, 10) for x, y in zip(range(-2, 2), range(-1, 3))] for value in truthList: fpSource.addPeak(*value) scaleFactor = 2 linTrans = afwGeom.LinearTransform( np.matrix([[scaleFactor, 0], [0, scaleFactor]], dtype=float)) linTransFootprint = fpSource.transform(linTrans, fpSource.getBBox(), False) for peak, truth in zip(linTransFootprint.peaks, truthList): # Multiplied by two because that is the linear transform scaling # factor self.assertEqual(peak.getIx(), truth[0] * scaleFactor) self.assertEqual(peak.getIy(), truth[1] * scaleFactor)
def testOtherAliases(self): with self.assertWarns(FutureWarning): self.assertIsInstance(afwGeom.BoxI(), lsst.geom.BoxI) with self.assertWarns(FutureWarning): self.assertIsInstance(afwGeom.BoxI(), lsst.geom.Box2I) with self.assertWarns(FutureWarning): self.assertIsInstance(afwGeom.BoxD(), lsst.geom.BoxD) with self.assertWarns(FutureWarning): self.assertIsInstance(afwGeom.BoxD(), lsst.geom.Box2D) with self.assertWarns(FutureWarning): self.assertIsInstance(afwGeom.SpherePoint(), lsst.geom.SpherePoint) with self.assertWarns(FutureWarning): self.assertIsInstance(afwGeom.AffineTransform(), lsst.geom.AffineTransform) with self.assertWarns(FutureWarning): self.assertIsInstance(afwGeom.LinearTransform(), lsst.geom.LinearTransform)
def setUp(self): scale = 2.0 self.data = afwGeom.LinearTransform().makeScaling(scale)
def setUp(self): scale = 2.2 linear = afwGeom.LinearTransform().makeScaling(scale) dx, dy = 1.1, 3.3 trans = afwGeom.Extent2D(dx, dy) self.data = afwGeom.AffineTransform(linear, trans)