def test_anomalous_trichromacy_matrix_Machado2009(self):
        """
        Tests :func:`colour.blindness.machado2009.\
anomalous_trichromacy_matrix_Machado2009` definition.
        """

        cmfs = LMS_CMFS.get('Smith & Pokorny 1975 Normal Trichromats')
        primaries = DISPLAYS_RGB_PRIMARIES['Typical CRT Brainard 1997']
        np.testing.assert_almost_equal(
            anomalous_trichromacy_matrix_Machado2009(cmfs, primaries,
                                                     np.array([0, 0, 0])),
            np.identity(3),
            decimal=7)

        np.testing.assert_allclose(
            anomalous_trichromacy_matrix_Machado2009(cmfs, primaries,
                                                     np.array([2, 0, 0])),
            CVD_MATRICES_MACHADO2010.get('Protanomaly').get(0.1),
            rtol=0.0001,
            atol=0.0001)

        np.testing.assert_allclose(
            anomalous_trichromacy_matrix_Machado2009(cmfs, primaries,
                                                     np.array([20, 0, 0])),
            CVD_MATRICES_MACHADO2010.get('Protanomaly').get(1.0),
            rtol=0.0001,
            atol=0.0001)

        np.testing.assert_allclose(
            anomalous_trichromacy_matrix_Machado2009(cmfs, primaries,
                                                     np.array([0, 2, 0])),
            CVD_MATRICES_MACHADO2010.get('Deuteranomaly').get(0.1),
            rtol=0.0001,
            atol=0.0001)

        np.testing.assert_allclose(
            anomalous_trichromacy_matrix_Machado2009(cmfs, primaries,
                                                     np.array([0, 20, 0])),
            CVD_MATRICES_MACHADO2010.get('Deuteranomaly').get(1.0),
            rtol=0.0001,
            atol=0.0001)

        np.testing.assert_allclose(
            anomalous_trichromacy_matrix_Machado2009(
                cmfs, primaries, np.array([0, 0, 5.00056688094503])),
            CVD_MATRICES_MACHADO2010.get('Tritanomaly').get(0.1),
            rtol=0.0001,
            atol=0.0001)

        np.testing.assert_allclose(
            anomalous_trichromacy_matrix_Machado2009(
                cmfs, primaries, np.array([0, 0, 59.00590434857581])),
            CVD_MATRICES_MACHADO2010.get('Tritanomaly').get(1.0),
            rtol=0.001,
            atol=0.001)
Example #2
0
    def test_anomalous_trichromacy_matrix_Machado2009(self):
        """
        Tests :func:`colour.blindness.machado2009.\
anomalous_trichromacy_matrix_Machado2009` definition.
        """

        cmfs = LMS_CMFS.get('Smith & Pokorny 1975 Normal Trichromats')
        primaries = DISPLAYS_RGB_PRIMARIES['Typical CRT Brainard 1997']
        np.testing.assert_almost_equal(
            anomalous_trichromacy_matrix_Machado2009(cmfs, primaries,
                                                     np.array([0, 0, 0])),
            np.identity(3),
            decimal=7)

        np.testing.assert_allclose(
            anomalous_trichromacy_matrix_Machado2009(cmfs, primaries,
                                                     np.array([2, 0, 0])),
            CVD_MATRICES_MACHADO2010.get('Protanomaly').get(0.1),
            rtol=0.0001,
            atol=0.0001)

        np.testing.assert_allclose(
            anomalous_trichromacy_matrix_Machado2009(cmfs, primaries,
                                                     np.array([20, 0, 0])),
            CVD_MATRICES_MACHADO2010.get('Protanomaly').get(1.0),
            rtol=0.0001,
            atol=0.0001)

        np.testing.assert_allclose(
            anomalous_trichromacy_matrix_Machado2009(cmfs, primaries,
                                                     np.array([0, 2, 0])),
            CVD_MATRICES_MACHADO2010.get('Deuteranomaly').get(0.1),
            rtol=0.0001,
            atol=0.0001)

        np.testing.assert_allclose(
            anomalous_trichromacy_matrix_Machado2009(cmfs, primaries,
                                                     np.array([0, 20, 0])),
            CVD_MATRICES_MACHADO2010.get('Deuteranomaly').get(1.0),
            rtol=0.0001,
            atol=0.0001)

        np.testing.assert_allclose(
            anomalous_trichromacy_matrix_Machado2009(
                cmfs, primaries, np.array([0, 0, 5.00056688094503])),
            CVD_MATRICES_MACHADO2010.get('Tritanomaly').get(0.1),
            rtol=0.0001,
            atol=0.0001)

        np.testing.assert_allclose(
            anomalous_trichromacy_matrix_Machado2009(
                cmfs, primaries, np.array([0, 0, 59.00590434857581])),
            CVD_MATRICES_MACHADO2010.get('Tritanomaly').get(1.0),
            rtol=0.001,
            atol=0.001)
