Exemplo n.º 1
0
    def test_signal_type(self):
        """
        Tests :func:`colour.continuous.multi_signal.MultiSignal.signal_type`
        property.
        """

        multi_signal = MultiSignal(signal_type=Signal)

        self.assertEqual(multi_signal.signal_type, Signal)
Exemplo n.º 2
0
    def test__init__(self):
        """
        Tests :func:`colour.continuous.multi_signal.MultiSignal.__init__`
        method.
        """

        multi_signal = MultiSignal(self._range_1)
        np.testing.assert_array_equal(multi_signal.domain, self._domain_1)
        np.testing.assert_array_equal(multi_signal.range,
                                      self._range_1[:, np.newaxis])

        multi_signal = MultiSignal(self._range_1, self._domain_2)
        np.testing.assert_array_equal(multi_signal.domain, self._domain_2)
        np.testing.assert_array_equal(multi_signal.range,
                                      self._range_1[:, np.newaxis])

        multi_signal = MultiSignal(self._range_2, self._domain_2)
        np.testing.assert_array_equal(multi_signal.domain, self._domain_2)
        np.testing.assert_array_equal(multi_signal.range, self._range_2)

        multi_signal = MultiSignal(dict(zip(self._domain_2, self._range_2)))
        np.testing.assert_array_equal(multi_signal.domain, self._domain_2)
        np.testing.assert_array_equal(multi_signal.range, self._range_2)

        multi_signal = MultiSignal(multi_signal)
        np.testing.assert_array_equal(multi_signal.domain, self._domain_2)
        np.testing.assert_array_equal(multi_signal.range, self._range_2)

        class NotSignal(Signal):
            """
            Not :class:`Signal` class.
            """

            pass

        multi_signal = MultiSignal(self._range_1, signal_type=NotSignal)
        self.assertIsInstance(multi_signal.signals[0], NotSignal)
        np.testing.assert_array_equal(multi_signal.domain, self._domain_1)
        np.testing.assert_array_equal(multi_signal.range,
                                      self._range_1[:, np.newaxis])

        if is_pandas_installed():
            from pandas import DataFrame, Series

            multi_signal = MultiSignal(
                Series(dict(zip(self._domain_2, self._range_1))))
            np.testing.assert_array_equal(multi_signal.domain, self._domain_2)
            np.testing.assert_array_equal(multi_signal.range,
                                          self._range_1[:, np.newaxis])

            data = dict(zip(['a', 'b', 'c'], tsplit(self._range_2)))
            multi_signal = MultiSignal(DataFrame(data, self._domain_2))
            np.testing.assert_array_equal(multi_signal.domain, self._domain_2)
            np.testing.assert_array_equal(multi_signal.range, self._range_2)
Exemplo n.º 3
0
    def setUp(self):
        """
        Initialises common tests attributes.
        """

        self._range_1 = np.linspace(10, 100, 10)
        self._range_2 = tstack([self._range_1] * 3) + np.array([0, 10, 20])
        self._domain_1 = np.arange(0, 10, 1)
        self._domain_2 = np.arange(100, 1100, 100)

        self._multi_signal = MultiSignal(self._range_2)
Exemplo n.º 4
0
    def test_to_dataframe(self):
        """
        Tests :func:`colour.continuous.multi_signal.MultiSignal.to_dataframe`
        method.
        """

        if is_pandas_installed():
            from pandas import DataFrame

            data = dict(zip(['a', 'b', 'c'], tsplit(self._range_2)))
            assert MultiSignal(
                self._range_2, self._domain_2,
                labels=['a', 'b', 'c']).to_dataframe().equals(
                    DataFrame(data, self._domain_2))