コード例 #1
0
    def setUp(self):
        """
        Initialises common tests attributes.
        """

        self._labels = ('x_bar', 'y_bar', 'z_bar')

        self._multi_sd = MultiSpectralDistribution(
            CIE_1931_2_DEGREE_STANDARD_OBSERVER,
            name='Observer',
            labels=self._labels)

        sd = SpectralDistribution(SAMPLE_SD_DATA)
        domain = sd.domain
        range_ = tstack([sd.values, sd.values, sd.values])
        self._sample_multi_sd = MultiSpectralDistribution(
            range_,
            domain,
            name='Sample Observer',
            labels=self._labels,
        )

        sd = SpectralDistribution(NON_UNIFORM_SAMPLE_SD_DATA)
        domain = sd.domain
        range_ = tstack([sd.values, sd.values, sd.values])
        self._non_uniform_sample_multi_sd = MultiSpectralDistribution(
            range_,
            domain,
            name='Non Uniform Sample Observer',
            strict_name='Strict Non Uniform Sample Observer',
            labels=self._labels,
            strict_labels=('Strict x_bar', 'Strict  y_bar', 'Strict  z_bar'))

        self._phi = (1 + np.sqrt(5)) / 2
コード例 #2
0
    def setUp(self):
        """
        Initialises common tests attributes.
        """

        self._sd = SpectralDistribution(SAMPLE_SD_DATA, name='Sample')

        self._non_uniform_sd = SpectralDistribution(
            NON_UNIFORM_SAMPLE_SD_DATA,
            name='Non Uniform Sample',
            strict_name='Strict Non Uniform Sample')

        self._phi = (1 + np.sqrt(5)) / 2
コード例 #3
0
    def setUp(self):
        """
        Initialises common tests attributes.
        """

        self._sd = SpectralDistribution(SAMPLE_SD_DATA, name='Sample')

        self._non_uniform_sd = SpectralDistribution(
            NON_UNIFORM_SAMPLE_SD_DATA,
            name='Non Uniform Sample',
            strict_name='Strict Non Uniform Sample')

        self._phi = (1 + np.sqrt(5)) / 2
コード例 #4
0
    def test_extrapolate(self):
        """
        Tests :func:`colour.colorimetry.spectrum.\
SpectralDistribution.extrapolate` method.
        """

        data = dict(zip(range(25, 35), [0] * 5 + [1] * 5))
        sd = SpectralDistribution(data)
        sd.extrapolate(SpectralShape(10, 50))

        self.assertAlmostEqual(sd[10], 0, places=7)
        self.assertAlmostEqual(sd[50], 1, places=7)

        sd = SpectralDistribution(
            np.linspace(0, 1, 10), np.linspace(25, 35, 10))
        sd.extrapolate(
            SpectralShape(10, 50),
            extrapolator_args={
                'method': 'Linear',
                'left': None,
                'right': None
            })

        self.assertAlmostEqual(sd[10], -1.5000000000000004, places=7)
        self.assertAlmostEqual(sd[50], 2.4999999999999964, places=7)
コード例 #5
0
    def test_extrapolate(self):
        """
        Tests :func:`colour.colorimetry.spectrum.\
SpectralDistribution.extrapolate` method.
        """

        data = dict(zip(range(25, 35), [0] * 5 + [1] * 5))
        sd = SpectralDistribution(data)
        sd.extrapolate(SpectralShape(10, 50))

        self.assertAlmostEqual(sd[10], 0, places=7)
        self.assertAlmostEqual(sd[50], 1, places=7)

        sd = SpectralDistribution(
            np.linspace(0, 1, 10), np.linspace(25, 35, 10))
        sd.extrapolate(
            SpectralShape(10, 50),
            extrapolator_args={
                'method': 'Linear',
                'left': None,
                'right': None
            })

        self.assertAlmostEqual(sd[10], -1.5000000000000004, places=7)
        self.assertAlmostEqual(sd[50], 2.4999999999999964, places=7)
コード例 #6
0
    def test_sds_and_multi_sds_to_sds(self):
        """
        Tests :func:`colour.colorimetry.spectrum.sds_and_multi_sds_to_sds`
        definition.
        """

        data = {
            500: 0.0651,
            520: 0.0705,
            540: 0.0772,
            560: 0.0870,
            580: 0.1128,
            600: 0.1360
        }
        sd_1 = SpectralDistribution(data)
        sd_2 = SpectralDistribution(data)
        data = {
            500: (0.004900, 0.323000, 0.272000),
            510: (0.009300, 0.503000, 0.158200),
            520: (0.063270, 0.710000, 0.078250),
            530: (0.165500, 0.862000, 0.042160),
            540: (0.290400, 0.954000, 0.020300),
            550: (0.433450, 0.994950, 0.008750),
            560: (0.594500, 0.995000, 0.003900)
        }

        multi_sds_1 = MultiSpectralDistributions(data)
        multi_sds_2 = MultiSpectralDistributions(data)

        self.assertEqual(
            len(
                sds_and_multi_sds_to_sds([
                    sd_1,
                    sd_2,
                    multi_sds_1,
                    multi_sds_2,
                ])), 8)

        self.assertEqual(len(sds_and_multi_sds_to_sds(multi_sds_1)), 3)
