Coverage for models/tests/test_cie_luv.py: 100%

257 statements  

« prev     ^ index     » next       coverage.py v7.11.0, created at 2025-11-16 22:49 +1300

1"""Define the unit tests for the :mod:`colour.models.cie_luv` module.""" 

2 

3from __future__ import annotations 

4 

5from itertools import product 

6 

7import numpy as np 

8 

9from colour.constants import TOLERANCE_ABSOLUTE_TESTS 

10from colour.models import ( 

11 CIE1976UCS_to_XYZ, 

12 Luv_to_uv, 

13 Luv_to_XYZ, 

14 Luv_uv_to_xy, 

15 XYZ_to_CIE1976UCS, 

16 XYZ_to_Luv, 

17 uv_to_Luv, 

18 xy_to_Luv_uv, 

19) 

20from colour.utilities import domain_range_scale, ignore_numpy_errors 

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

31 "TestLuv_to_XYZ", 

32 "TestLuv_to_uv", 

33 "Testuv_to_Luv", 

34 "TestLuv_uv_to_xy", 

35 "TestXy_to_Luv_uv", 

36 "TestXYZ_to_CIE1976UCS", 

37 "TestCIE1976UCS_to_XYZ", 

38] 

39 

40 

41class TestXYZ_to_Luv: 

42 """ 

43 Define :func:`colour.models.cie_luv.XYZ_to_Luv` definition unit tests 

44 methods. 

45 """ 

46 

47 def test_XYZ_to_Luv(self) -> None: 

48 """Test :func:`colour.models.cie_luv.XYZ_to_Luv` definition.""" 

49 

50 np.testing.assert_allclose( 

51 XYZ_to_Luv(np.array([0.20654008, 0.12197225, 0.05136952])), 

52 np.array([41.52787529, 96.83626054, 17.75210149]), 

53 atol=TOLERANCE_ABSOLUTE_TESTS, 

54 ) 

55 

56 np.testing.assert_allclose( 

57 XYZ_to_Luv(np.array([0.14222010, 0.23042768, 0.10495772])), 

58 np.array([55.11636304, -37.59308176, 44.13768458]), 

59 atol=TOLERANCE_ABSOLUTE_TESTS, 

60 ) 

61 

62 np.testing.assert_allclose( 

63 XYZ_to_Luv(np.array([0.07818780, 0.06157201, 0.28099326])), 

64 np.array([29.80565520, -10.96316802, -65.06751860]), 

65 atol=TOLERANCE_ABSOLUTE_TESTS, 

66 ) 

67 

68 np.testing.assert_allclose( 

69 XYZ_to_Luv( 

70 np.array([0.20654008, 0.12197225, 0.05136952]), 

71 np.array([0.44757, 0.40745]), 

72 ), 

73 np.array([41.52787529, 65.45180940, -12.46626977]), 

74 atol=TOLERANCE_ABSOLUTE_TESTS, 

75 ) 

76 

77 np.testing.assert_allclose( 

78 XYZ_to_Luv( 

79 np.array([0.20654008, 0.12197225, 0.05136952]), 

80 np.array([0.34570, 0.35850]), 

81 ), 

82 np.array([41.52787529, 90.70925962, 7.08455273]), 

83 atol=TOLERANCE_ABSOLUTE_TESTS, 

84 ) 

85 

86 np.testing.assert_allclose( 

87 XYZ_to_Luv( 

88 np.array([0.20654008, 0.12197225, 0.05136952]), 

89 np.array([0.34570, 0.35850, 1.00000]), 

90 ), 

91 np.array([41.52787529, 90.70925962, 7.08455273]), 

92 atol=TOLERANCE_ABSOLUTE_TESTS, 

93 ) 

94 

95 def test_n_dimensional_XYZ_to_Luv(self) -> None: 

96 """ 

97 Test :func:`colour.models.cie_luv.XYZ_to_Luv` definition n-dimensional 

98 support. 

99 """ 

100 

101 XYZ = np.array([0.20654008, 0.12197225, 0.05136952]) 

102 illuminant = np.array([0.31270, 0.32900]) 

103 Luv = XYZ_to_Luv(XYZ, illuminant) 

104 

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

106 Luv = np.tile(Luv, (6, 1)) 

107 np.testing.assert_allclose( 

108 XYZ_to_Luv(XYZ, illuminant), Luv, atol=TOLERANCE_ABSOLUTE_TESTS 

109 ) 

110 

111 illuminant = np.tile(illuminant, (6, 1)) 

