Esempio n. 1
0
    def test_kernel(self):
        """
        Tests :func:`colour.algebra.interpolation.KernelInterpolator.kernel`
        property.
        """

        x = y = np.linspace(0, 1, 10)
        kernel_interpolator = KernelInterpolator(x, y, kernel=kernel_linear)

        self.assertIs(kernel_interpolator.kernel, kernel_linear)
Esempio n. 2
0
    def test_window(self):
        """
        Tests :func:`colour.algebra.interpolation.KernelInterpolator.window`
        property.
        """

        x = y = np.linspace(0, 1, 10)
        kernel_interpolator = KernelInterpolator(x, y, window=3)

        self.assertEqual(kernel_interpolator.window, 3)
Esempio n. 3
0
    def test_y(self):
        """
        Tests :func:`colour.algebra.interpolation.KernelInterpolator.y`
        property.
        """

        x = y = np.linspace(0, 1, 10)
        kernel_interpolator = KernelInterpolator(x, y)

        np.testing.assert_equal(kernel_interpolator.y, y)
Esempio n. 4
0
    def test_x(self):
        """
        Test :attr:`colour.algebra.interpolation.KernelInterpolator.x`
        property.
        """

        x = y = np.linspace(0, 1, 10)
        kernel_interpolator = KernelInterpolator(x, y)

        np.testing.assert_equal(kernel_interpolator.x, x)
Esempio n. 5
0
    def test_kernel_args(self):
        """
        Tests :func:`colour.algebra.interpolation.KernelInterpolator.\
kernel_args` property.
        """

        x = y = np.linspace(0, 1, 10)
        kernel_args = {'a': 1}
        kernel_interpolator = KernelInterpolator(x, y, kernel_args=kernel_args)

        self.assertDictEqual(kernel_interpolator.kernel_args, kernel_args)
Esempio n. 6
0
    def test_raise_exception___call__(self):
        """
        Tests :func:`colour.algebra.interpolation.KernelInterpolator.__call__`
        method raised exception.
        """

        x = y = np.linspace(0, 1, 10)
        kernel_interpolator = KernelInterpolator(x, y)

        self.assertRaises(ValueError, kernel_interpolator, -1)

        self.assertRaises(ValueError, kernel_interpolator, 11)
Esempio n. 7
0
    def test_padding_args(self):
        """
        Tests :func:`colour.algebra.interpolation.KernelInterpolator.\
padding_args` property.
        """

        x = y = np.linspace(0, 1, 10)
        padding_args = {'pad_width': (3, 3), 'mode': 'mean'}
        kernel_interpolator = KernelInterpolator(
            x, y, padding_args=padding_args)

        self.assertDictEqual(kernel_interpolator.padding_args, padding_args)
Esempio n. 8
0
    def test_padding_kwargs(self):
        """
        Test :attr:`colour.algebra.interpolation.KernelInterpolator.\
padding_kwargs` property.
        """

        x = y = np.linspace(0, 1, 10)
        padding_kwargs = {"pad_width": (3, 3), "mode": "mean"}
        kernel_interpolator = KernelInterpolator(
            x, y, padding_kwargs=padding_kwargs
        )

        self.assertDictEqual(
            kernel_interpolator.padding_kwargs, padding_kwargs
        )
Esempio n. 9
0
    def test__call__(self):
        """
        Tests :func:`colour.algebra.interpolation.KernelInterpolator.__call__`
        method.
        """

        x = np.arange(11, 26, 1)
        y = np.sin(x / len(x) * np.pi * 6) / (x / len(x)) + np.pi
        x_i = np.linspace(11, 25, 25)

        kernel_interpolator = KernelInterpolator(x, y)
        np.testing.assert_almost_equal(
            kernel_interpolator(x_i),
            np.array([
                4.43848790, 4.26286480, 3.64640076, 2.77982023, 2.13474499,
                2.08206794, 2.50585862, 3.24992692, 3.84593162, 4.06289704,
                3.80825633, 3.21068994, 2.65177161, 2.32137382, 2.45995375,
                2.88799997, 3.43843598, 3.79504892, 3.79937086, 3.47673343,
                2.99303182, 2.59305006, 2.47805594, 2.82957843, 3.14159265
            ]),
            decimal=7)

        kernel_interpolator = KernelInterpolator(x, y, kernel=kernel_sinc)
        np.testing.assert_almost_equal(
            kernel_interpolator(x_i),
            np.array([
                4.43848790, 4.47570010, 3.84353906, 3.05959493, 2.53514958,
                2.19916874, 2.93225625, 3.32187855, 4.09458791, 4.23088094,
                3.92591447, 3.53263071, 2.65177161, 2.73541557, 2.65740315,
                3.17077616, 3.69624479, 3.87159620, 4.06433758, 3.56283868,
                3.28312289, 2.79652091, 2.62481419, 3.22117115, 3.14159265
            ]),
            decimal=7)

        kernel_interpolator = KernelInterpolator(x, y, window=1)
        np.testing.assert_almost_equal(
            kernel_interpolator(x_i),
            np.array([
                4.43848790, 4.96712277, 4.09584229, 3.23991575, 2.80418924,
                2.28470276, 3.20024753, 3.41120944, 4.46416970, 4.57878168,
                4.15371498, 3.92841633, 2.65177161, 3.02110187, 2.79812654,
                3.44218674, 4.00032377, 4.01356870, 4.47633386, 3.70912627,
                3.58365067, 3.14325415, 2.88247572, 3.37531662, 3.14159265
            ]),
            decimal=7)

        kernel_interpolator = KernelInterpolator(
            x, y, window=1, kernel_args={'a': 1})
        np.testing.assert_almost_equal(
            kernel_interpolator(x_i),
            np.array([
                4.43848790, 3.34379320, 3.62463711, 2.34585418, 2.04767083,
                2.09444849, 2.13349835, 3.10304927, 3.29553153, 3.59884738,
                3.48484031, 2.72974983, 2.65177161, 2.03850468, 2.29470194,
                2.76179863, 2.80189050, 3.75979450, 2.98422257, 3.48444099,
                2.49208997, 2.46516442, 2.42336082, 2.25975903, 3.14159265
            ]),
            decimal=7)

        kernel_interpolator = KernelInterpolator(
            x, y, padding_args={
                'pad_width': (3, 3),
                'mode': 'mean'
            })
        np.testing.assert_almost_equal(
            kernel_interpolator(x_i),
            np.array([
                4.4384879, 4.35723245, 3.62918155, 2.77471295, 2.13474499,
                2.08206794, 2.50585862, 3.24992692, 3.84593162, 4.06289704,
                3.80825633, 3.21068994, 2.65177161, 2.32137382, 2.45995375,
                2.88799997, 3.43843598, 3.79504892, 3.79937086, 3.47673343,
                2.99303182, 2.59771985, 2.49380017, 2.76339043, 3.14159265
            ]),
            decimal=7)

        x_1 = np.arange(1, 10, 1)
        x_2 = x_1 * 10
        x_3 = x_1 / 10
        y = np.sin(x_1 / len(x_1) * np.pi * 6) / (x_1 / len(x_1))
        x_i = np.linspace(1, 9, 25)

        np.testing.assert_almost_equal(
            KernelInterpolator(x_1, y)(x_i),
            KernelInterpolator(x_2, y)(x_i * 10),
            decimal=7)

        np.testing.assert_almost_equal(
            KernelInterpolator(x_1, y)(x_i),
            KernelInterpolator(x_3, y)(x_i / 10),
            decimal=7)