Coverage for temperature/tests/test_robertson1968.py: 100%
88 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.temperature.robertson1968` module."""
3from __future__ import annotations
5from itertools import product
7import numpy as np
9from colour.constants import TOLERANCE_ABSOLUTE_TESTS
10from colour.temperature import (
11 CCT_to_mired,
12 CCT_to_uv_Robertson1968,
13 mired_to_CCT,
14 uv_to_CCT_Robertson1968,
15)
16from colour.utilities import ignore_numpy_errors
18__author__ = "Colour Developers"
19__copyright__ = "Copyright 2013 Colour Developers"
20__license__ = "BSD-3-Clause - https://opensource.org/licenses/BSD-3-Clause"
21__maintainer__ = "Colour Developers"
22__email__ = "colour-developers@colour-science.org"
23__status__ = "Production"
25__all__ = [
26 "TestMired_to_CCT",
27 "TestCCT_to_mired",
28 "TestUv_to_CCT_Robertson1968",
29 "TestCCT_to_uv_Robertson1968",
30]
32TEMPERATURE_DUV_TO_UV: dict = {
33 (2000, -0.0500): np.array([0.309448284638118, 0.309263824757947]),
34 (2000, -0.0250): np.array([0.307249142319059, 0.334166912378974]),
35 (2000, 0.0000): np.array([0.305050000000000, 0.359070000000000]),
36 (2000, 0.0250): np.array([0.302850857680941, 0.383973087621026]),
37 (2000, 0.0500): np.array([0.300651715361882, 0.408876175242053]),
38 (4500, -0.0500): np.array([0.249455133366328, 0.290111562671684]),
39 (4500, -0.0250): np.array([0.233393122238719, 0.309269114669175]),
40 (4500, 0.0000): np.array([0.217331111111111, 0.328426666666667]),
41 (4500, 0.0250): np.array([0.201269099983503, 0.347584218664158]),
42 (4500, 0.0500): np.array([0.185207088855895, 0.366741770661649]),
43 (7000, -0.0500): np.array([0.239763542240142, 0.279200871249525]),
44 (7000, -0.0250): np.array([0.218977485405785, 0.293091149910477]),
45 (7000, 0.0000): np.array([0.198191428571429, 0.306981428571429]),
46 (7000, 0.0250): np.array([0.177405371737072, 0.320871707232380]),
47 (7000, 0.0500): np.array([0.156619314902715, 0.334761985893332]),
48 (9500, -0.0500): np.array([0.235948844766320, 0.272619554367689]),
49 (9500, -0.0250): np.array([0.213587053962107, 0.283797671920686]),
50 (9500, 0.0000): np.array([0.191225263157895, 0.294975789473684]),
51 (9500, 0.0250): np.array([0.168863472353682, 0.306153907026682]),
52 (9500, 0.0500): np.array([0.146501681549470, 0.317332024579680]),
53 (12000, -0.0500): np.array([0.233956908310164, 0.268393952067210]),
54 (12000, -0.0250): np.array([0.210911787488415, 0.278085309366938]),
55 (12000, 0.0000): np.array([0.187866666666667, 0.287776666666667]),
56 (12000, 0.0250): np.array([0.164821545844918, 0.297468023966395]),
57 (12000, 0.0500): np.array([0.141776425023169, 0.307159381266124]),
58 (14500, -0.0500): np.array([0.232785809380768, 0.265479540863524]),
59 (14500, -0.0250): np.array([0.209387387449005, 0.274283735949003]),
60 (14500, 0.0000): np.array([0.185988965517241, 0.283087931034483]),
61 (14500, 0.0250): np.array([0.162590543585478, 0.291892126119962]),
62 (14500, 0.0500): np.array([0.139192121653715, 0.300696321205442]),
63 (17000, -0.0500): np.array([0.232028466821727, 0.263383405240889]),
64 (17000, -0.0250): np.array([0.208421880469687, 0.271613173208680]),
65 (17000, 0.0000): np.array([0.184815294117647, 0.279842941176471]),
66 (17000, 0.0250): np.array([0.161208707765607, 0.288072709144261]),
67 (17000, 0.0500): np.array([0.137602121413567, 0.296302477112052]),
68 (19500, -0.0500): np.array([0.231498602829451, 0.261824985205592]),
69 (19500, -0.0250): np.array([0.207757250132674, 0.269657492602796]),
70 (19500, 0.0000): np.array([0.184015897435897, 0.277490000000000]),
71 (19500, 0.0250): np.array([0.160274544739121, 0.285322507397204]),
72 (19500, 0.0500): np.array([0.136533192042344, 0.293155014794408]),
73 (22000, -0.0500): np.array([0.231114936519607, 0.260621561540512]),
74 (22000, -0.0250): np.array([0.207281559168895, 0.268169417133892]),
75 (22000, 0.0000): np.array([0.183448181818182, 0.275717272727273]),
76 (22000, 0.0250): np.array([0.159614804467469, 0.283265128320653]),
77 (22000, 0.0500): np.array([0.135781427116756, 0.290812983914034]),
78 (24500, -0.0500): np.array([0.230812633988541, 0.259664771591227]),
79 (24500, -0.0250): np.array([0.206910092504474, 0.266990651101736]),
80 (24500, 0.0000): np.array([0.183007551020408, 0.274316530612245]),
81 (24500, 0.0250): np.array([0.159105009536342, 0.281642410122754]),
82 (24500, 0.0500): np.array([0.135202468052276, 0.288968289633262]),
83 (27000, -0.0500): np.array([0.230583187091274, 0.258895100975109]),
84 (27000, -0.0250): np.array([0.206630667619711, 0.266055883820888]),
85 (27000, 0.0000): np.array([0.182678148148148, 0.273216666666667]),
86 (27000, 0.0250): np.array([0.158725628676585, 0.280377449512446]),
87 (27000, 0.0500): np.array([0.134773109205022, 0.287538232358225]),
88 (29500, -0.0500): np.array([0.230395500499851, 0.258258464459758]),
89 (29500, -0.0250): np.array([0.206403428216027, 0.265285588162082]),
90 (29500, 0.0000): np.array([0.182411355932203, 0.272312711864407]),
91 (29500, 0.0250): np.array([0.158419283648380, 0.279339835566731]),
92 (29500, 0.0500): np.array([0.134427211364556, 0.286366959269056]),
93 (32000, -0.0500): np.array([0.230235978654155, 0.257721638699323]),
94 (32000, -0.0250): np.array([0.206211114327078, 0.264635819349661]),
95 (32000, 0.0000): np.array([0.182186250000000, 0.271550000000000]),
96 (32000, 0.0250): np.array([0.158161385672923, 0.278464180650339]),
97 (32000, 0.0500): np.array([0.134136521345845, 0.285378361300677]),
98 (34500, -0.0500): np.array([0.230105666168844, 0.257266749246258]),
99 (34500, -0.0250): np.array([0.206054789606161, 0.264089896362260]),
100 (34500, 0.0000): np.array([0.182003913043478, 0.270913043478261]),
101 (34500, 0.0250): np.array([0.157953036480796, 0.277736190594262]),
102 (34500, 0.0500): np.array([0.133902159918113, 0.284559337710263]),
103 (37000, -0.0500): np.array([0.229999835834901, 0.256877639136083]),
104 (37000, -0.0250): np.array([0.205928431430964, 0.263628008757231]),
105 (37000, 0.0000): np.array([0.181857027027027, 0.270378378378378]),
106 (37000, 0.0250): np.array([0.157785622623090, 0.277128747999526]),
107 (37000, 0.0500): np.array([0.133714218219153, 0.283879117620674]),
108 (39500, -0.0500): np.array([0.229907042065651, 0.256537886918202]),
109 (39500, -0.0250): np.array([0.205817888121433, 0.263224639661633]),
110 (39500, 0.0000): np.array([0.181728734177215, 0.269911392405063]),
111 (39500, 0.0250): np.array([0.157639580232997, 0.276598145148494]),
112 (39500, 0.0500): np.array([0.133550426288780, 0.283284897891924]),
113 (42000, -0.0500): np.array([0.229825016678223, 0.256238659086365]),
114 (42000, -0.0250): np.array([0.205720365481969, 0.262869329543182]),
115 (42000, 0.0000): np.array([0.181615714285714, 0.269500000000000]),
116 (42000, 0.0250): np.array([0.157511063089460, 0.276130670456817]),
117 (42000, 0.0500): np.array([0.133406411893206, 0.282761340913635]),
118 (44500, -0.0500): np.array([0.229751988653572, 0.255973111790163]),
119 (44500, -0.0250): np.array([0.205633690955999, 0.262553971625419]),
120 (44500, 0.0000): np.array([0.181515393258427, 0.269134831460674]),
121 (44500, 0.0250): np.array([0.157397095560855, 0.275715691295930]),
122 (44500, 0.0500): np.array([0.133278797863282, 0.282296551131185]),
123 (47000, -0.0500): np.array([0.229686555034366, 0.255735860408829]),
124 (47000, -0.0250): np.array([0.205556149857609, 0.262272185523563]),
125 (47000, 0.0000): np.array([0.181425744680851, 0.268808510638298]),
126 (47000, 0.0250): np.array([0.157295339504093, 0.275344835753032]),
127 (47000, 0.0500): np.array([0.133164934327336, 0.281881160867767]),
128 (49500, -0.0500): np.array([0.229627590056716, 0.255522610251793]),
129 (49500, -0.0250): np.array([0.205486370785934, 0.262018880883472]),
130 (49500, 0.0000): np.array([0.181345151515151, 0.268515151515151]),
131 (49500, 0.0250): np.array([0.157203932244369, 0.275011422146831]),
132 (49500, 0.0500): np.array([0.133062712973587, 0.281507692778510]),
133}
136class TestMired_to_CCT:
137 """
138 Define :func:`colour.temperature.robertson1968.mired_to_CCT`
139 definition unit tests methods.
140 """
142 def test_mired_to_CCT(self) -> None:
143 """
144 Test :func:`colour.temperature.robertson1968.mired_to_CCT`
145 definition.
146 """
148 np.testing.assert_allclose(
149 CCT_to_mired(312.5), 3200, atol=TOLERANCE_ABSOLUTE_TESTS
150 )
152 np.testing.assert_allclose(
153 CCT_to_mired(153.846153846154), 6500, atol=TOLERANCE_ABSOLUTE_TESTS
154 )
156 np.testing.assert_allclose(
157 CCT_to_mired(66.666666666666667),
158 15000,
159 atol=TOLERANCE_ABSOLUTE_TESTS,
160 )
162 def test_n_dimensional_mired_to_CCT(self) -> None:
163 """
164 Test :func:`colour.temperature.robertson1968.mired_to_CCT`
165 definition n-dimensional arrays support.
166 """
168 mired = 312.5
169 CCT = mired_to_CCT(mired)
171 mired = np.tile(mired, (6, 1))
172 CCT = np.tile(CCT, (6, 1))
173 np.testing.assert_allclose(
174 mired_to_CCT(mired), CCT, atol=TOLERANCE_ABSOLUTE_TESTS
175 )
177 mired = np.reshape(mired, (2, 3, 1))
178 CCT = np.reshape(CCT, (2, 3, 1))
179 np.testing.assert_allclose(
180 mired_to_CCT(mired), CCT, atol=TOLERANCE_ABSOLUTE_TESTS
181 )
183 @ignore_numpy_errors
184 def test_nan_mired_to_CCT(self) -> None:
185 """
186 Test :func:`colour.temperature.robertson1968.mired_to_CCT`
187 definition nan support.
188 """
190 cases = [-1.0, 0.0, 1.0, -np.inf, np.inf, np.nan]
191 cases = np.array(list(set(product(cases, repeat=2))))
192 mired_to_CCT(cases)
195class TestCCT_to_mired:
196 """
197 Define :func:`colour.temperature.robertson1968.CCT_to_mired`
198 definition unit tests methods.
199 """
201 def test_CCT_to_mired(self) -> None:
202 """
203 Test :func:`colour.temperature.robertson1968.CCT_to_mired`
204 definition.
205 """
207 np.testing.assert_allclose(
208 CCT_to_mired(3200), 312.5, atol=TOLERANCE_ABSOLUTE_TESTS
209 )
211 np.testing.assert_allclose(
212 CCT_to_mired(6500), 153.846153846154, atol=TOLERANCE_ABSOLUTE_TESTS
213 )
215 np.testing.assert_allclose(
216 CCT_to_mired(15000),
217 66.666666666666667,
218 atol=TOLERANCE_ABSOLUTE_TESTS,
219 )
221 def test_n_dimensional_CCT_to_mired(self) -> None:
222 """
223 Test :func:`colour.temperature.robertson1968.CCT_to_mired`
224 definition n-dimensional arrays support.
225 """
227 CCT = 3200
228 mired = CCT_to_mired(CCT)
230 CCT = np.tile(CCT, (6, 1))
231 mired = np.tile(mired, (6, 1))
232 np.testing.assert_allclose(
233 CCT_to_mired(CCT), mired, atol=TOLERANCE_ABSOLUTE_TESTS
234 )
236 CCT = np.reshape(CCT, (2, 3, 1))
237 mired = np.reshape(mired, (2, 3, 1))
238 np.testing.assert_allclose(
239 CCT_to_mired(CCT), mired, atol=TOLERANCE_ABSOLUTE_TESTS
240 )
242 @ignore_numpy_errors
243 def test_nan_CCT_to_mired(self) -> None:
244 """
245 Test :func:`colour.temperature.robertson1968.CCT_to_mired`
246 definition nan support.
247 """
249 cases = [-1.0, 0.0, 1.0, -np.inf, np.inf, np.nan]
250 cases = np.array(list(set(product(cases, repeat=2))))
251 CCT_to_mired(cases)
254class TestUv_to_CCT_Robertson1968:
255 """
256 Define :func:`colour.temperature.robertson1968.uv_to_CCT_Robertson1968`
257 definition unit tests methods.
258 """
260 def test_uv_to_CCT_Robertson1968(self) -> None:
261 """
262 Test :func:`colour.temperature.robertson1968.uv_to_CCT_Robertson1968`
263 definition.
264 """
266 for key, value in TEMPERATURE_DUV_TO_UV.items():
267 np.testing.assert_allclose(uv_to_CCT_Robertson1968(value), key, atol=0.25)
269 def test_n_dimensional_uv_to_CCT_Robertson1968(self) -> None:
270 """
271 Test :func:`colour.temperature.robertson1968.uv_to_CCT_Robertson1968`
272 definition n-dimensional arrays support.
273 """
275 uv = np.array([0.1978, 0.3122])
276 CCT_D_uv = uv_to_CCT_Robertson1968(uv)
278 uv = np.tile(uv, (6, 1))
279 CCT_D_uv = np.tile(CCT_D_uv, (6, 1))
280 np.testing.assert_allclose(
281 uv_to_CCT_Robertson1968(uv),
282 CCT_D_uv,
283 atol=TOLERANCE_ABSOLUTE_TESTS,
284 )
286 uv = np.reshape(uv, (2, 3, 2))
287 CCT_D_uv = np.reshape(CCT_D_uv, (2, 3, 2))
288 np.testing.assert_allclose(
289 uv_to_CCT_Robertson1968(uv),
290 CCT_D_uv,
291 atol=TOLERANCE_ABSOLUTE_TESTS,
292 )
294 @ignore_numpy_errors
295 def test_nan_uv_to_CCT_Robertson1968(self) -> None:
296 """
297 Test :func:`colour.temperature.robertson1968.uv_to_CCT_Robertson1968`
298 definition nan support.
299 """
301 cases = [-1.0, 0.0, 1.0, -np.inf, np.inf, np.nan]
302 cases = np.array(list(set(product(cases, repeat=2))))
303 uv_to_CCT_Robertson1968(cases)
306class TestCCT_to_uv_Robertson1968:
307 """
308 Define :func:`colour.temperature.robertson1968.CCT_to_uv_Robertson1968`
309 definition unit tests methods.
310 """
312 def test_CCT_to_uv_Robertson1968(self) -> None:
313 """
314 Test :func:`colour.temperature.robertson1968.CCT_to_uv_Robertson1968`
315 definition.
316 """
318 for key, value in TEMPERATURE_DUV_TO_UV.items():
319 np.testing.assert_allclose(
320 CCT_to_uv_Robertson1968(key),
321 value,
322 atol=TOLERANCE_ABSOLUTE_TESTS,
323 )
325 def test_n_dimensional_CCT_to_uv_Robertson1968(self) -> None:
326 """
327 Test :func:`colour.temperature.robertson1968.CCT_to_uv_Robertson1968`
328 definition n-dimensional arrays support.
329 """
331 CCT_D_uv = np.array([4500, 0.0250])
332 uv = CCT_to_uv_Robertson1968(CCT_D_uv)
334 CCT_D_uv = np.tile(CCT_D_uv, (6, 1))
335 uv = np.tile(uv, (6, 1))
336 np.testing.assert_allclose(
337 CCT_to_uv_Robertson1968(CCT_D_uv),
338 uv,
339 atol=TOLERANCE_ABSOLUTE_TESTS,
340 )
342 CCT_D_uv = np.reshape(CCT_D_uv, (2, 3, 2))
343 uv = np.reshape(uv, (2, 3, 2))
344 np.testing.assert_allclose(
345 CCT_to_uv_Robertson1968(CCT_D_uv),
346 uv,
347 atol=TOLERANCE_ABSOLUTE_TESTS,
348 )
350 @ignore_numpy_errors
351 def test_nan_CCT_to_uv_Robertson1968(self) -> None:
352 """
353 Test :func:`colour.temperature.robertson1968.CCT_to_uv_Robertson1968`
354 definition nan support.
355 """
357 cases = [-1.0, 0.0, 1.0, -np.inf, np.inf, np.nan]
358 cases = np.array(list(set(product(cases, repeat=2))))
359 CCT_to_uv_Robertson1968(cases)