Beispiel #1
0
def get_cmfs(cmfs):
    """
    Returns the colour matching functions with given name.

    Parameters
    ----------
    cmfs : unicode
        Colour matching functions name.

    Returns
    -------
    RGB_ColourMatchingFunctions or XYZ_ColourMatchingFunctions
        Colour matching functions.

    Raises
    ------
    KeyError
        If the given colour matching functions is not found in the factory
        colour matching functions.
    """

    cmfs, name = CMFS.get(cmfs), cmfs
    if cmfs is None:
        raise KeyError(
            ('"{0}" not found in factory colour matching functions: '
             '"{1}".').format(name, ', '.join(sorted(CMFS.keys()))))
    return cmfs
Beispiel #2
0
    def test_spectral_to_XYZ(self):
        """
        Tests :func:`colour.colorimetry.tristimulus.spectral_to_XYZ`
        definition.
        """

        cmfs = CMFS.get('CIE 1931 2 Degree Standard Observer')
        np.testing.assert_almost_equal(
            spectral_to_XYZ(
                RELATIVE_SPD_DATA.zeros(cmfs.shape), cmfs,
                ILLUMINANTS_RELATIVE_SPDS.get('A').clone().zeros(cmfs.shape)),
            np.array([14.46371626, 10.85832347, 2.04664796]),
            decimal=7)

        cmfs = CMFS.get('CIE 1964 10 Degree Standard Observer')
        np.testing.assert_almost_equal(
            spectral_to_XYZ(
                RELATIVE_SPD_DATA.zeros(cmfs.shape), cmfs,
                ILLUMINANTS_RELATIVE_SPDS.get('C').clone().zeros(cmfs.shape)),
            np.array([10.7704252, 9.44870313, 6.62742289]),
            decimal=7)

        np.testing.assert_almost_equal(
            spectral_to_XYZ(
                RELATIVE_SPD_DATA.zeros(cmfs.shape), cmfs,
                ILLUMINANTS_RELATIVE_SPDS.get('F2').clone().zeros(cmfs.shape)),
            np.array([11.57830745, 9.98744967, 3.95396539]),
            decimal=7)
Beispiel #3
0
    def test_spectral_to_XYZ_integration(self):
        """
        Tests :func:`colour.colorimetry.tristimulus.\
spectral_to_XYZ_integration`
        definition.
        """

        cmfs = CMFS.get('CIE 1931 2 Degree Standard Observer')
        np.testing.assert_almost_equal(
            spectral_to_XYZ_integration(
                SAMPLE_SPD,
                cmfs,
                ILLUMINANTS_RELATIVE_SPDS.get('A')),
            np.array([14.46365624, 10.85827910, 2.04662343]),
            decimal=7)

        cmfs = CMFS.get('CIE 1964 10 Degree Standard Observer')
        np.testing.assert_almost_equal(
            spectral_to_XYZ_integration(
                SAMPLE_SPD,
                cmfs,
                ILLUMINANTS_RELATIVE_SPDS.get('C')),
            np.array([10.77031004, 9.44863775, 6.62745989]),
            decimal=7)

        np.testing.assert_almost_equal(
            spectral_to_XYZ_integration(
                SAMPLE_SPD,
                cmfs,
                ILLUMINANTS_RELATIVE_SPDS.get('F2')),
            np.array([11.57834054, 9.98738373, 3.95462625]),
            decimal=7)
Beispiel #4
0
    def test_spectral_to_XYZ(self):
        """
        Tests :func:`colour.colorimetry.tristimulus.spectral_to_XYZ`
        definition.
        """

        cmfs = CMFS.get('CIE 1931 2 Degree Standard Observer')
        np.testing.assert_almost_equal(
            spectral_to_XYZ(
                RELATIVE_SPD_DATA.zeros(cmfs.shape),
                cmfs,
                ILLUMINANTS_RELATIVE_SPDS.get('A').clone().zeros(cmfs.shape)),
            np.array([14.46371626, 10.85832347, 2.04664796]),
            decimal=7)

        cmfs = CMFS.get('CIE 1964 10 Degree Standard Observer')
        np.testing.assert_almost_equal(
            spectral_to_XYZ(
                RELATIVE_SPD_DATA.zeros(cmfs.shape),
                cmfs,
                ILLUMINANTS_RELATIVE_SPDS.get('C').clone().zeros(cmfs.shape)),
            np.array([10.7704252, 9.44870313, 6.62742289]),
            decimal=7)

        np.testing.assert_almost_equal(
            spectral_to_XYZ(
                RELATIVE_SPD_DATA.zeros(cmfs.shape),
                cmfs,
                ILLUMINANTS_RELATIVE_SPDS.get('F2').clone().zeros(cmfs.shape)),
            np.array([11.57830745, 9.98744967, 3.95396539]),
            decimal=7)