112 np.testing.assert_allclose( 

113 XYZ_to_Luv(XYZ, illuminant), Luv, atol=TOLERANCE_ABSOLUTE_TESTS 

114 ) 

115 

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

117 illuminant = np.reshape(illuminant, (2, 3, 2)) 

118 Luv = np.reshape(Luv, (2, 3, 3)) 

119 np.testing.assert_allclose( 

120 XYZ_to_Luv(XYZ, illuminant), Luv, atol=TOLERANCE_ABSOLUTE_TESTS 

121 ) 

122 

123 def test_domain_range_scale_XYZ_to_Luv(self) -> None: 

124 """ 

125 Test :func:`colour.models.cie_luv.XYZ_to_Luv` definition 

126 domain and range scale support. 

127 """ 

128 

129 XYZ = np.array([0.20654008, 0.12197225, 0.05136952]) 

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

131 Luv = XYZ_to_Luv(XYZ, illuminant) 

132 

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

134 for scale, factor_a, factor_b in d_r: 

135 with domain_range_scale(scale): 

136 np.testing.assert_allclose( 

137 XYZ_to_Luv(XYZ * factor_a, illuminant), 

138 Luv * factor_b, 

139 atol=TOLERANCE_ABSOLUTE_TESTS, 

140 ) 

141 

142 @ignore_numpy_errors 

143 def test_nan_XYZ_to_Luv(self) -> None: 

144 """Test :func:`colour.models.cie_luv.XYZ_to_Luv` definition nan support.""" 

145 

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

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

148 XYZ_to_Luv(cases, cases[..., 0:2]) 

149 

150 

151class TestLuv_to_XYZ: 

152 """ 

153 Define :func:`colour.models.cie_luv.Luv_to_XYZ` definition unit tests 

154 methods. 

155 """ 

156 

157 def test_Luv_to_XYZ(self) -> None: 

158 """Test :func:`colour.models.cie_luv.Luv_to_XYZ` definition.""" 

159 

160 np.testing.assert_allclose( 

161 Luv_to_XYZ(np.array([41.52787529, 96.83626054, 17.75210149])), 

162 np.array([0.20654008, 0.12197225, 0.05136952]), 

163 atol=TOLERANCE_ABSOLUTE_TESTS, 

164 ) 

165 

166 np.testing.assert_allclose( 

167 Luv_to_XYZ(np.array([55.11636304, -37.59308176, 44.13768458])), 

168 np.array([0.14222010, 0.23042768, 0.10495772]), 

169 atol=TOLERANCE_ABSOLUTE_TESTS, 

170 ) 

171 

172 np.testing.assert_allclose( 

173 Luv_to_XYZ(np.array([29.80565520, -10.96316802, -65.06751860])), 

174 np.array([0.07818780, 0.06157201, 0.28099326]), 

175 atol=TOLERANCE_ABSOLUTE_TESTS, 

176 ) 

177 

178 np.testing.assert_allclose( 

179 Luv_to_XYZ( 

180 np.array([41.52787529, 65.45180940, -12.46626977]), 

181 np.array([0.44757, 0.40745]), 

182 ), 

183 np.array([0.20654008, 0.12197225, 0.05136952]), 

184 atol=TOLERANCE_ABSOLUTE_TESTS, 

185 ) 

186 

187 np.testing.assert_allclose( 

188 Luv_to_XYZ( 

189 np.array([41.52787529, 90.70925962, 7.08455273]), 

190 np.array([0.34570, 0.35850]), 

191 ), 

192 np.array([0.20654008, 0.12197225, 0.05136952]), 

193 atol=TOLERANCE_ABSOLUTE_TESTS, 

194 ) 

195 

196 np.testing.assert_allclose( 

197 Luv_to_XYZ( 

198 np.array([41.52787529, 90.70925962, 7.08455273]), 

199 np.array([0.34570, 0.35850, 1.00000]), 

200 ), 

201 np.array([0.20654008, 0.12197225, 0.05136952]), 

202 atol=TOLERANCE_ABSOLUTE_TESTS, 

203 ) 

204 

205 def test_n_dimensional_Luv_to_XYZ(self) -> None: 

206 """ 

207 Test :func:`colour.models.cie_luv.Luv_to_XYZ` definition n-dimensional 

208 support. 

209 """ 

210 

211 Luv = np.array([41.52787529, 96.83626054, 17.75210149]) 

212 illuminant = np.array([0.31270, 0.32900]) 

213 XYZ = Luv_to_XYZ(Luv, illuminant) 

214 

215 Luv = np.tile(Luv, (6, 1)) 

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

