Coverage for colour/recovery/tests/test_smits1999.py: 100%

30 statements  

« prev     ^ index     » next       coverage.py v7.11.0, created at 2025-11-15 19:01 +1300

1"""Define the unit tests for the :mod:`colour.recovery.smits1999` module.""" 

2 

3from __future__ import annotations 

4 

5import numpy as np 

6 

7from colour.colorimetry import sd_to_XYZ_integration 

8from colour.constants import TOLERANCE_ABSOLUTE_TESTS 

9from colour.recovery import RGB_to_sd_Smits1999 

10from colour.recovery.smits1999 import XYZ_to_RGB_Smits1999 

11from colour.utilities import domain_range_scale 

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 "TestRGB_to_sd_Smits1999", 

22] 

23 

24 

25class TestRGB_to_sd_Smits1999: 

26 """ 

27 Define :func:`colour.recovery.smits1999.RGB_to_sd_Smits1999` 

28 definition unit tests methods. 

29 """ 

30 

31 def test_RGB_to_sd_Smits1999(self) -> None: 

32 """ 

33 Test :func:`colour.recovery.smits1999.RGB_to_sd_Smits1999` 

34 definition. 

35 """ 

36 

37 np.testing.assert_allclose( 

38 RGB_to_sd_Smits1999( 

39 XYZ_to_RGB_Smits1999(np.array([0.21781186, 0.12541048, 0.04697113])) 

40 ).values, 

41 np.array( 

42 [ 

43 0.07691923, 

44 0.05870050, 

45 0.03943195, 

46 0.03024978, 

47 0.02750692, 

48 0.02808645, 

49 0.34298985, 

50 0.41185795, 

51 0.41185795, 

52 0.41180754, 

53 ] 

54 ), 

55 atol=TOLERANCE_ABSOLUTE_TESTS, 

56 ) 

57 

58 np.testing.assert_allclose( 

59 RGB_to_sd_Smits1999( 

60 XYZ_to_RGB_Smits1999(np.array([0.15434689, 0.22960951, 0.09620221])) 

61 ).values, 

62 np.array( 

63 [ 

64 0.06981477, 

65 0.06981351, 

66 0.07713379, 

67 0.25139495, 

68 0.30063408, 

69 0.28797045, 

70 0.11990414, 

71 0.08186170, 

72 0.08198613, 

73 0.08272671, 

74 ] 

75 ), 

76 atol=TOLERANCE_ABSOLUTE_TESTS, 

77 ) 

78 

79 np.testing.assert_allclose( 

80 RGB_to_sd_Smits1999( 

81 XYZ_to_RGB_Smits1999(np.array([0.07683480, 0.06006092, 0.25833845])) 

82 ).values, 

83 np.array( 

84 [ 

85 0.29091152, 

86 0.29010285, 

87 0.26572455, 

88 0.13140471, 

89 0.05160646, 

90 0.05162034, 

91 0.02765638, 

92 0.03199188, 

93 0.03472939, 

94 0.03504156, 

95 ] 

96 ), 

97 atol=TOLERANCE_ABSOLUTE_TESTS, 

98 ) 

99 

100 np.testing.assert_allclose( 

101 RGB_to_sd_Smits1999(XYZ_to_RGB_Smits1999(np.array([0.0, 1.0, 0.0]))).values, 

102 np.array( 

103 [ 

104 -0.2549796, 

105 -0.2848386, 

106 -0.1634905, 

107 1.5254829, 

108 1.9800433, 

109 1.8510762, 

110 -0.7327702, 

111 -1.2758621, 

112 -1.2758621, 

113 -1.2703551, 

114 ] 

115 ), 

116 atol=TOLERANCE_ABSOLUTE_TESTS, 

117 ) 

118 

119 np.testing.assert_allclose( 

120 RGB_to_sd_Smits1999(XYZ_to_RGB_Smits1999(np.array([1.0, 1.0, 0.0]))).values, 

121 np.array( 

122 [ 

123 -0.1168428, 

124 -0.1396982, 

125 -0.0414535, 

126 0.581391, 

127 0.9563091, 

128 0.9562111, 

129 1.3366949, 

130 1.3742666, 

131 1.3853491, 

132 1.4027005, 

133 ] 

134 ), 

135 atol=TOLERANCE_ABSOLUTE_TESTS, 

136 ) 

137 

138 np.testing.assert_allclose( 

139 RGB_to_sd_Smits1999(XYZ_to_RGB_Smits1999(np.array([0.5, 0.0, 1.0]))).values, 

140 np.array( 

141 [ 

142 1.1938776, 

143 1.1938776, 

144 1.1213867, 

145 -0.067889, 

146 -0.4668587, 

147 -0.4030985, 

148 0.703056, 

149 0.9407334, 

150 0.9437298, 

151 0.9383386, 

152 ] 

153 ), 

154 atol=TOLERANCE_ABSOLUTE_TESTS, 

155 ) 

156 

157 def test_domain_range_scale_RGB_to_sd_Smits1999(self) -> None: 

158 """ 

159 Test :func:`colour.recovery.smits1999.RGB_to_sd_Smits1999` 

160 definition domain and range scale support. 

161 """ 

162 

163 XYZ_i = np.array([0.20654008, 0.12197225, 0.05136952]) 

164 RGB_i = XYZ_to_RGB_Smits1999(XYZ_i) 

165 XYZ_o = sd_to_XYZ_integration(RGB_to_sd_Smits1999(RGB_i)) 

166 

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

168 for scale, factor_a, factor_b in d_r: 

169 with domain_range_scale(scale): 

170 np.testing.assert_allclose( 

171 sd_to_XYZ_integration(RGB_to_sd_Smits1999(RGB_i * factor_a)), 

172 XYZ_o * factor_b, 

173 atol=TOLERANCE_ABSOLUTE_TESTS, 

174 )