Coverage for models/rgb/transfer_functions/tests/test_aces.py: 100%

1"""

2 Define the unit tests for the :mod:`colour.models.rgb.transfer_functions.aces`

3 module.

4"""

5

6 import numpy as np

7

8 from colour.constants import TOLERANCE_ABSOLUTE_TESTS

9 from colour.models.rgb.transfer_functions import (

10 log_decoding_ACEScc,

11 log_decoding_ACEScct,

12 log_decoding_ACESproxy,

13 log_encoding_ACEScc,

14 log_encoding_ACEScct,

15 log_encoding_ACESproxy,

16)

17 from colour.utilities import domain_range_scale, ignore_numpy_errors

18

19 __author__ = "Colour Developers"

20 __copyright__ = "Copyright 2013 Colour Developers"

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

22 __maintainer__ = "Colour Developers"

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

24 __status__ = "Production"

25

26 __all__ = [

27 "TestLogEncoding_ACESproxy",

28 "TestLogDecoding_ACESproxy",

29 "TestLogEncoding_ACEScc",

30 "TestLogDecoding_ACEScc",

31 "TestLogDecoding_ACEScct",

32]

33

34

35 class TestLogEncoding_ACESproxy:

36 """

37 Define :func:`colour.models.rgb.transfer_functions.aces.\

38 log_encoding_ACESproxy`

39 definition unit tests methods.

40 """

41

42 def test_log_encoding_ACESproxy(self) -> None:

43 """

44 Test :func:`colour.models.rgb.transfer_functions.aces.\

45 log_encoding_ACESproxy` definition.

46 """

47

48 np.testing.assert_allclose(

49 log_encoding_ACESproxy(0.0),

50 0.062561094819159,

51 atol=TOLERANCE_ABSOLUTE_TESTS,

52 )

53

54 np.testing.assert_allclose(

55 log_encoding_ACESproxy(0.18),

56 0.416422287390029,

57 atol=TOLERANCE_ABSOLUTE_TESTS,

58 )

59

60 np.testing.assert_allclose(

61 log_encoding_ACESproxy(0.18, 12),

62 0.416361416361416,

63 atol=TOLERANCE_ABSOLUTE_TESTS,

64 )

65

66 np.testing.assert_allclose(

67 log_encoding_ACESproxy(1.0),

68 0.537634408602151,

69 atol=TOLERANCE_ABSOLUTE_TESTS,

70 )

71

72 assert log_encoding_ACESproxy(0.18, out_int=True) == 426

73

74 def test_n_dimensional_log_encoding_ACESproxy(self) -> None:

75 """

76 Test :func:`colour.models.rgb.transfer_functions.aces.\

77 log_encoding_ACESproxy` definition n-dimensional arrays support.

78 """

79

80 lin_AP1 = 0.18

81 ACESproxy = log_encoding_ACESproxy(lin_AP1)

82

83 lin_AP1 = np.tile(lin_AP1, 6)

84 ACESproxy = np.tile(ACESproxy, 6)

85 np.testing.assert_allclose(

86 log_encoding_ACESproxy(lin_AP1),

87 ACESproxy,

88 atol=TOLERANCE_ABSOLUTE_TESTS,

89 )

90

91 lin_AP1 = np.reshape(lin_AP1, (2, 3))

92 ACESproxy = np.reshape(ACESproxy, (2, 3))

93 np.testing.assert_allclose(

94 log_encoding_ACESproxy(lin_AP1),

95 ACESproxy,

96 atol=TOLERANCE_ABSOLUTE_TESTS,

97 )

98

99 lin_AP1 = np.reshape(lin_AP1, (2, 3, 1))

100 ACESproxy = np.reshape(ACESproxy, (2, 3, 1))

101 np.testing.assert_allclose(

102 log_encoding_ACESproxy(lin_AP1),

103 ACESproxy,

104 atol=TOLERANCE_ABSOLUTE_TESTS,

105 )

106

