Пример #1
0
 def test_d(self):
     ill = D('D_65')
     assert ill.temperature == 6504.
     assert ill.name == 'D_65'
     assert repr(ill) == 'D(6504)'
     obs = Standard(2)
     white_point = np.array([.950392, 1.000, 1.088639])
     np.testing.assert_allclose(ill.get_white_point(obs),
                                white_point,
                                rtol=1e-6,
                                atol=1e-14)
     ill = D(5400.)
     assert ill.name == 'D_5400K'
     white_point = np.array([.957976, 1.000, .902011])
     np.testing.assert_allclose(ill.get_white_point(obs),
                                white_point,
                                rtol=1e-6,
                                atol=1e-14)
     with raises(ValueError):
         D(3999)
     with raises(ValueError):
         D(25001)
     with raises(ValueError):
         D('D_47')
     with raises(AttributeError):
         ill.name = 'pizza'
     assert np.all(ill.wavelengths == np.arange(300, 835, 5))
     with raises(AttributeError):
         ill.wavelengths = 2
     with raises(AttributeError):
         ill.psd = 54
Пример #2
0
 def test_xyz2xyzr(self):
     ill = D()
     obs = Standard()
     xyz = 0.5 * ill.get_white_point(obs)
     expected_xyzr = 0.5 * np.ones((3, ))
     actual_xyzr = convert.xyz2xyzr(xyz, illuminant=ill, observer=obs)
     np.testing.assert_allclose(actual_xyzr,
                                expected_xyzr,
                                rtol=1e-5,
                                atol=1e-14)
Пример #3
0
 def test_spectrum2xyz_1d(self):
     spectra = np.array([1, 1, 0])
     wavelengths = np.array([450, 550, 650])
     ill = D()
     obs = Standard()
     expected_xyz = np.array([.588645, .961091, .950396])
     actual_xyz = convert.spectrum2xyz(spectra,
                                       wavelengths,
                                       illuminant=ill,
                                       observer=obs)
     np.testing.assert_allclose(actual_xyz,
                                expected_xyz,
                                rtol=1e-5,
                                atol=1e-14)
     assert actual_xyz.shape == (3, )
Пример #4
0
 def test_spectrum2xyz_axes0(self):
     spectra = np.array([[0, 1], [1, 1], [0, 0]])
     wavelengths = np.array([450, 550, 650])
     ill = D()
     obs = Standard()
     expected_xyz = np.array([[.4098627, .588645], [.9408818, .961091],
                              [.008271787, .950396]])
     actual_xyz = convert.spectrum2xyz(spectra,
                                       wavelengths,
                                       illuminant=ill,
                                       observer=obs)
     np.testing.assert_allclose(actual_xyz,
                                expected_xyz,
                                rtol=1e-5,
                                atol=1e-14)
Пример #5
0
 def test_xyz2xyz(self):
     obs = Standard()
     illuminant_d = D()
     illuminant_a = A()
     white_point_d = illuminant_d.get_white_point(obs)
     white_point_a = illuminant_a.get_white_point(obs)
     caa = Bradford()
     xyz_d = np.array([.25, .750, .350])
     expected_xyz_a = np.array([.33312305, .7051638, .13108368])
     actual_xyz_a = convert.xyz2xyz(xyz_d,
                                    white_point_d,
                                    white_point_a,
                                    caa=caa)
     np.testing.assert_allclose(actual_xyz_a,
                                expected_xyz_a,
                                rtol=1e-5,
                                atol=1e-14)
Пример #6
0
 def test_xyz2lab_small(self):
     ill = D()
     obs = Standard()
     xyz = np.array([0.008, 0.009, 0.007])
     expected_lab = np.array([8.1289723, -2.264535, 4.001228])
     actual_lab = convert.convert(xyz,
                                  'CIEXYZ',
                                  'CIELAB',
                                  illuminant=ill,
                                  observer=obs)
     np.testing.assert_allclose(actual_lab,
                                expected_lab,
                                rtol=1e-5,
                                atol=1e-14)
     actual_xyz = convert.convert(actual_lab,
                                  'CIELAB',
                                  'CIEXYZ',
                                  illuminant=ill,
                                  observer=obs)
     np.testing.assert_allclose(actual_xyz, xyz, rtol=1e-5, atol=1e-14)
Пример #7
0
 def test_xyz2lab_big(self):
     ill = D()
     obs = Standard()
     xyz = np.array([.2253731, .18418652, .09526464])
     expected_lab = np.array([50., 25., 25.])
     actual_lab = convert.convert(xyz,
                                  'CIEXYZ',
                                  'CIELAB',
                                  illuminant=ill,
                                  observer=obs)
     np.testing.assert_allclose(actual_lab,
                                expected_lab,
                                rtol=1e-5,
                                atol=1e-14)
     actual_xyz = convert.convert(actual_lab,
                                  'CIELAB',
                                  'CIEXYZ',
                                  illuminant=ill,
                                  observer=obs)
     np.testing.assert_allclose(actual_xyz, xyz, rtol=1e-5, atol=1e-14)
Пример #8
0
 def test_xyz2xyz_axis(self):
     obs = Standard()
     illuminant_d = D()
     illuminant_a = A()
     white_point_d = illuminant_d.get_white_point(obs)
     white_point_a = illuminant_a.get_white_point(obs)
     caa = Bradford()
     xyz_d = np.array([[[.25, .15], [.75, .55], [.35, .20]],
                       [[.35, .30], [.45, .40], [.15, .50]]])
     expected_xyz_a = np.array([[[.333123, .212521], [.705164, .515183],
                                 [.131084, .0790936]],
                                [[.452460, .331859], [.457123, .384096],
                                 [.0549786, .164526]]])
     actual_xyz_a = convert.xyz2xyz(xyz_d,
                                    white_point_d,
                                    white_point_a,
                                    axis=1,
                                    caa=caa)
     np.testing.assert_allclose(actual_xyz_a,
                                expected_xyz_a,
                                rtol=1e-5,
                                atol=1e-14)
Пример #9
0
 def test_linear_transformation(self):
     obs = Standard()
     illuminant_d = D()
     illuminant_a = A()
     white_point_d = illuminant_d.get_white_point(obs)
     white_point_a = illuminant_a.get_white_point(obs)
     caa = Bradford()
     expected_crd = np.array([[0.8951, -0.7502, 0.0389],
                              [0.2664, 1.7135, -0.0685],
                              [-0.1614, 0.0367, 1.0296]])
     actual_crd = caa.cone_response_domain
     np.testing.assert_allclose(actual_crd,
                                expected_crd,
                                rtol=1e-5,
                                atol=1e-14)
     expected_transform = np.array([[1.2164509, 0.15332493, -0.023949391],
                                    [.11098616, 0.91524230, 0.035903103],
                                    [-.1549409, -0.055997489, 0.31469628]])
     actual_transform = caa.get_linear_transformation(
         white_point_d, white_point_a)
     np.testing.assert_allclose(actual_transform,
                                expected_transform,
                                rtol=1e-5,
                                atol=1e-14)
Пример #10
0
def get_default_illuminant() -> Illuminant:
    return D()
Пример #11
0
 def test_lrgb2xyz_caa(self):
     run_forward_reverse(convert.lrgb2xyz,
                         convert.xyz2lrgb,
                         np.array([.5, .75, 0.]),
                         np.array([.506831, .64893, .079794]),
                         illuminant=D('D_50'))
Пример #12
0
 def illuminant(self):
     return D('D_65')