def testLanczosFunction1D(self): def basicLanczos1(x, n): return sinc(x) * sinc(x / float(n)) errMsg = "{} = {} != {} for n={}, x={}, xOffset={}, xAdj={}" for n in range(1, 5): f = afwMath.LanczosFunction1D(n) self.assertEqual(f.getOrder(), n) for xOffset in (-10.0, 0.0, 0.05): f.setParameters((xOffset, )) g = f.clone() for x in np.arange(-10.0, 10.1, 0.50): xAdj = x - xOffset predVal = basicLanczos1(xAdj, n) msg = errMsg.format( type(f).__name__, f(x), predVal, n, x, xOffset, xAdj) self.assertFloatsAlmostEqual(f(x), predVal, msg=msg, atol=self.atol, rtol=None) msg = errMsg.format( type(g).__name__, g(x), predVal, n, x, xOffset, xAdj) + "; clone" self.assertFloatsAlmostEqual(g(x), predVal, msg=msg, atol=self.atol, rtol=None)
def testCast(self): for instance in (afwMath.Chebyshev1Function1F(2), afwMath.GaussianFunction1F(1.0), afwMath.LanczosFunction1F(3), afwMath.NullFunction1F(), afwMath.PolynomialFunction1F(2)): Class = type(instance) base = instance.clone() self.assertEqual(type(base), afwMath.Function1F) derived = Class.cast(base) self.assertEqual(type(derived), Class) for instance in (afwMath.Chebyshev1Function1D(2), afwMath.GaussianFunction1D(1.0), afwMath.LanczosFunction1D(3), afwMath.NullFunction1D(), afwMath.PolynomialFunction1D(2)): Class = type(instance) base = instance.clone() self.assertEqual(type(base), afwMath.Function1D) derived = Class.cast(base) self.assertEqual(type(derived), Class) for instance in (afwMath.Chebyshev1Function2F(2), afwMath.GaussianFunction2F(1.0, 1.0), afwMath.DoubleGaussianFunction2F(1.0), afwMath.LanczosFunction2F(3), afwMath.NullFunction2F(), afwMath.PolynomialFunction2F(2)): Class = type(instance) base = instance.clone() self.assertEqual(type(base), afwMath.Function2F) derived = Class.cast(base) self.assertEqual(type(derived), Class) for instance in (afwMath.Chebyshev1Function2D(2), afwMath.GaussianFunction2D(1.0, 1.0), afwMath.DoubleGaussianFunction2D(1.0), afwMath.LanczosFunction2D(3), afwMath.NullFunction2D(), afwMath.PolynomialFunction2D(2)): Class = type(instance) base = instance.clone() self.assertEqual(type(base), afwMath.Function2D) derived = Class.cast(base) self.assertEqual(type(derived), Class)
def testLanczosFunction1D(self): """A test for LanczosFunction1D""" def basicLanczos1(x, n): return sinc(x) * sinc(x / float(n)) for n in range(1, 5): f = afwMath.LanczosFunction1D(n) self.assertEquals(f.getOrder(), n) for xOffset in (-10.0, 0.0, 0.05): f.setParameters((xOffset, )) g = f.clone() # self.assertEquals(g.getOrder(), n) for x in numpy.arange(-10.0, 10.1, 0.50): xAdj = x - xOffset predVal = basicLanczos1(xAdj, n) if not numpy.allclose(predVal, f(x)): self.fail("%s = %s != %s for n=%s, x=%s, xOffset=%s, xAdj=%s" % \ (type(f).__name__, f(x), predVal, n, x, xOffset, xAdj)) if not numpy.allclose(predVal, g(x)): self.fail("%s = %s != %s for n=%s, x=%s, xOffset=%s, xAdj=%s; clone" % \ (type(g).__name__, g(x), predVal, n, x, xOffset, xAdj))