Coverage for adaptation/tests/test_fairchild1990.py: 100%
60 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.adaptation.fairchild1990` module."""
3from __future__ import annotations
5import contextlib
6from itertools import product
8import numpy as np
9from numpy.linalg import LinAlgError
11from colour.adaptation import chromatic_adaptation_Fairchild1990
12from colour.constants import TOLERANCE_ABSOLUTE_TESTS
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 "TestChromaticAdaptationFairchild1990",
24]
27class TestChromaticAdaptationFairchild1990:
28 """
29 Define :func:`colour.adaptation.fairchild1990.\
30chromatic_adaptation_Fairchild1990` definition unit tests methods.
31 """
33 def test_chromatic_adaptation_Fairchild1990(self) -> None:
34 """
35 Test :func:`colour.adaptation.fairchild1990.\
36chromatic_adaptation_Fairchild1990` definition.
37 """
39 np.testing.assert_allclose(
40 chromatic_adaptation_Fairchild1990(
41 np.array([19.53, 23.07, 24.97]),
42 np.array([111.15, 100.00, 35.20]),
43 np.array([94.81, 100.00, 107.30]),
44 200,
45 ),
46 np.array([23.32526349, 23.32455819, 76.11593750]),
47 atol=TOLERANCE_ABSOLUTE_TESTS,
48 )
50 np.testing.assert_allclose(
51 chromatic_adaptation_Fairchild1990(
52 np.array([0.14222010, 0.23042768, 0.10495772]) * 100,
53 np.array([0.95045593, 1.00000000, 1.08905775]) * 100,
54 np.array([1.09846607, 1.00000000, 0.35582280]) * 100,
55 200,
56 ),
57 np.array([19.28089326, 22.91583715, 3.42923503]),
58 atol=TOLERANCE_ABSOLUTE_TESTS,
59 )
61 np.testing.assert_allclose(
62 chromatic_adaptation_Fairchild1990(
63 np.array([0.07818780, 0.06157201, 0.28099326]) * 100,
64 np.array([0.95045593, 1.00000000, 1.08905775]) * 100,
65 np.array([0.99144661, 1.00000000, 0.67315942]) * 100,
66 200,
67 ),
68 np.array([6.35093475, 6.13061347, 17.36852430]),
69 atol=TOLERANCE_ABSOLUTE_TESTS,
70 )
72 def test_n_dimensional_chromatic_adaptation_Fairchild1990(self) -> None:
73 """
74 Test :func:`colour.adaptation.fairchild1990.\
75chromatic_adaptation_Fairchild1990` definition n-dimensional arrays support.
76 """
78 XYZ_1 = np.array([19.53, 23.07, 24.97])
79 XYZ_n = np.array([111.15, 100.00, 35.20])
80 XYZ_r = np.array([94.81, 100.00, 107.30])
81 Y_n = 200
82 XYZ_c = chromatic_adaptation_Fairchild1990(XYZ_1, XYZ_n, XYZ_r, Y_n)
84 XYZ_1 = np.tile(XYZ_1, (6, 1))
85 XYZ_c = np.tile(XYZ_c, (6, 1))
86 np.testing.assert_allclose(
87 chromatic_adaptation_Fairchild1990(XYZ_1, XYZ_n, XYZ_r, Y_n),
88 XYZ_c,
89 atol=TOLERANCE_ABSOLUTE_TESTS,
90 )
92 XYZ_n = np.tile(XYZ_n, (6, 1))
93 XYZ_r = np.tile(XYZ_r, (6, 1))
94 Y_n = np.tile(Y_n, 6)
95 np.testing.assert_allclose(
96 chromatic_adaptation_Fairchild1990(XYZ_1, XYZ_n, XYZ_r, Y_n),
97 XYZ_c,
98 atol=TOLERANCE_ABSOLUTE_TESTS,
99 )
101 XYZ_1 = np.reshape(XYZ_1, (2, 3, 3))
102 XYZ_n = np.reshape(XYZ_n, (2, 3, 3))
103 XYZ_r = np.reshape(XYZ_r, (2, 3, 3))
104 Y_n = np.reshape(Y_n, (2, 3))
105 XYZ_c = np.reshape(XYZ_c, (2, 3, 3))
106 np.testing.assert_allclose(
107 chromatic_adaptation_Fairchild1990(XYZ_1, XYZ_n, XYZ_r, Y_n),
108 XYZ_c,
109 atol=TOLERANCE_ABSOLUTE_TESTS,
110 )
112 def test_domain_range_scale_chromatic_adaptation_Fairchild1990(self) -> None:
113 """
114 Test :func:`colour.adaptation.fairchild1990.\
115chromatic_adaptation_Fairchild1990` definition domain and range scale support.
116 """
118 XYZ_1 = np.array([19.53, 23.07, 24.97])
119 XYZ_n = np.array([111.15, 100.00, 35.20])
120 XYZ_r = np.array([94.81, 100.00, 107.30])
121 Y_n = 200
122 XYZ_c = chromatic_adaptation_Fairchild1990(XYZ_1, XYZ_n, XYZ_r, Y_n)
124 d_r = (("reference", 1), ("1", 0.01), ("100", 1))
125 for scale, factor in d_r:
126 with domain_range_scale(scale):
127 np.testing.assert_allclose(
128 chromatic_adaptation_Fairchild1990(
129 XYZ_1 * factor, XYZ_n * factor, XYZ_r * factor, Y_n
130 ),
131 XYZ_c * factor,
132 atol=TOLERANCE_ABSOLUTE_TESTS,
133 )
135 @ignore_numpy_errors
136 def test_nan_chromatic_adaptation_Fairchild1990(self) -> None:
137 """
138 Test :func:`colour.adaptation.fairchild1990.\
139chromatic_adaptation_Fairchild1990` definition nan support.
140 """
142 cases = [-1.0, 0.0, 1.0, -np.inf, np.inf, np.nan]
143 cases = np.array(list(set(product(cases, repeat=3))))
144 for case in cases:
145 XYZ_1 = case
146 XYZ_n = case
147 XYZ_r = case
148 Y_n = case[0]
149 with contextlib.suppress(LinAlgError):
150 chromatic_adaptation_Fairchild1990(XYZ_1, XYZ_n, XYZ_r, Y_n)