Coverage for colour/models/tests/test_ragoo2021.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.ragoo2021` module."""
3from __future__ import annotations
5from itertools import product
7import numpy as np
9from colour.constants import TOLERANCE_ABSOLUTE_TESTS
10from colour.models import IPT_Ragoo2021_to_XYZ, XYZ_to_IPT_Ragoo2021
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_IPT_Ragoo2021",
22 "TestIPT_Ragoo2021_to_XYZ",
23]
26class TestXYZ_to_IPT_Ragoo2021:
27 """
28 Define :func:`colour.models.ragoo2021.XYZ_to_IPT_Ragoo2021` definition
29 unit tests methods.
30 """
32 def test_XYZ_to_IPT_Ragoo2021(self) -> None:
33 """
34 Test :func:`colour.models.ragoo2021.XYZ_to_IPT_Ragoo2021` definition.
35 """
37 np.testing.assert_allclose(
38 XYZ_to_IPT_Ragoo2021(np.array([0.20654008, 0.12197225, 0.05136952])),
39 np.array([0.42248243, 0.29105140, 0.20410663]),
40 atol=TOLERANCE_ABSOLUTE_TESTS,
41 )
43 np.testing.assert_allclose(
44 XYZ_to_IPT_Ragoo2021(np.array([0.14222010, 0.23042768, 0.10495772])),
45 np.array([0.54745257, -0.22795249, 0.10109646]),
46 atol=TOLERANCE_ABSOLUTE_TESTS,
47 )
49 np.testing.assert_allclose(
50 XYZ_to_IPT_Ragoo2021(np.array([0.07818780, 0.06157201, 0.28099326])),
51 np.array([0.32151337, 0.06071424, -0.27388774]),
52 atol=TOLERANCE_ABSOLUTE_TESTS,
53 )
55 def test_n_dimensional_XYZ_to_IPT_Ragoo2021(self) -> None:
56 """
57 Test :func:`colour.models.ragoo2021.XYZ_to_IPT_Ragoo2021` definition
58 n-dimensional support.
59 """
61 XYZ = np.array([0.20654008, 0.12197225, 0.05136952])
62 IPT = XYZ_to_IPT_Ragoo2021(XYZ)
64 XYZ = np.tile(XYZ, (6, 1))
65 IPT = np.tile(IPT, (6, 1))
66 np.testing.assert_allclose(
67 XYZ_to_IPT_Ragoo2021(XYZ), IPT, atol=TOLERANCE_ABSOLUTE_TESTS
68 )
70 XYZ = np.reshape(XYZ, (2, 3, 3))
71 IPT = np.reshape(IPT, (2, 3, 3))
72 np.testing.assert_allclose(
73 XYZ_to_IPT_Ragoo2021(XYZ), IPT, atol=TOLERANCE_ABSOLUTE_TESTS
74 )
76 def test_domain_range_scale_XYZ_to_IPT_Ragoo2021(self) -> None:
77 """
78 Test :func:`colour.models.ragoo2021.XYZ_to_IPT_Ragoo2021` definition
79 domain and range scale support.
80 """
82 XYZ = np.array([0.20654008, 0.12197225, 0.05136952])
83 IPT = XYZ_to_IPT_Ragoo2021(XYZ)
85 d_r = (("reference", 1), ("1", 1), ("100", 100))
86 for scale, factor in d_r:
87 with domain_range_scale(scale):
88 np.testing.assert_allclose(
89 XYZ_to_IPT_Ragoo2021(XYZ * factor),
90 IPT * factor,
91 atol=TOLERANCE_ABSOLUTE_TESTS,
92 )
94 @ignore_numpy_errors
95 def test_nan_XYZ_to_IPT_Ragoo2021(self) -> None:
96 """
97 Test :func:`colour.models.ragoo2021.XYZ_to_IPT_Ragoo2021` definition
98 nan support.
99 """
101 cases = [-1.0, 0.0, 1.0, -np.inf, np.inf, np.nan]
102 cases = np.array(list(set(product(cases, repeat=3))))
103 XYZ_to_IPT_Ragoo2021(cases)
106class TestIPT_Ragoo2021_to_XYZ:
107 """
108 Define :func:`colour.models.ragoo2021.IPT_Ragoo2021_to_XYZ` definition
109 unit tests methods.
110 """
112 def test_IPT_Ragoo2021_to_XYZ(self) -> None:
113 """
114 Test :func:`colour.models.ragoo2021.IPT_Ragoo2021_to_XYZ` definition.
115 """
117 np.testing.assert_allclose(
118 IPT_Ragoo2021_to_XYZ(np.array([0.42248243, 0.29105140, 0.20410663])),
119 np.array([0.20654008, 0.12197225, 0.05136952]),
120 atol=TOLERANCE_ABSOLUTE_TESTS,
121 )
123 np.testing.assert_allclose(
124 IPT_Ragoo2021_to_XYZ(np.array([0.54745257, -0.22795249, 0.10109646])),
125 np.array([0.14222010, 0.23042768, 0.10495772]),
126 atol=TOLERANCE_ABSOLUTE_TESTS,
127 )
129 np.testing.assert_allclose(
130 IPT_Ragoo2021_to_XYZ(np.array([0.32151337, 0.06071424, -0.27388774])),
131 np.array([0.07818780, 0.06157201, 0.28099326]),
132 atol=TOLERANCE_ABSOLUTE_TESTS,
133 )
135 def test_n_dimensional_IPT_Ragoo2021_to_XYZ(self) -> None:
136 """
137 Test :func:`colour.models.ragoo2021.IPT_Ragoo2021_to_XYZ` definition
138 n-dimensional support.
139 """
141 IPT = np.array([0.42248243, 0.29105140, 0.20410663])
142 XYZ = IPT_Ragoo2021_to_XYZ(IPT)
144 IPT = np.tile(IPT, (6, 1))
145 XYZ = np.tile(XYZ, (6, 1))
146 np.testing.assert_allclose(
147 IPT_Ragoo2021_to_XYZ(IPT), XYZ, atol=TOLERANCE_ABSOLUTE_TESTS
148 )
150 IPT = np.reshape(IPT, (2, 3, 3))
151 XYZ = np.reshape(XYZ, (2, 3, 3))
152 np.testing.assert_allclose(
153 IPT_Ragoo2021_to_XYZ(IPT), XYZ, atol=TOLERANCE_ABSOLUTE_TESTS
154 )
156 def test_domain_range_scale_IPT_Ragoo2021_to_XYZ(self) -> None:
157 """
158 Test :func:`colour.models.ragoo2021.IPT_Ragoo2021_to_XYZ` definition
159 domain and range scale support.
160 """
162 IPT = np.array([0.42248243, 0.29105140, 0.20410663])
163 XYZ = IPT_Ragoo2021_to_XYZ(IPT)
165 d_r = (("reference", 1), ("1", 1), ("100", 100))
166 for scale, factor in d_r:
167 with domain_range_scale(scale):
168 np.testing.assert_allclose(
169 IPT_Ragoo2021_to_XYZ(IPT * factor),
170 XYZ * factor,
171 atol=TOLERANCE_ABSOLUTE_TESTS,
172 )
174 @ignore_numpy_errors
175 def test_nan_IPT_Ragoo2021_to_XYZ(self) -> None:
176 """
177 Test :func:`colour.models.ragoo2021.IPT_Ragoo2021_to_XYZ` definition
178 nan support.
179 """
181 cases = [-1.0, 0.0, 1.0, -np.inf, np.inf, np.nan]
182 cases = np.array(list(set(product(cases, repeat=3))))
183 IPT_Ragoo2021_to_XYZ(cases)