Coverage for quality/tests/test_tm3018.py: 100%

1"""

2 Define the unit tests for the :mod:`colour.quality.tm3018` module.

3

4 Notes

5-----

6- Reference data was created using the official Excel spreadsheet, published

7 by the IES at this URL:

8 http://media.ies.org/docs/errata/TM-30-18_tools_etc.zip.

9"""

10

11 from __future__ import annotations

12

13 import numpy as np

14

15 from colour.colorimetry import SDS_ILLUMINANTS

16 from colour.quality.tm3018 import (

17 averages_area,

18 colour_fidelity_index_ANSIIESTM3018,

19)

20 from colour.utilities import as_float_array

21

22 __author__ = "Colour Developers"

23 __copyright__ = "Copyright 2013 Colour Developers"

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

25 __maintainer__ = "Colour Developers"

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

27 __status__ = "Production"

28

29 __all__ = [

30 "TestColourFidelityIndexANSIIESTM3018",

31 "TestAveragesArea",

32]

33

34

35 class TestColourFidelityIndexANSIIESTM3018:

36 """

37 Define :func:`colour.quality.tm3018.colour_fidelity_index_ANSIIESTM3018`

38 definition unit tests methods.

39 """

40

41 def test_colour_fidelity_index_ANSIIESTM3018(self) -> None:

42 """

43 Test :func:`colour.quality.tm3018.colour_fidelity_index_ANSIIESTM3018`

44 definition.

45 """

46

47 # Test without additional data (returns R_f only)

48 R_f = colour_fidelity_index_ANSIIESTM3018(

49 SDS_ILLUMINANTS["FL2"], additional_data=False

50 )

51 np.testing.assert_allclose(R_f, 70, atol=2e-1)

52

53 # Test with additional data (returns full specification)

54 specification = colour_fidelity_index_ANSIIESTM3018(

55 SDS_ILLUMINANTS["FL2"], additional_data=True

56 )

57

58 np.testing.assert_allclose(specification.R_f, 70, atol=2e-1)

59 np.testing.assert_allclose(specification.R_g, 86, atol=5e-1)

60 np.testing.assert_allclose(specification.CCT, 4225, atol=1)

61 np.testing.assert_allclose(specification.D_uv, 0.0019, atol=1e-3)

62

63 np.testing.assert_allclose(

64 specification.R_s,

65 [

66 79,

67 59,

68 67,

69 66,

70 36,

71 66,

72 40,

73 35,

74 95,

75 54,

76 48,

77 45,

78 64,

79 87,

80 72,

81 49,

82 56,

83 69,

84 57,

85 44,

86 47,

87 47,

88 80,

89 63,

90 48,

91 59,

92 82,

93 85,

94 62,

95 70,

96 68,

97 62,

98 74,

99 74,

100 86,

101 88,

102 80,

103 76,

104 97,

105 93,

106 91,

107 89,

108 83,

109 99,

110 83,

111 81,

112 87,

113 66,

114 80,

115 81,

116 81,

117 76,

118 69,

119 77,

120 77,

121 66,

122 66,

123 67,

124 79,

125 90,

126 78,

127 87,

128 77,

129 60,

130 61,

131 58,

132 56,

133 62,

134 73,

135 58,

136 64,

137 84,

138 53,

139 96,

140 67,

141 57,

142 76,

143 63,

144 82,

145 85,

146 74,

147 94,

148 91,

149 86,

150 81,

151 64,

152 74,

153 69,

154 66,

155 68,

156 93,

157 51,

158 70,

159 41,

160 62,

161 70,

162 80,

163 67,

164 45,

165 ],

166 atol=0.75,

167 )

168

169 np.testing.assert_allclose(

170 specification.R_fs,

171 [60, 61, 53, 68, 80, 88, 77, 73, 76, 62, 70, 77, 81, 71, 64, 65],

172 atol=0.75,

173 )

174 np.testing.assert_allclose(

175 specification.R_cs,

176 [-25, -18, -9, 5, 11, 4, -8, -15, -17, -15, -4, 5, 11, 7, -6, -16],

177 atol=0.75,

178 )

179 np.testing.assert_allclose(

180 specification.R_hs,

181 [

182 -0.02,

183 0.14,

184 0.24,

185 0.20,

186 0.09,

187 -0.07,

188 -0.12,

189 -0.08,

190 0.01,

191 0.17,

192 0.19,

193 0.11,

194 -0.08,

195 -0.15,

196 -0.26,

197 -0.17,

198 ],

199 atol=0.75,

200 )

201

202

203 class TestAveragesArea:

204 """

205 Define :func:`colour.quality.tm3018.averages_area` definition unit tests

206 methods.

207 """

208

209 def test_averages_area(self) -> None:

210 """Test :func:`colour.quality.tm3018.averages_area` definition."""

211

212 # Simple 3 * sqrt(2) by sqrt(2) rectangle.

213 rectangle = as_float_array([[2, 1], [1, 2], [-2, -1], [-1, -2]])

214 np.allclose(averages_area(rectangle), 6)

215

216 # Concave polygon.

217 poly = np.array([[1.0, -1], [1, 1], [3, 1], [3, 3], [-1, 3], [-1, -1]])

218 np.allclose(averages_area(poly), 12)