217 np.testing.assert_allclose( 

218 Luv_to_XYZ(Luv, illuminant), XYZ, atol=TOLERANCE_ABSOLUTE_TESTS 

219 ) 

220 

221 illuminant = np.tile(illuminant, (6, 1)) 

222 np.testing.assert_allclose( 

223 Luv_to_XYZ(Luv, illuminant), XYZ, atol=TOLERANCE_ABSOLUTE_TESTS 

224 ) 

225 

226 Luv = np.reshape(Luv, (2, 3, 3)) 

227 illuminant = np.reshape(illuminant, (2, 3, 2)) 

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

229 np.testing.assert_allclose( 

230 Luv_to_XYZ(Luv, illuminant), XYZ, atol=TOLERANCE_ABSOLUTE_TESTS 

231 ) 

232 

233 def test_domain_range_scale_Luv_to_XYZ(self) -> None: 

234 """ 

235 Test :func:`colour.models.cie_luv.Luv_to_XYZ` definition 

236 domain and range scale support. 

237 """ 

238 

239 Luv = np.array([41.52787529, 96.83626054, 17.75210149]) 

240 illuminant = np.array([0.31270, 0.32900]) 

241 XYZ = Luv_to_XYZ(Luv, illuminant) 

242 

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

244 for scale, factor_a, factor_b in d_r: 

245 with domain_range_scale(scale): 

246 np.testing.assert_allclose( 

247 Luv_to_XYZ(Luv * factor_a, illuminant), 

248 XYZ * factor_b, 

249 atol=TOLERANCE_ABSOLUTE_TESTS, 

250 ) 

251 

252 @ignore_numpy_errors 

253 def test_nan_Luv_to_XYZ(self) -> None: 

254 """Test :func:`colour.models.cie_luv.Luv_to_XYZ` definition nan support.""" 

255 

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

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

258 Luv_to_XYZ(cases, cases[..., 0:2]) 

259 

260 

261class TestLuv_to_uv: 

262 """ 

263 Define :func:`colour.models.cie_luv.Luv_to_uv` definition unit tests 

264 methods. 

265 """ 

266 

267 def test_Luv_to_uv(self) -> None: 

268 """Test :func:`colour.models.cie_luv.Luv_to_uv` definition.""" 

269 

270 np.testing.assert_allclose( 

271 Luv_to_uv(np.array([41.52787529, 96.83626054, 17.75210149])), 

272 np.array([0.37720213, 0.50120264]), 

273 atol=TOLERANCE_ABSOLUTE_TESTS, 

274 ) 

275 

276 np.testing.assert_allclose( 

277 Luv_to_uv(np.array([55.11636304, -37.59308176, 44.13768458])), 

278 np.array([0.14536327, 0.52992069]), 

279 atol=TOLERANCE_ABSOLUTE_TESTS, 

280 ) 

281 

282 np.testing.assert_allclose( 

283 Luv_to_uv(np.array([29.80565520, -10.96316802, -65.06751860])), 

284 np.array([0.16953603, 0.30039234]), 

285 atol=TOLERANCE_ABSOLUTE_TESTS, 

286 ) 

287 

288 np.testing.assert_allclose( 

289 Luv_to_uv( 

290 np.array([41.52787529, 65.45180940, -12.46626977]), 

291 np.array([0.44757, 0.40745]), 

292 ), 

293 np.array([0.37720213, 0.50120264]), 

294 atol=TOLERANCE_ABSOLUTE_TESTS, 

295 ) 

296 

297 np.testing.assert_allclose( 

298 Luv_to_uv( 

299 np.array([41.52787529, 90.70925962, 7.08455273]), 

300 np.array([0.34570, 0.35850]), 

301 ), 

302 np.array([0.37720213, 0.50120264]), 

303 atol=TOLERANCE_ABSOLUTE_TESTS, 

304 ) 

305 

306 np.testing.assert_allclose( 

307 Luv_to_uv( 

308 np.array([41.52787529, 90.70925962, 7.08455273]), 

309 np.array([0.34570, 0.35850, 1.00000]), 

310 ), 

311 np.array([0.37720213, 0.50120264]), 

312 atol=TOLERANCE_ABSOLUTE_TESTS, 

313 ) 

314 

315 def test_n_dimensional_Luv_to_uv(self) -> None: 

316 """ 

317 Test :func:`colour.models.cie_luv.Luv_to_uv` definition n-dimensional 

318 support. 

319 """ 

320 

321 Luv = np.array([41.52787529, 96.83626054, 17.75210149]) 

322 illuminant = np.array([0.31270, 0.32900]) 

