Coverage for colour/corresponding/tests/test_prediction.py: 100%

43 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.corresponding.prediction` module.""" 

2 

3from __future__ import annotations 

4 

5import typing 

6 

7import numpy as np 

8 

9from colour.constants import TOLERANCE_ABSOLUTE_TESTS 

10from colour.corresponding import ( 

11 corresponding_chromaticities_prediction_CIE1994, 

12 corresponding_chromaticities_prediction_CMCCAT2000, 

13 corresponding_chromaticities_prediction_Fairchild1990, 

14 corresponding_chromaticities_prediction_VonKries, 

15 corresponding_chromaticities_prediction_Zhai2018, 

16) 

17from colour.corresponding.prediction import ( 

18 CorrespondingColourDataset, 

19 convert_experiment_results_Breneman1987, 

20) 

21 

22if typing.TYPE_CHECKING: 

23 from colour.hints import NDArrayFloat 

24 

25__author__ = "Colour Developers" 

26__copyright__ = "Copyright 2013 Colour Developers" 

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

28__maintainer__ = "Colour Developers" 

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

30__status__ = "Production" 

31 

32__all__ = [ 

33 "DATASET_CORRESPONDING_COLOUR_1", 

34 "DATA_PREDICTION_FAIRCHILD1990", 

35 "DATA_PREDICTION_CIE1994", 

36 "DATA_PREDICTION_CMCCAT2000", 

37 "DATA_PREDICTION_VONKRIES", 

38 "DATA_PREDICTION_ZHAI2018", 

39 "TestCorrespondingChromaticitiesPredictionFairchild1990", 

40 "TestCorrespondingChromaticitiesPredictionCIE1994", 

41 "TestCorrespondingChromaticitiesPredictionCMCCAT2000", 

42 "TestCorrespondingChromaticitiesPredictionVonKries", 

43 "TestCorrespondingChromaticitiesPredictionZhai2018", 

44] 

45 

46DATASET_CORRESPONDING_COLOUR_1: CorrespondingColourDataset = CorrespondingColourDataset( 

47 name=1, 

48 XYZ_r=np.array([0.947368421052632, 1.000000000000000, 1.000000000000000]), 

49 XYZ_t=np.array([1.107889733840304, 1.000000000000000, 0.334125475285171]), 

50 XYZ_cr=np.array( 

51 [ 

52 [ 

53 372.358829568788565, 

54 405.000000000000000, 

55 345.746919917864489, 

56 ], 

57 [250.638506876227865, 135.000000000000000, 37.131630648330052], 

58 [ 

59 456.541750503018136, 

60 405.000000000000000, 

61 267.487424547283638, 

62 ], 

63 [502.185218978102114, 405.000000000000000, 24.758211678831920], 

64 [164.036312849162016, 135.000000000000000, 24.511173184357535], 

65 [422.727888086642622, 405.000000000000000, 27.231498194945619], 

66 [110.245746691871460, 135.000000000000000, 53.846880907372366], 

67 [75.208733205374273, 135.000000000000000, 77.281669865642954], 

68 [ 

69 258.414179104477626, 

70 405.000000000000000, 

71 479.480277185501166, 

72 ], 

73 [ 

74 141.154411764705856, 

75 135.000000000000000, 

76 469.124999999999943, 

77 ], 

78 [ 

79 380.757042253521092, 

80 405.000000000000000, 

81 700.193661971831261, 

82 ], 

83 [ 

84 192.236301369863071, 

85 135.000000000000000, 

86 370.510273972602761, 

87 ], 

88 ] 

89 ), 

90 XYZ_ct=np.array( 

91 [ 

92 [ 

93 450.407919847328230, 

94 405.000000000000000, 

95 143.566316793893037, 

96 ], 

97 [267.090517241379359, 135.000000000000000, 11.831896551724059], 

98 [ 

99 531.851235741444839, 

100 405.000000000000000, 

101 107.602186311787023, 

102 ], 

103 [603.033088235294031, 405.000000000000000, 7.444852941176350], 

104 [196.511090573012893, 135.000000000000000, 8.109981515711597], 

105 [526.868181818181711, 405.000000000000000, 8.468181818181574], 

106 [144.589483394833962, 135.000000000000000, 24.035977859778562], 

107 [108.161900369003689, 135.000000000000000, 36.178505535055272], 

108 [ 

109 317.877906976744100, 

110 405.000000000000000, 

111 223.691860465116235, 

112 ], 

113 [ 

114 126.960674157303373, 

115 135.000000000000000, 

116 192.792134831460686, 

117 ], 

118 [ 

119 419.434826883910489, 

120 405.000000000000000, 

121 309.730142566191489, 

122 ], 

123 [ 

124 185.180921052631589, 

125 135.000000000000000, 

126 151.430921052631589, 

127 ], 

128 ] 

129 ), 

130 Y_r=1500, 

131 Y_t=1500, 

132 B_r=0.3, 

133 B_t=0.3, 

134 metadata={}, 

135) 

136 

137DATA_PREDICTION_FAIRCHILD1990: NDArrayFloat = np.array( 

138 [ 

139 [(0.199, 0.487), (0.200554934448681, 0.470155699619516)], 

140 [(0.420, 0.509), (0.389214449896027, 0.514002881379267)], 

141 [(0.249, 0.497), (0.241570029196649, 0.486033850388237)], 

142 [(0.302, 0.548), (0.290619228590390, 0.550282593092481)], 

143 [(0.290, 0.537), (0.280611339160018, 0.538348403477048)], 

144 [(0.257, 0.554), (0.248379871541202, 0.555741679220336)], 

145 [(0.192, 0.529), (0.194404361202511, 0.515869077684087)], 

146 [(0.129, 0.521), (0.139197382975043, 0.499578426956623)], 

147 [(0.133, 0.469), (0.140948349615191, 0.436038790232095)], 

148 [(0.158, 0.340), (0.170240154737059, 0.311121250518367)], 

149 [(0.178, 0.426), (0.184104505156227, 0.393143101221379)], 

150 [(0.231, 0.365), (0.229252692804442, 0.338033995795458)], 

151 ] 

152) 

153 

154DATA_PREDICTION_CIE1994: NDArrayFloat = np.array( 

155 [ 

156 [(0.199, 0.487), (0.261386136420622, 0.533662817418878)], 

157 [(0.420, 0.509), (0.451546322781523, 0.521730655299867)], 

158 [(0.249, 0.497), (0.310170032403198, 0.532080871352910)], 

159 [(0.302, 0.548), (0.362647256496429, 0.543095116682339)], 

160 [(0.290, 0.537), (0.342002205412566, 0.540654345195812)], 

161 [(0.257, 0.554), (0.320554395869614, 0.549100152511420)], 

162 [(0.192, 0.529), (0.249890733398992, 0.543032894366422)], 

163 [(0.129, 0.521), (0.184477356124214, 0.545089114658268)], 

164 [(0.133, 0.469), (0.179131489840910, 0.534176133801835)], 

165 [(0.158, 0.340), (0.173452103066259, 0.480817508459012)], 

166 [(0.178, 0.426), (0.226570643054285, 0.516988754071352)], 

167 [(0.231, 0.365), (0.272300292824155, 0.482318190580811)], 

168 ] 

169) 

170 

171DATA_PREDICTION_CMCCAT2000: NDArrayFloat = np.array( 

172 [ 

173 [(0.199, 0.487), (0.200011273633451, 0.470539230354398)], 

174 [(0.420, 0.509), (0.407637147823942, 0.504672206472439)], 

175 [(0.249, 0.497), (0.243303933122086, 0.483443483088972)], 

176 [(0.302, 0.548), (0.302738872704423, 0.542771391372065)], 

177 [(0.290, 0.537), (0.290517242292583, 0.531547633697717)], 

178 [(0.257, 0.554), (0.258674719568568, 0.548764239788161)], 

179 [(0.192, 0.529), (0.198993053394577, 0.512765194539863)], 

180 [(0.129, 0.521), (0.143324176185281, 0.499673343018787)], 

181 [(0.133, 0.469), (0.138424584031183, 0.442678688047099)], 

182 [(0.158, 0.340), (0.153353027792519, 0.330121253315695)], 

183 [(0.178, 0.426), (0.175382057838771, 0.401725889182425)], 

184 [(0.231, 0.365), (0.213770919959778, 0.348685954116193)], 

185 ] 

186) 

187 

188DATA_PREDICTION_VONKRIES: NDArrayFloat = np.array( 

189 [ 

190 [(0.199, 0.487), (0.199994235295863, 0.470596132542110)], 

191 [(0.420, 0.509), (0.414913855668385, 0.503766204685646)], 

192 [(0.249, 0.497), (0.244202332779817, 0.483154861151019)], 

193 [(0.302, 0.548), (0.307287743499555, 0.543174463393956)], 

194 [(0.290, 0.537), (0.294129765202449, 0.531627707350365)], 

195 [(0.257, 0.554), (0.261399171975815, 0.549476532253197)], 

196 [(0.192, 0.529), (0.199113248438711, 0.512769667764083)], 

197 [(0.129, 0.521), (0.142266217705415, 0.499812542997584)], 

198 [(0.133, 0.469), (0.138134593378073, 0.443768079552099)], 

199 [(0.158, 0.340), (0.154188271421900, 0.338322678880046)], 

200 [(0.178, 0.426), (0.175297924104065, 0.404343935551269)], 

201 [(0.231, 0.365), (0.213004721499844, 0.354595262694384)], 

202 ] 

203) 

204 

205DATA_PREDICTION_ZHAI2018: NDArrayFloat = np.array( 

206 [ 

207 [(0.199, 0.487), (0.199994235295863, 0.470596132542110)], 

208 [(0.420, 0.509), (0.414913855668385, 0.503766204685646)], 

209 [(0.249, 0.497), (0.244202332779817, 0.483154861151019)], 

210 [(0.302, 0.548), (0.307287743499555, 0.543174463393956)], 

211 [(0.290, 0.537), (0.294129765202449, 0.531627707350365)], 

212 [(0.257, 0.554), (0.261399171975815, 0.549476532253198)], 

213 [(0.192, 0.529), (0.199113248438711, 0.512769667764083)], 

214 [(0.129, 0.521), (0.142266217705415, 0.499812542997584)], 

215 [(0.133, 0.469), (0.138134593378073, 0.443768079552098)], 

216 [(0.158, 0.340), (0.154188271421900, 0.338322678880046)], 

217 [(0.178, 0.426), (0.175297924104065, 0.404343935551269)], 

218 [(0.231, 0.365), (0.213004721499844, 0.354595262694384)], 

219 ] 

220) 

221 

222 

223class TestConvertExperimentResultsBreneman1987: 

224 """ 

225 Define :func:`colour.corresponding.prediction.\ 