Beispiel #5
0
def get_cmfs(cmfs):
    """
    Returns the colour matching functions with given name.

    Parameters
    ----------
    cmfs : unicode
        Colour matching functions name.

    Returns
    -------
    RGB_ColourMatchingFunctions or XYZ_ColourMatchingFunctions
        Colour matching functions.

    Raises
    ------
    KeyError
        If the given colour matching functions is not found in the factory
        colour matching functions.
    """

    cmfs, name = CMFS.get(cmfs), cmfs
    if cmfs is None:
        raise KeyError(
            ('"{0}" not found in factory colour matching functions: '
             '"{1}".').format(name, ', '.join(sorted(CMFS.keys()))))
    return cmfs
Beispiel #6
0
    def test_wavelength_to_XYZ(self):
        """
        Tests
        :func:`colour.colorimetry.tristimulus.wavelength_to_XYZ` definition.
        """

        np.testing.assert_almost_equal(
            wavelength_to_XYZ(
                480,
                CMFS.get('CIE 1931 2 Degree Standard Observer')),
            np.array([0.09564, 0.13902, 0.81295]),
            decimal=7)

        np.testing.assert_almost_equal(
            wavelength_to_XYZ(
                480,
                CMFS.get('CIE 2012 2 Degree Standard Observer')),
            np.array([0.08182895, 0.1788048, 0.7552379]),
            decimal=7)

        np.testing.assert_almost_equal(
            wavelength_to_XYZ(
                641.5,
                CMFS.get('CIE 2012 2 Degree Standard Observer')),
            np.array([0.44575583, 0.18184213, 0.]),
            decimal=7)
Beispiel #7
0
    def test_spectral_to_XYZ_tristimulus_weighting_factors_ASTME30815(self):
        """
        Tests :func:`colour.colorimetry.tristimulus.\
spectral_to_XYZ_tristimulus_weighting_factors_ASTME30815`
        definition.
        """

        cmfs = CMFS.get('CIE 1931 2 Degree Standard Observer')
        np.testing.assert_almost_equal(
            spectral_to_XYZ_tristimulus_weighting_factors_ASTME30815(
                SAMPLE_SPD,
                cmfs,
                ILLUMINANTS_RELATIVE_SPDS.get('A')),
            np.array([14.46366344, 10.85828513, 2.04663792]),
            decimal=7)

        cmfs = CMFS.get('CIE 1964 10 Degree Standard Observer')
        np.testing.assert_almost_equal(
            spectral_to_XYZ_tristimulus_weighting_factors_ASTME30815(
                SAMPLE_SPD,
                cmfs,
                ILLUMINANTS_RELATIVE_SPDS.get('C')),
            np.array([10.77033881, 9.44864632, 6.62758924]),
            decimal=7)

        np.testing.assert_almost_equal(
            spectral_to_XYZ_tristimulus_weighting_factors_ASTME30815(
                SAMPLE_SPD,
                cmfs,
                ILLUMINANTS_RELATIVE_SPDS.get('F2')),
            np.array([11.57837130, 9.98734511, 3.95499522]),
            decimal=7)

        np.testing.assert_almost_equal(
            spectral_to_XYZ_tristimulus_weighting_factors_ASTME30815(
                SAMPLE_SPD.clone().trim_wavelengths(
                    SpectralShape(400, 700, 5)),
                cmfs,
                ILLUMINANTS_RELATIVE_SPDS.get('A')),
            np.array([14.38180830, 10.74512906, 2.01579131]),
            decimal=7)

        np.testing.assert_almost_equal(
            spectral_to_XYZ_tristimulus_weighting_factors_ASTME30815(
                SAMPLE_SPD.clone().interpolate(
                    SpectralShape(400, 700, 10)),
                cmfs,
                ILLUMINANTS_RELATIVE_SPDS.get('A')),
            np.array([14.38284399, 10.74577954, 2.01553721]),
            decimal=7)

        np.testing.assert_almost_equal(
            spectral_to_XYZ_tristimulus_weighting_factors_ASTME30815(
                SAMPLE_SPD.clone().interpolate(
                    SpectralShape(400, 700, 20)),
                cmfs,
                ILLUMINANTS_RELATIVE_SPDS.get('A')),
            np.array([14.38356848, 10.74613294, 2.01526418]),
            decimal=7)
