Exemplo n.º 1
0
    def test___call__(self):
        """
        Tests :func:`colour.algebra.extrapolation.Extrapolator.__call__`
        method.
        """

        extrapolator = Extrapolator(
            LinearInterpolator(
                np.array([5, 6, 7]),
                np.array([5, 6, 7])))
        np.testing.assert_almost_equal(extrapolator((4, 8)), (4, 8))
        self.assertEqual(extrapolator(4), 4)

        extrapolator = Extrapolator(
            LinearInterpolator(
                np.array([3, 4, 5]),
                np.array([1, 2, 3])),
            method='Constant')
        np.testing.assert_almost_equal(extrapolator((0.1, 0.2, 8, 9)),
                                       (1, 1, 3, 3))
        self.assertEqual(extrapolator(0.1), 1.)

        extrapolator = Extrapolator(
            LinearInterpolator(
                np.array([3, 4, 5]),
                np.array([1, 2, 3])),
            method='Constant',
            left=0)
        np.testing.assert_almost_equal(extrapolator((0.1, 0.2, 8, 9)),
                                       (0, 0, 3, 3))
        self.assertEqual(extrapolator(0.1), 0)

        extrapolator = Extrapolator(
            LinearInterpolator(
                np.array([3, 4, 5]),
                np.array([1, 2, 3])),
            method='Constant',
            right=0)
        np.testing.assert_almost_equal(extrapolator((0.1, 0.2, 8, 9)),
                                       (1, 1, 0, 0))
        self.assertEqual(extrapolator(9), 0)

        extrapolator = Extrapolator(
            CubicSplineInterpolator(
                np.array([3, 4, 5, 6]),
                np.array([1, 2, 3, 4])))
        np.testing.assert_almost_equal(extrapolator((0.1, 0.2, 8.0, 9.0)),
                                       (-1.9, -1.8, 6.0, 7.0))
        self.assertEqual(extrapolator(9), 7)

        extrapolator = Extrapolator(
            PchipInterpolator(
                np.array([3, 4, 5]),
                np.array([1, 2, 3])))
        np.testing.assert_almost_equal(extrapolator((0.1, 0.2, 8.0, 9.0)),
                                       (-1.9, -1.8, 6.0, 7.0))
        self.assertEqual(extrapolator(9), 7.)
Exemplo n.º 2
0
    def test_method(self):
        """
        Tests :func:`colour.algebra.extrapolation.Extrapolator.method`
        property.
        """

        extrapolator = Extrapolator(
            LinearInterpolator(np.array([5, 6, 7]), np.array([5, 6, 7])))
        self.assertEqual(extrapolator.method, 'linear')

        extrapolator = Extrapolator(
            LinearInterpolator(np.array([5, 6, 7]), np.array([5, 6, 7])),
            method='Constant')
        self.assertEqual(extrapolator.method, 'constant')
Exemplo n.º 3
0
    def test_method(self):
        """
        Test :attr:`colour.algebra.extrapolation.Extrapolator.method`
        property.
        """

        extrapolator = Extrapolator(
            LinearInterpolator(np.array([5, 6, 7]), np.array([5, 6, 7])))
        self.assertEqual(extrapolator.method, "linear")

        extrapolator = Extrapolator(
            LinearInterpolator(np.array([5, 6, 7]), np.array([5, 6, 7])),
            method="Constant",
        )
        self.assertEqual(extrapolator.method, "constant")
Exemplo n.º 4
0
    def test__call__(self):
        """
        Test :meth:`colour.algebra.interpolation.LinearInterpolator.__call__`
        method.
        """

        interval = 0.1
        x = np.arange(len(DATA_POINTS_A))
        linear_interpolator = LinearInterpolator(x, DATA_POINTS_A)

        for i, value in enumerate(
            np.arange(0, len(DATA_POINTS_A) - 1 + interval, interval)
        ):
            self.assertAlmostEqual(
                DATA_POINTS_A_LINEAR_INTERPOLATED_10_SAMPLES[i],
                linear_interpolator(value),
                places=7,
            )

        np.testing.assert_almost_equal(
            linear_interpolator(
                np.arange(0, len(DATA_POINTS_A) - 1 + interval, interval)
            ),
            DATA_POINTS_A_LINEAR_INTERPOLATED_10_SAMPLES,
        )
Exemplo n.º 5
0
    def test_interpolator(self):
        """
        Tests :func:`colour.algebra.extrapolation.Extrapolator.interpolator`
        property.
        """

        extrapolator = Extrapolator(
            LinearInterpolator(np.array([5, 6, 7]), np.array([5, 6, 7])))
        self.assertIsInstance(extrapolator.interpolator, LinearInterpolator)
Exemplo n.º 6
0
    def test_right(self):
        """
        Tests :func:`colour.algebra.extrapolation.Extrapolator.right`
        property.
        """

        extrapolator = Extrapolator(
            LinearInterpolator(np.array([5, 6, 7]), np.array([5, 6, 7])),
            right=0)
        self.assertEqual(extrapolator.right, 0)
Exemplo n.º 7
0
    def test_left(self):
        """
        Test :attr:`colour.algebra.extrapolation.Extrapolator.left`
        property.
        """

        extrapolator = Extrapolator(
            LinearInterpolator(np.array([5, 6, 7]), np.array([5, 6, 7])),
            left=0,
        )
        self.assertEqual(extrapolator.left, 0)
Exemplo n.º 8
0
    def test_raise_exception___call__(self):
        """
        Tests :func:`colour.algebra.interpolation.LinearInterpolator.__call__`
        method raised exception.
        """

        x = y = np.linspace(0, 1, 10)
        linear_interpolator = LinearInterpolator(x, y)

        self.assertRaises(ValueError, linear_interpolator, -1)

        self.assertRaises(ValueError, linear_interpolator, 11)
Exemplo n.º 9
0
def _log_decoding_FilmicPro6_interpolator():
    """
    Returns the *FiLMiC Pro 6* log decoding curve / electro-optical transfer
    function interpolator and caches it if not existing.

    Returns
    -------
    Extrapolator
        *FiLMiC Pro 6* log decoding curve / electro-optical transfer
        function interpolator.
    """

    global _LOG_DECODING_FILMICPRO_INTERPOLATOR_CACHE

    t = np.arange(0, 1, 0.0001)
    if _LOG_DECODING_FILMICPRO_INTERPOLATOR_CACHE is None:
        _LOG_DECODING_FILMICPRO_INTERPOLATOR_CACHE = Extrapolator(
            LinearInterpolator(log_encoding_FilmicPro6(t), t))

    return _LOG_DECODING_FILMICPRO_INTERPOLATOR_CACHE
Exemplo n.º 10
0
    def test___call__(self):
        """
        Tests :func:`colour.algebra.interpolation.LinearInterpolator.__call__`
        method.
        """

        steps = 0.1
        x = np.arange(len(POINTS_DATA_A))
        linear_interpolator = LinearInterpolator(x, POINTS_DATA_A)

        for i, value in enumerate(
                np.arange(0, len(POINTS_DATA_A) - 1 + steps, steps)):
            self.assertAlmostEqual(
                LINEAR_INTERPOLATED_POINTS_DATA_A_10_SAMPLES[i],
                linear_interpolator(value),
                places=7)

        np.testing.assert_almost_equal(
            linear_interpolator(
                np.arange(0, len(POINTS_DATA_A) - 1 + steps, steps)),
            LINEAR_INTERPOLATED_POINTS_DATA_A_10_SAMPLES)