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

209 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.colorimetry.luminance` module.""" 

2 

3from __future__ import annotations 

4 

5import numpy as np 

6 

7from colour.colorimetry import ( 

8 intermediate_luminance_function_CIE1976, 

9 luminance_Abebe2017, 

10 luminance_ASTMD1535, 

11 luminance_CIE1976, 

12 luminance_Fairchild2010, 

13 luminance_Fairchild2011, 

14 luminance_Newhall1943, 

15) 

16from colour.colorimetry.luminance import luminance 

17from colour.constants import TOLERANCE_ABSOLUTE_TESTS 

18from colour.utilities import domain_range_scale, ignore_numpy_errors 

19 

20__author__ = "Colour Developers" 

21__copyright__ = "Copyright 2013 Colour Developers" 

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

23__maintainer__ = "Colour Developers" 

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

25__status__ = "Production" 

26 

27__all__ = [ 

28 "TestLuminanceNewhall1943", 

29 "TestLuminanceASTMD1535", 

30 "TestIntermediateLuminanceFunctionCIE1976", 

31 "TestLuminanceCIE1976", 

32 "TestLuminanceFairchild2010", 

33 "TestLuminanceFairchild2011", 

34 "TestLuminanceAbebe2017", 

35 "TestLuminance", 

36] 

37 

38 

39class TestLuminanceNewhall1943: 

40 """ 

41 Define :func:`colour.colorimetry.luminance.luminance_Newhall1943` 

42 definition unit tests methods. 

43 """ 

44 

45 def test_luminance_Newhall1943(self) -> None: 

46 """ 

47 Test :func:`colour.colorimetry.luminance.luminance_Newhall1943` 

48 definition. 

49 """ 

50 

51 np.testing.assert_allclose( 

52 luminance_Newhall1943(4.08244375), 

53 12.550078816731881, 

54 atol=TOLERANCE_ABSOLUTE_TESTS, 

55 ) 

56 

57 np.testing.assert_allclose( 

58 luminance_Newhall1943(5.39132685), 

59 23.481252371310738, 

60 atol=TOLERANCE_ABSOLUTE_TESTS, 

61 ) 

62 

63 np.testing.assert_allclose( 

64 luminance_Newhall1943(2.97619312), 

65 6.4514266875601924, 

66 atol=TOLERANCE_ABSOLUTE_TESTS, 

67 ) 

68 

69 def test_n_dimensional_luminance_Newhall1943(self) -> None: 

70 """ 

71 Test :func:`colour.colorimetry.luminance.luminance_Newhall1943` 

72 definition n-dimensional arrays support. 

73 """ 

74 

75 V = 4.08244375 

76 Y = luminance_Newhall1943(V) 

77 

78 V = np.tile(V, 6) 

79 Y = np.tile(Y, 6) 

80 np.testing.assert_allclose( 

81 luminance_Newhall1943(V), Y, atol=TOLERANCE_ABSOLUTE_TESTS 

82 ) 

83 

84 V = np.reshape(V, (2, 3)) 

85 Y = np.reshape(Y, (2, 3)) 

86 np.testing.assert_allclose( 

87 luminance_Newhall1943(V), Y, atol=TOLERANCE_ABSOLUTE_TESTS 

88 ) 

89 

90 V = np.reshape(V, (2, 3, 1)) 

91 Y = np.reshape(Y, (2, 3, 1)) 

92 np.testing.assert_allclose( 

93 luminance_Newhall1943(V), Y, atol=TOLERANCE_ABSOLUTE_TESTS 

94 ) 

95 

96 def test_domain_range_scale_luminance_Newhall1943(self) -> None: 

97 """ 

98 Test :func:`colour.colorimetry.luminance.luminance_Newhall1943` 

99 definition domain and range scale support. 

100 """ 

101 

102 Y = luminance_Newhall1943(4.08244375) 

103 

104 d_r = (("reference", 1, 1), ("1", 0.1, 0.01), ("100", 10, 1)) 

105 for scale, factor_a, factor_b in d_r: 

106 with domain_range_scale(scale): 

107 np.testing.assert_allclose( 

108 luminance_Newhall1943(4.08244375 * factor_a), 

109 Y * factor_b, 

110 atol=TOLERANCE_ABSOLUTE_TESTS, 

111 ) 

112 

113 @ignore_numpy_errors 

114 def test_nan_luminance_Newhall1943(self) -> None: 

115 """ 

116 Test :func:`colour.colorimetry.luminance.luminance_Newhall1943` 

117 definition nan support. 

118 """ 

119 

120 luminance_Newhall1943(np.array([-1.0, 0.0, 1.0, -np.inf, np.inf, np.nan])) 

121 

122 

123class TestLuminanceASTMD1535: 

124 """ 

125 Define :func:`colour.colorimetry.luminance.luminance_ASTMD1535` 

126 definition unit tests methods. 

127 """ 

128 

129 def test_luminance_ASTMD1535(self) -> None: 

130 """ 

131 Test :func:`colour.colorimetry.luminance.luminance_ASTMD1535` 

132 definition. 

133 """ 

134 

135 np.testing.assert_allclose( 

136 luminance_ASTMD1535(4.08244375), 

137 12.236342675366036, 

138 atol=TOLERANCE_ABSOLUTE_TESTS, 

139 ) 

140 

141 np.testing.assert_allclose( 

142 luminance_ASTMD1535(5.39132685), 

143 22.893999867280378, 

144 atol=TOLERANCE_ABSOLUTE_TESTS, 

145 ) 

146 

147 np.testing.assert_allclose( 

148 luminance_ASTMD1535(2.97619312), 

149 6.2902253509053132, 

150 atol=TOLERANCE_ABSOLUTE_TESTS, 

151 ) 

152 

153 def test_n_dimensional_luminance_ASTMD1535(self) -> None: 

154 """ 

155 Test :func:`colour.colorimetry.luminance.luminance_ASTMD1535` 

156 definition n-dimensional arrays support. 

157 """ 

158 

159 V = 4.08244375 

160 Y = luminance_ASTMD1535(V) 

161 

162 V = np.tile(V, 6) 

163 Y = np.tile(Y, 6) 

164 np.testing.assert_allclose( 

165 luminance_ASTMD1535(V), Y, atol=TOLERANCE_ABSOLUTE_TESTS 

166 ) 

167 

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

169 Y = np.reshape(Y, (2, 3)) 

170 np.testing.assert_allclose( 

171 luminance_ASTMD1535(V), Y, atol=TOLERANCE_ABSOLUTE_TESTS 

172 ) 

173 

174 V = np.reshape(V, (2, 3, 1)) 

175 Y = np.reshape(Y, (2, 3, 1)) 

176 np.testing.assert_allclose( 

177 luminance_ASTMD1535(V), Y, atol=TOLERANCE_ABSOLUTE_TESTS 

178 ) 

179 

180 def test_domain_range_scale_luminance_ASTMD1535(self) -> None: 

181 """ 

182 Test :func:`colour.colorimetry.luminance.luminance_ASTMD1535` 

183 definition domain and range scale support. 

184 """ 

185 

186 Y = luminance_ASTMD1535(4.08244375) 

187 

188 d_r = (("reference", 1, 1), ("1", 0.1, 0.01), ("100", 10, 1)) 

189 for scale, factor_a, factor_b in d_r: 

190 with domain_range_scale(scale): 

191 np.testing.assert_allclose( 

192 luminance_ASTMD1535(4.08244375 * factor_a), 

193 Y * factor_b, 

194 atol=TOLERANCE_ABSOLUTE_TESTS, 

195 ) 

196 

197 @ignore_numpy_errors 

198 def test_nan_luminance_ASTMD1535(self) -> None: 

199 """ 

200 Test :func:`colour.colorimetry.luminance.luminance_ASTMD1535` 

201 definition nan support. 

202 """ 

203 

204 luminance_ASTMD1535(np.array([-1.0, 0.0, 1.0, -np.inf, np.inf, np.nan])) 

205 

206 

207class TestIntermediateLuminanceFunctionCIE1976: 

208 """ 

209 Define :func:`colour.colorimetry.luminance.\ 