Beispiel #8
0
    def test_n_dimensional_wavelength_to_XYZ(self):
        """
        Tests :func:`colour.colorimetry.tristimulus.wavelength_to_XYZ`
        definition n-dimensional arrays support.
        """

        cmfs = CMFS.get('CIE 1931 2 Degree Standard Observer')
        wl = 480
        XYZ = np.array([0.09564, 0.13902, 0.81295])
        np.testing.assert_almost_equal(
            wavelength_to_XYZ(wl, cmfs),
            XYZ,
            decimal=7)

        wl = np.tile(wl, 6)
        XYZ = np.tile(XYZ, (6, 1))
        np.testing.assert_almost_equal(
            wavelength_to_XYZ(wl, cmfs),
            XYZ,
            decimal=7)

        wl = np.reshape(wl, (2, 3))
        XYZ = np.reshape(XYZ, (2, 3, 3))
        np.testing.assert_almost_equal(
            wavelength_to_XYZ(wl, cmfs),
            XYZ,
            decimal=7)

        wl = np.reshape(wl, (2, 3, 1))
        XYZ = np.reshape(XYZ, (2, 3, 1, 3))
        np.testing.assert_almost_equal(
            wavelength_to_XYZ(wl, cmfs),
            XYZ,
            decimal=7)
Beispiel #9
0
    def test_tristimulus_weighting_factors_ASTME202211(self):
        """
        Tests :func:`colour.colorimetry.tristimulus.\
tristimulus_weighting_factors_ASTME202211` definition.

        Notes
        -----
        :attr:`A_CIE_1964_10_10_TWF`, :attr:`A_CIE_1964_10_20_TWF` and
        :attr:`D65_CIE_1931_2_20_TWF` attributes data is matching [1]_.

        References
        ----------
        .. [1]  ASTM International. (2015). ASTM E308–15 - Standard Practice
                for Computing the Colors of Objects by Using the CIE System,
                1–47. doi:10.1520/E0308-15
        """

        cmfs = CMFS.get('CIE 1964 10 Degree Standard Observer')
        wl = cmfs.shape.range()
        A = SpectralPowerDistribution(
            'A (360, 830, 1)',
            dict(zip(wl, CIE_standard_illuminant_A_function(wl))))

        twf = tristimulus_weighting_factors_ASTME202211(
            cmfs, A, SpectralShape(360, 830, 10))
        np.testing.assert_almost_equal(
            np.round(twf, 3),
            A_CIE_1964_10_10_TWF,
            decimal=3)

        twf = tristimulus_weighting_factors_ASTME202211(
            cmfs, A, SpectralShape(360, 830, 20))
        np.testing.assert_almost_equal(
            np.round(twf, 3),
            A_CIE_1964_10_20_TWF,
            decimal=3)

        cmfs = CMFS.get('CIE 1931 2 Degree Standard Observer')
        D65 = ILLUMINANTS_RELATIVE_SPDS['D65'].clone().align(
            cmfs.shape, interpolation_method='Linear')
        twf = tristimulus_weighting_factors_ASTME202211(
            cmfs, D65, SpectralShape(360, 830, 20))
        np.testing.assert_almost_equal(
            np.round(twf, 3),
            D65_CIE_1931_2_20_TWF,
            decimal=3)
Beispiel #10
0
    def setUp(self):
        """
        Initialises common tests attributes.
        """

        self._spd = SAMPLE_SPD.clone()
        self._cmfs = CMFS.get('CIE 1931 2 Degree Standard Observer')
        wl = self._cmfs.shape.range()
        self.__A = SpectralPowerDistribution(
            'A (360, 830, 1)',
            dict(zip(wl, CIE_standard_illuminant_A_function(wl))))
