Coverage for volume/tests/test_rgb.py: 100%
31 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"""
2Define the unit tests for the :mod:`colour.volume.rgb` module.
4Notes
5-----
6The MonteCarlo sampling based unit tests are assuming that
7:func:`np.random.RandomState` definition will return the same sequence no
8matter which *OS* or *Python* version is used. There is however no formal
9promise about the *prng* sequence reproducibility of either *Python* or *Numpy*
10implementations:
12References
13----------
14- :cite:`Laurent2012a` : Laurent. (2012). Reproducibility of python
15 pseudo-random numbers across systems and versions? Retrieved January 20,
16 2015, from
17 http://stackoverflow.com/questions/8786084/\
18reproducibility-of-python-pseudo-random-numbers-across-systems-and-versions
19"""
21from __future__ import annotations
23import numpy as np
25from colour.constants import TOLERANCE_ABSOLUTE_TESTS
26from colour.models import (
27 RGB_COLOURSPACE_ACES2065_1,
28 RGB_COLOURSPACE_BT709,
29 RGB_COLOURSPACE_BT2020,
30)
31from colour.utilities import disable_multiprocessing, is_scipy_installed
32from colour.volume import (
33 RGB_colourspace_limits,
34 RGB_colourspace_pointer_gamut_coverage_MonteCarlo,
35 RGB_colourspace_visible_spectrum_coverage_MonteCarlo,
36 RGB_colourspace_volume_coverage_MonteCarlo,
37 RGB_colourspace_volume_MonteCarlo,
38 is_within_pointer_gamut,
39)
41__author__ = "Colour Developers"
42__copyright__ = "Copyright 2013 Colour Developers"
43__license__ = "BSD-3-Clause - https://opensource.org/licenses/BSD-3-Clause"
44__maintainer__ = "Colour Developers"
45__email__ = "colour-developers@colour-science.org"
46__status__ = "Production"
48__all__ = [
49 "TestRGB_colourspaceLimits",
50 "TestRGB_colourspaceVolumeMonteCarlo",
51 "TestRGB_colourspace_volume_coverage_MonteCarlo",
52 "TestRGB_colourspacePointerGamutCoverageMonteCarlo",
53 "TestRGB_colourspaceVisibleSpectrumCoverageMonteCarlo",
54]
57class TestRGB_colourspaceLimits:
58 """
59 Define :func:`colour.volume.rgb.RGB_colourspace_limits` definition unit
60 tests methods.
61 """
63 def test_RGB_colourspace_limits(self) -> None:
64 """Test :func:`colour.volume.rgb.RGB_colourspace_limits` definition."""
66 np.testing.assert_allclose(
67 RGB_colourspace_limits(RGB_COLOURSPACE_BT709),
68 np.array(
69 [
70 [0.00000000, 100.00000000],
71 [-86.18159689, 98.23744381],
72 [-107.85546554, 94.48384002],
73 ]
74 ),
75 atol=TOLERANCE_ABSOLUTE_TESTS,
76 )
78 np.testing.assert_allclose(
79 RGB_colourspace_limits(RGB_COLOURSPACE_BT2020),
80 np.array(
81 [
82 [0.00000000, 100.00000000],
83 [-172.32005590, 130.52657313],
84 [-120.27412558, 136.88564561],
85 ]
86 ),
87 atol=TOLERANCE_ABSOLUTE_TESTS,
88 )
90 np.testing.assert_allclose(
91 RGB_colourspace_limits(RGB_COLOURSPACE_ACES2065_1),
92 np.array(
93 [
94 [-65.15706201, 102.72462756],
95 [-380.86283223, 281.23227495],
96 [-284.75355519, 177.11142683],
97 ]
98 ),
99 atol=TOLERANCE_ABSOLUTE_TESTS,
100 )
103class TestRGB_colourspaceVolumeMonteCarlo:
104 """
105 Define :func:`colour.volume.rgb.RGB_colourspace_volume_MonteCarlo`
106 definition unit tests methods.
108 References
109 ----------
110 :cite:`Laurent2012a`
111 """
113 @disable_multiprocessing()
114 def test_RGB_colourspace_volume_MonteCarlo(self) -> None:
115 """
116 Test :func:`colour.volume.rgb.RGB_colourspace_volume_MonteCarlo`
117 definition.
118 """
120 np.testing.assert_allclose(
121 RGB_colourspace_volume_MonteCarlo(
122 RGB_COLOURSPACE_BT709,
123 int(10e3),
124 random_state=np.random.RandomState(2),
125 )
126 * 1e-6,
127 821700.0 * 1e-6,
128 atol=1,
129 )
132class TestRGB_colourspace_volume_coverage_MonteCarlo:
133 """
134 Define :func:`colour.volume.rgb.\
135RGB_colourspace_volume_coverage_MonteCarlo` definition unit tests methods.
137 References
138 ----------
139 :cite:`Laurent2012a`
140 """
142 def test_RGB_colourspace_volume_coverage_MonteCarlo(self) -> None:
143 """
144 Test :func:`colour.volume.rgb.\
145RGB_colourspace_volume_coverage_MonteCarlo` definition.
146 """
148 if not is_scipy_installed(): # pragma: no cover
149 return
151 np.testing.assert_allclose(
152 RGB_colourspace_volume_coverage_MonteCarlo(
153 RGB_COLOURSPACE_BT709,
154 is_within_pointer_gamut,
155 int(10e3),
156 random_state=np.random.RandomState(2),
157 ),
158 81.044349070100140,
159 atol=TOLERANCE_ABSOLUTE_TESTS,
160 )
163class TestRGB_colourspacePointerGamutCoverageMonteCarlo:
164 """
165 Define :func:`colour.volume.rgb.\
166RGB_colourspace_pointer_gamut_coverage_MonteCarlo` definition unit tests
167 methods.
169 References
170 ----------
171 :cite:`Laurent2012a`
172 """
174 def test_RGB_colourspace_pointer_gamut_coverage_MonteCarlo(self) -> None:
175 """
176 Test :func:`colour.volume.rgb.\
177RGB_colourspace_pointer_gamut_coverage_MonteCarlo` definition.
178 """
180 if not is_scipy_installed(): # pragma: no cover
181 return
183 np.testing.assert_allclose(
184 RGB_colourspace_pointer_gamut_coverage_MonteCarlo(
185 RGB_COLOURSPACE_BT709,
186 int(10e3),
187 random_state=np.random.RandomState(2),
188 ),
189 81.044349070100140,
190 atol=TOLERANCE_ABSOLUTE_TESTS,
191 )
194class TestRGB_colourspaceVisibleSpectrumCoverageMonteCarlo:
195 """
196 Define :func:`colour.volume.rgb.\
197RGB_colourspace_visible_spectrum_coverage_MonteCarlo` definition unit tests
198 methods.
200 References
201 ----------
202 :cite:`Laurent2012a`
203 """
205 def test_RGB_colourspace_visible_spectrum_coverage_MonteCarlo(self) -> None:
206 """
207 Test :func:`colour.volume.rgb.\
208RGB_colourspace_visible_spectrum_coverage_MonteCarlo` definition.
209 """
211 if not is_scipy_installed(): # pragma: no cover
212 return
214 np.testing.assert_allclose(
215 RGB_colourspace_visible_spectrum_coverage_MonteCarlo(
216 RGB_COLOURSPACE_BT709,
217 int(10e3),
218 random_state=np.random.RandomState(2),
219 ),
220 46.931407942238266,
221 atol=TOLERANCE_ABSOLUTE_TESTS,
222 )