226convert_experiment_results_Breneman1987` definition unit tests 

227 methods. 

228 """ 

229 

230 def test_convert_experiment_results_Breneman1987(self) -> None: 

231 """ 

232 Test :func:`colour.corresponding.prediction.\ 

233convert_experiment_results_Breneman1987` definition. 

234 """ 

235 

236 corresponding_colour_dataset = convert_experiment_results_Breneman1987(1) 

237 

238 np.testing.assert_allclose( 

239 corresponding_colour_dataset.XYZ_r, 

240 DATASET_CORRESPONDING_COLOUR_1.XYZ_r, 

241 atol=TOLERANCE_ABSOLUTE_TESTS, 

242 ) 

243 

244 np.testing.assert_allclose( 

245 corresponding_colour_dataset.XYZ_t, 

246 DATASET_CORRESPONDING_COLOUR_1.XYZ_t, 

247 atol=TOLERANCE_ABSOLUTE_TESTS, 

248 ) 

249 

250 np.testing.assert_allclose( 

251 corresponding_colour_dataset.XYZ_cr, 

252 DATASET_CORRESPONDING_COLOUR_1.XYZ_cr, 

253 atol=TOLERANCE_ABSOLUTE_TESTS, 

254 ) 

255 

256 np.testing.assert_allclose( 

257 corresponding_colour_dataset.XYZ_ct, 

258 DATASET_CORRESPONDING_COLOUR_1.XYZ_ct, 

259 atol=TOLERANCE_ABSOLUTE_TESTS, 

260 ) 

261 

262 np.testing.assert_allclose( 

263 corresponding_colour_dataset.Y_r, 

264 DATASET_CORRESPONDING_COLOUR_1.Y_r, 

265 atol=TOLERANCE_ABSOLUTE_TESTS, 

266 ) 

267 

268 np.testing.assert_allclose( 

269 corresponding_colour_dataset.Y_t, 

270 DATASET_CORRESPONDING_COLOUR_1.Y_t, 

271 atol=TOLERANCE_ABSOLUTE_TESTS, 

272 ) 

273 

274 

275class TestCorrespondingChromaticitiesPredictionFairchild1990: 

276 """ 

277 Define :func:`colour.corresponding.prediction.\ 

