Coverage for colour/colorimetry/tests/test_illuminants.py: 100%
44 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.colorimetry.illuminants` module."""
3from __future__ import annotations
5import typing
7import numpy as np
9from colour.colorimetry import (
10 SDS_ILLUMINANTS,
11 SpectralShape,
12 daylight_locus_function,
13 sd_CIE_illuminant_D_series,
14 sd_CIE_standard_illuminant_A,
15)
16from colour.constants import TOLERANCE_ABSOLUTE_TESTS
18if typing.TYPE_CHECKING:
19 from colour.hints import NDArrayFloat
21from colour.temperature import CCT_to_xy_CIE_D
22from colour.utilities import ignore_numpy_errors
24__author__ = "Colour Developers"
25__copyright__ = "Copyright 2013 Colour Developers"
26__license__ = "BSD-3-Clause - https://opensource.org/licenses/BSD-3-Clause"
27__maintainer__ = "Colour Developers"
28__email__ = "colour-developers@colour-science.org"
29__status__ = "Production"
31__all__ = [
32 "DATA_A",
33 "TestSdCIEStandardIlluminantA",
34 "TestSdCIEIlluminantDSeries",
35 "TestDaylightLocusFunction",
36]
38DATA_A: NDArrayFloat = np.array(
39 [
40 6.14461778,
41 6.94719899,
42 7.82134941,
43 8.76980228,
44 9.79509961,
45 10.89957616,
46 12.08534536,
47 13.35428726,
48 14.70803845,
49 16.14798414,
50 17.67525215,
51 19.29070890,
52 20.99495729,
53 22.78833636,
54 24.67092269,
55 26.64253337,
56 28.70273044,
57 30.85082676,
58 33.08589297,
59 35.40676571,
60 37.81205669,
61 40.30016269,
62 42.86927625,
63 45.51739693,
64 48.24234315,
65 51.04176432,
66 53.91315329,
67 56.85385894,
68 59.86109896,
69 62.93197247,
70 66.06347275,
71 69.25249966,
72 72.49587199,
73 75.79033948,
74 79.13259455,
75 82.51928367,
76 85.94701837,
77 89.41238582,
78 92.91195891,
79 96.44230599,
80 100.00000000,
81 103.58162718,
82 107.18379528,
83 110.80314124,
84 114.43633837,
85 118.08010305,
86 121.73120094,
87 125.38645263,
88 129.04273891,
89 132.69700551,
90 136.34626740,
91 139.98761262,
92 143.61820577,
93 147.23529096,
94 150.83619449,
95 154.41832708,
96 157.97918574,
97 161.51635535,
98 165.02750987,
99 168.51041325,
100 171.96292009,
101 175.38297597,
102 178.76861756,
103 182.11797252,
104 185.42925911,
105 188.70078570,
106 191.93094995,
107 195.11823798,
108 198.26122323,
109 201.35856531,
110 204.40900861,
111 207.41138086,
112 210.36459156,
113 213.26763031,
114 216.11956508,
115 218.91954039,
116 221.66677545,
117 224.36056217,
118 227.00026327,
119 229.58531022,
120 232.11520118,
121 234.58949900,
122 237.00782911,
123 239.36987744,
124 241.67538835,
125 243.92416253,
126 246.11605493,
127 248.25097273,
128 250.32887325,
129 252.34976196,
130 254.31369047,
131 256.22075454,
132 258.07109218,
133 259.86488167,
134 261.60233977,
135 ]
136)
139class TestSdCIEStandardIlluminantA:
140 """
141 Define :func:`colour.colorimetry.illuminants.\
142sd_CIE_standard_illuminant_A` definition unit tests methods.
143 """
145 def test_sd_CIE_standard_illuminant_A(self) -> None:
146 """
147 Test :func:`colour.colorimetry.illuminants.\
148sd_CIE_standard_illuminant_A` definition.
149 """
151 np.testing.assert_allclose(
152 sd_CIE_standard_illuminant_A(SpectralShape(360, 830, 5)).values,
153 DATA_A,
154 atol=TOLERANCE_ABSOLUTE_TESTS,
155 )
158class TestSdCIEIlluminantDSeries:
159 """
160 Define :func:`colour.colorimetry.illuminants.sd_CIE_illuminant_D_series`
161 definition unit tests methods.
162 """
164 def test_sd_CIE_illuminant_D_series(self) -> None:
165 """
166 Test :func:`colour.colorimetry.illuminants.\
167sd_CIE_illuminant_D_series` definition.
168 """
170 for name, CCT, tolerance in (
171 ("D50", 5000, 0.001),
172 ("D55", 5500, 0.001),
173 ("D65", 6500, 0.001),
174 ("D75", 7500, 0.001),
175 ):
176 CCT *= 1.4388 / 1.4380 # noqa: PLW2901
177 xy = CCT_to_xy_CIE_D(CCT)
178 sd_r = SDS_ILLUMINANTS[name]
179 sd_t = sd_CIE_illuminant_D_series(xy)
181 np.testing.assert_allclose(
182 sd_r.values,
183 sd_t[sd_r.wavelengths],
184 atol=tolerance,
185 )
188class TestDaylightLocusFunction:
189 """
190 Define :func:`colour.colorimetry.illuminants.daylight_locus_function`
191 definition unit tests methods.
192 """
194 def test_daylight_locus_function(self) -> None:
195 """
196 Test :func:`colour.colorimetry.illuminants.daylight_locus_function`
197 definition.
198 """
200 np.testing.assert_allclose(
201 daylight_locus_function(0.31270),
202 0.329105129999999,
203 atol=TOLERANCE_ABSOLUTE_TESTS,
204 )
206 np.testing.assert_allclose(
207 daylight_locus_function(0.34570),
208 0.358633529999999,
209 atol=TOLERANCE_ABSOLUTE_TESTS,
210 )
212 np.testing.assert_allclose(
213 daylight_locus_function(0.44758),
214 0.408571030799999,
215 atol=TOLERANCE_ABSOLUTE_TESTS,
216 )
218 def test_n_dimensional_daylight_locus_function(self) -> None:
219 """
220 Test :func:`colour.colorimetry.illuminants.daylight_locus_function`
221 definition n-dimensional support.
222 """
224 x_D = np.array([0.31270])
225 y_D = daylight_locus_function(x_D)
227 x_D = np.tile(x_D, (6, 1))
228 y_D = np.tile(y_D, (6, 1))
229 np.testing.assert_allclose(
230 daylight_locus_function(x_D), y_D, atol=TOLERANCE_ABSOLUTE_TESTS
231 )
233 x_D = np.reshape(x_D, (2, 3, 1))
234 y_D = np.reshape(y_D, (2, 3, 1))
235 np.testing.assert_allclose(
236 daylight_locus_function(x_D), y_D, atol=TOLERANCE_ABSOLUTE_TESTS
237 )
239 @ignore_numpy_errors
240 def test_nan_daylight_locus_function(self) -> None:
241 """
242 Test :func:`colour.colorimetry.illuminants.daylight_locus_function`
243 definition nan support.
244 """
246 cases = [-1.0, 0.0, 1.0, -np.inf, np.inf, np.nan]
247 daylight_locus_function(cases)