コード例 #7
0
def chromaticity(spectral_df):
    sd_list = [SpectralDistribution(spectral_df[color], name=color) for color in spectral_df.columns]
    callable = partial(plot_sds_in_chromaticity_diagram_CIE1931, sd_list)
    colour_spaces = [BT2020_COLOURSPACE, BT709_COLOURSPACE]
    fig, ax = plot_RGB_colourspaces_in_chromaticity_diagram_CIE1931(
        colourspaces=colour_spaces,
        chromaticity_diagram_callable_CIE1931=callable,
        standalone=False
    )
    fig.set_size_inches(10, 7)
    ax.legend(handles=ax.legend().legendHandles[-2:])
    format_ax(xlabel='CIE X', ylabel='CIE Y')
    ax.set_title('CIE 1931 2 Degree Standard Observer', fontsize=24)
    plt.close()
    return fig
コード例 #8
0
ファイル: smits1999.py プロジェクト: Munins-eye/colour
        417.7778: 1.0000,
        455.5556: 0.8916,
        493.3333: 0.3323,
        531.1111: 0.0000,
        568.8889: 0.0000,
        606.6667: 0.0003,
        644.4444: 0.0369,
        682.2222: 0.0483,
        720.0000: 0.0496
    }
}

SMITS_1999_SDS = CaseInsensitiveMapping({
    'white':
        SpectralDistribution(
            SMITS_1999_SDS_DATA['white'],
            name='white'),
    'cyan':
        SpectralDistribution(
            SMITS_1999_SDS_DATA['cyan'],
            name='cyan'),
    'magenta':
        SpectralDistribution(
            SMITS_1999_SDS_DATA['magenta'],
            name='magenta'),
    'yellow':
        SpectralDistribution(
            SMITS_1999_SDS_DATA['yellow'],
            name='yellow'),
    'red':
        SpectralDistribution(
コード例 #9
0
class TestSpectralDistribution(unittest.TestCase):
    """
    Defines :class:`colour.colorimetry.spectrum.SpectralDistribution`
    class unit tests methods.
    """
    def setUp(self):
        """
        Initialises common tests attributes.
        """

        self._sd = SpectralDistribution(SAMPLE_SD_DATA, name='Sample')

        self._non_uniform_sd = SpectralDistribution(
            NON_UNIFORM_SAMPLE_SD_DATA,
            name='Non Uniform Sample',
            strict_name='Strict Non Uniform Sample')

        self._phi = (1 + np.sqrt(5)) / 2

    def test_required_attributes(self):
        """
        Tests presence of required attributes.
        """

        required_attributes = ('strict_name', 'wavelengths', 'values', 'shape')

        for attribute in required_attributes:
            self.assertIn(attribute, dir(SpectralDistribution))

    def test_required_methods(self):
        """
        Tests presence of required methods.
        """

        required_methods = ('__init__', 'extrapolate', 'interpolate', 'align',
                            'trim', 'normalise')

        for method in required_methods:
            self.assertIn(method, dir(SpectralDistribution))

    def test_strict_name(self):
        """
        Tests :attr:`colour.colorimetry.spectrum.\
SpectralDistribution.strict_name` attribute.
        """

        self.assertEqual(self._sd.strict_name, 'Sample')
        self.assertEqual(self._non_uniform_sd.strict_name,
                         'Strict Non Uniform Sample')

    def test_wavelengths(self):
        """
        Tests :attr:`colour.colorimetry.spectrum.\
SpectralDistribution.wavelengths` attribute.
        """

        np.testing.assert_array_equal(self._sd.wavelengths, self._sd.domain)

    def test_values(self):
        """
        Tests :attr:`colour.colorimetry.spectrum.\
SpectralDistribution.values` attribute.
        """

        np.testing.assert_array_equal(self._sd.values, self._sd.range)

    def test_shape(self):
        """
        Tests :attr:`colour.colorimetry.spectrum.\
SpectralDistribution.shape` attribute.
        """

        self.assertEqual(self._sd.shape, SpectralShape(340, 820, 20))

    def test_extrapolate(self):
        """
        Tests :func:`colour.colorimetry.spectrum.\
SpectralDistribution.extrapolate` method.
        """

        data = dict(zip(range(25, 35), [0] * 5 + [1] * 5))
        sd = SpectralDistribution(data)
        sd.extrapolate(SpectralShape(10, 50))

        self.assertAlmostEqual(sd[10], 0, places=7)
        self.assertAlmostEqual(sd[50], 1, places=7)

        sd = SpectralDistribution(np.linspace(0, 1, 10),
                                  np.linspace(25, 35, 10))
        sd.extrapolate(SpectralShape(10, 50),
                       extrapolator_args={
                           'method': 'Linear',
                           'left': None,
                           'right': None
                       })

        self.assertAlmostEqual(sd[10], -1.5000000000000004, places=7)
        self.assertAlmostEqual(sd[50], 2.4999999999999964, places=7)

    def test_interpolate(self):
        """
        Tests :func:`colour.colorimetry.spectrum.\
SpectralDistribution.interpolate` method.
        """

        np.testing.assert_almost_equal(self._sd.copy().interpolate(
            SpectralShape(interval=1)).values,
                                       INTERPOLATED_SAMPLE_SD_DATA,
                                       decimal=7)

        # TODO: Remove statement whenever we make "Scipy" 0.19.0 the minimum
        # version.
        # Skipping tests because of "Scipy" 0.19.0 interpolation code changes.
        if LooseVersion(scipy.__version__) < LooseVersion('0.19.0'):
            return

        np.testing.assert_allclose(self._non_uniform_sd.copy().interpolate(
            SpectralShape(interval=1)).values,
                                   INTERPOLATED_NON_UNIFORM_SAMPLE_SD_DATA,
                                   rtol=0.0000001,
                                   atol=0.0000001)

    def test_align(self):
        """
        Tests :func:`colour.colorimetry.spectrum.\
SpectralDistribution.align` method.
        """

        shape = SpectralShape(100, 900, 5)
        self.assertEqual(self._sd.copy().align(shape).shape, shape)

        shape = SpectralShape(600, 650, 1)
        self.assertEqual(self._sd.copy().align(shape).shape, shape)

    def test_trim(self):
        """
        Tests :func:`colour.colorimetry.spectrum.\
SpectralDistribution.trim` method.
        """

        shape = SpectralShape(400, 700, 20)
        self.assertEqual(self._sd.copy().trim(shape).shape, shape)

        shape = SpectralShape(200, 900, 1)
        self.assertEqual(self._sd.copy().trim(shape).shape, self._sd.shape)

    def test_normalise(self):
        """
        Tests :func:`colour.colorimetry.spectrum.\
SpectralDistribution.normalise` method.
        """

        np.testing.assert_almost_equal(self._sd.copy().normalise(100).values,
                                       NORMALISED_SAMPLE_SD_DATA)
コード例 #10
0
        380.0000: 1.0000,
        417.7778: 1.0000,
        455.5556: 0.8916,
        493.3333: 0.3323,
        531.1111: 0.0000,
        568.8889: 0.0000,
        606.6667: 0.0003,
        644.4444: 0.0369,
        682.2222: 0.0483,
        720.0000: 0.0496,
    },
}

SDS_SMITS1999: CaseInsensitiveMapping = CaseInsensitiveMapping({
    "white":
    SpectralDistribution(DATA_SMITS1999["white"], name="white"),
    "cyan":
    SpectralDistribution(DATA_SMITS1999["cyan"], name="cyan"),
    "magenta":
    SpectralDistribution(DATA_SMITS1999["magenta"], name="magenta"),
    "yellow":
    SpectralDistribution(DATA_SMITS1999["yellow"], name="yellow"),
    "red":
    SpectralDistribution(DATA_SMITS1999["red"], name="red"),
    "green":
    SpectralDistribution(DATA_SMITS1999["green"], name="green"),
    "blue":
    SpectralDistribution(DATA_SMITS1999["blue"], name="blue"),
})
SDS_SMITS1999.__doc__ = """
*Smits (1999)* spectral distributions.
コード例 #11
0
class TestSpectralDistribution(unittest.TestCase):
    """
    Defines :class:`colour.colorimetry.spectrum.SpectralDistribution`
    class unit tests methods.
    """

    def setUp(self):
        """
        Initialises common tests attributes.
        """

        self._sd = SpectralDistribution(SAMPLE_SD_DATA, name='Sample')

        self._non_uniform_sd = SpectralDistribution(
            NON_UNIFORM_SAMPLE_SD_DATA,
            name='Non Uniform Sample',
            strict_name='Strict Non Uniform Sample')

        self._phi = (1 + np.sqrt(5)) / 2

    def test_required_attributes(self):
        """
        Tests presence of required attributes.
        """

        required_attributes = ('strict_name', 'wavelengths', 'values', 'shape')

        for attribute in required_attributes:
            self.assertIn(attribute, dir(SpectralDistribution))

    def test_required_methods(self):
        """
        Tests presence of required methods.
        """

        required_methods = ('__init__', 'extrapolate', 'interpolate', 'align',
                            'trim', 'normalise')

        for method in required_methods:
            self.assertIn(method, dir(SpectralDistribution))

    def test_strict_name(self):
        """
        Tests :attr:`colour.colorimetry.spectrum.\
SpectralDistribution.strict_name` attribute.
        """

        self.assertEqual(self._sd.strict_name, 'Sample')
        self.assertEqual(self._non_uniform_sd.strict_name,
                         'Strict Non Uniform Sample')

    def test_wavelengths(self):
        """
        Tests :attr:`colour.colorimetry.spectrum.\
SpectralDistribution.wavelengths` attribute.
        """

        np.testing.assert_array_equal(self._sd.wavelengths, self._sd.domain)

    def test_values(self):
        """
        Tests :attr:`colour.colorimetry.spectrum.\
SpectralDistribution.values` attribute.
        """

        np.testing.assert_array_equal(self._sd.values, self._sd.range)

    def test_shape(self):
        """
        Tests :attr:`colour.colorimetry.spectrum.\
SpectralDistribution.shape` attribute.
        """

        self.assertEqual(self._sd.shape, SpectralShape(340, 820, 20))

    def test_extrapolate(self):
        """
        Tests :func:`colour.colorimetry.spectrum.\
SpectralDistribution.extrapolate` method.
        """

        data = dict(zip(range(25, 35), [0] * 5 + [1] * 5))
        sd = SpectralDistribution(data)
        sd.extrapolate(SpectralShape(10, 50))

        self.assertAlmostEqual(sd[10], 0, places=7)
        self.assertAlmostEqual(sd[50], 1, places=7)

        sd = SpectralDistribution(
            np.linspace(0, 1, 10), np.linspace(25, 35, 10))
        sd.extrapolate(
            SpectralShape(10, 50),
            extrapolator_args={
                'method': 'Linear',
                'left': None,
                'right': None
            })

        self.assertAlmostEqual(sd[10], -1.5000000000000004, places=7)
        self.assertAlmostEqual(sd[50], 2.4999999999999964, places=7)

    def test_interpolate(self):
        """
        Tests :func:`colour.colorimetry.spectrum.\
SpectralDistribution.interpolate` method.
        """

        np.testing.assert_almost_equal(
            self._sd.copy().interpolate(SpectralShape(interval=1)).values,
            INTERPOLATED_SAMPLE_SD_DATA,
            decimal=7)

        # TODO: Remove statement whenever we make "Scipy" 0.19.0 the minimum
        # version.
        # Skipping tests because of "Scipy" 0.19.0 interpolation code changes.
        if LooseVersion(scipy.__version__) < LooseVersion('0.19.0'):
            return

        np.testing.assert_allclose(
            self._non_uniform_sd.copy().interpolate(
                SpectralShape(interval=1)).values,
            INTERPOLATED_NON_UNIFORM_SAMPLE_SD_DATA,
            rtol=0.0000001,
            atol=0.0000001)

    def test_align(self):
        """
        Tests :func:`colour.colorimetry.spectrum.\
SpectralDistribution.align` method.
        """

        shape = SpectralShape(100, 900, 5)
        self.assertEqual(self._sd.copy().align(shape).shape, shape)

        shape = SpectralShape(600, 650, 1)
        self.assertEqual(self._sd.copy().align(shape).shape, shape)

    def test_trim(self):
        """
        Tests :func:`colour.colorimetry.spectrum.\
SpectralDistribution.trim` method.
        """

        shape = SpectralShape(400, 700, 20)
        self.assertEqual(self._sd.copy().trim(shape).shape, shape)

        shape = SpectralShape(200, 900, 1)
        self.assertEqual(self._sd.copy().trim(shape).shape, self._sd.shape)

    def test_normalise(self):
        """
        Tests :func:`colour.colorimetry.spectrum.\
SpectralDistribution.normalise` method.
        """

        np.testing.assert_almost_equal(self._sd.copy().normalise(100).values,
                                       NORMALISED_SAMPLE_SD_DATA)