278corresponding_chromaticities_prediction_Fairchild1990` definition unit tests 

279 methods. 

280 """ 

281 

282 def test_corresponding_chromaticities_prediction_Fairchild1990(self) -> None: 

283 """ 

284 Test :func:`colour.corresponding.prediction.\ 

285corresponding_chromaticities_prediction_Fairchild1990` definition. 

286 """ 

287 

288 np.testing.assert_allclose( 

289 np.array( 

290 [ 

291 (p.uv_m, p.uv_p) 

292 for p in corresponding_chromaticities_prediction_Fairchild1990() 

293 ] 

294 ), 

295 DATA_PREDICTION_FAIRCHILD1990, 

296 atol=TOLERANCE_ABSOLUTE_TESTS, 

297 ) 

298 

299 

300class TestCorrespondingChromaticitiesPredictionCIE1994: 

301 """ 

302 Define :func:`colour.corresponding.prediction.\ 

303corresponding_chromaticities_prediction_CIE1994` definition unit tests methods. 

304 """ 

305 

306 def test_corresponding_chromaticities_prediction_CIE1994(self) -> None: 

307 """ 

308 Test :func:`colour.corresponding.prediction.\ 

309corresponding_chromaticities_prediction_CIE1994` definition. 

310 """ 

311 

312 np.testing.assert_allclose( 

313 np.array( 

314 [ 

315 (p.uv_m, p.uv_p) 

316 for p in corresponding_chromaticities_prediction_CIE1994() 

317 ] 

318 ), 

319 DATA_PREDICTION_CIE1994, 

320 atol=TOLERANCE_ABSOLUTE_TESTS, 

321 ) 

322 

323 

324class TestCorrespondingChromaticitiesPredictionCMCCAT2000: 

325 """ 

326 Define :func:`colour.corresponding.prediction.\ 