107 def test_domain_range_scale_log_encoding_ACESproxy(self) -> None:

108 """

109 Test :func:`colour.models.rgb.transfer_functions.aces.\

110 log_encoding_ACESproxy` definition domain and range scale support.

111 """

112

113 lin_AP1 = 0.18

114 ACESproxy = log_encoding_ACESproxy(lin_AP1)

115

116 d_r = (("reference", 1), ("1", 1), ("100", 100))

117 for scale, factor in d_r:

118 with domain_range_scale(scale):

119 np.testing.assert_allclose(

120 log_encoding_ACESproxy(lin_AP1 * factor),

121 ACESproxy * factor,

122 atol=TOLERANCE_ABSOLUTE_TESTS,

123 )

124

125 @ignore_numpy_errors

126 def test_nan_log_encoding_ACESproxy(self) -> None:

127 """

128 Test :func:`colour.models.rgb.transfer_functions.aces.\

129 log_encoding_ACESproxy` definition nan support.

130 """

131

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

133

134

135 class TestLogDecoding_ACESproxy:

136 """

137 Define :func:`colour.models.rgb.transfer_functions.aces.\

138 log_decoding_ACESproxy`

139 definition unit tests methods.

140 """

141

142 def test_log_decoding_ACESproxy(self) -> None:

143 """

144 Test :func:`colour.models.rgb.transfer_functions.aces.\

145 log_decoding_ACESproxy` definition.

146 """

147

148 np.testing.assert_allclose(

149 log_decoding_ACESproxy(0.062561094819159),

150 0.0,

151 atol=0.01,

152 )

153

154 np.testing.assert_allclose(

155 log_decoding_ACESproxy(0.416422287390029),

156 0.18,

157 atol=0.01,

158 )

159

160 np.testing.assert_allclose(

161 log_decoding_ACESproxy(0.416361416361416, 12),

162 0.18,

163 atol=0.01,

164 )

165

166 np.testing.assert_allclose(

167 log_decoding_ACESproxy(0.537634408602151),

168 1.0,

169 atol=0.01,

170 )

171

172 np.testing.assert_allclose(

173 log_decoding_ACESproxy(426, in_int=True),

174 0.18,

175 atol=0.01,

176 )

177

178 def test_n_dimensional_log_decoding_ACESproxy(self) -> None:

179 """

180 Test :func:`colour.models.rgb.transfer_functions.aces.\

181 log_decoding_ACESproxy` definition n-dimensional arrays support.

182 """

183

184 ACESproxy = 0.416422287390029

185 lin_AP1 = log_decoding_ACESproxy(ACESproxy)

186

187 ACESproxy = np.tile(ACESproxy, 6)

188 lin_AP1 = np.tile(lin_AP1, 6)

189 np.testing.assert_allclose(

190 log_decoding_ACESproxy(ACESproxy),

191 lin_AP1,

192 atol=TOLERANCE_ABSOLUTE_TESTS,

193 )

194

195 ACESproxy = np.reshape(ACESproxy, (2, 3))

196 lin_AP1 = np.reshape(lin_AP1, (2, 3))

197 np.testing.assert_allclose(

198 log_decoding_ACESproxy(ACESproxy),

199 lin_AP1,

200 atol=TOLERANCE_ABSOLUTE_TESTS,

201 )

202

203 ACESproxy = np.reshape(ACESproxy, (2, 3, 1))

204 lin_AP1 = np.reshape(lin_AP1, (2, 3, 1))

205 np.testing.assert_allclose(

206 log_decoding_ACESproxy(ACESproxy),

207 lin_AP1,

208 atol=TOLERANCE_ABSOLUTE_TESTS,

209 )

210

211 def test_domain_range_scale_log_decoding_ACESproxy(self) -> None:

212 """

213 Test :func:`colour.models.rgb.transfer_functions.aces.\

214 log_decoding_ACESproxy` definition domain and range scale support.

215 """

216

217 ACESproxy = 426.0

