Coverage for models/tests/test_prolab.py: 100%
65 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.models.prolab` module."""
3from __future__ import annotations
5from itertools import product
7import numpy as np
9from colour.constants import TOLERANCE_ABSOLUTE_TESTS
10from colour.models import ProLab_to_XYZ, XYZ_to_ProLab
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_ProLab",
22 "TestProLab_to_XYZ",
23]
26class TestXYZ_to_ProLab:
27 """
28 Define :func:`colour.models.ProLab.TestXYZ_to_ProLab` definition unit
29 tests methods.
30 """
32 def test_XYZ_to_ProLab(self) -> None:
33 """Test :func:`colour.models.ProLab.XYZ_to_ProLab` definition."""
35 np.testing.assert_allclose(
36 XYZ_to_ProLab(np.array([0.20654008, 0.12197225, 0.05136952])),
37 np.array([48.7948929, 35.31503175, 13.30044932]),
38 atol=TOLERANCE_ABSOLUTE_TESTS,
39 )
41 np.testing.assert_allclose(
42 XYZ_to_ProLab(np.array([0.14222010, 0.23042768, 0.10495772])),
43 np.array([64.45929636, -21.67007419, 13.25749056]),
44 atol=TOLERANCE_ABSOLUTE_TESTS,
45 )
47 np.testing.assert_allclose(
48 XYZ_to_ProLab(np.array([0.96907232, 1.00000000, 0.12179215])),
49 np.array([100.0, 5.47367608, 37.26313098]),
50 atol=TOLERANCE_ABSOLUTE_TESTS,
51 )
53 def test_n_dimensional_XYZ_to_ProLab(self) -> None:
54 """
55 Test :func:`colour.models.prolab.XYZ_to_ProLab` definition
56 n-dimensional support.
57 """
59 XYZ = np.array([0.20654008, 0.12197225, 0.05136952])
60 ProLab = XYZ_to_ProLab(XYZ)
62 XYZ = np.tile(XYZ, (6, 1))
63 ProLab = np.tile(ProLab, (6, 1))
64 np.testing.assert_allclose(
65 XYZ_to_ProLab(XYZ), ProLab, atol=TOLERANCE_ABSOLUTE_TESTS
66 )
68 XYZ = np.reshape(XYZ, (2, 3, 3))
69 ProLab = np.reshape(ProLab, (2, 3, 3))
70 np.testing.assert_allclose(
71 XYZ_to_ProLab(XYZ), ProLab, atol=TOLERANCE_ABSOLUTE_TESTS
72 )
74 def test_domain_range_scale_XYZ_to_ProLab(self) -> None:
75 """
76 Test :func:`colour.models.prolab.XYZ_to_ProLab` definition domain and
77 range scale support.
78 """
80 XYZ = np.array([0.20654008, 0.12197225, 0.05136952])
81 ProLab = XYZ_to_ProLab(XYZ)
83 d_r = (("reference", 1), ("1", 1), ("100", 100))
84 for scale, factor in d_r:
85 with domain_range_scale(scale):
86 np.testing.assert_allclose(
87 XYZ_to_ProLab(XYZ * factor),
88 ProLab * factor,
89 atol=TOLERANCE_ABSOLUTE_TESTS,
90 )
92 @ignore_numpy_errors
93 def test_nan_XYZ_to_ProLab(self) -> None:
94 """
95 Test :func:`colour.models.ProLab.XYZ_to_ProLab` definition
96 nan 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_ProLab(cases)
104class TestProLab_to_XYZ:
105 """
106 Define :func:`colour.models.ProLab.ProLab_to_XYZ` definition unit tests
107 methods.
108 """
110 def test_ProLab_to_XYZ(self) -> None:
111 """Test :func:`colour.models.ProLab.ProLab_to_XYZ` definition."""
113 np.testing.assert_allclose(
114 ProLab_to_XYZ(np.array([48.7948929, 35.31503175, 13.30044932])),
115 np.array([0.20654008, 0.12197225, 0.05136952]),
116 atol=TOLERANCE_ABSOLUTE_TESTS,
117 )
119 np.testing.assert_allclose(
120 ProLab_to_XYZ(np.array([64.45929636, -21.67007419, 13.25749056])),
121 np.array([0.14222010, 0.23042768, 0.10495772]),
122 atol=TOLERANCE_ABSOLUTE_TESTS,
123 )
125 np.testing.assert_allclose(
126 ProLab_to_XYZ(np.array([100.0, 5.47367608, 37.26313098])),
127 np.array([0.96907232, 1.00000000, 0.12179215]),
128 atol=TOLERANCE_ABSOLUTE_TESTS,
129 )
131 def test_n_dimensional_XYZ_to_ProLab(self) -> None:
132 """
133 Test :func:`colour.models.prolab.XYZ_to_ProLab` definition
134 n-dimensional support.
135 """
137 ProLab = np.array([48.7948929, 35.31503175, 13.30044932])
138 XYZ = ProLab_to_XYZ(ProLab)
140 ProLab = np.tile(ProLab, (6, 1))
141 XYZ = np.tile(XYZ, (6, 1))
142 np.testing.assert_allclose(
143 ProLab_to_XYZ(ProLab), XYZ, atol=TOLERANCE_ABSOLUTE_TESTS
144 )
146 ProLab = np.reshape(ProLab, (2, 3, 3))
147 XYZ = np.reshape(XYZ, (2, 3, 3))
148 np.testing.assert_allclose(
149 ProLab_to_XYZ(ProLab), XYZ, atol=TOLERANCE_ABSOLUTE_TESTS
150 )
152 def test_domain_range_scale_XYZ_to_ProLab(self) -> None:
153 """
154 Test :func:`colour.models.prolab.XYZ_to_ProLab` definition domain and
155 range scale support.
156 """
158 ProLab = np.array([48.7948929, 35.31503175, 13.30044932])
159 XYZ = XYZ_to_ProLab(ProLab)
161 d_r = (("reference", 1), ("1", 1), ("100", 100))
162 for scale, factor in d_r:
163 with domain_range_scale(scale):
164 np.testing.assert_allclose(
165 XYZ_to_ProLab(ProLab * factor),
166 XYZ * factor,
167 atol=TOLERANCE_ABSOLUTE_TESTS,
168 )
170 @ignore_numpy_errors
171 def test_nan_ProLab_to_XYZ(self) -> None:
172 """
173 Test :func:`colour.models.ProLab.ProLab_to_XYZ` definition nan
174 support.
175 """
177 cases = [-1.0, 0.0, 1.0, -np.inf, np.inf, np.nan]
178 cases = np.array(list(set(product(cases, repeat=3))))
179 ProLab_to_XYZ(cases)