def testComplexPersistence(self): """Test persistence of a TransformBoundedField whose string representation is huge """ # DM-11964 shows that CFITSIO cannot handle string fields # in binary tables that have more than 28799 characters # make sure the test has plenty of margin minChars = 10*28799 degree = 100 # make large enough that len(transform.writeString()) > minChars n_coeffs = (degree + 1)*(degree + 2)//2 coeffs = np.zeros((n_coeffs, 4), dtype=float) k = 0 for j in range(degree + 1): for i in range(degree - j + 1): coeffs[k][0] = np.random.random() coeffs[k][1] = 1 coeffs[k][2] = i coeffs[k][3] = j k += 1 chebyMap = astshim.PolyMap(coeffs, 1) transform = lsst.afw.geom.TransformPoint2ToGeneric(chebyMap) print("nchar=%s; minChar=%s" % (len(transform.writeString()), minChars)) self.assertGreater(len(transform.writeString()), minChars) complexBoundedField = TransformBoundedField(self.bbox, transform) with lsst.utils.tests.getTempFilePath(".fits") as filename: complexBoundedField.writeFits(filename) readField = TransformBoundedField.readFits(filename) self.assertTrue(complexBoundedField == readField) self.assertFalse(complexBoundedField != readField) self.assertEqual(complexBoundedField, readField) resArr = complexBoundedField.evaluate(self.xList, self.yList) readResArr = readField.evaluate(self.xList, self.yList) assert_allclose(resArr, readResArr) self.assertEqual(readField.getBBox(), self.bbox)
def testBBox(self): """The BBox should have no effect on the kind of transform being tested Use an empty bbox as an extreme test of this """ self.assertEqual(self.boundedField.getBBox(), self.bbox) emptyBBox = lsst.afw.geom.Box2I() noBBoxField = TransformBoundedField(emptyBBox, self.transform) self.assertEqual(noBBoxField.getBBox(), emptyBBox) resArr = self.boundedField.evaluate(self.xList, self.yList) resArrNoBBox = noBBoxField.evaluate(self.xList, self.yList) assert_allclose(resArr, resArrNoBBox)
def testBBox(self): """The BBox should have no effect on the kind of transform being tested Use an empty bbox as an extreme test of this """ self.assertEqual(self.boundedField.getBBox(), self.bbox) emptyBBox = lsst.geom.Box2I() noBBoxField = TransformBoundedField(emptyBBox, self.transform) self.assertEqual(noBBoxField.getBBox(), emptyBBox) resArr = self.boundedField.evaluate(self.xList, self.yList) resArrNoBBox = noBBoxField.evaluate(self.xList, self.yList) assert_allclose(resArr, resArrNoBBox)
def setUp(self): self.longMessage = True # an arbitrary bounding box (not that this kind of field cares) self.bbox = lsst.afw.geom.Box2I(lsst.afw.geom.Point2I(-3, 4), lsst.afw.geom.Extent2I(5, 30)) # a list of points contained in the bbox self.pointList = lsst.afw.geom.Box2D(self.bbox).getCorners() self.pointList.append(lsst.afw.geom.Box2D(self.bbox).getCenter()) self.xList = np.array([p[0] for p in self.pointList]) self.yList = np.array([p[1] for p in self.pointList]) # a simple polynomial mapping coeff_f = np.array([ [1.5, 1, 0, 0], [-0.5, 1, 1, 0], [1.0, 1, 0, 1], ]) polyMap = astshim.PolyMap(coeff_f, 1) self.transform = lsst.afw.geom.TransformPoint2ToGeneric(polyMap) self.boundedField = TransformBoundedField(self.bbox, self.transform)
def testPersistenceAndEquality(self): """Test persistence using writeFits and readFits Also test operator== """ with lsst.utils.tests.getTempFilePath(".fits") as filename: self.boundedField.writeFits(filename) readField = TransformBoundedField.readFits(filename) self.assertTrue(self.boundedField == readField) self.assertFalse(self.boundedField != readField) self.assertEqual(self.boundedField, readField) resArr = self.boundedField.evaluate(self.xList, self.yList) readResArr = readField.evaluate(self.xList, self.yList) assert_allclose(resArr, readResArr) self.assertEqual(readField.getBBox(), self.bbox)
def setUp(self): self.longMessage = True # an arbitrary bounding box (not that this kind of field cares) self.bbox = lsst.geom.Box2I(lsst.geom.Point2I(-3, 4), lsst.geom.Extent2I(5, 30)) # a list of points contained in the bbox self.pointList = lsst.geom.Box2D(self.bbox).getCorners() self.pointList.append(lsst.geom.Box2D(self.bbox).getCenter()) self.xList = np.array([p[0] for p in self.pointList]) self.yList = np.array([p[1] for p in self.pointList]) # a simple polynomial mapping coeff_f = np.array([ [1.5, 1, 0, 0], [-0.5, 1, 1, 0], [1.0, 1, 0, 1], ]) polyMap = astshim.PolyMap(coeff_f, 1) self.transform = lsst.afw.geom.TransformPoint2ToGeneric(polyMap) self.boundedField = TransformBoundedField(self.bbox, self.transform)
def testComplexPersistence(self): """Test persistence of a TransformBoundedField whose string representation is huge """ # DM-11964 shows that CFITSIO cannot handle string fields # in binary tables that have more than 28799 characters # make sure the test has plenty of margin minChars = 10 * 28799 degree = 100 # make large enough that len(transform.writeString()) > minChars n_coeffs = (degree + 1) * (degree + 2) // 2 coeffs = np.zeros((n_coeffs, 4), dtype=float) k = 0 for j in range(degree + 1): for i in range(degree - j + 1): coeffs[k][0] = np.random.random() coeffs[k][1] = 1 coeffs[k][2] = i coeffs[k][3] = j k += 1 chebyMap = astshim.PolyMap(coeffs, 1) transform = lsst.afw.geom.TransformPoint2ToGeneric(chebyMap) print("nchar=%s; minChar=%s" % (len(transform.writeString()), minChars)) self.assertGreater(len(transform.writeString()), minChars) complexBoundedField = TransformBoundedField(self.bbox, transform) with lsst.utils.tests.getTempFilePath(".fits") as filename: complexBoundedField.writeFits(filename) readField = TransformBoundedField.readFits(filename) self.assertTrue(complexBoundedField == readField) self.assertFalse(complexBoundedField != readField) self.assertEqual(complexBoundedField, readField) resArr = complexBoundedField.evaluate(self.xList, self.yList) readResArr = readField.evaluate(self.xList, self.yList) assert_allclose(resArr, readResArr) self.assertEqual(readField.getBBox(), self.bbox)
class TransformBoundedFieldTestCase(lsst.utils.tests.TestCase): def setUp(self): self.longMessage = True # an arbitrary bounding box (not that this kind of field cares) self.bbox = lsst.afw.geom.Box2I(lsst.afw.geom.Point2I(-3, 4), lsst.afw.geom.Extent2I(5, 30)) # a list of points contained in the bbox self.pointList = lsst.afw.geom.Box2D(self.bbox).getCorners() self.pointList.append(lsst.afw.geom.Box2D(self.bbox).getCenter()) self.xList = np.array([p[0] for p in self.pointList]) self.yList = np.array([p[1] for p in self.pointList]) # a simple polynomial mapping coeff_f = np.array([ [1.5, 1, 0, 0], [-0.5, 1, 1, 0], [1.0, 1, 0, 1], ]) polyMap = astshim.PolyMap(coeff_f, 1) self.transform = lsst.afw.geom.TransformPoint2ToGeneric(polyMap) self.boundedField = TransformBoundedField(self.bbox, self.transform) def tearDown(self): del self.transform def testEvaluate(self): """Test the various overloads of `evaluate` """ for point in self.pointList: # applylForward returns a vector with one entry per axis # and in this case there is just one axis predRes = self.transform.applyForward(point)[0] res = self.boundedField.evaluate(point) self.assertFloatsAlmostEqual(res, predRes) x, y = point res2 = self.boundedField.evaluate(x, y) self.assertFloatsAlmostEqual(res2, predRes) resArr = self.boundedField.evaluate(self.xList, self.yList) # applylForward returns an array with one row of values per axis # and in this case there is just one axis predResArr = self.transform.applyForward(self.pointList)[0] assert_allclose(resArr, predResArr) def testMultiplyOperator(self): """Test operator* """ maxVal = np.max(np.abs(self.transform.applyForward(self.pointList)[0])) for multFactor in (-9e99, -1.5e-7, 3.6e-7, 1.5, 9.23e99): atol = abs(maxVal * multFactor * 1e-15) predResult = self.transform.applyForward( self.pointList)[0] * multFactor scaledField1 = self.boundedField * multFactor assert_allclose(scaledField1.evaluate(self.xList, self.yList), predResult, atol=atol) scaledField2 = multFactor * self.boundedField assert_allclose(scaledField2.evaluate(self.xList, self.yList), predResult, atol=atol) def testBBox(self): """The BBox should have no effect on the kind of transform being tested Use an empty bbox as an extreme test of this """ self.assertEqual(self.boundedField.getBBox(), self.bbox) emptyBBox = lsst.afw.geom.Box2I() noBBoxField = TransformBoundedField(emptyBBox, self.transform) self.assertEqual(noBBoxField.getBBox(), emptyBBox) resArr = self.boundedField.evaluate(self.xList, self.yList) resArrNoBBox = noBBoxField.evaluate(self.xList, self.yList) assert_allclose(resArr, resArrNoBBox) def testPersistenceAndEquality(self): """Test persistence using writeFits and readFits Also test operator== """ with lsst.utils.tests.getTempFilePath(".fits") as filename: self.boundedField.writeFits(filename) readField = TransformBoundedField.readFits(filename) self.assertTrue(self.boundedField == readField) self.assertFalse(self.boundedField != readField) self.assertEqual(self.boundedField, readField) resArr = self.boundedField.evaluate(self.xList, self.yList) readResArr = readField.evaluate(self.xList, self.yList) assert_allclose(resArr, readResArr) self.assertEqual(readField.getBBox(), self.bbox)
class TransformBoundedFieldTestCase(lsst.utils.tests.TestCase): def setUp(self): self.longMessage = True # an arbitrary bounding box (not that this kind of field cares) self.bbox = lsst.geom.Box2I(lsst.geom.Point2I(-3, 4), lsst.geom.Extent2I(5, 30)) # a list of points contained in the bbox self.pointList = lsst.geom.Box2D(self.bbox).getCorners() self.pointList.append(lsst.geom.Box2D(self.bbox).getCenter()) self.xList = np.array([p[0] for p in self.pointList]) self.yList = np.array([p[1] for p in self.pointList]) # a simple polynomial mapping coeff_f = np.array([ [1.5, 1, 0, 0], [-0.5, 1, 1, 0], [1.0, 1, 0, 1], ]) polyMap = astshim.PolyMap(coeff_f, 1) self.transform = lsst.afw.geom.TransformPoint2ToGeneric(polyMap) self.boundedField = TransformBoundedField(self.bbox, self.transform) def tearDown(self): del self.transform def testEvaluate(self): """Test the various overloads of `evaluate` """ for point in self.pointList: # applylForward returns a vector with one entry per axis # and in this case there is just one axis predRes = self.transform.applyForward(point)[0] res = self.boundedField.evaluate(point) self.assertFloatsAlmostEqual(res, predRes) x, y = point res2 = self.boundedField.evaluate(x, y) self.assertFloatsAlmostEqual(res2, predRes) resArr = self.boundedField.evaluate(self.xList, self.yList) # applylForward returns an array with one row of values per axis # and in this case there is just one axis predResArr = self.transform.applyForward(self.pointList)[0] assert_allclose(resArr, predResArr) def testMultiplyOperator(self): """Test operator* """ maxVal = np.max(np.abs(self.transform.applyForward(self.pointList)[0])) for multFactor in (-9e99, -1.5e-7, 3.6e-7, 1.5, 9.23e99): atol = abs(maxVal*multFactor*1e-15) predResult = self.transform.applyForward(self.pointList)[0]*multFactor scaledField1 = self.boundedField*multFactor assert_allclose(scaledField1.evaluate(self.xList, self.yList), predResult, atol=atol) scaledField2 = multFactor*self.boundedField assert_allclose(scaledField2.evaluate(self.xList, self.yList), predResult, atol=atol) def testBBox(self): """The BBox should have no effect on the kind of transform being tested Use an empty bbox as an extreme test of this """ self.assertEqual(self.boundedField.getBBox(), self.bbox) emptyBBox = lsst.geom.Box2I() noBBoxField = TransformBoundedField(emptyBBox, self.transform) self.assertEqual(noBBoxField.getBBox(), emptyBBox) resArr = self.boundedField.evaluate(self.xList, self.yList) resArrNoBBox = noBBoxField.evaluate(self.xList, self.yList) assert_allclose(resArr, resArrNoBBox) def testPersistenceAndEquality(self): """Test persistence using writeFits and readFits Also test operator== """ with lsst.utils.tests.getTempFilePath(".fits") as filename: self.boundedField.writeFits(filename) readField = TransformBoundedField.readFits(filename) self.assertTrue(self.boundedField == readField) self.assertFalse(self.boundedField != readField) self.assertEqual(self.boundedField, readField) resArr = self.boundedField.evaluate(self.xList, self.yList) readResArr = readField.evaluate(self.xList, self.yList) assert_allclose(resArr, readResArr) self.assertEqual(readField.getBBox(), self.bbox) def testComplexPersistence(self): """Test persistence of a TransformBoundedField whose string representation is huge """ # DM-11964 shows that CFITSIO cannot handle string fields # in binary tables that have more than 28799 characters # make sure the test has plenty of margin minChars = 10*28799 degree = 100 # make large enough that len(transform.writeString()) > minChars n_coeffs = (degree + 1)*(degree + 2)//2 coeffs = np.zeros((n_coeffs, 4), dtype=float) k = 0 for j in range(degree + 1): for i in range(degree - j + 1): coeffs[k][0] = np.random.random() coeffs[k][1] = 1 coeffs[k][2] = i coeffs[k][3] = j k += 1 chebyMap = astshim.PolyMap(coeffs, 1) transform = lsst.afw.geom.TransformPoint2ToGeneric(chebyMap) print("nchar=%s; minChar=%s" % (len(transform.writeString()), minChars)) self.assertGreater(len(transform.writeString()), minChars) complexBoundedField = TransformBoundedField(self.bbox, transform) with lsst.utils.tests.getTempFilePath(".fits") as filename: complexBoundedField.writeFits(filename) readField = TransformBoundedField.readFits(filename) self.assertTrue(complexBoundedField == readField) self.assertFalse(complexBoundedField != readField) self.assertEqual(complexBoundedField, readField) resArr = complexBoundedField.evaluate(self.xList, self.yList) readResArr = readField.evaluate(self.xList, self.yList) assert_allclose(resArr, readResArr) self.assertEqual(readField.getBBox(), self.bbox)
class TransformBoundedFieldTestCase(lsst.utils.tests.TestCase): def setUp(self): self.longMessage = True # an arbitrary bounding box (not that this kind of field cares) self.bbox = lsst.geom.Box2I(lsst.geom.Point2I(-3, 4), lsst.geom.Extent2I(5, 30)) # a list of points contained in the bbox self.pointList = lsst.geom.Box2D(self.bbox).getCorners() self.pointList.append(lsst.geom.Box2D(self.bbox).getCenter()) self.xList = np.array([p[0] for p in self.pointList]) self.yList = np.array([p[1] for p in self.pointList]) # a simple polynomial mapping coeff_f = np.array([ [1.5, 1, 0, 0], [-0.5, 1, 1, 0], [1.0, 1, 0, 1], ]) polyMap = astshim.PolyMap(coeff_f, 1) self.transform = lsst.afw.geom.TransformPoint2ToGeneric(polyMap) self.boundedField = TransformBoundedField(self.bbox, self.transform) def tearDown(self): del self.transform def testEvaluate(self): """Test the various overloads of `evaluate` """ for point in self.pointList: # applylForward returns a vector with one entry per axis # and in this case there is just one axis predRes = self.transform.applyForward(point)[0] res = self.boundedField.evaluate(point) self.assertFloatsAlmostEqual(res, predRes) x, y = point res2 = self.boundedField.evaluate(x, y) self.assertFloatsAlmostEqual(res2, predRes) resArr = self.boundedField.evaluate(self.xList, self.yList) # applylForward returns an array with one row of values per axis # and in this case there is just one axis predResArr = self.transform.applyForward(self.pointList)[0] assert_allclose(resArr, predResArr) def testMultiplyOperator(self): """Test operator* """ maxVal = np.max(np.abs(self.transform.applyForward(self.pointList)[0])) for multFactor in (-9e99, -1.5e-7, 3.6e-7, 1.5, 9.23e99): atol = abs(maxVal * multFactor * 1e-15) predResult = self.transform.applyForward( self.pointList)[0] * multFactor scaledField1 = self.boundedField * multFactor assert_allclose(scaledField1.evaluate(self.xList, self.yList), predResult, atol=atol) scaledField2 = multFactor * self.boundedField assert_allclose(scaledField2.evaluate(self.xList, self.yList), predResult, atol=atol) def testBBox(self): """The BBox should have no effect on the kind of transform being tested Use an empty bbox as an extreme test of this """ self.assertEqual(self.boundedField.getBBox(), self.bbox) emptyBBox = lsst.geom.Box2I() noBBoxField = TransformBoundedField(emptyBBox, self.transform) self.assertEqual(noBBoxField.getBBox(), emptyBBox) resArr = self.boundedField.evaluate(self.xList, self.yList) resArrNoBBox = noBBoxField.evaluate(self.xList, self.yList) assert_allclose(resArr, resArrNoBBox) def testPersistenceAndEquality(self): """Test persistence using writeFits and readFits Also test operator== """ with lsst.utils.tests.getTempFilePath(".fits") as filename: self.boundedField.writeFits(filename) readField = TransformBoundedField.readFits(filename) self.assertTrue(self.boundedField == readField) self.assertFalse(self.boundedField != readField) self.assertEqual(self.boundedField, readField) resArr = self.boundedField.evaluate(self.xList, self.yList) readResArr = readField.evaluate(self.xList, self.yList) assert_allclose(resArr, readResArr) self.assertEqual(readField.getBBox(), self.bbox) def testComplexPersistence(self): """Test persistence of a TransformBoundedField whose string representation is huge """ # DM-11964 shows that CFITSIO cannot handle string fields # in binary tables that have more than 28799 characters # make sure the test has plenty of margin minChars = 10 * 28799 degree = 100 # make large enough that len(transform.writeString()) > minChars n_coeffs = (degree + 1) * (degree + 2) // 2 coeffs = np.zeros((n_coeffs, 4), dtype=float) k = 0 for j in range(degree + 1): for i in range(degree - j + 1): coeffs[k][0] = np.random.random() coeffs[k][1] = 1 coeffs[k][2] = i coeffs[k][3] = j k += 1 chebyMap = astshim.PolyMap(coeffs, 1) transform = lsst.afw.geom.TransformPoint2ToGeneric(chebyMap) print("nchar=%s; minChar=%s" % (len(transform.writeString()), minChars)) self.assertGreater(len(transform.writeString()), minChars) complexBoundedField = TransformBoundedField(self.bbox, transform) with lsst.utils.tests.getTempFilePath(".fits") as filename: complexBoundedField.writeFits(filename) readField = TransformBoundedField.readFits(filename) self.assertTrue(complexBoundedField == readField) self.assertFalse(complexBoundedField != readField) self.assertEqual(complexBoundedField, readField) resArr = complexBoundedField.evaluate(self.xList, self.yList) readResArr = readField.evaluate(self.xList, self.yList) assert_allclose(resArr, readResArr) self.assertEqual(readField.getBBox(), self.bbox)