323 uv = Luv_to_uv(Luv, illuminant) 

324 

325 Luv = np.tile(Luv, (6, 1)) 

326 uv = np.tile(uv, (6, 1)) 

327 np.testing.assert_allclose( 

328 Luv_to_uv(Luv, illuminant), uv, atol=TOLERANCE_ABSOLUTE_TESTS 

329 ) 

330 

331 illuminant = np.tile(illuminant, (6, 1)) 

332 np.testing.assert_allclose( 

333 Luv_to_uv(Luv, illuminant), uv, atol=TOLERANCE_ABSOLUTE_TESTS 

334 ) 

335 

336 Luv = np.reshape(Luv, (2, 3, 3)) 

337 illuminant = np.reshape(illuminant, (2, 3, 2)) 

338 uv = np.reshape(uv, (2, 3, 2)) 

339 np.testing.assert_allclose( 

340 Luv_to_uv(Luv, illuminant), uv, atol=TOLERANCE_ABSOLUTE_TESTS 

341 ) 

342 

343 def test_domain_range_scale_Luv_to_uv(self) -> None: 

344 """ 

345 Test :func:`colour.models.cie_luv.Luv_to_uv` definition 

346 domain and range scale support. 

347 """ 

348 

349 Luv = np.array([41.52787529, 96.83626054, 17.75210149]) 

350 illuminant = np.array([0.31270, 0.32900]) 

351 uv = Luv_to_uv(Luv, illuminant) 

352 

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

354 for scale, factor in d_r: 

355 with domain_range_scale(scale): 

356 np.testing.assert_allclose( 

357 Luv_to_uv(Luv * factor, illuminant), 

358 uv, 

359 atol=TOLERANCE_ABSOLUTE_TESTS, 

360 ) 

361 

362 @ignore_numpy_errors 

363 def test_nan_Luv_to_uv(self) -> None: 

364 """Test :func:`colour.models.cie_luv.Luv_to_uv` definition nan support.""" 

365 

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

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

368 Luv_to_uv(cases, cases[..., 0:2]) 

369 

370 

371class Testuv_to_Luv: 

372 """ 

373 Define :func:`colour.models.cie_luv.uv_to_Luv` definition unit tests 

374 methods. 

375 """ 

376 

377 def test_uv_to_Luv(self) -> None: 

378 """Test :func:`colour.models.cie_luv.uv_to_Luv` definition.""" 

379 

380 np.testing.assert_allclose( 

381 uv_to_Luv(np.array([0.37720213, 0.50120264])), 

382 np.array([100.00000000, 233.18376036, 42.74743858]), 

383 atol=TOLERANCE_ABSOLUTE_TESTS, 

384 ) 

385 

386 np.testing.assert_allclose( 

387 uv_to_Luv(np.array([0.14536327, 0.52992069])), 

388 np.array([100.00000000, -68.20675764, 80.08090358]), 

389 atol=TOLERANCE_ABSOLUTE_TESTS, 

390 ) 

391 

392 np.testing.assert_allclose( 

393 uv_to_Luv(np.array([0.16953603, 0.30039234])), 

394 np.array([100.00000000, -36.78216964, -218.3059514]), 

395 atol=TOLERANCE_ABSOLUTE_TESTS, 

396 ) 

397 

398 np.testing.assert_allclose( 

399 uv_to_Luv( 

400 np.array([0.37720213, 0.50120264]), 

401 np.array([0.44757, 0.40745]), 

402 ), 

403 np.array([100.00000000, 157.60933976, -30.01903705]), 

404 atol=TOLERANCE_ABSOLUTE_TESTS, 

405 ) 

406 

407 np.testing.assert_allclose( 

408 uv_to_Luv( 

409 np.array([0.37720213, 0.50120264]), 

410 np.array([0.34570, 0.35850]), 

411 ), 

412 np.array([100.00000000, 218.42981284, 17.05975609]), 

413 atol=TOLERANCE_ABSOLUTE_TESTS, 

414 ) 

415 

416 np.testing.assert_allclose( 

417 uv_to_Luv( 

418 np.array([0.37720213, 0.50120264]), 

419 np.array([0.34570, 0.35850, 1.00000]), 

420 ), 

421 np.array([100.00000000, 218.42981284, 17.05975609]), 

422 atol=TOLERANCE_ABSOLUTE_TESTS, 

423 ) 

424 

425 np.testing.assert_allclose( 

426 uv_to_Luv(np.array([0.37720213, 0.50120264]), L=41.5278752), 

427 np.array([41.52787529, 96.83626054, 17.75210149]), 

428 atol=TOLERANCE_ABSOLUTE_TESTS, 

429 ) 

