Coverage for colour/adaptation/tests/test_zhai2018.py: 100%
56 statements
« prev ^ index » next coverage.py v7.11.0, created at 2025-11-15 19:01 +1300
« prev ^ index » next coverage.py v7.11.0, created at 2025-11-15 19:01 +1300
1"""Define the unit tests for the :mod:`colour.adaptation.zhai2018` module."""
3from __future__ import annotations
5from itertools import product
7import numpy as np
9from colour.adaptation import chromatic_adaptation_Zhai2018
10from colour.constants import TOLERANCE_ABSOLUTE_TESTS
11from colour.utilities import domain_range_scale, ignore_numpy_errors
13__author__ = "Colour Developers"
14__copyright__ = "Copyright 2013 Colour Developers"
15__license__ = "BSD-3-Clause - https://opensource.org/licenses/BSD-3-Clause"
16__maintainer__ = "Colour Developers"
17__email__ = "colour-developers@colour-science.org"
18__status__ = "Production"
20__all__ = [
21 "TestChromaticAdaptationZhai2018",
22]
25class TestChromaticAdaptationZhai2018:
26 """
27 Define :func:`colour.adaptation.zhai2018.chromatic_adaptation_Zhai2018`
28 definition unit tests methods.
29 """
31 def test_chromatic_adaptation_Zhai2018(self) -> None:
32 """
33 Test :func:`colour.adaptation.zhai2018.chromatic_adaptation_Zhai2018`
34 definition.
35 """
37 np.testing.assert_allclose(
38 chromatic_adaptation_Zhai2018(
39 XYZ_b=np.array([48.900, 43.620, 6.250]),
40 XYZ_wb=np.array([109.850, 100, 35.585]),
41 XYZ_wd=np.array([95.047, 100, 108.883]),
42 D_b=0.9407,
43 D_d=0.9800,
44 XYZ_wo=np.array([100, 100, 100]),
45 ),
46 np.array([39.18561644, 42.15461798, 19.23672036]),
47 atol=TOLERANCE_ABSOLUTE_TESTS,
48 )
50 np.testing.assert_allclose(
51 chromatic_adaptation_Zhai2018(
52 XYZ_b=np.array([48.900, 43.620, 6.250]),
53 XYZ_wb=np.array([109.850, 100, 35.585]),
54 XYZ_wd=np.array([95.047, 100, 108.883]),
55 D_b=0.9407,
56 D_d=0.9800,
57 XYZ_wo=np.array([100, 100, 100]),
58 transform="CAT16",
59 ),
60 np.array([40.37398343, 43.69426311, 20.51733764]),
61 atol=TOLERANCE_ABSOLUTE_TESTS,
62 )
64 np.testing.assert_allclose(
65 chromatic_adaptation_Zhai2018(
66 XYZ_b=np.array([52.034, 58.824, 23.703]),
67 XYZ_wb=np.array([92.288, 100, 38.775]),
68 XYZ_wd=np.array([105.432, 100, 137.392]),
69 D_b=0.6709,
70 D_d=0.5331,
71 XYZ_wo=np.array([97.079, 100, 141.798]),
72 ),
73 np.array([57.03242915, 58.93434364, 64.76261333]),
74 atol=TOLERANCE_ABSOLUTE_TESTS,
75 )
77 np.testing.assert_allclose(
78 chromatic_adaptation_Zhai2018(
79 XYZ_b=np.array([52.034, 58.824, 23.703]),
80 XYZ_wb=np.array([92.288, 100, 38.775]),
81 XYZ_wd=np.array([105.432, 100, 137.392]),
82 D_b=0.6709,
83 D_d=0.5331,
84 XYZ_wo=np.array([97.079, 100, 141.798]),
85 transform="CAT16",
86 ),
87 np.array([56.77130011, 58.81317888, 64.66922808]),
88 atol=TOLERANCE_ABSOLUTE_TESTS,
89 )
91 np.testing.assert_allclose(
92 chromatic_adaptation_Zhai2018(
93 XYZ_b=np.array([48.900, 43.620, 6.250]),
94 XYZ_wb=np.array([109.850, 100, 35.585]),
95 XYZ_wd=np.array([95.047, 100, 108.883]),
96 ),
97 np.array([38.72444735, 42.09232891, 20.05297620]),
98 atol=TOLERANCE_ABSOLUTE_TESTS,
99 )
101 def test_n_dimensional_chromatic_adaptation_Zhai2018(self) -> None:
102 """
103 Test :func:`colour.adaptation.zhai2018.chromatic_adaptation_Zhai2018`
104 definition n-dimensional arrays support.
105 """
107 XYZ_b = np.array([48.900, 43.620, 6.250])
108 XYZ_wb = np.array([109.850, 100, 35.585])
109 XYZ_wd = np.array([95.047, 100, 108.883])
110 D_b = 0.9407
111 D_d = 0.9800
112 XYZ_d = chromatic_adaptation_Zhai2018(XYZ_b, XYZ_wb, XYZ_wd, D_b, D_d)
114 XYZ_b = np.tile(XYZ_b, (6, 1))
115 XYZ_d = np.tile(XYZ_d, (6, 1))
116 np.testing.assert_allclose(
117 chromatic_adaptation_Zhai2018(XYZ_b, XYZ_wb, XYZ_wd, D_b, D_d),
118 XYZ_d,
119 atol=TOLERANCE_ABSOLUTE_TESTS,
120 )
122 XYZ_wb = np.tile(XYZ_wb, (6, 1))
123 XYZ_wd = np.tile(XYZ_wd, (6, 1))
124 D_b = np.tile(D_b, (6, 1))
125 D_d = np.tile(D_d, (6, 1))
126 np.testing.assert_allclose(
127 chromatic_adaptation_Zhai2018(XYZ_b, XYZ_wb, XYZ_wd, D_b, D_d),
128 XYZ_d,
129 atol=TOLERANCE_ABSOLUTE_TESTS,
130 )
132 XYZ_b = np.reshape(XYZ_b, (2, 3, 3))
133 XYZ_wb = np.reshape(XYZ_wb, (2, 3, 3))
134 XYZ_wd = np.reshape(XYZ_wd, (2, 3, 3))
135 D_b = np.reshape(D_b, (2, 3, 1))
136 D_d = np.reshape(D_d, (2, 3, 1))
137 XYZ_d = np.reshape(XYZ_d, (2, 3, 3))
138 np.testing.assert_allclose(
139 chromatic_adaptation_Zhai2018(XYZ_b, XYZ_wb, XYZ_wd, D_b, D_d),
140 XYZ_d,
141 atol=TOLERANCE_ABSOLUTE_TESTS,
142 )
144 def test_domain_range_scale_chromatic_adaptation_Zhai2018(self) -> None:
145 """
146 Test :func:`colour.adaptation.zhai2018.chromatic_adaptation_Zhai2018`
147 definition domain and range scale support.
148 """
150 XYZ_b = np.array([48.900, 43.620, 6.250])
151 XYZ_wb = np.array([109.850, 100, 35.585])
152 XYZ_wd = np.array([95.047, 100, 108.883])
153 XYZ_d = chromatic_adaptation_Zhai2018(XYZ_b, XYZ_wb, XYZ_wd)
155 d_r = (("reference", 1), ("1", 0.01), ("100", 1))
156 for scale, factor in d_r:
157 with domain_range_scale(scale):
158 np.testing.assert_allclose(
159 chromatic_adaptation_Zhai2018(
160 XYZ_b * factor, XYZ_wb * factor, XYZ_wd * factor
161 ),
162 XYZ_d * factor,
163 atol=TOLERANCE_ABSOLUTE_TESTS,
164 )
166 @ignore_numpy_errors
167 def test_nan_chromatic_adaptation_Zhai2018(self) -> None:
168 """
169 Test :func:`colour.adaptation.zhai2018.chromatic_adaptation_Zhai2018`
170 definition nan support.
171 """
173 cases = [-1.0, 0.0, 1.0, -np.inf, np.inf, np.nan]
174 cases = np.array(list(set(product(cases, repeat=3))))
175 chromatic_adaptation_Zhai2018(
176 cases, cases, cases, cases[0, 0], cases[0, 0], cases
177 )