示例#1
0
    def test_luminous_efficacy(self):
        """
        Tests :func:`colour.colorimetry.photometry.luminous_efficacy`
        definition.
        """

        self.assertAlmostEqual(
            luminous_efficacy(
                ILLUMINANTS_RELATIVE_SPDS.get('F2').clone().normalise()),
            336.83937176,
            places=7)

        self.assertAlmostEqual(
            luminous_efficacy(LIGHT_SOURCES_RELATIVE_SPDS.get(
                'Neodimium Incandescent')),
            136.21708032,
            places=7)

        self.assertAlmostEqual(
            luminous_efficacy(LIGHT_SOURCES_RELATIVE_SPDS.get(
                'F32T8/TL841 (Triphosphor)')),
            348.88267549,
            places=7)

        spd = zeros_spd()
        spd[555] = 1
        self.assertAlmostEqual(
            luminous_efficacy(spd),
            683.00000000,
            places=7)
示例#2
0
def RGB_to_spectral_Smits1999(RGB):
    """
    Recovers the spectral power distribution of given *RGB* colourspace matrix
    using Smits (1999) method.

    Parameters
    ----------
    RGB : array_like, (3,)
        *RGB* colourspace matrix.

    Returns
    -------
    SpectralPowerDistribution
        Recovered spectral power distribution.

    Examples
    --------
    >>> RGB = np.array([0.02144962, 0.13154603, 0.09287601])
    >>> RGB_to_spectral_Smits1999(RGB)  # doctest: +ELLIPSIS
    <...SpectralPowerDistribution object at 0x...>
    """

    white_spd = SMITS_1999_SPDS.get('white').clone()
    cyan_spd = SMITS_1999_SPDS.get('cyan').clone()
    magenta_spd = SMITS_1999_SPDS.get('magenta').clone()
    yellow_spd = SMITS_1999_SPDS.get('yellow').clone()
    red_spd = SMITS_1999_SPDS.get('red').clone()
    green_spd = SMITS_1999_SPDS.get('green').clone()
    blue_spd = SMITS_1999_SPDS.get('blue').clone()

    R, G, B = np.ravel(RGB)
    spd = zeros_spd(SMITS_1999_SPDS.get('white').shape)

    if R <= G and R <= B:
        spd += white_spd * R
        if G <= B:
            spd += cyan_spd * (G - R)
            spd += blue_spd * (B - G)
        else:
            spd += cyan_spd * (B - R)
            spd += green_spd * (G - B)
    elif G <= R and G <= B:
        spd += white_spd * G
        if R <= B:
            spd += magenta_spd * (R - G)
            spd += blue_spd * (B - R)
        else:
            spd += magenta_spd * (B - G)
            spd += red_spd * (R - B)
    else:
        spd += white_spd * B
        if R <= G:
            spd += yellow_spd * (R - B)
            spd += green_spd * (G - R)
        else:
            spd += yellow_spd * (G - B)
            spd += red_spd * (R - G)

    return spd
