Coverage for colorimetry/tests/test_yellowness.py: 100%
103 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"""Define the unit tests for the :mod:`colour.colorimetry.yellowness` module."""
3from __future__ import annotations
5from itertools import product
7import numpy as np
9from colour.colorimetry import (
10 yellowness_ASTMD1925,
11 yellowness_ASTME313,
12 yellowness_ASTME313_alternative,
13)
14from colour.colorimetry.yellowness import YELLOWNESS_COEFFICIENTS_ASTME313, yellowness
15from colour.constants import TOLERANCE_ABSOLUTE_TESTS
16from colour.utilities import domain_range_scale, ignore_numpy_errors
18__author__ = "Colour Developers"
19__copyright__ = "Copyright 2013 Colour Developers"
20__license__ = "BSD-3-Clause - https://opensource.org/licenses/BSD-3-Clause"
21__maintainer__ = "Colour Developers"
22__email__ = "colour-developers@colour-science.org"
23__status__ = "Production"
25__all__ = [
26 "TestYellownessASTMD1925",
27 "TestYellownessASTM313Alternative",
28 "TestYellownessASTM313",
29 "TestYellowness",
30]
33class TestYellownessASTMD1925:
34 """
35 Define :func:`colour.colorimetry.yellowness.yellowness_ASTMD1925`
36 definition unit tests methods.
37 """
39 def test_yellowness_ASTMD1925(self) -> None:
40 """
41 Test :func:`colour.colorimetry.yellowness.yellowness_ASTMD1925`
42 definition.
43 """
45 np.testing.assert_allclose(
46 yellowness_ASTMD1925(np.array([95.00000000, 100.00000000, 105.00000000])),
47 10.299999999999997,
48 atol=TOLERANCE_ABSOLUTE_TESTS,
49 )
51 np.testing.assert_allclose(
52 yellowness_ASTMD1925(np.array([105.00000000, 100.00000000, 95.00000000])),
53 33.700000000000003,
54 atol=TOLERANCE_ABSOLUTE_TESTS,
55 )
57 np.testing.assert_allclose(
58 yellowness_ASTMD1925(np.array([100.00000000, 100.00000000, 100.00000000])),
59 22.0,
60 atol=TOLERANCE_ABSOLUTE_TESTS,
61 )
63 def test_n_dimensional_yellowness_ASTMD1925(self) -> None:
64 """
65 Test :func:`colour.colorimetry.yellowness.yellowness_ASTMD1925`
66 definition n_dimensional arrays support.
67 """
69 XYZ = np.array([95.00000000, 100.00000000, 105.00000000])
70 YI = yellowness_ASTMD1925(XYZ)
72 XYZ = np.tile(XYZ, (6, 1))
73 YI = np.tile(YI, 6)
74 np.testing.assert_allclose(
75 yellowness_ASTMD1925(XYZ), YI, atol=TOLERANCE_ABSOLUTE_TESTS
76 )
78 XYZ = np.reshape(XYZ, (2, 3, 3))
79 YI = np.reshape(YI, (2, 3))
80 np.testing.assert_allclose(
81 yellowness_ASTMD1925(XYZ), YI, atol=TOLERANCE_ABSOLUTE_TESTS
82 )
84 def test_domain_range_scale_yellowness_ASTMD1925(self) -> None:
85 """
86 Test :func:`colour.colorimetry.yellowness.yellowness_ASTMD1925`
87 definition domain and range scale support.
88 """
90 XYZ = np.array([95.00000000, 100.00000000, 105.00000000])
91 YI = 10.299999999999997
93 d_r = (("reference", 1), ("1", 0.01), ("100", 1))
94 for scale, factor in d_r:
95 with domain_range_scale(scale):
96 np.testing.assert_allclose(
97 yellowness_ASTMD1925(XYZ * factor),
98 YI * factor,
99 atol=TOLERANCE_ABSOLUTE_TESTS,
100 )
102 @ignore_numpy_errors
103 def test_nan_yellowness_ASTMD1925(self) -> None:
104 """
105 Test :func:`colour.colorimetry.yellowness.yellowness_ASTMD1925`
106 definition nan support.
107 """
109 cases = [-1.0, 0.0, 1.0, -np.inf, np.inf, np.nan]
110 cases = np.array(list(set(product(cases, repeat=3))))
111 yellowness_ASTMD1925(cases)
114class TestYellownessASTM313Alternative:
115 """
116 Define :func:`colour.colorimetry.yellowness.\
117yellowness_ASTME313_alternative` definition unit tests methods.
118 """
120 def test_yellowness_ASTME313_alternative(self) -> None:
121 """
122 Test :func:`colour.colorimetry.yellowness.\
123yellowness_ASTME313_alternative` definition.
124 """
126 np.testing.assert_allclose(
127 yellowness_ASTME313_alternative(
128 np.array([95.00000000, 100.00000000, 105.00000000])
129 ),
130 11.065000000000003,
131 atol=TOLERANCE_ABSOLUTE_TESTS,
132 )
134 np.testing.assert_allclose(
135 yellowness_ASTME313_alternative(
136 np.array([105.00000000, 100.00000000, 95.00000000])
137 ),
138 19.534999999999989,
139 atol=TOLERANCE_ABSOLUTE_TESTS,
140 )
142 np.testing.assert_allclose(
143 yellowness_ASTME313_alternative(
144 np.array([100.00000000, 100.00000000, 100.00000000])
145 ),
146 15.300000000000002,
147 atol=TOLERANCE_ABSOLUTE_TESTS,
148 )
150 def test_n_dimensional_yellowness_ASTME313_alternative(self) -> None:
151 """
152 Test :func:`colour.colorimetry.yellowness.\
153yellowness_ASTME313_alternative` definition n_dimensional arrays support.
154 """
156 XYZ = np.array([95.00000000, 100.00000000, 105.00000000])
157 YI = yellowness_ASTME313_alternative(XYZ)
159 XYZ = np.tile(XYZ, (6, 1))
160 YI = np.tile(YI, 6)
161 np.testing.assert_allclose(
162 yellowness_ASTME313_alternative(XYZ),
163 YI,
164 atol=TOLERANCE_ABSOLUTE_TESTS,
165 )
167 XYZ = np.reshape(XYZ, (2, 3, 3))
168 YI = np.reshape(YI, (2, 3))
169 np.testing.assert_allclose(
170 yellowness_ASTME313_alternative(XYZ),
171 YI,
172 atol=TOLERANCE_ABSOLUTE_TESTS,
173 )
175 def test_domain_range_scale_yellowness_ASTME313_alternative(self) -> None:
176 """
177 Test :func:`colour.colorimetry.yellowness.\
178yellowness_ASTME313_alternative` definition domain and range scale support.
179 """
181 XYZ = np.array([95.00000000, 100.00000000, 105.00000000])
182 YI = 11.065000000000003
184 d_r = (("reference", 1), ("1", 0.01), ("100", 1))
185 for scale, factor in d_r:
186 with domain_range_scale(scale):
187 np.testing.assert_allclose(
188 yellowness_ASTME313_alternative(XYZ * factor),
189 YI * factor,
190 atol=TOLERANCE_ABSOLUTE_TESTS,
191 )
193 @ignore_numpy_errors
194 def test_nan_yellowness_ASTME313_alternative(self) -> None:
195 """
196 Test :func:`colour.colorimetry.yellowness.\
197yellowness_ASTME313_alternative` definition nan support.
198 """
200 cases = [-1.0, 0.0, 1.0, -np.inf, np.inf, np.nan]
201 cases = np.array(list(set(product(cases, repeat=3))))
202 yellowness_ASTME313_alternative(cases)
205class TestYellownessASTM313:
206 """
207 Define :func:`colour.colorimetry.yellowness.yellowness_ASTME313`
208 definition unit tests methods.
209 """
211 def test_yellowness_ASTME313(self) -> None:
212 """
213 Test :func:`colour.colorimetry.yellowness.yellowness_ASTME313`
214 definition.
215 """
217 np.testing.assert_allclose(
218 yellowness_ASTME313(np.array([95.00000000, 100.00000000, 105.00000000])),
219 4.340000000000003,
220 atol=TOLERANCE_ABSOLUTE_TESTS,
221 )
223 np.testing.assert_allclose(
224 yellowness_ASTME313(np.array([105.00000000, 100.00000000, 95.00000000])),
225 28.660000000000011,
226 atol=TOLERANCE_ABSOLUTE_TESTS,
227 )
229 np.testing.assert_allclose(
230 yellowness_ASTME313(np.array([100.00000000, 100.00000000, 100.00000000])),
231 16.500000000000000,
232 atol=TOLERANCE_ABSOLUTE_TESTS,
233 )
235 np.testing.assert_allclose(
236 yellowness_ASTME313(
237 np.array([95.00000000, 100.00000000, 105.00000000]),
238 YELLOWNESS_COEFFICIENTS_ASTME313["CIE 1931 2 Degree Standard Observer"][
239 "C"
240 ],
241 ),
242 10.089500000000001,
243 atol=TOLERANCE_ABSOLUTE_TESTS,
244 )
246 def test_n_dimensional_yellowness_ASTME313(self) -> None:
247 """
248 Test :func:`colour.colorimetry.yellowness.yellowness_ASTME313`
249 definition n_dimensional arrays support.
250 """
252 XYZ = np.array([95.00000000, 100.00000000, 105.00000000])
253 YI = yellowness_ASTME313(XYZ)
255 XYZ = np.tile(XYZ, (6, 1))
256 YI = np.tile(YI, 6)
257 np.testing.assert_allclose(
258 yellowness_ASTME313(XYZ), YI, atol=TOLERANCE_ABSOLUTE_TESTS
259 )
261 XYZ = np.reshape(XYZ, (2, 3, 3))
262 YI = np.reshape(YI, (2, 3))
263 np.testing.assert_allclose(
264 yellowness_ASTME313(XYZ), YI, atol=TOLERANCE_ABSOLUTE_TESTS
265 )
267 def test_domain_range_scale_yellowness_ASTME313(self) -> None:
268 """
269 Test :func:`colour.colorimetry.yellowness.yellowness_ASTME313`
270 definition domain and range scale support.
271 """
273 XYZ = np.array([95.00000000, 100.00000000, 105.00000000])
274 YI = 4.340000000000003
276 d_r = (("reference", 1), ("1", 0.01), ("100", 1))
277 for scale, factor in d_r:
278 with domain_range_scale(scale):
279 np.testing.assert_allclose(
280 yellowness_ASTME313(XYZ * factor),
281 YI * factor,
282 atol=TOLERANCE_ABSOLUTE_TESTS,
283 )
285 @ignore_numpy_errors
286 def test_nan_yellowness_ASTME313(self) -> None:
287 """
288 Test :func:`colour.colorimetry.yellowness.yellowness_ASTME313`
289 definition nan support.
290 """
292 cases = [-1.0, 0.0, 1.0, -np.inf, np.inf, np.nan]
293 cases = np.array(list(set(product(cases, repeat=3))))
294 yellowness_ASTME313(cases)
297class TestYellowness:
298 """
299 Define :func:`colour.colorimetry.yellowness.yellowness` definition unit
300 tests methods.
301 """
303 def test_domain_range_scale_yellowness(self) -> None:
304 """
305 Test :func:`colour.colorimetry.yellowness.yellowness` definition
306 domain and range scale support.
307 """
309 XYZ = np.array([95.00000000, 100.00000000, 105.00000000])
311 m = ("ASTM D1925", "ASTM E313")
312 v = [yellowness(XYZ, method) for method in m]
314 d_r = (("reference", 1), ("1", 0.01), ("100", 1))
315 for method, value in zip(m, v, strict=True):
316 for scale, factor in d_r:
317 with domain_range_scale(scale):
318 np.testing.assert_allclose(
319 yellowness(XYZ * factor, method),
320 value * factor,
321 atol=TOLERANCE_ABSOLUTE_TESTS,
322 )