Coverage for adaptation/tests/test_cie1994.py: 100%

1"""Define the unit tests for the :mod:`colour.adaptation.cie1994` module."""

2

3 from __future__ import annotations

4

5 from itertools import product

6

7 import numpy as np

8

9 from colour.adaptation import chromatic_adaptation_CIE1994

10 from colour.constants import TOLERANCE_ABSOLUTE_TESTS

11 from colour.utilities import domain_range_scale, ignore_numpy_errors

12

13 __author__ = "Colour Developers"

14 __copyright__ = "Copyright 2013 Colour Developers"

15 __license__ = "BSD-3-Clause - https://opensource.org/licenses/BSD-3-Clause"

16 __maintainer__ = "Colour Developers"

17 __email__ = "colour-developers@colour-science.org"

18 __status__ = "Production"

19

20 __all__ = [

21 "TestChromaticAdaptationCIE1994",

22]

23

24

25 class TestChromaticAdaptationCIE1994:

26 """

27 Define :func:`colour.adaptation.cie1994.chromatic_adaptation_CIE1994`

28 definition unit tests methods.

29 """

30

31 def test_chromatic_adaptation_CIE1994(self) -> None:

32 """

33 Test :func:`colour.adaptation.cie1994.chromatic_adaptation_CIE1994`

34 definition.

35 """

36

37 np.testing.assert_allclose(

38 chromatic_adaptation_CIE1994(

39 XYZ_1=np.array([28.00, 21.26, 5.27]),

40 xy_o1=np.array([0.44760, 0.40740]),

41 xy_o2=np.array([0.31270, 0.32900]),

42 Y_o=20,

43 E_o1=1000,

44 E_o2=1000,

45 ),

46 np.array([24.03379521, 21.15621214, 17.64301199]),

47 atol=TOLERANCE_ABSOLUTE_TESTS,

48 )

49

50 np.testing.assert_allclose(

51 chromatic_adaptation_CIE1994(

52 XYZ_1=np.array([21.77, 19.18, 16.73]),

53 xy_o1=np.array([0.31270, 0.32900]),

54 xy_o2=np.array([0.31270, 0.32900]),

55 Y_o=50,

56 E_o1=100,

57 E_o2=1000,

58 ),

59 np.array([21.12891746, 19.42980532, 19.49577765]),

60 atol=TOLERANCE_ABSOLUTE_TESTS,

61 )

62

63 np.testing.assert_allclose(

64 chromatic_adaptation_CIE1994(

65 XYZ_1=np.array([0.07818780, 0.06157201, 0.28099326]) * 100,

66 xy_o1=np.array([0.31270, 0.32900]),

67 xy_o2=np.array([0.37208, 0.37529]),

68 Y_o=20,

69 E_o1=100,

70 E_o2=1000,

71 ),

72 np.array([9.14287406, 9.35843355, 15.95753504]),

73 atol=TOLERANCE_ABSOLUTE_TESTS,

74 )

75

76 def test_n_dimensional_chromatic_adaptation_CIE1994(self) -> None:

77 """

78 Test :func:`colour.adaptation.cie1994.chromatic_adaptation_CIE1994`

79 definition n-dimensional arrays support.

80 """

81

82 XYZ_1 = np.array([28.00, 21.26, 5.27])

83 xy_o1 = np.array([0.44760, 0.40740])

84 xy_o2 = np.array([0.31270, 0.32900])

85 Y_o = 20

86 E_o1 = 1000

87 E_o2 = 1000

88 XYZ_2 = chromatic_adaptation_CIE1994(XYZ_1, xy_o1, xy_o2, Y_o, E_o1, E_o2)

89

90 XYZ_1 = np.tile(XYZ_1, (6, 1))

91 XYZ_2 = np.tile(XYZ_2, (6, 1))

92 np.testing.assert_allclose(

93 chromatic_adaptation_CIE1994(XYZ_1, xy_o1, xy_o2, Y_o, E_o1, E_o2),

94 XYZ_2,

95 atol=TOLERANCE_ABSOLUTE_TESTS,

96 )

97

98 xy_o1 = np.tile(xy_o1, (6, 1))

99 xy_o2 = np.tile(xy_o2, (6, 1))

100 Y_o = np.tile(Y_o, 6)

101 E_o1 = np.tile(E_o1, 6)

102 E_o2 = np.tile(E_o2, 6)

103 np.testing.assert_allclose(

104 chromatic_adaptation_CIE1994(XYZ_1, xy_o1, xy_o2, Y_o, E_o1, E_o2),

105 XYZ_2,

106 atol=TOLERANCE_ABSOLUTE_TESTS,

107 )

108

109 XYZ_1 = np.reshape(XYZ_1, (2, 3, 3))

110 xy_o1 = np.reshape(xy_o1, (2, 3, 2))

111 xy_o2 = np.reshape(xy_o2, (2, 3, 2))

112 Y_o = np.reshape(Y_o, (2, 3))

113 E_o1 = np.reshape(E_o1, (2, 3))

114 E_o2 = np.reshape(E_o2, (2, 3))

115 XYZ_2 = np.reshape(XYZ_2, (2, 3, 3))

116 np.testing.assert_allclose(

117 chromatic_adaptation_CIE1994(XYZ_1, xy_o1, xy_o2, Y_o, E_o1, E_o2),

118 XYZ_2,

119 atol=TOLERANCE_ABSOLUTE_TESTS,

120 )

121

122 def test_domain_range_scale_chromatic_adaptation_CIE1994(self) -> None:

123 """

124 Test :func:`colour.adaptation.cie1994.chromatic_adaptation_CIE1994`

125 definition domain and range scale support.

126 """

127

128 XYZ_1 = np.array([28.00, 21.26, 5.27])

129 xy_o1 = np.array([0.44760, 0.40740])

130 xy_o2 = np.array([0.31270, 0.32900])

131 Y_o = 20

132 E_o1 = 1000

133 E_o2 = 1000

134 XYZ_2 = chromatic_adaptation_CIE1994(XYZ_1, xy_o1, xy_o2, Y_o, E_o1, E_o2)

135

136 d_r = (("reference", 1), ("1", 0.01), ("100", 1))

137 for scale, factor in d_r:

138 with domain_range_scale(scale):

139 np.testing.assert_allclose(

140 chromatic_adaptation_CIE1994(

141 XYZ_1 * factor, xy_o1, xy_o2, Y_o * factor, E_o1, E_o2

142 ),

143 XYZ_2 * factor,

144 atol=TOLERANCE_ABSOLUTE_TESTS,

145 )

146

147 @ignore_numpy_errors

148 def test_nan_chromatic_adaptation_CIE1994(self) -> None:

149 """

150 Test :func:`colour.adaptation.cie1994.chromatic_adaptation_CIE1994`

151 definition nan support.

152 """

153

154 cases = [-1.0, 0.0, 1.0, -np.inf, np.inf, np.nan]

155 cases = np.array(list(set(product(cases, repeat=3))))

156 chromatic_adaptation_CIE1994(

157 cases,

158 cases[..., 0:2],

159 cases[..., 0:2],

160 cases[..., 0],

161 cases[..., 0],

162 cases[..., 0],

163 )