Coverage for colour/plotting/tests/test_volume.py: 100%
35 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.plotting.volume` module."""
3from __future__ import annotations
5import numpy as np
6from matplotlib.axes import Axes
7from matplotlib.figure import Figure
9from colour.constants import TOLERANCE_ABSOLUTE_TESTS
10from colour.plotting import plot_RGB_colourspaces_gamuts, plot_RGB_scatter
11from colour.plotting.volume import RGB_identity_cube, nadir_grid
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 "TestNadirGrid",
22 "TestRGBIdentityCube",
23 "TestPlotRGBColourspacesGamuts",
24 "TestPlotRGBScatter",
25]
28class TestNadirGrid:
29 """
30 Define :func:`colour.plotting.volume.nadir_grid` definition unit tests
31 methods.
32 """
34 def test_nadir_grid(self) -> None:
35 """Test :func:`colour.plotting.volume.nadir_grid` definition."""
37 quads, faces_colours, edges_colours = nadir_grid(segments=1)
39 np.testing.assert_allclose(
40 quads,
41 np.array(
42 [
43 [
44 [-1.00000000, -1.00000000, 0.00000000],
45 [1.00000000, -1.00000000, 0.00000000],
46 [1.00000000, 1.00000000, 0.00000000],
47 [-1.00000000, 1.00000000, 0.00000000],
48 ],
49 [
50 [-1.00000000, -1.00000000, 0.00000000],
51 [0.00000000, -1.00000000, 0.00000000],
52 [0.00000000, 0.00000000, 0.00000000],
53 [-1.00000000, 0.00000000, 0.00000000],
54 ],
55 [
56 [-1.00000000, 0.00000000, 0.00000000],
57 [0.00000000, 0.00000000, 0.00000000],
58 [0.00000000, 1.00000000, 0.00000000],
59 [-1.00000000, 1.00000000, 0.00000000],
60 ],
61 [
62 [0.00000000, -1.00000000, 0.00000000],
63 [1.00000000, -1.00000000, 0.00000000],
64 [1.00000000, 0.00000000, 0.00000000],
65 [0.00000000, 0.00000000, 0.00000000],
66 ],
67 [
68 [0.00000000, 0.00000000, 0.00000000],
69 [1.00000000, 0.00000000, 0.00000000],
70 [1.00000000, 1.00000000, 0.00000000],
71 [0.00000000, 1.00000000, 0.00000000],
72 ],
73 [
74 [-1.00000000, -0.00100000, 0.00000000],
75 [1.00000000, -0.00100000, 0.00000000],
76 [1.00000000, 0.00100000, 0.00000000],
77 [-1.00000000, 0.00100000, 0.00000000],
78 ],
79 [
80 [-0.00100000, -1.00000000, 0.00000000],
81 [0.00100000, -1.00000000, 0.00000000],
82 [0.00100000, 1.00000000, 0.00000000],
83 [-0.00100000, 1.00000000, 0.00000000],
84 ],
85 ]
86 ),
87 atol=TOLERANCE_ABSOLUTE_TESTS,
88 )
90 np.testing.assert_allclose(
91 faces_colours,
92 np.array(
93 [
94 [0.25000000, 0.25000000, 0.25000000, 0.10000000],
95 [0.00000000, 0.00000000, 0.00000000, 0.00000000],
96 [0.00000000, 0.00000000, 0.00000000, 0.00000000],
97 [0.00000000, 0.00000000, 0.00000000, 0.00000000],
98 [0.00000000, 0.00000000, 0.00000000, 0.00000000],
99 [0.00000000, 0.00000000, 0.00000000, 1.00000000],
100 [0.00000000, 0.00000000, 0.00000000, 1.00000000],
101 ]
102 ),
103 atol=TOLERANCE_ABSOLUTE_TESTS,
104 )
106 np.testing.assert_allclose(
107 edges_colours,
108 np.array(
109 [
110 [0.50000000, 0.50000000, 0.50000000, 0.50000000],
111 [0.75000000, 0.75000000, 0.75000000, 0.25000000],
112 [0.75000000, 0.75000000, 0.75000000, 0.25000000],
113 [0.75000000, 0.75000000, 0.75000000, 0.25000000],
114 [0.75000000, 0.75000000, 0.75000000, 0.25000000],
115 [0.00000000, 0.00000000, 0.00000000, 1.00000000],
116 [0.00000000, 0.00000000, 0.00000000, 1.00000000],
117 ]
118 ),
119 atol=TOLERANCE_ABSOLUTE_TESTS,
120 )
123class TestRGBIdentityCube:
124 """
125 Define :func:`colour.plotting.volume.RGB_identity_cube` definition unit
126 tests methods.
127 """
129 def test_RGB_identity_cube(self) -> None:
130 """Test :func:`colour.plotting.volume.RGB_identity_cube` definition."""
132 vertices, RGB = RGB_identity_cube(1, 1, 1)
134 np.testing.assert_allclose(
135 vertices,
136 np.array(
137 [
138 [
139 [0.00000000, 0.00000000, 0.00000000],
140 [1.00000000, 0.00000000, 0.00000000],
141 [1.00000000, 1.00000000, 0.00000000],
142 [0.00000000, 1.00000000, 0.00000000],
143 ],
144 [
145 [0.00000000, 0.00000000, 1.00000000],
146 [1.00000000, 0.00000000, 1.00000000],
147 [1.00000000, 1.00000000, 1.00000000],
148 [0.00000000, 1.00000000, 1.00000000],
149 ],
150 [
151 [0.00000000, 0.00000000, 0.00000000],
152 [1.00000000, 0.00000000, 0.00000000],
153 [1.00000000, 0.00000000, 1.00000000],
154 [0.00000000, 0.00000000, 1.00000000],
155 ],
156 [
157 [0.00000000, 1.00000000, 0.00000000],
158 [1.00000000, 1.00000000, 0.00000000],
159 [1.00000000, 1.00000000, 1.00000000],
160 [0.00000000, 1.00000000, 1.00000000],
161 ],
162 [
163 [0.00000000, 0.00000000, 0.00000000],
164 [0.00000000, 1.00000000, 0.00000000],
165 [0.00000000, 1.00000000, 1.00000000],
166 [0.00000000, 0.00000000, 1.00000000],
167 ],
168 [
169 [1.00000000, 0.00000000, 0.00000000],
170 [1.00000000, 1.00000000, 0.00000000],
171 [1.00000000, 1.00000000, 1.00000000],
172 [1.00000000, 0.00000000, 1.00000000],
173 ],
174 ]
175 ),
176 atol=TOLERANCE_ABSOLUTE_TESTS,
177 )
179 np.testing.assert_allclose(
180 RGB,
181 np.array(
182 [
183 [0.50000000, 0.50000000, 0.00000000],
184 [0.50000000, 0.50000000, 1.00000000],
185 [0.50000000, 0.00000000, 0.50000000],
186 [0.50000000, 1.00000000, 0.50000000],
187 [0.00000000, 0.50000000, 0.50000000],
188 [1.00000000, 0.50000000, 0.50000000],
189 ]
190 ),
191 atol=TOLERANCE_ABSOLUTE_TESTS,
192 )
195class TestPlotRGBColourspacesGamuts:
196 """
197 Define :func:`colour.plotting.volume.plot_RGB_colourspaces_gamuts`
198 definition unit tests methods.
199 """
201 def test_plot_RGB_colourspaces_gamuts(self) -> None:
202 """
203 Test :func:`colour.plotting.volume.plot_RGB_colourspaces_gamuts`
204 definition.
205 """
207 figure, axes = plot_RGB_colourspaces_gamuts(
208 ["ITU-R BT.709", "ACEScg", "S-Gamut"],
209 show_spectral_locus=True,
210 face_colours=[0.18, 0.18, 0.18],
211 chromatically_adapt=True,
212 )
214 assert isinstance(figure, Figure)
215 assert isinstance(axes, Axes)
218class TestPlotRGBScatter:
219 """
220 Define :func:`colour.plotting.volume.plot_RGB_scatter` definition unit
221 tests methods.
222 """
224 def test_plot_RGB_scatter(self) -> None:
225 """Test :func:`colour.plotting.volume.plot_RGB_scatter` definition."""
227 figure, axes = plot_RGB_scatter(np.random.random((128, 128, 3)), "ITU-R BT.709")
229 assert isinstance(figure, Figure)
230 assert isinstance(axes, Axes)