Esempio n. 1
0
    def testNaturalSplineDerivative1(self):
        """Test fitting a natural spline to a smooth function and finding its derivative"""
        sp = afwMath.TautSpline(self.x, self.ySin)

        y2 = afwMath.vectorD()
        sp.derivative(self.x2, y2)

        for x, y in zip(self.x2, y2):
            self.assertTrue(abs(y - self.smooth(x, True)) < 1.5e-3)
Esempio n. 2
0
    def testNaturalSplineDerivative1(self):
        """Test fitting a natural spline to a smooth function and finding its derivative"""
        sp = afwMath.TautSpline(self.x, self.ySin)

        y2 = []
        sp.derivative(self.x2, y2)

        for x, y in zip(self.x2, y2):
            self.assertAlmostEqual(y, self.smooth(x, True), delta=1.5e-3)
Esempio n. 3
0
    def testNaturalSpline1(self):
        """Test fitting a natural spline to a smooth function"""
        gamma = 0
        sp = afwMath.TautSpline(self.x, self.ySin, gamma)

        y2 = afwMath.vectorD()
        sp.interpolate(self.x2, y2)

        for x, y in zip(self.x2, y2):
            self.assertAlmostEqual(y, self.smooth(x), 1)  # fails at 2 places!
Esempio n. 4
0
    def testTautSpline2(self):
        """Test fitting a taut spline to a non-differentiable function"""
        gamma = 2.5
        sp = afwMath.TautSpline(self.x, self.yND, gamma)

        y2 = afwMath.vectorD()
        sp.interpolate(self.x2, y2)

        for x, y in zip(self.x2, y2):
            self.assertAlmostEqual(y, self.noDerivative(x))
Esempio n. 5
0
    def testTautSpline1(self):
        """Test fitting a taut spline to a smooth function"""
        gamma = 2.5
        sp = afwMath.TautSpline(self.x, self.ySin, gamma)

        y2 = afwMath.vectorD()
        sp.interpolate(self.x2, y2)

        for x, y in zip(self.x2, y2):
            self.assertAlmostEqual(y, self.smooth(x), 4)
Esempio n. 6
0
    def testNaturalSpline2(self):
        """Test fitting a natural spline to a non-differentiable function (we basically fail)"""
        gamma = 0
        sp = afwMath.TautSpline(self.x, self.yND, gamma)

        y2 = afwMath.vectorD()
        sp.interpolate(self.x2, y2)

        for x, y in zip(self.x2, y2):
            self.assertAlmostEqual(y, self.noDerivative(x), 1)  # fails at 2 places!
Esempio n. 7
0
    def testRootFinding(self):
        """Test finding roots of Spline = value"""

        gamma = 2.5
        sp = afwMath.TautSpline(self.x, self.yND, gamma)

        for value in (0.1, 0.5):
            self.assertEqual(sp.roots(value, self.x[0], self.x[-1])[0], 1 - value)

        if False:
            y = afwMath.vectorD()
            sp.interpolate(self.x, y)
            for x, y in zip(self.x, y):
                print(x, y)
        #
        # Solve sin(x) = 0.5
        #
        sp = afwMath.TautSpline(self.x, self.ySin)
        roots = [math.degrees(x) for x in sp.roots(0.5, self.x[0], self.x[-1])]
        self.assertAlmostEqual(roots[0], 30, 5)
        self.assertAlmostEqual(roots[1], 150, 5)