430 

431 def test_n_dimensional_uv_to_Luv(self) -> None: 

432 """ 

433 Test :func:`colour.models.cie_luv.uv_to_Luv` definition n-dimensional 

434 support. 

435 """ 

436 

437 uv = np.array([0.37720213, 0.50120264]) 

438 illuminant = np.array([0.31270, 0.32900]) 

439 Luv = uv_to_Luv(uv, illuminant) 

440 

441 uv = np.tile(uv, (6, 1)) 

442 Luv = np.tile(Luv, (6, 1)) 

443 np.testing.assert_allclose( 

444 uv_to_Luv(uv, illuminant), Luv, atol=TOLERANCE_ABSOLUTE_TESTS 

445 ) 

446 

447 illuminant = np.tile(illuminant, (6, 1)) 

448 np.testing.assert_allclose( 

449 uv_to_Luv(uv, illuminant), Luv, atol=TOLERANCE_ABSOLUTE_TESTS 

450 ) 

451 

452 uv = np.reshape(uv, (2, 3, 2)) 

453 illuminant = np.reshape(illuminant, (2, 3, 2)) 

454 Luv = np.reshape(Luv, (2, 3, 3)) 

455 np.testing.assert_allclose( 

456 uv_to_Luv(uv, illuminant), Luv, atol=TOLERANCE_ABSOLUTE_TESTS 

457 ) 

458 

459 def test_domain_range_scale_uv_to_Luv(self) -> None: 

460 """ 

461 Test :func:`colour.models.cie_luv.uv_to_Luv` definition 

462 domain and range scale support. 

463 """ 

464 

465 uv = np.array([0.37720213, 0.50120264]) 

466 illuminant = np.array([0.31270, 0.32900]) 

467 L = 100 

468 Luv = uv_to_Luv(uv, illuminant, L) 

469 

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

471 for scale, factor in d_r: 

472 with domain_range_scale(scale): 

473 np.testing.assert_allclose( 

474 uv_to_Luv(uv, illuminant, L * factor), 

475 Luv * factor, 

476 atol=TOLERANCE_ABSOLUTE_TESTS, 

477 ) 

478 

479 @ignore_numpy_errors 

480 def test_nan_uv_to_Luv(self) -> None: 

481 """Test :func:`colour.models.cie_luv.uv_to_Luv` definition nan support.""" 

482 

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

484 cases = np.array(list(set(product(cases, repeat=2)))) 

485 uv_to_Luv(cases, cases[..., 0:2]) 

486 

487 

488class TestLuv_uv_to_xy: 

489 """ 

490 Define :func:`colour.models.cie_luv.Luv_uv_to_xy` definition unit tests 

491 methods. 

492 """ 

493 

494 def test_Luv_uv_to_xy(self) -> None: 

495 """Test :func:`colour.models.cie_luv.Luv_uv_to_xy` definition.""" 

496 

497 np.testing.assert_allclose( 

498 Luv_uv_to_xy(np.array([0.37720213, 0.50120264])), 

499 np.array([0.54369558, 0.32107944]), 

500 atol=TOLERANCE_ABSOLUTE_TESTS, 

501 ) 

502 

503 np.testing.assert_allclose( 

504 Luv_uv_to_xy(np.array([0.14536327, 0.52992069])), 

505 np.array([0.29777734, 0.48246445]), 

506 atol=TOLERANCE_ABSOLUTE_TESTS, 

507 ) 

508 

509 np.testing.assert_allclose( 

510 Luv_uv_to_xy(np.array([0.16953603, 0.30039234])), 

511 np.array([0.18582824, 0.14633764]), 

512 atol=TOLERANCE_ABSOLUTE_TESTS, 

513 ) 

514 

515 def test_n_dimensional_Luv_uv_to_xy(self) -> None: 

516 """ 

517 Test :func:`colour.models.cie_luv.Luv_uv_to_xy` definition 

518 n-dimensional arrays support. 

519 """ 

520 

521 uv = np.array([0.37720213, 0.50120264]) 

522 xy = Luv_uv_to_xy(uv) 

523 

524 uv = np.tile(uv, (6, 1)) 

525 xy = np.tile(xy, (6, 1)) 

526 np.testing.assert_allclose(Luv_uv_to_xy(uv), xy, atol=TOLERANCE_ABSOLUTE_TESTS) 

527 

528 uv = np.reshape(uv, (2, 3, 2)) 

529 xy = np.reshape(xy, (2, 3, 2)) 