Example #3
0
def LMS_10_degree_cmfs_to_XYZ_10_degree_cmfs(wavelength):
    """
    Converts *Stockman & Sharpe 10 Degree Cone Fundamentals* colour matching
    functions into the *CIE 2012 10 Degree Standard Observer* colour matching
    functions.

    Parameters
    ----------
    wavelength : numeric
        Wavelength :math:`\lambda` in nm.

    Returns
    -------
    ndarray, (3,)
        *CIE 2012 10 Degree Standard Observer* spectral tristimulus values.

    Raises
    ------
    KeyError
        If wavelength :math:`\lambda` is not available in the colour matching
        functions.

    Notes
    -----
    -   Data for the *CIE 2012 10 Degree Standard Observer* already exists,
        this definition is intended for educational purpose.

    References
    ----------
    .. [5]  CVRL. (n.d.). CIE (2012) 10-deg XYZ “physiologically-relevant”
            colour matching functions. Retrieved June 25, 2014, from
            http://www.cvrl.org/database/text/cienewxyz/cie2012xyz10.htm

    Examples
    --------
    >>> LMS_10_degree_cmfs_to_XYZ_10_degree_cmfs(700)  # doctest: +ELLIPSIS
    array([ 0.0098162...,  0.0037761...,  0.        ])
    """

    cmfs = LMS_CMFS.get('Stockman & Sharpe 10 Degree Cone Fundamentals')
    l_bar, m_bar, s_bar = cmfs.l_bar.get(wavelength), cmfs.m_bar.get(
        wavelength), cmfs.s_bar.get(wavelength)
    if None in (l_bar, m_bar, s_bar):
        raise KeyError(('"{0} nm" wavelength not available in "{1}" colour '
                        'matching functions with "{2}" shape!').format(
            wavelength, cmfs.name, cmfs.shape))

    x_bar = 1.93986443 * l_bar - 1.34664359 * m_bar + 0.43044935 * s_bar
    y_bar = 0.69283932 * l_bar + 0.34967567 * m_bar
    z_bar = 2.14687945 * s_bar

    return np.array([x_bar, y_bar, z_bar])
Example #4
0
def LMS_2_degree_cmfs_to_XYZ_2_degree_cmfs(wavelength):
    """
    Converts *Stockman & Sharpe 2 Degree Cone Fundamentals* colour matching
    functions into the *CIE 2012 2 Degree Standard Observer* colour matching
    functions.

    Parameters
    ----------
    wavelength : numeric
        Wavelength :math:`\lambda` in nm.

    Returns
    -------
    ndarray, (3,)
        *CIE 2012 2 Degree Standard Observer* spectral tristimulus values.

    Raises
    ------
    KeyError
        If wavelength :math:`\lambda` is not available in the colour matching
        functions.

    Notes
    -----
    -   Data for the *CIE 2012 2 Degree Standard Observer* already exists,
        this definition is intended for educational purpose.

    References
    ----------
    .. [4]  CVRL. (n.d.). CIE (2012) 2-deg XYZ “physiologically-relevant”
            colour matching functions. Retrieved June 25, 2014, from
            http://www.cvrl.org/database/text/cienewxyz/cie2012xyz2.htm

    Examples
    --------
    >>> LMS_2_degree_cmfs_to_XYZ_2_degree_cmfs(700)  # doctest: +ELLIPSIS
    array([ 0.0109677...,  0.0041959...,  0.        ])
    """

    cmfs = LMS_CMFS.get('Stockman & Sharpe 2 Degree Cone Fundamentals')
    l_bar, m_bar, s_bar = cmfs.l_bar.get(wavelength), cmfs.m_bar.get(
        wavelength), cmfs.s_bar.get(wavelength)
    if None in (l_bar, m_bar, s_bar):
        raise KeyError(('"{0} nm" wavelength not available in "{1}" colour '
                        'matching functions with "{2}" shape!').format(
            wavelength, cmfs.name, cmfs.shape))

    x_bar = 1.94735469 * l_bar - 1.41445123 * m_bar + 0.36476327 * s_bar
    y_bar = 0.68990272 * l_bar + 0.34832189 * m_bar
    z_bar = 1.93485343 * s_bar

    return np.array([x_bar, y_bar, z_bar])