218 lin_AP1 = log_decoding_ACESproxy(ACESproxy)

219

220 d_r = (("reference", 1), ("1", 1), ("100", 100))

221 for scale, factor in d_r:

222 with domain_range_scale(scale):

223 np.testing.assert_allclose(

224 log_decoding_ACESproxy(ACESproxy * factor),

225 lin_AP1 * factor,

226 atol=TOLERANCE_ABSOLUTE_TESTS,

227 )

228

229 @ignore_numpy_errors

230 def test_nan_log_decoding_ACESproxy(self) -> None:

231 """

232 Test :func:`colour.models.rgb.transfer_functions.aces.\

233 log_decoding_ACESproxy` definition nan support.

234 """

235

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

237

238

239 class TestLogEncoding_ACEScc:

240 """

241 Define :func:`colour.models.rgb.transfer_functions.aces.\

242 log_encoding_ACEScc` definition unit tests methods.

243 """

244

245 def test_log_encoding_ACEScc(self) -> None:

246 """

247 Test :func:`colour.models.rgb.transfer_functions.aces.\

248 log_encoding_ACEScc` definition.

249 """

250

251 np.testing.assert_allclose(

252 log_encoding_ACEScc(0.0),

253 -0.358447488584475,

254 atol=TOLERANCE_ABSOLUTE_TESTS,

255 )

256

257 np.testing.assert_allclose(

258 log_encoding_ACEScc(0.18),

259 0.413588402492442,

260 atol=TOLERANCE_ABSOLUTE_TESTS,

261 )

262

263 np.testing.assert_allclose(

264 log_encoding_ACEScc(1.0),

265 0.554794520547945,

266 atol=TOLERANCE_ABSOLUTE_TESTS,

267 )

268

269 def test_n_dimensional_log_encoding_ACEScc(self) -> None:

270 """

271 Test :func:`colour.models.rgb.transfer_functions.aces.\

272 log_encoding_ACEScc` definition n-dimensional arrays support.

273 """

274

275 lin_AP1 = 0.18

276 ACEScc = log_encoding_ACEScc(lin_AP1)

277

278 lin_AP1 = np.tile(lin_AP1, 6)

279 ACEScc = np.tile(ACEScc, 6)

280 np.testing.assert_allclose(

281 log_encoding_ACEScc(lin_AP1), ACEScc, atol=TOLERANCE_ABSOLUTE_TESTS

282 )

283

284 lin_AP1 = np.reshape(lin_AP1, (2, 3))

285 ACEScc = np.reshape(ACEScc, (2, 3))

286 np.testing.assert_allclose(

287 log_encoding_ACEScc(lin_AP1), ACEScc, atol=TOLERANCE_ABSOLUTE_TESTS

288 )

289

290 lin_AP1 = np.reshape(lin_AP1, (2, 3, 1))

291 ACEScc = np.reshape(ACEScc, (2, 3, 1))

292 np.testing.assert_allclose(

293 log_encoding_ACEScc(lin_AP1), ACEScc, atol=TOLERANCE_ABSOLUTE_TESTS

294 )

295

296 def test_domain_range_scale_log_encoding_ACEScc(self) -> None:

297 """

298 Test :func:`colour.models.rgb.transfer_functions.aces.\

299 log_encoding_ACEScc` definition domain and range scale support.

300 """

301

302 lin_AP1 = 0.18

303 ACEScc = log_encoding_ACEScc(lin_AP1)

304

305 d_r = (("reference", 1), ("1", 1), ("100", 100))

306 for scale, factor in d_r:

307 with domain_range_scale(scale):

308 np.testing.assert_allclose(

309 log_encoding_ACEScc(lin_AP1 * factor),

310 ACEScc * factor,

311 atol=TOLERANCE_ABSOLUTE_TESTS,

312 )

313

314 @ignore_numpy_errors

315 def test_nan_log_encoding_ACEScc(self) -> None:

316 """

317 Test :func:`colour.models.rgb.transfer_functions.aces.\

318 log_encoding_ACEScc` definition nan support.

319 """

320

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

322

323

324 class TestLogDecoding_ACEScc:

325 """

326 Define :func:`colour.models.rgb.transfer_functions.aces.\

327 log_decoding_ACEScc` definition unit tests methods.

328 """

329

330 def test_log_decoding_ACEScc(self) -> None:

331 """

332 Test :func:`colour.models.rgb.transfer_functions.aces.\

333 log_decoding_ACEScc` definition.

334 """

335

336 np.testing.assert_allclose(

337 log_decoding_ACEScc(-0.358447488584475),

338 0.0,

339 atol=TOLERANCE_ABSOLUTE_TESTS,

340 )

341

342 np.testing.assert_allclose(

343 log_decoding_ACEScc(0.413588402492442),

344 0.18,

345 atol=TOLERANCE_ABSOLUTE_TESTS,

346 )

347

348 np.testing.assert_allclose(

349 log_decoding_ACEScc(0.554794520547945),

350 1.0,

351 atol=TOLERANCE_ABSOLUTE_TESTS,

352 )

353

354 def test_n_dimensional_log_decoding_ACEScc(self) -> None:

355 """

356 Test :func:`colour.models.rgb.transfer_functions.aces.\

357 log_decoding_ACEScc` definition n-dimensional arrays support.

358 """

359

360 ACEScc = 0.413588402492442

361 lin_AP1 = log_decoding_ACEScc(ACEScc)

362

363 ACEScc = np.tile(ACEScc, 6)

364 lin_AP1 = np.tile(lin_AP1, 6)

365 np.testing.assert_allclose(

366 log_decoding_ACEScc(ACEScc), lin_AP1, atol=TOLERANCE_ABSOLUTE_TESTS

367 )

368

369 ACEScc = np.reshape(ACEScc, (2, 3))

370 lin_AP1 = np.reshape(lin_AP1, (2, 3))

371 np.testing.assert_allclose(

372 log_decoding_ACEScc(ACEScc), lin_AP1, atol=TOLERANCE_ABSOLUTE_TESTS

373 )

374

375 ACEScc = np.reshape(ACEScc, (2, 3, 1))

376 lin_AP1 = np.reshape(lin_AP1, (2, 3, 1))

377 np.testing.assert_allclose(

378 log_decoding_ACEScc(ACEScc), lin_AP1, atol=TOLERANCE_ABSOLUTE_TESTS

379 )

380

381 def test_domain_range_scale_log_decoding_ACEScc(self) -> None:

382 """

383 Test :func:`colour.models.rgb.transfer_functions.aces.\

384 log_decoding_ACEScc` definition domain and range scale support.

385 """

386

387 ACEScc = 0.413588402492442

388 lin_AP1 = log_decoding_ACEScc(ACEScc)

389

390 d_r = (("reference", 1), ("1", 1), ("100", 100))

391 for scale, factor in d_r:

392 with domain_range_scale(scale):

393 np.testing.assert_allclose(

394 log_decoding_ACEScc(ACEScc * factor),

395 lin_AP1 * factor,

396 atol=TOLERANCE_ABSOLUTE_TESTS,

397 )

398

399 @ignore_numpy_errors

400 def test_nan_log_decoding_ACEScc(self) -> None:

401 """

402 Test :func:`colour.models.rgb.transfer_functions.aces.\

403 log_decoding_ACEScc` definition nan support.

404 """

405

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

407

408

409 class TestLogEncoding_ACEScct:

410 """

411 Define :func:`colour.models.rgb.transfer_functions.aces.\

412 log_encoding_ACEScct` definition unit tests methods.

413 """

414

415 def test_log_encoding_ACEScct(self) -> None:

416 """

417 Test :func:`colour.models.rgb.transfer_functions.aces.\

418 log_encoding_ACEScct` definition.

419 """

420