530 np.testing.assert_allclose(Luv_uv_to_xy(uv), xy, atol=TOLERANCE_ABSOLUTE_TESTS) 

531 

532 @ignore_numpy_errors 

533 def test_nan_Luv_uv_to_xy(self) -> None: 

534 """ 

535 Test :func:`colour.models.cie_luv.Luv_uv_to_xy` definition nan 

536 support. 

537 """ 

538 

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

540 cases = np.array(list(set(product(cases, repeat=2)))) 

541 Luv_uv_to_xy(cases) 

542 

543 

544class TestXy_to_Luv_uv: 

545 """ 

546 Define :func:`colour.models.cie_luv.xy_to_Luv_uv` definition unit tests 

547 methods. 

548 """ 

549 

550 def test_xy_to_Luv_uv(self) -> None: 

551 """Test :func:`colour.models.cie_luv.xy_to_Luv_uv` definition.""" 

552 

553 np.testing.assert_allclose( 

554 xy_to_Luv_uv(np.array([0.54369558, 0.32107944])), 

555 np.array([0.37720213, 0.50120264]), 

556 atol=TOLERANCE_ABSOLUTE_TESTS, 

557 ) 

558 

559 np.testing.assert_allclose( 

560 xy_to_Luv_uv(np.array([0.29777734, 0.48246445])), 

561 np.array([0.14536327, 0.52992069]), 

562 atol=TOLERANCE_ABSOLUTE_TESTS, 

563 ) 

564 

565 np.testing.assert_allclose( 

566 xy_to_Luv_uv(np.array([0.18582824, 0.14633764])), 

567 np.array([0.16953603, 0.30039234]), 

568 atol=TOLERANCE_ABSOLUTE_TESTS, 

569 ) 

570 

571 def test_n_dimensional_xy_to_Luv_uv(self) -> None: 

572 """ 

573 Test :func:`colour.models.cie_luv.xy_to_Luv_uv` definition 

574 n-dimensional arrays support. 

575 """ 

576 

577 xy = np.array([0.54369558, 0.32107944]) 

578 uv = xy_to_Luv_uv(xy) 

579 

580 xy = np.tile(xy, (6, 1)) 

581 uv = np.tile(uv, (6, 1)) 

582 np.testing.assert_allclose(xy_to_Luv_uv(xy), uv, atol=TOLERANCE_ABSOLUTE_TESTS) 

583 

584 xy = np.reshape(xy, (2, 3, 2)) 

585 uv = np.reshape(uv, (2, 3, 2)) 

586 np.testing.assert_allclose(xy_to_Luv_uv(xy), uv, atol=TOLERANCE_ABSOLUTE_TESTS) 

587 

588 @ignore_numpy_errors 

589 def test_nan_xy_to_Luv_uv(self) -> None: 

590 """ 

591 Test :func:`colour.models.cie_luv.xy_to_Luv_uv` definition nan 

592 support. 

593 """ 

594 

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

596 cases = np.array(list(set(product(cases, repeat=2)))) 

597 xy_to_Luv_uv(cases) 

598 

599 

600class TestXYZ_to_CIE1976UCS: 

601 """ 

602 Define :func:`colour.models.cie_luv.XYZ_to_CIE1976UCS` definition unit tests 

603 methods. 

604 """ 

605 

606 def test_XYZ_to_CIE1976UCS(self) -> None: 

607 """Test :func:`colour.models.cie_luv.XYZ_to_CIE1976UCS` definition.""" 

608 

609 np.testing.assert_allclose( 

610 XYZ_to_CIE1976UCS(np.array([0.20654008, 0.12197225, 0.05136952])), 

611 np.array([0.37720213, 0.50120264, 41.52787529]), 

612 atol=TOLERANCE_ABSOLUTE_TESTS, 

613 ) 

614 

615 np.testing.assert_allclose( 

616 XYZ_to_CIE1976UCS(np.array([0.14222010, 0.23042768, 0.10495772])), 

617 np.array([0.14536327, 0.52992069, 55.11636304]), 

618 atol=TOLERANCE_ABSOLUTE_TESTS, 

619 ) 

620 

621 np.testing.assert_allclose( 

622 XYZ_to_CIE1976UCS(np.array([0.07818780, 0.06157201, 0.28099326])), 

623 np.array([0.16953603, 0.30039234, 29.80565520]), 

624 atol=TOLERANCE_ABSOLUTE_TESTS, 

625 ) 

626 

