Coverage for colorimetry/tests/test_generation.py: 100%
76 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.colorimetry.generation` module."""
3from __future__ import annotations
5import numpy as np
7from colour.colorimetry.generation import (
8 msds_constant,
9 msds_ones,
10 msds_zeros,
11 sd_constant,
12 sd_gaussian_fwhm,
13 sd_gaussian_normal,
14 sd_multi_leds_Ohno2005,
15 sd_ones,
16 sd_single_led_Ohno2005,
17 sd_zeros,
18)
19from colour.constants import TOLERANCE_ABSOLUTE_TESTS
21__author__ = "Colour Developers"
22__copyright__ = "Copyright 2013 Colour Developers"
23__license__ = "BSD-3-Clause - https://opensource.org/licenses/BSD-3-Clause"
24__maintainer__ = "Colour Developers"
25__email__ = "colour-developers@colour-science.org"
26__status__ = "Production"
28__all__ = [
29 "TestSdConstant",
30 "TestSdZeros",
31 "TestSdOnes",
32 "TestMsdsConstant",
33 "TestMsdsZeros",
34 "TestMsdsOnes",
35 "TestSdGaussianNormal",
36 "TestSdGaussianFwhm",
37 "TestSdSingleLedOhno2005",
38 "TestSdMultiLedsOhno2005",
39]
42class TestSdConstant:
43 """
44 Define :func:`colour.colorimetry.generation.sd_constant` definition unit
45 tests methods.
46 """
48 def test_sd_constant(self) -> None:
49 """Test :func:`colour.colorimetry.generation.sd_constant` definition."""
51 sd = sd_constant(np.pi)
53 np.testing.assert_allclose(sd[360], np.pi, atol=TOLERANCE_ABSOLUTE_TESTS)
55 np.testing.assert_allclose(sd[555], np.pi, atol=TOLERANCE_ABSOLUTE_TESTS)
57 np.testing.assert_allclose(sd[780], np.pi, atol=TOLERANCE_ABSOLUTE_TESTS)
60class TestSdZeros:
61 """
62 Define :func:`colour.colorimetry.generation.sd_zeros` definition unit
63 tests methods.
64 """
66 def test_sd_zeros(self) -> None:
67 """
68 Test :func:`colour.colorimetry.generation.sd_zeros`
69 definition.
70 """
72 sd = sd_zeros()
74 assert sd[360] == 0
76 assert sd[555] == 0
78 assert sd[780] == 0
81class TestSdOnes:
82 """
83 Define :func:`colour.colorimetry.generation.sd_ones` definition unit
84 tests methods.
85 """
87 def test_sd_ones(self) -> None:
88 """Test :func:`colour.colorimetry.generation.sd_ones` definition."""
90 sd = sd_ones()
92 assert sd[360] == 1
94 assert sd[555] == 1
96 assert sd[780] == 1
99class TestMsdsConstant:
100 """
101 Define :func:`colour.colorimetry.generation.msds_constant` definition unit
102 tests methods.
103 """
105 def test_msds_constant(self) -> None:
106 """Test :func:`colour.colorimetry.generation.msds_constant` definition."""
108 msds = msds_constant(np.pi, labels=["a", "b", "c"])
110 np.testing.assert_allclose(
111 msds[360],
112 np.array([np.pi, np.pi, np.pi]),
113 atol=TOLERANCE_ABSOLUTE_TESTS,
114 )
116 np.testing.assert_allclose(
117 msds[555],
118 np.array([np.pi, np.pi, np.pi]),
119 atol=TOLERANCE_ABSOLUTE_TESTS,
120 )
122 np.testing.assert_allclose(
123 msds[780],
124 np.array([np.pi, np.pi, np.pi]),
125 atol=TOLERANCE_ABSOLUTE_TESTS,
126 )
129class TestMsdsZeros:
130 """
131 Define :func:`colour.colorimetry.generation.msds_zeros` definition unit
132 tests methods.
133 """
135 def test_msds_zeros(self) -> None:
136 """
137 Test :func:`colour.colorimetry.generation.msds_zeros`
138 definition.
139 """
141 msds = msds_zeros(labels=["a", "b", "c"])
143 np.testing.assert_equal(msds[360], np.array([0, 0, 0]))
145 np.testing.assert_equal(msds[555], np.array([0, 0, 0]))
147 np.testing.assert_equal(msds[780], np.array([0, 0, 0]))
150class TestMsdsOnes:
151 """
152 Define :func:`colour.colorimetry.generation.msds_ones` definition unit
153 tests methods.
154 """
156 def test_msds_ones(self) -> None:
157 """Test :func:`colour.colorimetry.generation.msds_ones` definition."""
159 msds = msds_ones(labels=["a", "b", "c"])
161 np.testing.assert_equal(msds[360], np.array([1, 1, 1]))
163 np.testing.assert_equal(msds[555], np.array([1, 1, 1]))
165 np.testing.assert_equal(msds[780], np.array([1, 1, 1]))
168class TestSdGaussianNormal:
169 """
170 Define :func:`colour.colorimetry.generation.sd_gaussian_normal`
171 definition unit tests methods.
172 """
174 def test_sd_gaussian_normal(self) -> None:
175 """
176 Test :func:`colour.colorimetry.generation.sd_gaussian_normal`
177 definition.
178 """
180 sd = sd_gaussian_normal(555, 25)
182 np.testing.assert_allclose(
183 sd[530], 0.606530659712633, atol=TOLERANCE_ABSOLUTE_TESTS
184 )
186 np.testing.assert_allclose(sd[555], 1, atol=TOLERANCE_ABSOLUTE_TESTS)
188 np.testing.assert_allclose(
189 sd[580], 0.606530659712633, atol=TOLERANCE_ABSOLUTE_TESTS
190 )
193class TestSdGaussianFwhm:
194 """
195 Define :func:`colour.colorimetry.generation.sd_gaussian_fwhm` definition
196 unit tests methods.
197 """
199 def test_sd_gaussian_fwhm(self) -> None:
200 """
201 Test :func:`colour.colorimetry.generation.sd_gaussian_fwhm` definition.
202 """
204 sd = sd_gaussian_fwhm(555, 25)
206 np.testing.assert_allclose(sd[530], 0.0625, atol=TOLERANCE_ABSOLUTE_TESTS)
208 np.testing.assert_allclose(sd[555], 1, atol=TOLERANCE_ABSOLUTE_TESTS)
210 np.testing.assert_allclose(
211 sd[580], 0.062499999999999, atol=TOLERANCE_ABSOLUTE_TESTS
212 )
214 np.testing.assert_allclose(sd[555 - 25 / 2], 0.5, atol=TOLERANCE_ABSOLUTE_TESTS)
217class TestSdSingleLedOhno2005:
218 """
219 Define :func:`colour.colorimetry.generation.sd_single_led_Ohno2005`
220 definition unit tests methods.
221 """
223 def test_sd_single_led_Ohno2005(self) -> None:
224 """
225 Test :func:`colour.colorimetry.generation.sd_single_led_Ohno2005`
226 definition.
227 """
229 sd = sd_single_led_Ohno2005(555, 25)
231 np.testing.assert_allclose(
232 sd[530], 0.127118445056538, atol=TOLERANCE_ABSOLUTE_TESTS
233 )
235 np.testing.assert_allclose(sd[555], 1, atol=TOLERANCE_ABSOLUTE_TESTS)
237 np.testing.assert_allclose(
238 sd[580], 0.127118445056538, atol=TOLERANCE_ABSOLUTE_TESTS
239 )
242class TestSdMultiLedsOhno2005:
243 """
244 Define :func:`colour.colorimetry.generation.sd_multi_leds_Ohno2005`
245 definition unit tests methods.
246 """
248 def test_sd_multi_leds_Ohno2005(self) -> None:
249 """
250 Test :func:`colour.colorimetry.generation.sd_multi_leds_Ohno2005`
251 definition.
252 """
254 sd = sd_multi_leds_Ohno2005(
255 np.array([457, 530, 615]),
256 np.array([20, 30, 20]),
257 np.array([0.731, 1.000, 1.660]),
258 )
260 np.testing.assert_allclose(
261 sd[500], 0.129513248576116, atol=TOLERANCE_ABSOLUTE_TESTS
262 )
264 np.testing.assert_allclose(
265 sd[570], 0.059932156222703, atol=TOLERANCE_ABSOLUTE_TESTS
266 )
268 np.testing.assert_allclose(
269 sd[640], 0.116433257970624, atol=TOLERANCE_ABSOLUTE_TESTS
270 )
272 sd = sd_multi_leds_Ohno2005(
273 np.array([457, 530, 615]),
274 np.array([20, 30, 20]),
275 )
277 np.testing.assert_allclose(
278 sd[500], 0.130394510062799, atol=TOLERANCE_ABSOLUTE_TESTS
279 )
281 np.testing.assert_allclose(
282 sd[570], 0.058539618824187, atol=TOLERANCE_ABSOLUTE_TESTS
283 )
285 np.testing.assert_allclose(
286 sd[640], 0.070140708922879, atol=TOLERANCE_ABSOLUTE_TESTS
287 )