Coverage for colour/models/tests/test_osa_ucs.py: 100%
65 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.models.osa_ucs` module."""
3from __future__ import annotations
5from itertools import product
7import numpy as np
9from colour.constants import TOLERANCE_ABSOLUTE_TESTS
10from colour.models import OSA_UCS_to_XYZ, XYZ_to_OSA_UCS
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 "TestXYZ_to_OSA_UCS",
22 "TestOSA_UCS_to_XYZ",
23]
26class TestXYZ_to_OSA_UCS:
27 """
28 Define :func:`colour.models.osa_ucs.XYZ_to_OSA_UCS` definition unit tests
29 methods.
30 """
32 def test_XYZ_to_OSA_UCS(self) -> None:
33 """Test :func:`colour.models.osa_ucs.XYZ_to_OSA_UCS` definition."""
35 np.testing.assert_allclose(
36 XYZ_to_OSA_UCS(np.array([0.20654008, 0.12197225, 0.05136952]) * 100),
37 np.array([-3.00499790, 2.99713697, -9.66784231]),
38 atol=TOLERANCE_ABSOLUTE_TESTS,
39 )
41 np.testing.assert_allclose(
42 XYZ_to_OSA_UCS(np.array([0.14222010, 0.23042768, 0.10495772]) * 100),
43 np.array([-1.64657491, 4.59201565, 5.31738757]),
44 atol=TOLERANCE_ABSOLUTE_TESTS,
45 )
47 np.testing.assert_allclose(
48 XYZ_to_OSA_UCS(np.array([0.07818780, 0.06157201, 0.28099326]) * 100),
49 np.array([-5.08589672, -7.91062749, 0.98107575]),
50 atol=TOLERANCE_ABSOLUTE_TESTS,
51 )
53 def test_n_dimensional_XYZ_to_OSA_UCS(self) -> None:
54 """
55 Test :func:`colour.models.osa_ucs.XYZ_to_OSA_UCS` definition
56 n-dimensional support.
57 """
59 XYZ = np.array([0.20654008, 0.12197225, 0.05136952]) * 100
60 Ljg = XYZ_to_OSA_UCS(XYZ)
62 XYZ = np.tile(XYZ, (6, 1))
63 Ljg = np.tile(Ljg, (6, 1))
64 np.testing.assert_allclose(
65 XYZ_to_OSA_UCS(XYZ), Ljg, atol=TOLERANCE_ABSOLUTE_TESTS
66 )
68 XYZ = np.reshape(XYZ, (2, 3, 3))
69 Ljg = np.reshape(Ljg, (2, 3, 3))
70 np.testing.assert_allclose(
71 XYZ_to_OSA_UCS(XYZ), Ljg, atol=TOLERANCE_ABSOLUTE_TESTS
72 )
74 def test_domain_range_scale_XYZ_to_OSA_UCS(self) -> None:
75 """
76 Test :func:`colour.models.osa_ucs.XYZ_to_OSA_UCS` definition domain
77 and range scale support.
78 """
80 XYZ = np.array([0.20654008, 0.12197225, 0.05136952]) * 100
81 Ljg = XYZ_to_OSA_UCS(XYZ)
83 d_r = (("reference", 1), ("1", 0.01), ("100", 1))
84 for scale, factor in d_r:
85 with domain_range_scale(scale):
86 np.testing.assert_allclose(
87 XYZ_to_OSA_UCS(XYZ * factor),
88 Ljg * factor,
89 atol=TOLERANCE_ABSOLUTE_TESTS,
90 )
92 @ignore_numpy_errors
93 def test_nan_XYZ_to_OSA_UCS(self) -> None:
94 """
95 Test :func:`colour.models.osa_ucs.XYZ_to_OSA_UCS` definition nan
96 support.
97 """
99 cases = [-1.0, 0.0, 1.0, -np.inf, np.inf, np.nan]
100 cases = np.array(list(set(product(cases, repeat=3))))
101 XYZ_to_OSA_UCS(cases)
104class TestOSA_UCS_to_XYZ:
105 """
106 Define :func:`colour.models.osa_ucs.OSA_UCS_to_XYZ` definition unit tests
107 methods.
108 """
110 def test_OSA_UCS_to_XYZ(self) -> None:
111 """Test :func:`colour.models.osa_ucs.OSA_UCS_to_XYZ` definition."""
113 np.testing.assert_allclose(
114 OSA_UCS_to_XYZ(
115 np.array([-3.00499790, 2.99713697, -9.66784231]),
116 {"disp": False},
117 ),
118 np.array([0.20654008, 0.12197225, 0.05136952]) * 100,
119 atol=5e-5,
120 )
122 np.testing.assert_allclose(
123 OSA_UCS_to_XYZ(
124 np.array([-1.64657491, 4.59201565, 5.31738757]),
125 {"disp": False},
126 ),
127 np.array([0.14222010, 0.23042768, 0.10495772]) * 100,
128 atol=5e-5,
129 )
131 np.testing.assert_allclose(
132 OSA_UCS_to_XYZ(
133 np.array([-5.08589672, -7.91062749, 0.98107575]),
134 {"disp": False},
135 ),
136 np.array([0.07818780, 0.06157201, 0.28099326]) * 100,
137 atol=5e-5,
138 )
140 def test_n_dimensional_OSA_UCS_to_XYZ(self) -> None:
141 """
142 Test :func:`colour.models.osa_ucs.OSA_UCS_to_XYZ` definition
143 n-dimensional support.
144 """
146 Ljg = np.array([-3.00499790, 2.99713697, -9.66784231])
147 XYZ = OSA_UCS_to_XYZ(Ljg)
149 Ljg = np.tile(Ljg, (6, 1))
150 XYZ = np.tile(XYZ, (6, 1))
151 np.testing.assert_allclose(
152 OSA_UCS_to_XYZ(Ljg), XYZ, atol=TOLERANCE_ABSOLUTE_TESTS
153 )
155 Ljg = np.reshape(Ljg, (2, 3, 3))
156 XYZ = np.reshape(XYZ, (2, 3, 3))
157 np.testing.assert_allclose(
158 OSA_UCS_to_XYZ(Ljg), XYZ, atol=TOLERANCE_ABSOLUTE_TESTS
159 )
161 def test_domain_range_scale_OSA_UCS_to_XYZ(self) -> None:
162 """
163 Test :func:`colour.models.osa_ucs.OSA_UCS_to_XYZ` definition domain
164 and range scale support.
165 """
167 Ljg = np.array([-3.00499790, 2.99713697, -9.66784231])
168 XYZ = OSA_UCS_to_XYZ(Ljg)
170 d_r = (("reference", 1), ("1", 0.01), ("100", 1))
171 for scale, factor in d_r:
172 with domain_range_scale(scale):
173 np.testing.assert_allclose(
174 OSA_UCS_to_XYZ(Ljg * factor),
175 XYZ * factor,
176 atol=TOLERANCE_ABSOLUTE_TESTS,
177 )
179 @ignore_numpy_errors
180 def test_nan_OSA_UCS_to_XYZ(self) -> None:
181 """
182 Test :func:`colour.models.osa_ucs.OSA_UCS_to_XYZ` definition nan
183 support.
184 """
186 cases = [-1.0, 0.0, 1.0, -np.inf, np.inf, np.nan]
187 cases = np.array(list(set(product(cases, repeat=3))))
188 OSA_UCS_to_XYZ(cases)