627 np.testing.assert_allclose( 

628 XYZ_to_CIE1976UCS( 

629 np.array([0.20654008, 0.12197225, 0.05136952]), 

630 np.array([0.44757, 0.40745]), 

631 ), 

632 np.array([0.37720213, 0.50120264, 41.52787529]), 

633 atol=TOLERANCE_ABSOLUTE_TESTS, 

634 ) 

635 

636 np.testing.assert_allclose( 

637 XYZ_to_CIE1976UCS( 

638 np.array([0.20654008, 0.12197225, 0.05136952]), 

639 np.array([0.34570, 0.35850]), 

640 ), 

641 np.array([0.37720213, 0.50120264, 41.52787529]), 

642 atol=TOLERANCE_ABSOLUTE_TESTS, 

643 ) 

644 

645 np.testing.assert_allclose( 

646 XYZ_to_CIE1976UCS( 

647 np.array([0.20654008, 0.12197225, 0.05136952]), 

648 np.array([0.34570, 0.35850, 1.00000]), 

649 ), 

650 np.array([0.37720213, 0.50120264, 41.52787529]), 

651 atol=TOLERANCE_ABSOLUTE_TESTS, 

652 ) 

653 

654 def test_n_dimensional_XYZ_to_CIE1976UCS(self) -> None: 

655 """ 

656 Test :func:`colour.models.cie_luv.XYZ_to_CIE1976UCS` definition n-dimensional 

657 support. 

658 """ 

659 

660 XYZ = np.array([0.20654008, 0.12197225, 0.05136952]) 

661 illuminant = np.array([0.31270, 0.32900]) 

662 Luv = XYZ_to_CIE1976UCS(XYZ, illuminant) 

663 

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

665 Luv = np.tile(Luv, (6, 1)) 

666 np.testing.assert_allclose( 

667 XYZ_to_CIE1976UCS(XYZ, illuminant), Luv, atol=TOLERANCE_ABSOLUTE_TESTS 

668 ) 

669 

670 illuminant = np.tile(illuminant, (6, 1)) 

671 np.testing.assert_allclose( 

672 XYZ_to_CIE1976UCS(XYZ, illuminant), Luv, atol=TOLERANCE_ABSOLUTE_TESTS 

673 ) 

674 

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

676 illuminant = np.reshape(illuminant, (2, 3, 2)) 

677 Luv = np.reshape(Luv, (2, 3, 3)) 

678 np.testing.assert_allclose( 

679 XYZ_to_CIE1976UCS(XYZ, illuminant), Luv, atol=TOLERANCE_ABSOLUTE_TESTS 

680 ) 

681 

682 def test_domain_range_scale_XYZ_to_CIE1976UCS(self) -> None: 

683 """ 

684 Test :func:`colour.models.cie_luv.XYZ_to_CIE1976UCS` definition 

685 domain and range scale support. 

686 """ 

687 

688 XYZ = np.array([0.20654008, 0.12197225, 0.05136952]) 

689 illuminant = np.array([0.31270, 0.32900]) 

690 uvL = XYZ_to_CIE1976UCS(XYZ, illuminant) 

691 

692 d_r = (("reference", 1, 1), ("1", 1, np.array([1, 1, 0.01])), ("100", 100, 1)) 

693 for scale, factor_a, factor_b in d_r: 

694 with domain_range_scale(scale): 

695 np.testing.assert_allclose( 

696 XYZ_to_CIE1976UCS(XYZ * factor_a, illuminant), 

697 uvL * factor_b, 

698 atol=TOLERANCE_ABSOLUTE_TESTS, 

699 ) 

700 

701 @ignore_numpy_errors 

702 def test_nan_XYZ_to_CIE1976UCS(self) -> None: 

703 """ 

704 Test :func:`colour.models.cie_luv.XYZ_to_CIE1976UCS` definition nan 

705 support. 

706 """ 

707 

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

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

710 XYZ_to_CIE1976UCS(cases, cases[..., 0:2]) 

711 

712 

713class TestCIE1976UCS_to_XYZ: 

714 """ 

715 Define :func:`colour.models.cie_luv.CIE1976UCS_to_XYZ` definition unit tests 

716 methods. 

717 """ 

718 

719 def test_CIE1976UCS_to_XYZ(self) -> None: 

720 """Test :func:`colour.models.cie_luv.CIE1976UCS_to_XYZ` definition.""" 

721 

722 np.testing.assert_allclose( 

723 CIE1976UCS_to_XYZ(np.array([0.37720213, 0.50120264, 41.52787529])), 

724 np.array([0.20654008, 0.12197225, 0.05136952]), 

725 atol=TOLERANCE_ABSOLUTE_TESTS, 

726 ) 

727 