421 np.testing.assert_allclose(

422 log_encoding_ACEScct(0.0),

423 0.072905534195835495,

424 atol=TOLERANCE_ABSOLUTE_TESTS,

425 )

426

427 np.testing.assert_allclose(

428 log_encoding_ACEScct(0.18),

429 0.413588402492442,

430 atol=TOLERANCE_ABSOLUTE_TESTS,

431 )

432

433 np.testing.assert_allclose(

434 log_encoding_ACEScct(1.0),

435 0.554794520547945,

436 atol=TOLERANCE_ABSOLUTE_TESTS,

437 )

438

439 def test_n_dimensional_log_encoding_ACEScct(self) -> None:

440 """

441 Test :func:`colour.models.rgb.transfer_functions.aces.\

442 log_encoding_ACEScct` definition n-dimensional arrays support.

443 """

444

445 lin_AP1 = 0.18

446 ACEScct = log_encoding_ACEScct(lin_AP1)

447

448 lin_AP1 = np.tile(lin_AP1, 6)

449 ACEScct = np.tile(ACEScct, 6)

450 np.testing.assert_allclose(

451 log_encoding_ACEScct(lin_AP1),

452 ACEScct,

453 atol=TOLERANCE_ABSOLUTE_TESTS,

454 )

455

456 lin_AP1 = np.reshape(lin_AP1, (2, 3))

457 ACEScct = np.reshape(ACEScct, (2, 3))

458 np.testing.assert_allclose(

459 log_encoding_ACEScct(lin_AP1),

460 ACEScct,

461 atol=TOLERANCE_ABSOLUTE_TESTS,

462 )

463

464 lin_AP1 = np.reshape(lin_AP1, (2, 3, 1))

465 ACEScct = np.reshape(ACEScct, (2, 3, 1))

466 np.testing.assert_allclose(

467 log_encoding_ACEScct(lin_AP1),

468 ACEScct,

469 atol=TOLERANCE_ABSOLUTE_TESTS,

470 )

471

472 def test_domain_range_scale_log_encoding_ACEScct(self) -> None:

473 """

474 Test :func:`colour.models.rgb.transfer_functions.aces.\

475 log_encoding_ACEScct` definition domain and range scale support.

476 """

477

478 lin_AP1 = 0.18

479 ACEScct = log_encoding_ACEScct(lin_AP1)

480

481 d_r = (("reference", 1), ("1", 1), ("100", 100))

482 for scale, factor in d_r:

483 with domain_range_scale(scale):

484 np.testing.assert_allclose(

485 log_encoding_ACEScct(lin_AP1 * factor),

486 ACEScct * factor,

487 atol=TOLERANCE_ABSOLUTE_TESTS,

488 )

489

490 def test_ACEScc_equivalency_log_encoding_ACEScct(self) -> None:

491 """

492 Test :func:`colour.models.rgb.transfer_functions.aces.\

493 log_encoding_ACEScct` definition ACEScc equivalency, and explicit requirement

494 specified by AMPAS ACES specification S-2016-001

495 (https://github.com/ampas/aces-dev/blob/v1.0.3/documents/LaTeX/\

496 S-2016-001/introduction.tex#L14)

497 """

498

499 equiv = np.linspace(0.0078125, 222.86094420380761, 100)

500 np.testing.assert_allclose(

501 log_encoding_ACEScct(equiv),

502 log_encoding_ACEScc(equiv),

503 atol=TOLERANCE_ABSOLUTE_TESTS,

504 )

505

506 @ignore_numpy_errors

507 def test_nan_log_encoding_ACEScct(self) -> None:

508 """

509 Test :func:`colour.models.rgb.transfer_functions.aces.\

510 log_encoding_ACEScct` definition nan support.

511 """

512

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

514

515

516 class TestLogDecoding_ACEScct:

517 """

518 Define :func:`colour.models.rgb.transfer_functions.aces.\

519 log_decoding_ACEScct` definition unit tests methods.

520 """

521