Beispiel #11
0
    def test_wavelength_to_XYZ(self):
        """
        Tests
        :func:`colour.colorimetry.tristimulus.wavelength_to_XYZ` definition.
        """

        np.testing.assert_almost_equal(wavelength_to_XYZ(
            480, CMFS.get('CIE 1931 2 Degree Standard Observer')),
                                       np.array([0.09564, 0.13902, 0.81295]),
                                       decimal=7)

        np.testing.assert_almost_equal(
            wavelength_to_XYZ(480,
                              CMFS.get('CIE 2012 2 Degree Standard Observer')),
            np.array([0.08182895, 0.1788048, 0.7552379]),
            decimal=7)

        np.testing.assert_almost_equal(wavelength_to_XYZ(
            641.5, CMFS.get('CIE 2012 2 Degree Standard Observer')),
                                       np.array([0.44575583, 0.18184213, 0.]),
                                       decimal=7)
    def test_RGB_2_degree_cmfs_to_XYZ_2_degree_cmfs(self):
        """
        Tests :func:`colour.colorimetry.transformations.\
RGB_2_degree_cmfs_to_XYZ_2_degree_cmfs` definition.
        """

        cmfs = CMFS.get('CIE 1931 2 Degree Standard Observer')
        np.testing.assert_allclose(RGB_2_degree_cmfs_to_XYZ_2_degree_cmfs(435),
                                   cmfs.get(435),
                                   atol=0.0025)

        np.testing.assert_allclose(RGB_2_degree_cmfs_to_XYZ_2_degree_cmfs(545),
                                   cmfs.get(545),
                                   atol=0.0025)

        np.testing.assert_allclose(RGB_2_degree_cmfs_to_XYZ_2_degree_cmfs(700),
                                   cmfs.get(700),
                                   atol=0.0025)
    def test_LMS_2_degree_cmfs_to_XYZ_2_degree_cmfs(self):
        """
        Tests
        :func:`colour.colorimetry.transformations.LMS_2_degree_cmfs_to_XYZ_2_degree_cmfs`  # noqa
        definition.
        """

        cmfs = CMFS.get('CIE 2012 2 Degree Standard Observer')
        np.testing.assert_allclose(LMS_2_degree_cmfs_to_XYZ_2_degree_cmfs(435),
                                   cmfs.get(435),
                                   atol=0.00015)

        np.testing.assert_allclose(LMS_2_degree_cmfs_to_XYZ_2_degree_cmfs(545),
                                   cmfs.get(545),
                                   atol=0.00015)

        np.testing.assert_allclose(LMS_2_degree_cmfs_to_XYZ_2_degree_cmfs(700),
                                   cmfs.get(700),
                                   atol=0.00015)
Beispiel #14
0
    def test_wavelength_to_XYZ(self):
        """
        Tests :func:`colour.colorimetry.tristimulus.wavelength_to_XYZ`
        definition.
        """

        np.testing.assert_almost_equal(
            wavelength_to_XYZ(
                480,
                CMFS.get('CIE 1931 2 Degree Standard Observer')),
            np.array([0.09564, 0.13902, 0.81295]),
            decimal=7)

        np.testing.assert_almost_equal(
            wavelength_to_XYZ(
                480,
                CMFS.get('CIE 2012 2 Degree Standard Observer')),
            np.array([0.08182895, 0.1788048, 0.7552379]),
            decimal=7)

        np.testing.assert_almost_equal(
            wavelength_to_XYZ(
                641.5,
                CMFS.get('CIE 2012 2 Degree Standard Observer')),
            np.array([0.44575583, 0.18184213, 0.]),
            decimal=7)

        np.testing.assert_almost_equal(
            wavelength_to_XYZ(
                480.5,
                CMFS.get('CIE 2012 2 Degree Standard Observer'),
                'Cubic Spline'),
            np.array([0.07773422, 0.18148028, 0.7337162]),
            decimal=7)

        np.testing.assert_almost_equal(
            wavelength_to_XYZ(
                480.5,
                CMFS.get('CIE 2012 2 Degree Standard Observer'),
                'Linear'),
            np.array([0.07779856, 0.18149335, 0.7340129]),
            decimal=7)

        np.testing.assert_almost_equal(
            wavelength_to_XYZ(
                480.5,
                CMFS.get('CIE 2012 2 Degree Standard Observer'),
                'Pchip'),
            np.array([0.07773515, 0.18148048, 0.73372294]),
            decimal=7)
def _get_cmfs_xy():
    """
    xy色度図のプロットのための馬蹄形の外枠のxy値を求める。

    Returns
    -------
    array_like
        xy coordinate for chromaticity diagram

    """
    # 基本パラメータ設定
    # ------------------
    cmf = CMFS.get(CMFS_NAME)
    d65_white = D65_WHITE

    # 馬蹄形のxy値を算出
    # --------------------------
    cmf_xy = XYZ_to_xy(cmf.values, d65_white)

    return cmf_xy