327corresponding_chromaticities_prediction_CMCCAT2000` definition unit tests 

328 methods. 

329 """ 

330 

331 def test_corresponding_chromaticities_prediction_CMCCAT2000(self) -> None: 

332 """ 

333 Test :func:`colour.corresponding.prediction.\ 

334corresponding_chromaticities_prediction_CMCCAT2000` definition. 

335 """ 

336 

337 np.testing.assert_allclose( 

338 np.array( 

339 [ 

340 (p.uv_m, p.uv_p) 

341 for p in corresponding_chromaticities_prediction_CMCCAT2000() 

342 ] 

343 ), 

344 DATA_PREDICTION_CMCCAT2000, 

345 atol=TOLERANCE_ABSOLUTE_TESTS, 

346 ) 

347 

348 

349class TestCorrespondingChromaticitiesPredictionVonKries: 

350 """ 

351 Define :func:`colour.corresponding.prediction.\ 

352corresponding_chromaticities_prediction_VonKries` definition unit tests 

353 methods. 

354 """ 

355 

356 def test_corresponding_chromaticities_prediction_VonKries(self) -> None: 

357 """ 

358 Test :func:`colour.corresponding.prediction.\ 

359corresponding_chromaticities_prediction_VonKries` definition. 

360 """ 

361 

362 np.testing.assert_allclose( 

363 np.array( 

364 [ 

365 (p.uv_m, p.uv_p) 

366 for p in corresponding_chromaticities_prediction_VonKries() 

367 ] 

368 ), 

369 DATA_PREDICTION_VONKRIES, 

370 atol=TOLERANCE_ABSOLUTE_TESTS, 

371 ) 

372 

373 

374class TestCorrespondingChromaticitiesPredictionZhai2018: 

375 """ 

376 Define :func:`colour.corresponding.prediction.\ 

377corresponding_chromaticities_prediction_Zhai2018` definition unit tests 

378 methods. 

379 """ 

380 

381 def test_corresponding_chromaticities_prediction_Zhai2018(self) -> None: 

382 """ 

383 Test :func:`colour.corresponding.prediction.\ 

384corresponding_chromaticities_prediction_Zhai2018` definition. 

385 """ 

386 

387 np.testing.assert_allclose( 

388 np.array( 

389 [ 

390 (p.uv_m, p.uv_p) 

391 for p in corresponding_chromaticities_prediction_Zhai2018() 

392 ] 

393 ), 

394 DATA_PREDICTION_ZHAI2018, 

395 atol=TOLERANCE_ABSOLUTE_TESTS, 

396 )