Exemplo n.º 1
0
    def test_luminous_efficacy(self):
        """
        Test :func:`colour.colorimetry.photometry.luminous_efficacy`
        definition.
        """

        self.assertAlmostEqual(
            luminous_efficacy(SDS_ILLUMINANTS["FL2"].copy().normalise()),
            336.83937176,
            places=7,
        )

        self.assertAlmostEqual(
            luminous_efficacy(SDS_LIGHT_SOURCES["Neodimium Incandescent"]),
            136.21708032,
            places=7,
        )

        self.assertAlmostEqual(
            luminous_efficacy(SDS_LIGHT_SOURCES["F32T8/TL841 (Triphosphor)"]),
            348.88267549,
            places=7,
        )

        sd = sd_zeros()
        sd[555] = 1
        self.assertAlmostEqual(luminous_efficacy(sd), 683.00000000, places=7)
Exemplo n.º 2
0
    def test_luminous_efficacy(self):
        """
        Tests :func:`colour.colorimetry.photometry.luminous_efficacy`
        definition.
        """

        self.assertAlmostEqual(
            luminous_efficacy(ILLUMINANTS_SDS['FL2'].copy().normalise()),
            336.83937176,
            places=7)

        self.assertAlmostEqual(
            luminous_efficacy(LIGHT_SOURCES_SDS['Neodimium Incandescent']),
            136.21708032,
            places=7)

        self.assertAlmostEqual(
            luminous_efficacy(LIGHT_SOURCES_SDS['F32T8/TL841 (Triphosphor)']),
            348.88267549,
            places=7)

        sd = sd_zeros()
        sd[555] = 1
        self.assertAlmostEqual(luminous_efficacy(sd), 683.00000000, places=7)
Exemplo n.º 3
0
def XYZ_to_spectral(
        XYZ,
        cmfs=colour.STANDARD_OBSERVERS_CMFS['CIE 1931 2 Degree Standard Observer'],
        interval=5,
        tolerance=1e-10,
        maximum_iterations=5000,
        illuminant=sd_ones(),
        max_refl=1.0):

    XYZ = to_domain_1(XYZ)
    shape = SpectralShape(cmfs.shape.start, cmfs.shape.end, interval)
    cmfs = cmfs.copy().align(shape)
    illuminant = illuminant.copy().align(shape)
    spd = sd_zeros(shape)

    def function_objective(a):
        """
        Objective function.
        """
        
        return np.sum(np.diff(a)**2)

    def function_constraint(a):
        """
        Function defining the constraint for XYZ=XYZ.
        """
        
        spd[:] = np.exp(a)
        
        return (XYZ -
                (colour.colorimetry.spectral_to_XYZ_integration(
                    spd, cmfs=cmfs, illuminant=illuminant)))

    def function_constraint2(a):
        """
        Function defining constraint on emission/reflectance
        """
        if max_refl <= 0.0:
            return 0.0
        return max_refl - np.exp(np.max(a)) * 100.

    wavelengths = spd.wavelengths
    bins = wavelengths.size
    constraints = ({'type': 'eq', 'fun': function_constraint},
                   {'type': 'ineq', 'fun': function_constraint2})

    result = minimize(
        function_objective,
        spd.values,
        method='SLSQP',
        constraints=constraints,
        options={
            'ftol': tolerance,
            'maxiter': maximum_iterations,
            'disp': True
        })

    if not result.success:
        raise RuntimeError(
            'Optimization failed for {0} after {1} iterations: "{2}".'.format(
                XYZ, result.nit, result.message))

    return SpectralDistribution(
        from_range_100(np.exp(result.x) * 100),
        wavelengths,
        name='Meng (2015) - {0}'.format(XYZ))