Beispiel #16
0
    def test_RGB_10_degree_cmfs_to_LMS_10_degree_cmfs(self):
        """
        Tests :func:`colour.colorimetry.transformations.\
RGB_10_degree_cmfs_to_LMS_10_degree_cmfs` definition.
        """

        cmfs = CMFS.get('Stockman & Sharpe 10 Degree Cone Fundamentals')
        np.testing.assert_allclose(
            RGB_10_degree_cmfs_to_LMS_10_degree_cmfs(435),
            cmfs.get(435),
            atol=0.0025)

        np.testing.assert_allclose(
            RGB_10_degree_cmfs_to_LMS_10_degree_cmfs(545),
            cmfs.get(545),
            atol=0.0025)

        np.testing.assert_allclose(
            RGB_10_degree_cmfs_to_LMS_10_degree_cmfs(700),
            cmfs.get(700),
            atol=0.0025)
Beispiel #17
0
    def test_RGB_2_degree_cmfs_to_XYZ_2_degree_cmfs(self):
        """
        Tests :func:`colour.colorimetry.transformations.\
RGB_2_degree_cmfs_to_XYZ_2_degree_cmfs` definition.
        """

        cmfs = CMFS.get('CIE 1931 2 Degree Standard Observer')
        np.testing.assert_allclose(
            RGB_2_degree_cmfs_to_XYZ_2_degree_cmfs(435),
            cmfs.get(435),
            atol=0.0025)

        np.testing.assert_allclose(
            RGB_2_degree_cmfs_to_XYZ_2_degree_cmfs(545),
            cmfs.get(545),
            atol=0.0025)

        np.testing.assert_allclose(
            RGB_2_degree_cmfs_to_XYZ_2_degree_cmfs(700),
            cmfs.get(700),
            atol=0.0025)
    def test_RGB_10_degree_cmfs_to_LMS_10_degree_cmfs(self):
        """
        Tests :func:`colour.colorimetry.transformations.\
RGB_10_degree_cmfs_to_LMS_10_degree_cmfs` definition.
        """

        cmfs = CMFS.get('Stockman & Sharpe 10 Degree Cone Fundamentals')
        np.testing.assert_allclose(
            RGB_10_degree_cmfs_to_LMS_10_degree_cmfs(435),
            cmfs.get(435),
            atol=0.0025)

        np.testing.assert_allclose(
            RGB_10_degree_cmfs_to_LMS_10_degree_cmfs(545),
            cmfs.get(545),
            atol=0.0025)

        np.testing.assert_allclose(
            RGB_10_degree_cmfs_to_LMS_10_degree_cmfs(700),
            cmfs.get(700),
            atol=0.0025)
Beispiel #19
0
    def test_LMS_10_degree_cmfs_to_XYZ_10_degree_cmfs(self):
        """
        Tests :func:`colour.colorimetry.transformations.\
LMS_10_degree_cmfs_to_XYZ_10_degree_cmfs` definition.
        """

        cmfs = CMFS.get('CIE 2012 10 Degree Standard Observer')
        np.testing.assert_allclose(
            LMS_10_degree_cmfs_to_XYZ_10_degree_cmfs(435),
            cmfs.get(435),
            atol=0.00015)

        np.testing.assert_allclose(
            LMS_10_degree_cmfs_to_XYZ_10_degree_cmfs(545),
            cmfs.get(545),
            atol=0.00015)

        np.testing.assert_allclose(
            LMS_10_degree_cmfs_to_XYZ_10_degree_cmfs(700),
            cmfs.get(700),
            atol=0.00015)
