Coverage for colorimetry/tests/test_yellowness.py: 100%

1"""Define the unit tests for the :mod:`colour.colorimetry.yellowness` module."""

2

3 from __future__ import annotations

4

5 from itertools import product

6

7 import numpy as np

8

9 from colour.colorimetry import (

10 yellowness_ASTMD1925,

11 yellowness_ASTME313,

12 yellowness_ASTME313_alternative,

13)

14 from colour.colorimetry.yellowness import YELLOWNESS_COEFFICIENTS_ASTME313, yellowness

15 from colour.constants import TOLERANCE_ABSOLUTE_TESTS

16 from colour.utilities import domain_range_scale, ignore_numpy_errors

17

18 __author__ = "Colour Developers"

19 __copyright__ = "Copyright 2013 Colour Developers"

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

21 __maintainer__ = "Colour Developers"

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

23 __status__ = "Production"

24

25 __all__ = [

26 "TestYellownessASTMD1925",

27 "TestYellownessASTM313Alternative",

28 "TestYellownessASTM313",

29 "TestYellowness",

30]

31

32

33 class TestYellownessASTMD1925:

34 """

35 Define :func:`colour.colorimetry.yellowness.yellowness_ASTMD1925`

36 definition unit tests methods.

37 """

38

39 def test_yellowness_ASTMD1925(self) -> None:

40 """

41 Test :func:`colour.colorimetry.yellowness.yellowness_ASTMD1925`

42 definition.

43 """

44

45 np.testing.assert_allclose(

46 yellowness_ASTMD1925(np.array([95.00000000, 100.00000000, 105.00000000])),

47 10.299999999999997,

48 atol=TOLERANCE_ABSOLUTE_TESTS,

49 )

50

51 np.testing.assert_allclose(

52 yellowness_ASTMD1925(np.array([105.00000000, 100.00000000, 95.00000000])),

53 33.700000000000003,

54 atol=TOLERANCE_ABSOLUTE_TESTS,

55 )

56

57 np.testing.assert_allclose(

58 yellowness_ASTMD1925(np.array([100.00000000, 100.00000000, 100.00000000])),

59 22.0,

60 atol=TOLERANCE_ABSOLUTE_TESTS,

61 )

62

63 def test_n_dimensional_yellowness_ASTMD1925(self) -> None:

64 """

65 Test :func:`colour.colorimetry.yellowness.yellowness_ASTMD1925`

66 definition n_dimensional arrays support.

67 """

68

69 XYZ = np.array([95.00000000, 100.00000000, 105.00000000])

70 YI = yellowness_ASTMD1925(XYZ)

71

72 XYZ = np.tile(XYZ, (6, 1))

73 YI = np.tile(YI, 6)

74 np.testing.assert_allclose(

75 yellowness_ASTMD1925(XYZ), YI, atol=TOLERANCE_ABSOLUTE_TESTS

76 )

77

78 XYZ = np.reshape(XYZ, (2, 3, 3))

79 YI = np.reshape(YI, (2, 3))

80 np.testing.assert_allclose(

81 yellowness_ASTMD1925(XYZ), YI, atol=TOLERANCE_ABSOLUTE_TESTS

82 )

83

84 def test_domain_range_scale_yellowness_ASTMD1925(self) -> None:

85 """

86 Test :func:`colour.colorimetry.yellowness.yellowness_ASTMD1925`

87 definition domain and range scale support.

88 """

89

90 XYZ = np.array([95.00000000, 100.00000000, 105.00000000])

91 YI = 10.299999999999997

92

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

94 for scale, factor in d_r:

95 with domain_range_scale(scale):

96 np.testing.assert_allclose(

97 yellowness_ASTMD1925(XYZ * factor),

98 YI * factor,

99 atol=TOLERANCE_ABSOLUTE_TESTS,

100 )

101

102 @ignore_numpy_errors

