Coverage for adaptation/tests/test__init__.py: 100%
45 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` module."""
3from __future__ import annotations
5import numpy as np
7from colour.adaptation import chromatic_adaptation
8from colour.constants import TOLERANCE_ABSOLUTE_TESTS
9from colour.utilities import domain_range_scale
11__author__ = "Colour Developers"
12__copyright__ = "Copyright 2013 Colour Developers"
13__license__ = "BSD-3-Clause - https://opensource.org/licenses/BSD-3-Clause"
14__maintainer__ = "Colour Developers"
15__email__ = "colour-developers@colour-science.org"
16__status__ = "Production"
18__all__ = [
19 "TestChromaticAdaptation",
20]
23class TestChromaticAdaptation:
24 """
25 Define :func:`colour.adaptation.chromatic_adaptation` definition unit
26 tests methods.
27 """
29 def test_chromatic_adaptation(self) -> None:
30 """Test :func:`colour.adaptation.chromatic_adaptation` definition."""
32 XYZ = np.array([0.20654008, 0.12197225, 0.05136952])
33 XYZ_w = np.array([0.95045593, 1.00000000, 1.08905775])
34 XYZ_wr = np.array([0.96429568, 1.00000000, 0.82510460])
35 np.testing.assert_allclose(
36 chromatic_adaptation(XYZ, XYZ_w, XYZ_wr),
37 np.array([0.21638819, 0.12570000, 0.03847494]),
38 atol=TOLERANCE_ABSOLUTE_TESTS,
39 )
41 Y_o = 0.2
42 E_o = 1000
43 np.testing.assert_allclose(
44 chromatic_adaptation(
45 XYZ,
46 XYZ_w,
47 XYZ_wr,
48 method="CIE 1994",
49 Y_o=Y_o,
50 E_o1=E_o,
51 E_o2=E_o,
52 ),
53 np.array([0.21347453, 0.12252986, 0.03347887]),
54 atol=TOLERANCE_ABSOLUTE_TESTS,
55 )
57 L_A = 200
58 np.testing.assert_allclose(
59 chromatic_adaptation(
60 XYZ, XYZ_w, XYZ_wr, method="CMCCAT2000", L_A1=L_A, L_A2=L_A
61 ),
62 np.array([0.21498829, 0.12474711, 0.03910138]),
63 atol=TOLERANCE_ABSOLUTE_TESTS,
64 )
66 Y_n = 200
67 np.testing.assert_allclose(
68 chromatic_adaptation(XYZ, XYZ_w, XYZ_wr, method="Fairchild 1990", Y_n=Y_n),
69 np.array([0.21394049, 0.12262315, 0.03891917]),
70 atol=TOLERANCE_ABSOLUTE_TESTS,
71 )
73 np.testing.assert_allclose(
74 chromatic_adaptation(
75 XYZ, XYZ_w, XYZ_wr, method="Li 2025", L_A=100, F_surround=1
76 ),
77 np.array([0.21166965, 0.12234633, 0.03888754]),
78 atol=TOLERANCE_ABSOLUTE_TESTS,
79 )
81 np.testing.assert_allclose(
82 chromatic_adaptation(XYZ, XYZ_w, XYZ_wr, method="Zhai 2018", L_A=100),
83 np.array([0.21638819, 0.1257, 0.03847494]),
84 atol=TOLERANCE_ABSOLUTE_TESTS,
85 )
87 XYZ_wo = np.array([1.0, 1.0, 1.0])
88 np.testing.assert_allclose(
89 chromatic_adaptation(
90 XYZ, XYZ_w, XYZ_wr, method="Zhai 2018", L_A=100, XYZ_wo=XYZ_wo
91 ),
92 np.array([0.21638819, 0.1257, 0.03847494]),
93 atol=TOLERANCE_ABSOLUTE_TESTS,
94 )
96 np.testing.assert_allclose(
97 chromatic_adaptation(XYZ, XYZ_w, XYZ_wr, method="vK20"),
98 np.array([0.21468842, 0.12456164, 0.04662558]),
99 atol=TOLERANCE_ABSOLUTE_TESTS,
100 )
102 def test_domain_range_scale_chromatic_adaptation(self) -> None:
103 """
104 Test :func:`colour.adaptation.chromatic_adaptation` definition domain
105 and range scale support.
106 """
108 XYZ = np.array([0.20654008, 0.12197225, 0.05136952])
109 XYZ_w = np.array([0.95045593, 1.00000000, 1.08905775])
110 XYZ_wr = np.array([0.96429568, 1.00000000, 0.82510460])
111 Y_o = 0.2
112 E_o = 1000
113 L_A = 200
114 Y_n = 200
116 m = ("Von Kries", "CIE 1994", "CMCCAT2000", "Fairchild 1990")
117 v = [
118 chromatic_adaptation(
119 XYZ,
120 XYZ_w,
121 XYZ_wr,
122 method=method,
123 Y_o=Y_o,
124 E_o1=E_o,
125 E_o2=E_o,
126 L_A1=L_A,
127 L_A2=L_A,
128 Y_n=Y_n,
129 )
130 for method in m
131 ]
133 d_r = (("reference", 1), ("1", 1), ("100", 100))
134 for method, value in zip(m, v, strict=True):
135 for scale, factor in d_r:
136 with domain_range_scale(scale):
137 np.testing.assert_allclose(
138 chromatic_adaptation(
139 XYZ * factor,
140 XYZ_w * factor,
141 XYZ_wr * factor,
142 method=method,
143 Y_o=Y_o * factor,
144 E_o1=E_o,
145 E_o2=E_o,
146 L_A1=L_A,
147 L_A2=L_A,
148 Y_n=Y_n,
149 ),
150 value * factor,
151 atol=TOLERANCE_ABSOLUTE_TESTS,
152 )