Beispiel #20
0
def planckian_locus_CIE_1931_chromaticity_diagram_plot(
        illuminants=None,
        **kwargs):
    """
    Plots the planckian locus and given illuminants in
    *CIE 1931 Chromaticity Diagram*.

    Parameters
    ----------
    illuminants : array_like, optional
        Factory illuminants to plot.
    \**kwargs : dict, optional
        Keywords arguments.

    Returns
    -------
    Figure
        Current figure or None.

    Raises
    ------
    KeyError
        If one of the given illuminant is not found in the factory illuminants.

    Examples
    --------
    >>> ils = ['A', 'B', 'C']
    >>> planckian_locus_CIE_1931_chromaticity_diagram_plot(
    ...     ils)  # doctest: +SKIP
    """

    if illuminants is None:
        illuminants = ('A', 'B', 'C')

    cmfs = CMFS.get('CIE 1931 2 Degree Standard Observer')

    settings = {
        'title': ('{0} Illuminants - Planckian Locus\n'
                  'CIE 1931 Chromaticity Diagram - '
                  'CIE 1931 2 Degree Standard Observer').format(
            ', '.join(illuminants))
        if illuminants else
        ('Planckian Locus\nCIE 1931 Chromaticity Diagram - '
         'CIE 1931 2 Degree Standard Observer'),
        'standalone': False}
    settings.update(kwargs)

    CIE_1931_chromaticity_diagram_plot(**settings)

    start, end = 1667, 100000
    xy = np.array([UCS_uv_to_xy(CCT_to_uv(x, 0, method='Robertson 1968'))
                   for x in np.arange(start, end + 250, 250)])

    pylab.plot(xy[..., 0], xy[..., 1], color='black', linewidth=2)

    for i in (1667, 2000, 2500, 3000, 4000, 6000, 10000):
        x0, y0 = UCS_uv_to_xy(CCT_to_uv(i, -0.025, method='Robertson 1968'))
        x1, y1 = UCS_uv_to_xy(CCT_to_uv(i, 0.025, method='Robertson 1968'))
        pylab.plot((x0, x1), (y0, y1), color='black', linewidth=2)
        pylab.annotate('{0}K'.format(i),
                       xy=(x0, y0),
                       xytext=(0, -10),
                       color='black',
                       textcoords='offset points',
                       size='x-small')

    for illuminant in illuminants:
        xy = ILLUMINANTS.get(cmfs.name).get(illuminant)
        if xy is None:
            raise KeyError(
                ('Illuminant "{0}" not found in factory illuminants: '
                 '"{1}".').format(illuminant,
                                  sorted(ILLUMINANTS.get(cmfs.name).keys())))

        pylab.plot(xy[0], xy[1], 'o', color='white', linewidth=2)

        pylab.annotate(illuminant,
                       xy=(xy[0], xy[1]),
                       xytext=(-50, 30),
                       color='black',
                       textcoords='offset points',
                       arrowprops=dict(arrowstyle='->',
                                       connectionstyle='arc3, rad=-0.2'))

    settings.update({
        'x_tighten': True,
        'y_tighten': True,
        'limits': (-0.1, 0.9, -0.1, 0.9),
        'standalone': True})
    settings.update(kwargs)

    boundaries(**settings)
    decorate(**settings)

    return display(**settings)
Beispiel #21
0
def planckian_locus_CIE_1960_UCS_chromaticity_diagram_plot(
        illuminants=None,
        **kwargs):
    """
    Plots the planckian locus and given illuminants in
    *CIE 1960 UCS Chromaticity Diagram*.

    Parameters
    ----------
    illuminants : array_like, optional
        Factory illuminants to plot.
    \*\*kwargs : \*\*
        Keywords arguments.

    Returns
    -------
    bool
        Definition success.

    Raises
    ------
    KeyError
        If one of the given illuminant is not found in the factory illuminants.

    Examples
    --------
    >>> ils = ['A', 'C', 'E']
    >>> planckian_locus_CIE_1960_UCS_chromaticity_diagram_plot(ils)  # noqa  # doctest: +SKIP
    True
    """

    if illuminants is None:
        illuminants = ('A', 'C', 'E')

    cmfs = CMFS.get('CIE 1931 2 Degree Standard Observer')

    settings = {
        'title': ('{0} Illuminants - Planckian Locus\n'
                  'CIE 1960 UCS Chromaticity Diagram - '
                  'CIE 1931 2 Degree Standard Observer').format(
            ', '.join(illuminants))
        if illuminants else
        ('Planckian Locus\nCIE 1960 UCS Chromaticity Diagram - '
         'CIE 1931 2 Degree Standard Observer'),
        'standalone': False}
    settings.update(kwargs)

    if not CIE_1960_UCS_chromaticity_diagram_plot(**settings):
        return

    xy_to_uv = lambda x: UCS_to_uv(XYZ_to_UCS(xy_to_XYZ(x)))

    start, end = 1667, 100000
    uv = np.array([CCT_to_uv(x, 0, cmfs=cmfs)
                   for x in np.arange(start, end + 250, 250)])

    pylab.plot(uv[:, 0], uv[:, 1], color='black', linewidth=2)

    for i in [1667, 2000, 2500, 3000, 4000, 6000, 10000]:
        u0, v0 = CCT_to_uv(i, -0.05)
        u1, v1 = CCT_to_uv(i, 0.05)
        pylab.plot([u0, u1], [v0, v1], color='black', linewidth=2)
        pylab.annotate('{0}K'.format(i),
                       xy=(u0, v0),
                       xytext=(0, -10),
                       textcoords='offset points',
                       size='x-small')

    for illuminant in illuminants:
        uv = xy_to_uv(ILLUMINANTS.get(cmfs.name).get(illuminant))
        if uv is None:
            raise KeyError(
                ('Illuminant "{0}" not found in factory illuminants: '
                 '"{1}".').format(illuminant,
                                  sorted(ILLUMINANTS.get(cmfs.name).keys())))

        pylab.plot(uv[0], uv[1], 'o', color='white', linewidth=2)

        pylab.annotate(illuminant,
                       xy=(uv[0], uv[1]),
                       xytext=(-50, 30),
                       textcoords='offset points',
                       arrowprops=dict(arrowstyle='->',
                                       connectionstyle='arc3, rad=-0.2'))

    settings.update({'standalone': True})
    settings.update(kwargs)

    return display(**settings)
