Coverage for models/rgb/transfer_functions/tests/test_gopro.py: 100%
65 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
3:mod:`colour.models.rgb.transfer_functions.gopro` module.
4"""
6import numpy as np
8from colour.constants import TOLERANCE_ABSOLUTE_TESTS
9from colour.models.rgb.transfer_functions import (
10 log_decoding_Protune,
11 log_encoding_Protune,
12)
13from colour.utilities import domain_range_scale, ignore_numpy_errors
15__author__ = "Colour Developers"
16__copyright__ = "Copyright 2013 Colour Developers"
17__license__ = "BSD-3-Clause - https://opensource.org/licenses/BSD-3-Clause"
18__maintainer__ = "Colour Developers"
19__email__ = "colour-developers@colour-science.org"
20__status__ = "Production"
22__all__ = [
23 "TestLogEncoding_Protune",
24 "TestLogDecoding_Protune",
25]
28class TestLogEncoding_Protune:
29 """
30 Define :func:`colour.models.rgb.transfer_functions.gopro.\
31log_encoding_Protune` definition unit tests methods.
32 """
34 def test_log_encoding_Protune(self) -> None:
35 """
36 Test :func:`colour.models.rgb.transfer_functions.gopro.\
37log_encoding_Protune` definition.
38 """
40 np.testing.assert_allclose(
41 log_encoding_Protune(0.0), 0.0, atol=TOLERANCE_ABSOLUTE_TESTS
42 )
44 np.testing.assert_allclose(
45 log_encoding_Protune(0.18),
46 0.645623486803636,
47 atol=TOLERANCE_ABSOLUTE_TESTS,
48 )
50 np.testing.assert_allclose(
51 log_encoding_Protune(1.0), 1.0, atol=TOLERANCE_ABSOLUTE_TESTS
52 )
54 def test_n_dimensional_log_encoding_Protune(self) -> None:
55 """
56 Test :func:`colour.models.rgb.transfer_functions.gopro.\
57log_encoding_Protune` definition n-dimensional arrays support.
58 """
60 x = 0.18
61 y = log_encoding_Protune(x)
63 x = np.tile(x, 6)
64 y = np.tile(y, 6)
65 np.testing.assert_allclose(
66 log_encoding_Protune(x), y, atol=TOLERANCE_ABSOLUTE_TESTS
67 )
69 x = np.reshape(x, (2, 3))
70 y = np.reshape(y, (2, 3))
71 np.testing.assert_allclose(
72 log_encoding_Protune(x), y, atol=TOLERANCE_ABSOLUTE_TESTS
73 )
75 x = np.reshape(x, (2, 3, 1))
76 y = np.reshape(y, (2, 3, 1))
77 np.testing.assert_allclose(
78 log_encoding_Protune(x), y, atol=TOLERANCE_ABSOLUTE_TESTS
79 )
81 def test_domain_range_scale_log_encoding_Protune(self) -> None:
82 """
83 Test :func:`colour.models.rgb.transfer_functions.gopro.\
84log_encoding_Protune` definition domain and range scale support.
85 """
87 x = 0.18
88 y = log_encoding_Protune(x)
90 d_r = (("reference", 1), ("1", 1), ("100", 100))
91 for scale, factor in d_r:
92 with domain_range_scale(scale):
93 np.testing.assert_allclose(
94 log_encoding_Protune(x * factor),
95 y * factor,
96 atol=TOLERANCE_ABSOLUTE_TESTS,
97 )
99 @ignore_numpy_errors
100 def test_nan_log_encoding_Protune(self) -> None:
101 """
102 Test :func:`colour.models.rgb.transfer_functions.gopro.\
103log_encoding_Protune` definition nan support.
104 """
106 log_encoding_Protune(np.array([-1.0, 0.0, 1.0, -np.inf, np.inf, np.nan]))
109class TestLogDecoding_Protune:
110 """
111 Define :func:`colour.models.rgb.transfer_functions.gopro.\
112log_decoding_Protune` definition unit tests methods.
113 """
115 def test_log_decoding_Protune(self) -> None:
116 """
117 Test :func:`colour.models.rgb.transfer_functions.gopro.\
118log_decoding_Protune` definition.
119 """
121 np.testing.assert_allclose(
122 log_decoding_Protune(0.0), 0.0, atol=TOLERANCE_ABSOLUTE_TESTS
123 )
125 np.testing.assert_allclose(
126 log_decoding_Protune(0.645623486803636),
127 0.18,
128 atol=TOLERANCE_ABSOLUTE_TESTS,
129 )
131 np.testing.assert_allclose(
132 log_decoding_Protune(1.0), 1.0, atol=TOLERANCE_ABSOLUTE_TESTS
133 )
135 def test_n_dimensional_log_decoding_Protune(self) -> None:
136 """
137 Test :func:`colour.models.rgb.transfer_functions.gopro.\
138log_decoding_Protune` definition n-dimensional arrays support.
139 """
141 y = 0.645623486803636
142 x = log_decoding_Protune(y)
144 y = np.tile(y, 6)
145 x = np.tile(x, 6)
146 np.testing.assert_allclose(
147 log_decoding_Protune(y), x, atol=TOLERANCE_ABSOLUTE_TESTS
148 )
150 y = np.reshape(y, (2, 3))
151 x = np.reshape(x, (2, 3))
152 np.testing.assert_allclose(
153 log_decoding_Protune(y), x, atol=TOLERANCE_ABSOLUTE_TESTS
154 )
156 y = np.reshape(y, (2, 3, 1))
157 x = np.reshape(x, (2, 3, 1))
158 np.testing.assert_allclose(
159 log_decoding_Protune(y), x, atol=TOLERANCE_ABSOLUTE_TESTS
160 )
162 def test_domain_range_scale_log_decoding_Protune(self) -> None:
163 """
164 Test :func:`colour.models.rgb.transfer_functions.gopro.\
165log_decoding_Protune` definition domain and range scale support.
166 """
168 y = 0.645623486803636
169 x = log_decoding_Protune(y)
171 d_r = (("reference", 1), ("1", 1), ("100", 100))
172 for scale, factor in d_r:
173 with domain_range_scale(scale):
174 np.testing.assert_allclose(
175 log_decoding_Protune(y * factor),
176 x * factor,
177 atol=TOLERANCE_ABSOLUTE_TESTS,
178 )
180 @ignore_numpy_errors
181 def test_nan_log_decoding_Protune(self) -> None:
182 """
183 Test :func:`colour.models.rgb.transfer_functions.gopro.\
184log_decoding_Protune` definition nan support.
185 """
187 log_decoding_Protune(np.array([-1.0, 0.0, 1.0, -np.inf, np.inf, np.nan]))