103 def test_nan_yellowness_ASTMD1925(self) -> None:

104 """

105 Test :func:`colour.colorimetry.yellowness.yellowness_ASTMD1925`

106 definition nan support.

107 """

108

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

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

111 yellowness_ASTMD1925(cases)

112

113

114 class TestYellownessASTM313Alternative:

115 """

116 Define :func:`colour.colorimetry.yellowness.\

117 yellowness_ASTME313_alternative` definition unit tests methods.

118 """

119

120 def test_yellowness_ASTME313_alternative(self) -> None:

121 """

122 Test :func:`colour.colorimetry.yellowness.\

123 yellowness_ASTME313_alternative` definition.

124 """

125

126 np.testing.assert_allclose(

127 yellowness_ASTME313_alternative(

128 np.array([95.00000000, 100.00000000, 105.00000000])

129 ),

130 11.065000000000003,

131 atol=TOLERANCE_ABSOLUTE_TESTS,

132 )

133

134 np.testing.assert_allclose(

135 yellowness_ASTME313_alternative(

136 np.array([105.00000000, 100.00000000, 95.00000000])

137 ),

138 19.534999999999989,

139 atol=TOLERANCE_ABSOLUTE_TESTS,

140 )

141

142 np.testing.assert_allclose(

143 yellowness_ASTME313_alternative(

144 np.array([100.00000000, 100.00000000, 100.00000000])

145 ),

146 15.300000000000002,

147 atol=TOLERANCE_ABSOLUTE_TESTS,

148 )

149

150 def test_n_dimensional_yellowness_ASTME313_alternative(self) -> None:

151 """

152 Test :func:`colour.colorimetry.yellowness.\

153 yellowness_ASTME313_alternative` definition n_dimensional arrays support.

154 """

155

156 XYZ = np.array([95.00000000, 100.00000000, 105.00000000])

157 YI = yellowness_ASTME313_alternative(XYZ)

158

159 XYZ = np.tile(XYZ, (6, 1))

160 YI = np.tile(YI, 6)

161 np.testing.assert_allclose(

162 yellowness_ASTME313_alternative(XYZ),

163 YI,

164 atol=TOLERANCE_ABSOLUTE_TESTS,

165 )

166

167 XYZ = np.reshape(XYZ, (2, 3, 3))

168 YI = np.reshape(YI, (2, 3))

169 np.testing.assert_allclose(

170 yellowness_ASTME313_alternative(XYZ),

171 YI,

172 atol=TOLERANCE_ABSOLUTE_TESTS,

173 )

174

175 def test_domain_range_scale_yellowness_ASTME313_alternative(self) -> None:

176 """

177 Test :func:`colour.colorimetry.yellowness.\

178 yellowness_ASTME313_alternative` definition domain and range scale support.

179 """

180

181 XYZ = np.array([95.00000000, 100.00000000, 105.00000000])

182 YI = 11.065000000000003

183

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

185 for scale, factor in d_r:

186 with domain_range_scale(scale):

187 np.testing.assert_allclose(

188 yellowness_ASTME313_alternative(XYZ * factor),

189 YI * factor,

190 atol=TOLERANCE_ABSOLUTE_TESTS,

191 )

192

193 @ignore_numpy_errors

194 def test_nan_yellowness_ASTME313_alternative(self) -> None:

195 """

196 Test :func:`colour.colorimetry.yellowness.\

197 yellowness_ASTME313_alternative` definition nan support.

198 """

199

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

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

202 yellowness_ASTME313_alternative(cases)

203

204

205 class TestYellownessASTM313:

206 """

207 Define :func:`colour.colorimetry.yellowness.yellowness_ASTME313`

208 definition unit tests methods.

209 """

210

211 def test_yellowness_ASTME313(self) -> None:

212 """

213 Test :func:`colour.colorimetry.yellowness.yellowness_ASTME313`

214 definition.

215 """

216