728 np.testing.assert_allclose( 

729 CIE1976UCS_to_XYZ(np.array([0.14536327, 0.52992069, 55.11636304])), 

730 np.array([0.14222010, 0.23042768, 0.10495772]), 

731 atol=TOLERANCE_ABSOLUTE_TESTS, 

732 ) 

733 

734 np.testing.assert_allclose( 

735 CIE1976UCS_to_XYZ(np.array([0.16953603, 0.30039234, 29.80565520])), 

736 np.array([0.07818780, 0.06157201, 0.28099326]), 

737 atol=TOLERANCE_ABSOLUTE_TESTS, 

738 ) 

739 

740 np.testing.assert_allclose( 

741 CIE1976UCS_to_XYZ( 

742 np.array([0.37720213, 0.50120264, 41.52787529]), 

743 np.array([0.44757, 0.40745]), 

744 ), 

745 np.array([0.20654008, 0.12197225, 0.05136952]), 

746 atol=TOLERANCE_ABSOLUTE_TESTS, 

747 ) 

748 

749 np.testing.assert_allclose( 

750 CIE1976UCS_to_XYZ( 

751 np.array([0.37720213, 0.50120264, 41.52787529]), 

752 np.array([0.34570, 0.35850]), 

753 ), 

754 np.array([0.20654008, 0.12197225, 0.05136952]), 

755 atol=TOLERANCE_ABSOLUTE_TESTS, 

756 ) 

757 

758 np.testing.assert_allclose( 

759 CIE1976UCS_to_XYZ( 

760 np.array([0.37720213, 0.50120264, 41.52787529]), 

761 np.array([0.34570, 0.35850, 1.00000]), 

762 ), 

763 np.array([0.20654008, 0.12197225, 0.05136952]), 

764 atol=TOLERANCE_ABSOLUTE_TESTS, 

765 ) 

766 

767 def test_n_dimensional_CIE1976UCS_to_XYZ(self) -> None: 

768 """ 

769 Test :func:`colour.models.cie_luv.CIE1976UCS_to_XYZ` definition n-dimensional 

770 support. 

771 """ 

772 

773 Luv = np.array([0.37720213, 0.50120264, 41.52787529]) 

774 illuminant = np.array([0.31270, 0.32900]) 

775 XYZ = CIE1976UCS_to_XYZ(Luv, illuminant) 

776 

777 Luv = np.tile(Luv, (6, 1)) 

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

779 np.testing.assert_allclose( 

780 CIE1976UCS_to_XYZ(Luv, illuminant), XYZ, atol=TOLERANCE_ABSOLUTE_TESTS 

781 ) 

782 

783 illuminant = np.tile(illuminant, (6, 1)) 

784 np.testing.assert_allclose( 

785 CIE1976UCS_to_XYZ(Luv, illuminant), XYZ, atol=TOLERANCE_ABSOLUTE_TESTS 

786 ) 

787 

788 Luv = np.reshape(Luv, (2, 3, 3)) 

789 illuminant = np.reshape(illuminant, (2, 3, 2)) 

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

791 np.testing.assert_allclose( 

792 CIE1976UCS_to_XYZ(Luv, illuminant), XYZ, atol=TOLERANCE_ABSOLUTE_TESTS 

793 ) 

794 

795 def test_domain_range_scale_CIE1976UCS_to_XYZ(self) -> None: 

796 """ 

797 Test :func:`colour.models.cie_luv.CIE1976UCS_to_XYZ` definition 

798 domain and range scale support. 

799 """ 

800 

801 uvL = np.array([0.37720213, 0.50120264, 41.52787529]) 

802 illuminant = np.array([0.31270, 0.32900]) 

803 XYZ = CIE1976UCS_to_XYZ(uvL, illuminant) 

804 

805 d_r = (("reference", 1, 1), ("1", np.array([1, 1, 0.01]), 1), ("100", 1, 100)) 

806 for scale, factor_a, factor_b in d_r: 

807 with domain_range_scale(scale): 

808 np.testing.assert_allclose( 

809 CIE1976UCS_to_XYZ(uvL * factor_a, illuminant), 

810 XYZ * factor_b, 

811 atol=TOLERANCE_ABSOLUTE_TESTS, 

812 ) 

813 

814 @ignore_numpy_errors 

815 def test_nan_CIE1976UCS_to_XYZ(self) -> None: 

816 """ 

817 Test :func:`colour.models.cie_luv.CIE1976UCS_to_XYZ` definition nan 

818 support. 

819 """ 

820 

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

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

823 CIE1976UCS_to_XYZ(cases, cases[..., 0:2])