210intermediate_luminance_function_CIE1976` definition unit tests methods. 

211 """ 

212 

213 def test_intermediate_luminance_function_CIE1976(self) -> None: 

214 """ 

215 Test :func:`colour.colorimetry.luminance.\ 

216intermediate_luminance_function_CIE1976` definition. 

217 """ 

218 

219 np.testing.assert_allclose( 

220 intermediate_luminance_function_CIE1976(0.495929964178047), 

221 12.197225350000002, 

222 atol=TOLERANCE_ABSOLUTE_TESTS, 

223 ) 

224 

225 np.testing.assert_allclose( 

226 intermediate_luminance_function_CIE1976(0.613072093530391), 

227 23.042767810000004, 

228 atol=TOLERANCE_ABSOLUTE_TESTS, 

229 ) 

230 

231 np.testing.assert_allclose( 

232 intermediate_luminance_function_CIE1976(0.394876333449113), 

233 6.157200790000001, 

234 atol=TOLERANCE_ABSOLUTE_TESTS, 

235 ) 

236 

237 def test_n_dimensional_intermediate_luminance_function_CIE1976(self) -> None: 

238 """ 

239 Test :func:`colour.colorimetry.luminance.\ 

240intermediate_luminance_function_CIE1976` definition n-dimensional arrays 

241 support. 

242 """ 

243 

244 f_Y_Y_n = 0.495929964178047 

245 Y = intermediate_luminance_function_CIE1976(f_Y_Y_n) 

246 

247 f_Y_Y_n = np.tile(f_Y_Y_n, 6) 

248 Y = np.tile(Y, 6) 

249 np.testing.assert_allclose( 

250 intermediate_luminance_function_CIE1976(f_Y_Y_n), 

251 Y, 

252 atol=TOLERANCE_ABSOLUTE_TESTS, 

253 ) 

254 

255 f_Y_Y_n = np.reshape(f_Y_Y_n, (2, 3)) 

256 Y = np.reshape(Y, (2, 3)) 

257 np.testing.assert_allclose( 

258 intermediate_luminance_function_CIE1976(f_Y_Y_n), 

259 Y, 

260 atol=TOLERANCE_ABSOLUTE_TESTS, 

261 ) 

262 

263 f_Y_Y_n = np.reshape(f_Y_Y_n, (2, 3, 1)) 

264 Y = np.reshape(Y, (2, 3, 1)) 

265 np.testing.assert_allclose( 

266 intermediate_luminance_function_CIE1976(f_Y_Y_n), 

267 Y, 

268 atol=TOLERANCE_ABSOLUTE_TESTS, 

269 ) 

270 

271 def test_domain_range_scale_intermediate_luminance_function_CIE1976(self) -> None: 

272 """ 

273 Test :func:`colour.colorimetry.luminance.\ 