522 def test_log_decoding_ACEScct(self) -> None:

523 """

524 Test :func:`colour.models.rgb.transfer_functions.aces.\

525 log_decoding_ACEScct` definition.

526 """

527

528 np.testing.assert_allclose(

529 log_decoding_ACEScct(0.072905534195835495),

530 0.0,

531 atol=TOLERANCE_ABSOLUTE_TESTS,

532 )

533

534 np.testing.assert_allclose(

535 log_decoding_ACEScct(0.41358840249244228),

536 0.18,

537 atol=TOLERANCE_ABSOLUTE_TESTS,

538 )

539

540 np.testing.assert_allclose(

541 log_decoding_ACEScct(0.554794520547945),

542 1.0,

543 atol=TOLERANCE_ABSOLUTE_TESTS,

544 )

545

546 def test_n_dimensional_log_decoding_ACEScct(self) -> None:

547 """

548 Test :func:`colour.models.rgb.transfer_functions.aces.\

549 log_decoding_ACEScct` definition n-dimensional arrays support.

550 """

551

552 ACEScct = 0.413588402492442

553 lin_AP1 = log_decoding_ACEScct(ACEScct)

554

555 ACEScct = np.tile(ACEScct, 6)

556 lin_AP1 = np.tile(lin_AP1, 6)

557 np.testing.assert_allclose(

558 log_decoding_ACEScct(ACEScct),

559 lin_AP1,

560 atol=TOLERANCE_ABSOLUTE_TESTS,

561 )

562

563 ACEScct = np.reshape(ACEScct, (2, 3))

564 lin_AP1 = np.reshape(lin_AP1, (2, 3))

565 np.testing.assert_allclose(

566 log_decoding_ACEScct(ACEScct),

567 lin_AP1,

568 atol=TOLERANCE_ABSOLUTE_TESTS,

569 )

570

571 ACEScct = np.reshape(ACEScct, (2, 3, 1))

572 lin_AP1 = np.reshape(lin_AP1, (2, 3, 1))

573 np.testing.assert_allclose(

574 log_decoding_ACEScct(ACEScct),

575 lin_AP1,

576 atol=TOLERANCE_ABSOLUTE_TESTS,

577 )

578

579 def test_domain_range_scale_log_decoding_ACEScct(self) -> None:

580 """

581 Test :func:`colour.models.rgb.transfer_functions.aces.\

582 log_decoding_ACEScct` definition domain and range scale support.

583 """

584

585 ACEScc = 0.413588402492442

586 lin_AP1 = log_decoding_ACEScct(ACEScc)

587

588 d_r = (("reference", 1), ("1", 1), ("100", 100))

589 for scale, factor in d_r:

590 with domain_range_scale(scale):

591 np.testing.assert_allclose(

592 log_decoding_ACEScct(ACEScc * factor),

593 lin_AP1 * factor,

594 atol=TOLERANCE_ABSOLUTE_TESTS,

595 )

596

597 def test_ACEScc_equivalency_log_decoding_ACEScct(self) -> None:

598 """

599 Test :func:`colour.models.rgb.transfer_functions.aces.\

600 log_decoding_ACEScct` definition ACEScc equivalency, and explicit requirement

601 specified by AMPAS ACES specification S-2016-001

602 (https://github.com/ampas/aces-dev/blob/v1.0.3/documents/LaTeX/\

603 S-2016-001/introduction.tex#L14)

604 """

605

606 equiv = np.linspace(0.15525114155251146, 1.0, 100)

607 np.testing.assert_allclose(

608 log_decoding_ACEScct(equiv),

609 log_decoding_ACEScc(equiv),

610 atol=TOLERANCE_ABSOLUTE_TESTS,

611 )

612

613 @ignore_numpy_errors

614 def test_nan_log_decoding_ACEScct(self) -> None:

615 """

616 Test :func:`colour.models.rgb.transfer_functions.aces.\

617 log_decoding_ACEScct` definition nan support.

618 """

619

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