Coverage for models/rgb/transfer_functions/tests/test_aces.py: 100%
183 statements
« prev ^ index » next coverage.py v7.11.0, created at 2025-11-16 22:49 +1300
« prev ^ index » next coverage.py v7.11.0, created at 2025-11-16 22:49 +1300
1"""
2Define the unit tests for the :mod:`colour.models.rgb.transfer_functions.aces`
3module.
4"""
6import numpy as np
8from colour.constants import TOLERANCE_ABSOLUTE_TESTS
9from 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)
17from colour.utilities import domain_range_scale, ignore_numpy_errors
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"
26__all__ = [
27 "TestLogEncoding_ACESproxy",
28 "TestLogDecoding_ACESproxy",
29 "TestLogEncoding_ACEScc",
30 "TestLogDecoding_ACEScc",
31 "TestLogDecoding_ACEScct",
32]
35class TestLogEncoding_ACESproxy:
36 """
37 Define :func:`colour.models.rgb.transfer_functions.aces.\
38log_encoding_ACESproxy`
39 definition unit tests methods.
40 """
42 def test_log_encoding_ACESproxy(self) -> None:
43 """
44 Test :func:`colour.models.rgb.transfer_functions.aces.\
45log_encoding_ACESproxy` definition.
46 """
48 np.testing.assert_allclose(
49 log_encoding_ACESproxy(0.0),
50 0.062561094819159,
51 atol=TOLERANCE_ABSOLUTE_TESTS,
52 )
54 np.testing.assert_allclose(
55 log_encoding_ACESproxy(0.18),
56 0.416422287390029,
57 atol=TOLERANCE_ABSOLUTE_TESTS,
58 )
60 np.testing.assert_allclose(
61 log_encoding_ACESproxy(0.18, 12),
62 0.416361416361416,
63 atol=TOLERANCE_ABSOLUTE_TESTS,
64 )
66 np.testing.assert_allclose(
67 log_encoding_ACESproxy(1.0),
68 0.537634408602151,
69 atol=TOLERANCE_ABSOLUTE_TESTS,
70 )
72 assert log_encoding_ACESproxy(0.18, out_int=True) == 426
74 def test_n_dimensional_log_encoding_ACESproxy(self) -> None:
75 """
76 Test :func:`colour.models.rgb.transfer_functions.aces.\
77log_encoding_ACESproxy` definition n-dimensional arrays support.
78 """
80 lin_AP1 = 0.18
81 ACESproxy = log_encoding_ACESproxy(lin_AP1)
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 )
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 )
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 )
107 def test_domain_range_scale_log_encoding_ACESproxy(self) -> None:
108 """
109 Test :func:`colour.models.rgb.transfer_functions.aces.\
110log_encoding_ACESproxy` definition domain and range scale support.
111 """
113 lin_AP1 = 0.18
114 ACESproxy = log_encoding_ACESproxy(lin_AP1)
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 )
125 @ignore_numpy_errors
126 def test_nan_log_encoding_ACESproxy(self) -> None:
127 """
128 Test :func:`colour.models.rgb.transfer_functions.aces.\
129log_encoding_ACESproxy` definition nan support.
130 """
132 log_encoding_ACESproxy(np.array([-1.0, 0.0, 1.0, -np.inf, np.inf, np.nan]))
135class TestLogDecoding_ACESproxy:
136 """
137 Define :func:`colour.models.rgb.transfer_functions.aces.\
138log_decoding_ACESproxy`
139 definition unit tests methods.
140 """
142 def test_log_decoding_ACESproxy(self) -> None:
143 """
144 Test :func:`colour.models.rgb.transfer_functions.aces.\
145log_decoding_ACESproxy` definition.
146 """
148 np.testing.assert_allclose(
149 log_decoding_ACESproxy(0.062561094819159),
150 0.0,
151 atol=0.01,
152 )
154 np.testing.assert_allclose(
155 log_decoding_ACESproxy(0.416422287390029),
156 0.18,
157 atol=0.01,
158 )
160 np.testing.assert_allclose(
161 log_decoding_ACESproxy(0.416361416361416, 12),
162 0.18,
163 atol=0.01,
164 )
166 np.testing.assert_allclose(
167 log_decoding_ACESproxy(0.537634408602151),
168 1.0,
169 atol=0.01,
170 )
172 np.testing.assert_allclose(
173 log_decoding_ACESproxy(426, in_int=True),
174 0.18,
175 atol=0.01,
176 )
178 def test_n_dimensional_log_decoding_ACESproxy(self) -> None:
179 """
180 Test :func:`colour.models.rgb.transfer_functions.aces.\
181log_decoding_ACESproxy` definition n-dimensional arrays support.
182 """
184 ACESproxy = 0.416422287390029
185 lin_AP1 = log_decoding_ACESproxy(ACESproxy)
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 )
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 )
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 )
211 def test_domain_range_scale_log_decoding_ACESproxy(self) -> None:
212 """
213 Test :func:`colour.models.rgb.transfer_functions.aces.\
214log_decoding_ACESproxy` definition domain and range scale support.
215 """
217 ACESproxy = 426.0
218 lin_AP1 = log_decoding_ACESproxy(ACESproxy)
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 )
229 @ignore_numpy_errors
230 def test_nan_log_decoding_ACESproxy(self) -> None:
231 """
232 Test :func:`colour.models.rgb.transfer_functions.aces.\
233log_decoding_ACESproxy` definition nan support.
234 """
236 log_decoding_ACESproxy(np.array([-1.0, 0.0, 1.0, -np.inf, np.inf, np.nan]))
239class TestLogEncoding_ACEScc:
240 """
241 Define :func:`colour.models.rgb.transfer_functions.aces.\
242log_encoding_ACEScc` definition unit tests methods.
243 """
245 def test_log_encoding_ACEScc(self) -> None:
246 """
247 Test :func:`colour.models.rgb.transfer_functions.aces.\
248log_encoding_ACEScc` definition.
249 """
251 np.testing.assert_allclose(
252 log_encoding_ACEScc(0.0),
253 -0.358447488584475,
254 atol=TOLERANCE_ABSOLUTE_TESTS,
255 )
257 np.testing.assert_allclose(
258 log_encoding_ACEScc(0.18),
259 0.413588402492442,
260 atol=TOLERANCE_ABSOLUTE_TESTS,
261 )
263 np.testing.assert_allclose(
264 log_encoding_ACEScc(1.0),
265 0.554794520547945,
266 atol=TOLERANCE_ABSOLUTE_TESTS,
267 )
269 def test_n_dimensional_log_encoding_ACEScc(self) -> None:
270 """
271 Test :func:`colour.models.rgb.transfer_functions.aces.\
272log_encoding_ACEScc` definition n-dimensional arrays support.
273 """
275 lin_AP1 = 0.18
276 ACEScc = log_encoding_ACEScc(lin_AP1)
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 )
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 )
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 )
296 def test_domain_range_scale_log_encoding_ACEScc(self) -> None:
297 """
298 Test :func:`colour.models.rgb.transfer_functions.aces.\
299log_encoding_ACEScc` definition domain and range scale support.
300 """
302 lin_AP1 = 0.18
303 ACEScc = log_encoding_ACEScc(lin_AP1)
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 )
314 @ignore_numpy_errors
315 def test_nan_log_encoding_ACEScc(self) -> None:
316 """
317 Test :func:`colour.models.rgb.transfer_functions.aces.\
318log_encoding_ACEScc` definition nan support.
319 """
321 log_encoding_ACEScc(np.array([-1.0, 0.0, 1.0, -np.inf, np.inf, np.nan]))
324class TestLogDecoding_ACEScc:
325 """
326 Define :func:`colour.models.rgb.transfer_functions.aces.\
327log_decoding_ACEScc` definition unit tests methods.
328 """
330 def test_log_decoding_ACEScc(self) -> None:
331 """
332 Test :func:`colour.models.rgb.transfer_functions.aces.\
333log_decoding_ACEScc` definition.
334 """
336 np.testing.assert_allclose(
337 log_decoding_ACEScc(-0.358447488584475),
338 0.0,
339 atol=TOLERANCE_ABSOLUTE_TESTS,
340 )
342 np.testing.assert_allclose(
343 log_decoding_ACEScc(0.413588402492442),
344 0.18,
345 atol=TOLERANCE_ABSOLUTE_TESTS,
346 )
348 np.testing.assert_allclose(
349 log_decoding_ACEScc(0.554794520547945),
350 1.0,
351 atol=TOLERANCE_ABSOLUTE_TESTS,
352 )
354 def test_n_dimensional_log_decoding_ACEScc(self) -> None:
355 """
356 Test :func:`colour.models.rgb.transfer_functions.aces.\
357log_decoding_ACEScc` definition n-dimensional arrays support.
358 """
360 ACEScc = 0.413588402492442
361 lin_AP1 = log_decoding_ACEScc(ACEScc)
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 )
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 )
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 )
381 def test_domain_range_scale_log_decoding_ACEScc(self) -> None:
382 """
383 Test :func:`colour.models.rgb.transfer_functions.aces.\
384log_decoding_ACEScc` definition domain and range scale support.
385 """
387 ACEScc = 0.413588402492442
388 lin_AP1 = log_decoding_ACEScc(ACEScc)
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 )
399 @ignore_numpy_errors
400 def test_nan_log_decoding_ACEScc(self) -> None:
401 """
402 Test :func:`colour.models.rgb.transfer_functions.aces.\
403log_decoding_ACEScc` definition nan support.
404 """
406 log_decoding_ACEScc(np.array([-1.0, 0.0, 1.0, -np.inf, np.inf, np.nan]))
409class TestLogEncoding_ACEScct:
410 """
411 Define :func:`colour.models.rgb.transfer_functions.aces.\
412log_encoding_ACEScct` definition unit tests methods.
413 """
415 def test_log_encoding_ACEScct(self) -> None:
416 """
417 Test :func:`colour.models.rgb.transfer_functions.aces.\
418log_encoding_ACEScct` definition.
419 """
421 np.testing.assert_allclose(
422 log_encoding_ACEScct(0.0),
423 0.072905534195835495,
424 atol=TOLERANCE_ABSOLUTE_TESTS,
425 )
427 np.testing.assert_allclose(
428 log_encoding_ACEScct(0.18),
429 0.413588402492442,
430 atol=TOLERANCE_ABSOLUTE_TESTS,
431 )
433 np.testing.assert_allclose(
434 log_encoding_ACEScct(1.0),
435 0.554794520547945,
436 atol=TOLERANCE_ABSOLUTE_TESTS,
437 )
439 def test_n_dimensional_log_encoding_ACEScct(self) -> None:
440 """
441 Test :func:`colour.models.rgb.transfer_functions.aces.\
442log_encoding_ACEScct` definition n-dimensional arrays support.
443 """
445 lin_AP1 = 0.18
446 ACEScct = log_encoding_ACEScct(lin_AP1)
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 )
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 )
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 )
472 def test_domain_range_scale_log_encoding_ACEScct(self) -> None:
473 """
474 Test :func:`colour.models.rgb.transfer_functions.aces.\
475log_encoding_ACEScct` definition domain and range scale support.
476 """
478 lin_AP1 = 0.18
479 ACEScct = log_encoding_ACEScct(lin_AP1)
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 )
490 def test_ACEScc_equivalency_log_encoding_ACEScct(self) -> None:
491 """
492 Test :func:`colour.models.rgb.transfer_functions.aces.\
493log_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/\
496S-2016-001/introduction.tex#L14)
497 """
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 )
506 @ignore_numpy_errors
507 def test_nan_log_encoding_ACEScct(self) -> None:
508 """
509 Test :func:`colour.models.rgb.transfer_functions.aces.\
510log_encoding_ACEScct` definition nan support.
511 """
513 log_encoding_ACEScct(np.array([-1.0, 0.0, 1.0, -np.inf, np.inf, np.nan]))
516class TestLogDecoding_ACEScct:
517 """
518 Define :func:`colour.models.rgb.transfer_functions.aces.\
519log_decoding_ACEScct` definition unit tests methods.
520 """
522 def test_log_decoding_ACEScct(self) -> None:
523 """
524 Test :func:`colour.models.rgb.transfer_functions.aces.\
525log_decoding_ACEScct` definition.
526 """
528 np.testing.assert_allclose(
529 log_decoding_ACEScct(0.072905534195835495),
530 0.0,
531 atol=TOLERANCE_ABSOLUTE_TESTS,
532 )
534 np.testing.assert_allclose(
535 log_decoding_ACEScct(0.41358840249244228),
536 0.18,
537 atol=TOLERANCE_ABSOLUTE_TESTS,
538 )
540 np.testing.assert_allclose(
541 log_decoding_ACEScct(0.554794520547945),
542 1.0,
543 atol=TOLERANCE_ABSOLUTE_TESTS,
544 )
546 def test_n_dimensional_log_decoding_ACEScct(self) -> None:
547 """
548 Test :func:`colour.models.rgb.transfer_functions.aces.\
549log_decoding_ACEScct` definition n-dimensional arrays support.
550 """
552 ACEScct = 0.413588402492442
553 lin_AP1 = log_decoding_ACEScct(ACEScct)
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 )
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 )
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 )
579 def test_domain_range_scale_log_decoding_ACEScct(self) -> None:
580 """
581 Test :func:`colour.models.rgb.transfer_functions.aces.\
582log_decoding_ACEScct` definition domain and range scale support.
583 """
585 ACEScc = 0.413588402492442
586 lin_AP1 = log_decoding_ACEScct(ACEScc)
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 )
597 def test_ACEScc_equivalency_log_decoding_ACEScct(self) -> None:
598 """
599 Test :func:`colour.models.rgb.transfer_functions.aces.\
600log_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/\
603S-2016-001/introduction.tex#L14)
604 """
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 )
613 @ignore_numpy_errors
614 def test_nan_log_decoding_ACEScct(self) -> None:
615 """
616 Test :func:`colour.models.rgb.transfer_functions.aces.\
617log_decoding_ACEScct` definition nan support.
618 """
620 log_decoding_ACEScct(np.array([-1.0, 0.0, 1.0, -np.inf, np.inf, np.nan]))