Example #5
0
def LMS_10_degree_cmfs_to_XYZ_10_degree_cmfs(wavelength):
    """
    Converts *Stockman & Sharpe 10 Degree Cone Fundamentals* colour matching
    functions into the *CIE 2012 10 Degree Standard Observer* colour matching
    functions.

    Parameters
    ----------
    wavelength : numeric
        Wavelength :math:`\lambda` in nm.

    Returns
    -------
    ndarray, (3,)
        *CIE 2012 10 Degree Standard Observer* spectral tristimulus values.

    Raises
    ------
    KeyError
        If wavelength :math:`\lambda` is not available in the colour matching
        functions.

    Notes
    -----
    -   Data for the *CIE 2012 10 Degree Standard Observer* already exists,
        this definition is intended for educational purpose.

    References
    ----------
    .. [5]  http://www.cvrl.org/database/text/cienewxyz/cie2012xyz10.htm
            (Last accessed 25 June 2014)

    Examples
    --------
    >>> LMS_10_degree_cmfs_to_XYZ_10_degree_cmfs(700)  # doctest: +ELLIPSIS
    array([ 0.0098162...,  0.0037761...,  0.        ])
    """

    cmfs = LMS_CMFS.get('Stockman & Sharpe 10 Degree Cone Fundamentals')
    l_bar, m_bar, s_bar = cmfs.l_bar.get(wavelength), cmfs.m_bar.get(
        wavelength), cmfs.s_bar.get(wavelength)
    if None in (l_bar, m_bar, s_bar):
        raise KeyError(('"{0} nm" wavelength not available in "{1}" colour '
                        'matching functions with "{2}" shape!').format(
                            wavelength, cmfs.name, cmfs.shape))

    x_bar = 1.93986443 * l_bar - 1.34664359 * m_bar + 0.43044935 * s_bar
    y_bar = 0.69283932 * l_bar + 0.34967567 * m_bar
    z_bar = 2.14687945 * s_bar

    return np.array([x_bar, y_bar, z_bar])
Example #6
0
def LMS_2_degree_cmfs_to_XYZ_2_degree_cmfs(wavelength):
    """
    Converts *Stockman & Sharpe 2 Degree Cone Fundamentals* colour matching
    functions into the *CIE 2012 2 Degree Standard Observer* colour matching
    functions.

    Parameters
    ----------
    wavelength : numeric
        Wavelength :math:`\lambda` in nm.

    Returns
    -------
    ndarray, (3,)
        *CIE 2012 2 Degree Standard Observer* spectral tristimulus values.

    Raises
    ------
    KeyError
        If wavelength :math:`\lambda` is not available in the colour matching
        functions.

    Notes
    -----
    -   Data for the *CIE 2012 2 Degree Standard Observer* already exists,
        this definition is intended for educational purpose.

    References
    ----------
    .. [4]  http://www.cvrl.org/database/text/cienewxyz/cie2012xyz2.htm
            (Last accessed 25 June 2014)

    Examples
    --------
    >>> LMS_2_degree_cmfs_to_XYZ_2_degree_cmfs(700)  # doctest: +ELLIPSIS
    array([ 0.0109677...,  0.0041959...,  0.        ])
    """

    cmfs = LMS_CMFS.get('Stockman & Sharpe 2 Degree Cone Fundamentals')
    l_bar, m_bar, s_bar = cmfs.l_bar.get(wavelength), cmfs.m_bar.get(
        wavelength), cmfs.s_bar.get(wavelength)
    if None in (l_bar, m_bar, s_bar):
        raise KeyError(('"{0} nm" wavelength not available in "{1}" colour '
                        'matching functions with "{2}" shape!').format(
                            wavelength, cmfs.name, cmfs.shape))

    x_bar = 1.94735469 * l_bar - 1.41445123 * m_bar + 0.36476327 * s_bar
    y_bar = 0.68990272 * l_bar + 0.34832189 * m_bar
    z_bar = 1.93485343 * s_bar

    return np.array([x_bar, y_bar, z_bar])