274intermediate_luminance_function_CIE1976` definition domain and range scale 

275 support. 

276 """ 

277 

278 Y = intermediate_luminance_function_CIE1976(41.527875844653451, 100) 

279 

280 for scale in ("reference", "1", "100"): 

281 with domain_range_scale(scale): 

282 np.testing.assert_allclose( 

283 intermediate_luminance_function_CIE1976(41.527875844653451, 100), 

284 Y, 

285 atol=TOLERANCE_ABSOLUTE_TESTS, 

286 ) 

287 

288 @ignore_numpy_errors 

289 def test_nan_intermediate_luminance_function_CIE1976(self) -> None: 

290 """ 

291 Test :func:`colour.colorimetry.luminance.\ 

292intermediate_luminance_function_CIE1976` definition nan support. 

293 """ 

294 

295 intermediate_luminance_function_CIE1976( 

296 np.array([-1.0, 0.0, 1.0, -np.inf, np.inf, np.nan]) 

297 ) 

298 

299 

300class TestLuminanceCIE1976: 

301 """ 

302 Define :func:`colour.colorimetry.luminance.luminance_CIE1976` definition 

303 unit tests methods. 

304 """ 

305 

306 def test_luminance_CIE1976(self) -> None: 

307 """ 

308 Test :func:`colour.colorimetry.luminance.luminance_CIE1976` 

309 definition. 

310 """ 

311 

312 np.testing.assert_allclose( 

313 luminance_CIE1976(41.527875844653451), 

314 12.197225350000002, 

315 atol=TOLERANCE_ABSOLUTE_TESTS, 

316 ) 

317 

318 np.testing.assert_allclose( 

319 luminance_CIE1976(55.116362849525402), 

320 23.042767810000004, 

321 atol=TOLERANCE_ABSOLUTE_TESTS, 

322 ) 

323 

324 np.testing.assert_allclose( 

325 luminance_CIE1976(29.805654680097106), 

326 6.157200790000001, 

327 atol=TOLERANCE_ABSOLUTE_TESTS, 

328 ) 

329 

330 np.testing.assert_allclose( 

331 luminance_CIE1976(56.480581732417676, 50), 

332 12.197225349999998, 

333 atol=TOLERANCE_ABSOLUTE_TESTS, 

334 ) 

335 

336 np.testing.assert_allclose( 

337 luminance_CIE1976(47.317620274162735, 75), 

338 12.197225350000002, 

339 atol=TOLERANCE_ABSOLUTE_TESTS, 

340 ) 

341 

342 np.testing.assert_allclose( 

343 luminance_CIE1976(42.519930728120940, 95), 

344 12.197225350000005, 

345 atol=TOLERANCE_ABSOLUTE_TESTS, 

346 ) 

347 

348 def test_n_dimensional_luminance_CIE1976(self) -> None: 

349 """ 

350 Test :func:`colour.colorimetry.luminance.luminance_CIE1976` 

351 definition n-dimensional arrays support. 

352 """ 

353 

354 L_star = 41.527875844653451 

355 Y = luminance_CIE1976(L_star) 

356 

357 L_star = np.tile(L_star, 6) 

358 Y = np.tile(Y, 6) 

359 np.testing.assert_allclose( 

360 luminance_CIE1976(L_star), Y, atol=TOLERANCE_ABSOLUTE_TESTS 

361 ) 

362 

363 L_star = np.reshape(L_star, (2, 3)) 

364 Y = np.reshape(Y, (2, 3)) 

365 np.testing.assert_allclose( 

366 luminance_CIE1976(L_star), Y, atol=TOLERANCE_ABSOLUTE_TESTS 

367 ) 

368 

369 L_star = np.reshape(L_star, (2, 3, 1)) 

370 Y = np.reshape(Y, (2, 3, 1)) 

371 np.testing.assert_allclose( 

372 luminance_CIE1976(L_star), Y, atol=TOLERANCE_ABSOLUTE_TESTS 

373 ) 

374 

375 def test_domain_range_scale_luminance_CIE1976(self) -> None: 

376 """ 

377 Test :func:`colour.colorimetry.luminance.luminance_CIE1976` 

378 definition domain and range scale support. 

379 """ 

380 

381 Y = luminance_CIE1976(41.527875844653451, 100) 

382 

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

384 for scale, factor in d_r: 

385 with domain_range_scale(scale): 

386 np.testing.assert_allclose( 

387 luminance_CIE1976(41.527875844653451 * factor, 100 * factor), 

388 Y * factor, 

389 atol=TOLERANCE_ABSOLUTE_TESTS, 

390 ) 

391 

392 @ignore_numpy_errors 

393 def test_nan_luminance_CIE1976(self) -> None: 

394 """ 

395 Test :func:`colour.colorimetry.luminance.luminance_CIE1976` 

396 definition nan support. 

397 """ 

398 

399 luminance_CIE1976(np.array([-1.0, 0.0, 1.0, -np.inf, np.inf, np.nan])) 

400 

401 

402class TestLuminanceFairchild2010: 

403 """ 

404 Define :func:`colour.colorimetry.luminance.luminance_Fairchild2010` 

405 definition unit tests methods. 

406 """ 

407 

408 def test_luminance_Fairchild2010(self) -> None: 

409 """ 

410 Test :func:`colour.colorimetry.luminance.luminance_Fairchild2010` 

411 definition. 

412 """ 

413 

414 np.testing.assert_allclose( 

415 luminance_Fairchild2010(31.996390226262736), 

416 0.12197225350000002, 

417 atol=TOLERANCE_ABSOLUTE_TESTS, 

418 ) 

419 

420 np.testing.assert_allclose( 

421 luminance_Fairchild2010(60.203153682783302), 

422 0.23042767809999998, 

423 atol=TOLERANCE_ABSOLUTE_TESTS, 

424 ) 

425 

426 np.testing.assert_allclose( 

427 luminance_Fairchild2010(11.836517240976489), 

428 0.06157200790000001, 

429 atol=TOLERANCE_ABSOLUTE_TESTS, 

430 ) 

431 

432 np.testing.assert_allclose( 

433 luminance_Fairchild2010(24.424283249379986, 2.75), 

434 0.12197225350000002, 

435 atol=TOLERANCE_ABSOLUTE_TESTS, 

436 ) 

437 

438 np.testing.assert_allclose( 

439 luminance_Fairchild2010(100.019986327374240), 

440 1008.00000024, 

441 atol=TOLERANCE_ABSOLUTE_TESTS, 

442 ) 

443 

444 np.testing.assert_allclose( 

445 luminance_Fairchild2010(100.019999997090270), 

446 100799.92312466, 

447 atol=TOLERANCE_ABSOLUTE_TESTS, 

448 ) 

449 

450 def test_n_dimensional_luminance_Fairchild2010(self) -> None: 

451 """ 

452 Test :func:`colour.colorimetry.luminance.luminance_Fairchild2010` 

453 definition n-dimensional arrays support. 

454 """ 

455 

456 L_hdr = 31.996390226262736 

457 Y = luminance_Fairchild2010(L_hdr) 

458 

459 L_hdr = np.tile(L_hdr, 6) 

460 Y = np.tile(Y, 6) 

461 np.testing.assert_allclose( 

462 luminance_Fairchild2010(L_hdr), Y, atol=TOLERANCE_ABSOLUTE_TESTS 

463 ) 

464 

465 L_hdr = np.reshape(L_hdr, (2, 3)) 

466 Y = np.reshape(Y, (2, 3)) 

467 np.testing.assert_allclose( 

468 luminance_Fairchild2010(L_hdr), Y, atol=TOLERANCE_ABSOLUTE_TESTS 

469 ) 

470 

471 L_hdr = np.reshape(L_hdr, (2, 3, 1)) 

472 Y = np.reshape(Y, (2, 3, 1)) 

473 np.testing.assert_allclose( 

474 luminance_Fairchild2010(L_hdr), Y, atol=TOLERANCE_ABSOLUTE_TESTS 

475 ) 

476 

477 def test_domain_range_scale_luminance_Fairchild2010(self) -> None: 

478 """ 

479 Test :func:`colour.colorimetry.luminance.luminance_Fairchild2010` 

480 definition domain and range scale support. 

481 """ 

482 

483 Y = luminance_Fairchild2010(31.996390226262736) 

484 

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

486 for scale, factor_a, factor_b in d_r: 

487 with domain_range_scale(scale): 

488 np.testing.assert_allclose( 

489 luminance_Fairchild2010(31.996390226262736 * factor_a), 

490 Y * factor_b, 

491 atol=TOLERANCE_ABSOLUTE_TESTS, 

492 ) 

493 

494 @ignore_numpy_errors 

495 def test_nan_luminance_Fairchild2010(self) -> None: 

496 """ 

497 Test :func:`colour.colorimetry.luminance.luminance_Fairchild2010` 

498 definition nan support. 

499 """ 

500 

501 luminance_Fairchild2010(np.array([-1.0, 0.0, 1.0, -np.inf, np.inf, np.nan])) 

502 

503 

504class TestLuminanceFairchild2011: 

505 """ 

506 Define :func:`colour.colorimetry.luminance.luminance_Fairchild2011` 

507 definition unit tests methods. 

508 """ 

509 

510 def test_luminance_Fairchild2011(self) -> None: 

511 """ 

512 Test :func:`colour.colorimetry.luminance.luminance_Fairchild2011` 

513 definition. 

514 """ 

515 

516 np.testing.assert_allclose( 

517 luminance_Fairchild2011(51.852958445912506), 

518 0.12197225350000007, 

519 atol=TOLERANCE_ABSOLUTE_TESTS, 

520 ) 

521 

522 np.testing.assert_allclose( 

523 luminance_Fairchild2011(65.275207956353853), 

524 0.23042767809999998, 

525 atol=TOLERANCE_ABSOLUTE_TESTS, 

526 ) 

527 

528 np.testing.assert_allclose( 

529 luminance_Fairchild2011(39.818935510715917), 

530 0.061572007900000038, 

531 atol=TOLERANCE_ABSOLUTE_TESTS, 

532 ) 

533 

534 np.testing.assert_allclose( 

535 luminance_Fairchild2011(0.13268968410139345, 2.75), 

536 0.12197225350000002, 

537 atol=TOLERANCE_ABSOLUTE_TESTS, 

538 ) 

539 

540 np.testing.assert_allclose( 

541 luminance_Fairchild2011(234.72925681957565), 

542 1008.00000000, 

543 atol=TOLERANCE_ABSOLUTE_TESTS, 

544 ) 

545 

546 np.testing.assert_allclose( 

547 luminance_Fairchild2011(245.57059778237573), 

548 100800.00000000, 

549 atol=TOLERANCE_ABSOLUTE_TESTS, 

550 ) 

551 

552 def test_n_dimensional_luminance_Fairchild2011(self) -> None: 

553 """ 

554 Test :func:`colour.colorimetry.luminance.luminance_Fairchild2011` 

555 definition n-dimensional arrays support. 

556 """ 

557 

558 L_hdr = 51.852958445912506 

559 Y = luminance_Fairchild2011(L_hdr) 

560 

561 L_hdr = np.tile(L_hdr, 6) 

562 Y = np.tile(Y, 6) 

563 np.testing.assert_allclose( 

564 luminance_Fairchild2011(L_hdr), Y, atol=TOLERANCE_ABSOLUTE_TESTS 

565 ) 

566 

567 L_hdr = np.reshape(L_hdr, (2, 3)) 

568 Y = np.reshape(Y, (2, 3)) 

569 np.testing.assert_allclose( 

570 luminance_Fairchild2011(L_hdr), Y, atol=TOLERANCE_ABSOLUTE_TESTS 

571 ) 

572 

573 L_hdr = np.reshape(L_hdr, (2, 3, 1)) 

574 Y = np.reshape(Y, (2, 3, 1)) 

575 np.testing.assert_allclose( 

576 luminance_Fairchild2011(L_hdr), Y, atol=TOLERANCE_ABSOLUTE_TESTS 

577 ) 

578 

579 def test_domain_range_scale_luminance_Fairchild2011(self) -> None: 

580 """ 

581 Test :func:`colour.colorimetry.luminance.luminance_Fairchild2011` 

582 definition domain and range scale support. 

583 """ 

584 

585 Y = luminance_Fairchild2011(26.459509817572265) 

586 

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

588 for scale, factor_a, factor_b in d_r: 

589 with domain_range_scale(scale): 

590 np.testing.assert_allclose( 

591 luminance_Fairchild2011(26.459509817572265 * factor_a), 

592 Y * factor_b, 

593 atol=TOLERANCE_ABSOLUTE_TESTS, 

594 ) 

595 

596 @ignore_numpy_errors 

597 def test_nan_luminance_Fairchild2011(self) -> None: 

598 """ 

599 Test :func:`colour.colorimetry.luminance.luminance_Fairchild2011` 

600 definition nan support. 

601 """ 

602 

603 luminance_Fairchild2011(np.array([-1.0, 0.0, 1.0, -np.inf, np.inf, np.nan])) 

604 

605 

606class TestLuminanceAbebe2017: 

607 """ 

608 Define :func:`colour.colorimetry.luminance.luminance_Abebe2017` 

609 definition unit tests methods. 

610 """ 

611 

612 def test_luminance_Abebe2017(self) -> None: 

613 """ 

614 Test :func:`colour.colorimetry.luminance.luminance_Abebe2017` 

615 definition. 

616 """ 

617 

618 np.testing.assert_allclose( 

619 luminance_Abebe2017(0.486955571109229), 

620 12.197225350000004, 

621 atol=TOLERANCE_ABSOLUTE_TESTS, 

622 ) 

623 

624 np.testing.assert_allclose( 

625 luminance_Abebe2017(0.474544792145434, method="Stevens"), 

626 12.197225350000025, 

627 atol=TOLERANCE_ABSOLUTE_TESTS, 

628 ) 

629 

630 np.testing.assert_allclose( 

631 luminance_Abebe2017(0.286847428534793, 1000), 

632 12.197225350000046, 

633 atol=TOLERANCE_ABSOLUTE_TESTS, 

634 ) 

635 

636 np.testing.assert_allclose( 

637 luminance_Abebe2017(0.192145492588158, 4000), 

638 12.197225350000121, 

639 atol=TOLERANCE_ABSOLUTE_TESTS, 

640 ) 

641 

642 np.testing.assert_allclose( 

643 luminance_Abebe2017(0.170365211220992, 4000, method="Stevens"), 

644 12.197225349999933, 

645 atol=TOLERANCE_ABSOLUTE_TESTS, 

646 ) 

647 

648 def test_n_dimensional_luminance_Abebe2017(self) -> None: 

649 """ 

650 Test :func:`colour.colorimetry.luminance.luminance_Abebe2017` 

651 definition n-dimensional arrays support. 

652 """ 

653 

654 L = 0.486955571109229 

655 Y = luminance_Abebe2017(L) 

656 

657 L = np.tile(L, 6) 

658 Y = np.tile(Y, 6) 

659 np.testing.assert_allclose( 

660 luminance_Abebe2017(L), Y, atol=TOLERANCE_ABSOLUTE_TESTS 

661 ) 

662 

663 L = np.reshape(L, (2, 3)) 

664 Y = np.reshape(Y, (2, 3)) 

665 np.testing.assert_allclose( 

666 luminance_Abebe2017(L), Y, atol=TOLERANCE_ABSOLUTE_TESTS 

667 ) 

668 

669 L = np.reshape(L, (2, 3, 1)) 

670 Y = np.reshape(Y, (2, 3, 1)) 

671 np.testing.assert_allclose( 

672 luminance_Abebe2017(L), Y, atol=TOLERANCE_ABSOLUTE_TESTS 

673 ) 

674 

675 @ignore_numpy_errors 

676 def test_nan_luminance_Abebe2017(self) -> None: 

677 """ 

678 Test :func:`colour.colorimetry.luminance.luminance_Abebe2017` 

679 definition nan support. 

680 """ 

681 

682 cases = np.array([-1.0, 0.0, 1.0, -np.inf, np.inf, np.nan]) 

683 luminance_Abebe2017(cases, cases) 

684 

685 

686class TestLuminance: 

687 """ 

688 Define :func:`colour.colorimetry.luminance.luminance` definition unit 

689 tests methods. 

690 """ 

691 

692 def test_domain_range_scale_luminance(self) -> None: 

693 """ 

694 Test :func:`colour.colorimetry.luminance.luminance` definition 

695 domain and range scale support. 

696 """ 

697 

698 m = ( 

699 "Newhall 1943", 

700 "ASTM D1535", 

701 "CIE 1976", 

702 "Fairchild 2010", 

703 "Fairchild 2011", 

704 "Abebe 2017", 

705 ) 

706 v = [luminance(41.527875844653451, method, Y_n=100) for method in m] 

707 

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

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

710 for scale, factor in d_r: 

711 with domain_range_scale(scale): 

712 np.testing.assert_allclose( 

713 luminance( 

714 41.527875844653451 * factor, method, Y_n=100 * factor 

715 ), 

716 value * factor, 

717 atol=TOLERANCE_ABSOLUTE_TESTS, 

718 )