217 np.testing.assert_allclose(

218 yellowness_ASTME313(np.array([95.00000000, 100.00000000, 105.00000000])),

219 4.340000000000003,

220 atol=TOLERANCE_ABSOLUTE_TESTS,

221 )

222

223 np.testing.assert_allclose(

224 yellowness_ASTME313(np.array([105.00000000, 100.00000000, 95.00000000])),

225 28.660000000000011,

226 atol=TOLERANCE_ABSOLUTE_TESTS,

227 )

228

229 np.testing.assert_allclose(

230 yellowness_ASTME313(np.array([100.00000000, 100.00000000, 100.00000000])),

231 16.500000000000000,

232 atol=TOLERANCE_ABSOLUTE_TESTS,

233 )

234

235 np.testing.assert_allclose(

236 yellowness_ASTME313(

237 np.array([95.00000000, 100.00000000, 105.00000000]),

238 YELLOWNESS_COEFFICIENTS_ASTME313["CIE 1931 2 Degree Standard Observer"][

239 "C"

240 ],

241 ),

242 10.089500000000001,

243 atol=TOLERANCE_ABSOLUTE_TESTS,

244 )

245

246 def test_n_dimensional_yellowness_ASTME313(self) -> None:

247 """

248 Test :func:`colour.colorimetry.yellowness.yellowness_ASTME313`

249 definition n_dimensional arrays support.

250 """

251

252 XYZ = np.array([95.00000000, 100.00000000, 105.00000000])

253 YI = yellowness_ASTME313(XYZ)

254

255 XYZ = np.tile(XYZ, (6, 1))

256 YI = np.tile(YI, 6)

257 np.testing.assert_allclose(

258 yellowness_ASTME313(XYZ), YI, atol=TOLERANCE_ABSOLUTE_TESTS

259 )

260

261 XYZ = np.reshape(XYZ, (2, 3, 3))

262 YI = np.reshape(YI, (2, 3))

263 np.testing.assert_allclose(

264 yellowness_ASTME313(XYZ), YI, atol=TOLERANCE_ABSOLUTE_TESTS

265 )

266

267 def test_domain_range_scale_yellowness_ASTME313(self) -> None:

268 """

269 Test :func:`colour.colorimetry.yellowness.yellowness_ASTME313`

270 definition domain and range scale support.

271 """

272

273 XYZ = np.array([95.00000000, 100.00000000, 105.00000000])

274 YI = 4.340000000000003

275

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

277 for scale, factor in d_r:

278 with domain_range_scale(scale):

279 np.testing.assert_allclose(

280 yellowness_ASTME313(XYZ * factor),

281 YI * factor,

282 atol=TOLERANCE_ABSOLUTE_TESTS,

283 )

284

285 @ignore_numpy_errors

286 def test_nan_yellowness_ASTME313(self) -> None:

287 """

288 Test :func:`colour.colorimetry.yellowness.yellowness_ASTME313`

289 definition nan support.

290 """

291

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

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

294 yellowness_ASTME313(cases)

295

296

297 class TestYellowness:

298 """

299 Define :func:`colour.colorimetry.yellowness.yellowness` definition unit

300 tests methods.

301 """

302

303 def test_domain_range_scale_yellowness(self) -> None:

304 """

305 Test :func:`colour.colorimetry.yellowness.yellowness` definition

306 domain and range scale support.

307 """

308

309 XYZ = np.array([95.00000000, 100.00000000, 105.00000000])

310

311 m = ("ASTM D1925", "ASTM E313")

312 v = [yellowness(XYZ, method) for method in m]

313

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

315 for method, value in zip(m, v, strict=True):

316 for scale, factor in d_r:

317 with domain_range_scale(scale):

318 np.testing.assert_allclose(

319 yellowness(XYZ * factor, method),

320 value * factor,

321 atol=TOLERANCE_ABSOLUTE_TESTS,

322 )