Example #7
0
    def test_anomalous_trichromacy_cmfs_Machado2009(self):
        """
        Tests :func:`colour.blindness.machado2009.\
anomalous_trichromacy_cmfs_Machado2009` definition.
        """

        cmfs = LMS_CMFS.get('Smith & Pokorny 1975 Normal Trichromats')
        np.testing.assert_almost_equal(
            anomalous_trichromacy_cmfs_Machado2009(cmfs,
                                                   np.array([0, 0, 0], ))[450],
            cmfs[450],
            decimal=7)

        np.testing.assert_almost_equal(
            anomalous_trichromacy_cmfs_Machado2009(cmfs,
                                                   np.array([1, 0, 0], ))[450],
            np.array([0.03631700, 0.06350000, 0.91000000]),
            decimal=7)

        np.testing.assert_almost_equal(
            anomalous_trichromacy_cmfs_Machado2009(cmfs,
                                                   np.array([0, 1, 0], ))[450],
            np.array([0.03430000, 0.06178404, 0.91000000]),
            decimal=7)

        np.testing.assert_almost_equal(
            anomalous_trichromacy_cmfs_Machado2009(cmfs,
                                                   np.array([0, 0, 1], ))[450],
            np.array([0.03430000, 0.06350000, 0.92270240]),
            decimal=7)

        np.testing.assert_almost_equal(
            anomalous_trichromacy_cmfs_Machado2009(cmfs, np.array(
                [10, 0, 0], ))[450],
            np.array([0.05447001, 0.06350000, 0.91000000]),
            decimal=7)

        np.testing.assert_almost_equal(
            anomalous_trichromacy_cmfs_Machado2009(cmfs, np.array(
                [0, 10, 0], ))[450],
            np.array([0.03430000, 0.04634036, 0.91000000]),
            decimal=7)

        np.testing.assert_almost_equal(
            anomalous_trichromacy_cmfs_Machado2009(cmfs, np.array(
                [0, 0, 10], ))[450],
            np.array([0.03430000, 0.06350000, 1.00000000]),
            decimal=7)
Example #8
0
def LMS_10_degree_cmfs_to_XYZ_10_degree_cmfs(wavelength):
    """
    Converts *Stockman & Sharpe 10 Degree Cone Fundamentals* colour matching
    functions into the *CIE 2012 10 Degree Standard Observer* colour matching
    functions.

    Parameters
    ----------
    wavelength : numeric or array_like
        Wavelength :math:`\lambda` in nm.

    Returns
    -------
    ndarray
        *CIE 2012 10 Degree Standard Observer* spectral tristimulus values.

    Notes
    -----
    -   Data for the *CIE 2012 10 Degree Standard Observer* already exists,
        this definition is intended for educational purpose.

    References
    ----------
    .. [5]  CVRL. (n.d.). CIE (2012) 10-deg XYZ “physiologically-relevant”
            colour matching functions. Retrieved June 25, 2014, from
            http://www.cvrl.org/database/text/cienewxyz/cie2012xyz10.htm

    Examples
    --------
    >>> LMS_10_degree_cmfs_to_XYZ_10_degree_cmfs(700)  # doctest: +ELLIPSIS
    array([ 0.0098162...,  0.0037761...,  0.        ])
    """

    cmfs = LMS_CMFS.get('Stockman & Sharpe 10 Degree Cone Fundamentals')

    lms_bar = cmfs.get(wavelength)

    M = np.array([[1.93986443, -1.34664359, 0.43044935],
                  [0.69283932, 0.34967567, 0.00000000],
                  [0.00000000, 0.00000000, 2.14687945]])

    xyz_bar = dot_vector(M, lms_bar)

    return xyz_bar