示例#3
0
def RGB_to_spectral_Smits1999(RGB):
    """
    Recovers the spectral power distribution of given *RGB* colourspace array
    using Smits (1999) method.

    Parameters
    ----------
    RGB : array_like, (3,)
        *RGB* colourspace array.

    Returns
    -------
    SpectralPowerDistribution
        Recovered spectral power distribution.

    Examples
    --------
    >>> RGB = np.array([0.02144962, 0.13154603, 0.09287601])
    >>> RGB_to_spectral_Smits1999(RGB)  # doctest: +ELLIPSIS
    <...SpectralPowerDistribution object at 0x...>
    """

    white_spd = SMITS_1999_SPDS.get('white').clone()
    cyan_spd = SMITS_1999_SPDS.get('cyan').clone()
    magenta_spd = SMITS_1999_SPDS.get('magenta').clone()
    yellow_spd = SMITS_1999_SPDS.get('yellow').clone()
    red_spd = SMITS_1999_SPDS.get('red').clone()
    green_spd = SMITS_1999_SPDS.get('green').clone()
    blue_spd = SMITS_1999_SPDS.get('blue').clone()

    R, G, B = np.ravel(RGB)
    spd = zeros_spd(SMITS_1999_SPDS.get('white').shape)

    if R <= G and R <= B:
        spd += white_spd * R
        if G <= B:
            spd += cyan_spd * (G - R)
            spd += blue_spd * (B - G)
        else:
            spd += cyan_spd * (B - R)
            spd += green_spd * (G - B)
    elif G <= R and G <= B:
        spd += white_spd * G
        if R <= B:
            spd += magenta_spd * (R - G)
            spd += blue_spd * (B - R)
        else:
            spd += magenta_spd * (B - G)
            spd += red_spd * (R - B)
    else:
        spd += white_spd * B
        if R <= G:
            spd += yellow_spd * (R - B)
            spd += green_spd * (G - R)
        else:
            spd += yellow_spd * (G - B)
            spd += red_spd * (R - G)

    return spd
示例#4
0
def RGB_to_spectral_Smits1999(RGB):
    """
    Recovers the spectral power distribution of given *RGB* colourspace array
    using *Smits (1999)* method.

    Parameters
    ----------
    RGB : array_like, (3,)
        *RGB* colourspace array.

    Returns
    -------
    SpectralPowerDistribution
        Recovered spectral power distribution.

    Examples
    --------
    >>> RGB = np.array([0.02144962, 0.13154603, 0.09287601])
    >>> print(RGB_to_spectral_Smits1999(RGB))  # doctest: +ELLIPSIS
    SpectralPowerDistribution('0 Constant', (380.0, 720.0, 37.7777777...))
    """

    white_spd = SMITS_1999_SPDS['white'].clone()
    cyan_spd = SMITS_1999_SPDS['cyan'].clone()
    magenta_spd = SMITS_1999_SPDS['magenta'].clone()
    yellow_spd = SMITS_1999_SPDS['yellow'].clone()
    red_spd = SMITS_1999_SPDS['red'].clone()
    green_spd = SMITS_1999_SPDS['green'].clone()
    blue_spd = SMITS_1999_SPDS['blue'].clone()

    R, G, B = np.ravel(RGB)
    spd = zeros_spd(SMITS_1999_SPDS['white'].shape)

    if R <= G and R <= B:
        spd += white_spd * R
        if G <= B:
            spd += cyan_spd * (G - R)
            spd += blue_spd * (B - G)
        else:
            spd += cyan_spd * (B - R)
            spd += green_spd * (G - B)
    elif G <= R and G <= B:
        spd += white_spd * G
        if R <= B:
            spd += magenta_spd * (R - G)
            spd += blue_spd * (B - R)
        else:
            spd += magenta_spd * (B - G)
            spd += red_spd * (R - B)
    else:
        spd += white_spd * B
        if R <= G:
            spd += yellow_spd * (R - B)
            spd += green_spd * (G - R)
        else:
            spd += yellow_spd * (G - B)
            spd += red_spd * (R - G)

    return spd
示例#5
0
    def test_luminous_efficacy(self):
        """
        Tests :func:`colour.colorimetry.photometry.luminous_efficacy`
        definition.
        """

        self.assertAlmostEqual(luminous_efficacy(
            ILLUMINANTS_RELATIVE_SPDS.get('F2').clone().normalise()),
                               336.83937176,
                               places=7)

        self.assertAlmostEqual(luminous_efficacy(
            LIGHT_SOURCES_RELATIVE_SPDS.get('Neodimium Incandescent')),
                               136.21708032,
                               places=7)

        self.assertAlmostEqual(luminous_efficacy(
            LIGHT_SOURCES_RELATIVE_SPDS.get('F32T8/TL841 (Triphosphor)')),
                               348.88267549,
                               places=7)

        spd = zeros_spd()
        spd[555] = 1
        self.assertAlmostEqual(luminous_efficacy(spd), 683.00000000, places=7)