Beispiel #22
0
def planckian_locus_CIE_1931_chromaticity_diagram_plot(
        illuminants=None,
        **kwargs):
    """
    Plots the planckian locus and given illuminants in
    *CIE 1931 Chromaticity Diagram*.

    Parameters
    ----------
    illuminants : array_like, optional
        Factory illuminants to plot.
    \*\*kwargs : \*\*
        Keywords arguments.

    Returns
    -------
    bool
        Definition success.

    Raises
    ------
    KeyError
        If one of the given illuminant is not found in the factory illuminants.

    Examples
    --------
    >>> ils = ['A', 'B', 'C']
    >>> planckian_locus_CIE_1931_chromaticity_diagram_plot(ils)  # noqa  # doctest: +SKIP
    True
    """

    if illuminants is None:
        illuminants = ('A', 'B', 'C')

    cmfs = CMFS.get('CIE 1931 2 Degree Standard Observer')

    settings = {
        'title': ('{0} Illuminants - Planckian Locus\n'
                  'CIE 1931 Chromaticity Diagram - '
                  'CIE 1931 2 Degree Standard Observer').format(
            ', '.join(illuminants))
        if illuminants else
        ('Planckian Locus\nCIE 1931 Chromaticity Diagram - '
         'CIE 1931 2 Degree Standard Observer'),
        'standalone': False}
    settings.update(kwargs)

    if not CIE_1931_chromaticity_diagram_plot(**settings):
        return

    start, end = 1667, 100000
    x, y = tuple(zip(*[UCS_uv_to_xy(CCT_to_uv(x, 0, cmfs=cmfs))
                       for x in np.arange(start, end + 250, 250)]))

    pylab.plot(x, y, color='black', linewidth=2)

    for i in [1667, 2000, 2500, 3000, 4000, 6000, 10000]:
        x0, y0 = UCS_uv_to_xy(CCT_to_uv(i, -0.025, cmfs=cmfs))
        x1, y1 = UCS_uv_to_xy(CCT_to_uv(i, 0.025, cmfs=cmfs))
        pylab.plot([x0, x1], [y0, y1], color='black', linewidth=2)
        pylab.annotate('{0}K'.format(i),
                       xy=(x0, y0),
                       xytext=(0, -10),
                       textcoords='offset points',
                       size='x-small')

    for illuminant in illuminants:
        xy = ILLUMINANTS.get(cmfs.name).get(illuminant)
        if xy is None:
            raise KeyError(
                ('Illuminant "{0}" not found in factory illuminants: '
                 '"{1}".').format(illuminant,
                                  sorted(ILLUMINANTS.get(cmfs.name).keys())))

        pylab.plot(xy[0], xy[1], 'o', color='white', linewidth=2)

        pylab.annotate(illuminant,
                       xy=(xy[0], xy[1]),
                       xytext=(-50, 30),
                       textcoords='offset points',
                       arrowprops=dict(arrowstyle='->',
                                       connectionstyle='arc3, rad=-0.2'))

    settings.update({'standalone': True})

    return display(**settings)