Example #9
0
def LMS_2_degree_cmfs_to_XYZ_2_degree_cmfs(wavelength):
    """
    Converts *Stockman & Sharpe 2 Degree Cone Fundamentals* colour matching
    functions into the *CIE 2012 2 Degree Standard Observer* colour matching
    functions.

    Parameters
    ----------
    wavelength : numeric or array_like
        Wavelength :math:`\lambda` in nm.

    Returns
    -------
    ndarray
        *CIE 2012 2 Degree Standard Observer* spectral tristimulus values.

    Notes
    -----
    -   Data for the *CIE 2012 2 Degree Standard Observer* already exists,
        this definition is intended for educational purpose.

    References
    ----------
    .. [4]  CVRL. (n.d.). CIE (2012) 2-deg XYZ “physiologically-relevant”
            colour matching functions. Retrieved June 25, 2014, from
            http://www.cvrl.org/database/text/cienewxyz/cie2012xyz2.htm

    Examples
    --------
    >>> LMS_2_degree_cmfs_to_XYZ_2_degree_cmfs(700)  # doctest: +ELLIPSIS
    array([ 0.0109677...,  0.0041959...,  0.        ])
    """

    cmfs = LMS_CMFS.get('Stockman & Sharpe 2 Degree Cone Fundamentals')

    lms_bar = cmfs.get(wavelength)

    M = np.array([[1.94735469, -1.41445123, 0.36476327],
                  [0.68990272, 0.34832189, 0.00000000],
                  [0.00000000, 0.00000000, 1.93485343]])

    xyz_bar = dot_vector(M, lms_bar)

    return xyz_bar
Example #10
0
def LMS_10_degree_cmfs_to_XYZ_10_degree_cmfs(wavelength):
    """
    Converts *Stockman & Sharpe 10 Degree Cone Fundamentals* colour matching
    functions into the *CIE 2012 10 Degree Standard Observer* colour matching
    functions.

    Parameters
    ----------
    wavelength : numeric or array_like
        Wavelength :math:`\lambda` in nm.

    Returns
    -------
    ndarray
        *CIE 2012 10 Degree Standard Observer* spectral tristimulus values.

    Notes
    -----
    -   Data for the *CIE 2012 10 Degree Standard Observer* already exists,
        this definition is intended for educational purpose.

    References
    ----------
    .. [5]  CVRL. (n.d.). CIE (2012) 10-deg XYZ “physiologically-relevant”
            colour matching functions. Retrieved June 25, 2014, from
            http://www.cvrl.org/database/text/cienewxyz/cie2012xyz10.htm

    Examples
    --------
    >>> LMS_10_degree_cmfs_to_XYZ_10_degree_cmfs(700)  # doctest: +ELLIPSIS
    array([ 0.0098162...,  0.0037761...,  0.        ])
    """

    cmfs = LMS_CMFS.get('Stockman & Sharpe 10 Degree Cone Fundamentals')

    lms_bar = cmfs.get(wavelength)

    M = np.array([[1.93986443, -1.34664359, 0.43044935],
                  [0.69283932, 0.34967567, 0.00000000],
                  [0.00000000, 0.00000000, 2.14687945]])

    xyz_bar = dot_vector(M, lms_bar)

    return xyz_bar
Example #11
0
def LMS_2_degree_cmfs_to_XYZ_2_degree_cmfs(wavelength):
    """
    Converts *Stockman & Sharpe 2 Degree Cone Fundamentals* colour matching
    functions into the *CIE 2012 2 Degree Standard Observer* colour matching
    functions.

    Parameters
    ----------
    wavelength : numeric or array_like
        Wavelength :math:`\lambda` in nm.

    Returns
    -------
    ndarray
        *CIE 2012 2 Degree Standard Observer* spectral tristimulus values.

    Notes
    -----
    -   Data for the *CIE 2012 2 Degree Standard Observer* already exists,
        this definition is intended for educational purpose.

    References
    ----------
    .. [4]  CVRL. (n.d.). CIE (2012) 2-deg XYZ “physiologically-relevant”
            colour matching functions. Retrieved June 25, 2014, from
            http://www.cvrl.org/database/text/cienewxyz/cie2012xyz2.htm

    Examples
    --------
    >>> LMS_2_degree_cmfs_to_XYZ_2_degree_cmfs(700)  # doctest: +ELLIPSIS
    array([ 0.0109677...,  0.0041959...,  0.        ])
    """

    cmfs = LMS_CMFS.get('Stockman & Sharpe 2 Degree Cone Fundamentals')

    lms_bar = cmfs.get(wavelength)

    M = np.array([[1.94735469, -1.41445123, 0.36476327],
                  [0.68990272, 0.34832189, 0.00000000],
                  [0.00000000, 0.00000000, 1.93485343]])

    xyz_bar = dot_vector(M, lms_bar)

    return xyz_bar