Coverage for colour/colorimetry/tests/test_lefs.py: 100%
36 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.lefs` module."""
3from __future__ import annotations
5import numpy as np
7from colour.colorimetry import (
8 mesopic_weighting_function,
9 sd_mesopic_luminous_efficiency_function,
10)
11from colour.constants import TOLERANCE_ABSOLUTE_TESTS
12from colour.utilities import ignore_numpy_errors
14__author__ = "Colour Developers"
15__copyright__ = "Copyright 2013 Colour Developers"
16__license__ = "BSD-3-Clause - https://opensource.org/licenses/BSD-3-Clause"
17__maintainer__ = "Colour Developers"
18__email__ = "colour-developers@colour-science.org"
19__status__ = "Production"
21__all__ = [
22 "DATA_MESOPIC_LEF",
23 "TestMesopicWeightingFunction",
24 "TestSdMesopicLuminousEfficiencyFunction",
25]
27DATA_MESOPIC_LEF: tuple = (
28 0.000423996221042,
29 0.000478105586021,
30 0.000539901310829,
31 0.000612292743837,
32 0.000696128469661,
33 0.000792943994169,
34 0.000907002019269,
35 0.001038991062951,
36 0.001192298013423,
37 0.001370309788741,
38 0.001577100133700,
39 0.001816732944066,
40 0.002094217578858,
41 0.002416076568544,
42 0.002788832443596,
43 0.003219694655734,
44 0.003722285106836,
45 0.004295769587890,
46 0.004953150383591,
47 0.005714298941411,
48 0.006578479021522,
49 0.007565798249134,
50 0.008691294922216,
51 0.009963802139828,
52 0.011405891376328,
53 0.013040134056330,
54 0.014875060844050,
55 0.016931081053406,
56 0.019221107382718,
57 0.021751183317789,
58 0.024534221556937,
59 0.027577375342778,
60 0.030917278398861,
61 0.034514896661912,
62 0.038399887696429,
63 0.042574431719405,
64 0.047107420323755,
65 0.051932288874149,
66 0.057054111113075,
67 0.062546652908218,
68 0.068346295876871,
69 0.074525532476839,
70 0.080944093388470,
71 0.087734408501845,
72 0.094891523456653,
73 0.102273099642187,
74 0.109877001609769,
75 0.117842125286601,
76 0.126031604242477,
77 0.134377265167241,
78 0.143017004659794,
79 0.151812831610346,
80 0.160832831284698,
81 0.170008823906160,
82 0.179272634672297,
83 0.188693478005329,
84 0.198204129185973,
85 0.207803250139006,
86 0.217418447891767,
87 0.227114713721992,
88 0.236819654657020,
89 0.246462295387537,
90 0.256115392006985,
91 0.265716062322745,
92 0.275338793469816,
93 0.284852031027409,
94 0.294464840899776,
95 0.303490271989407,
96 0.313234753059177,
97 0.322325715015028,
98 0.331451347544553,
99 0.340612983748718,
100 0.349811757758196,
101 0.358361748146747,
102 0.367637792269774,
103 0.376267037500552,
104 0.384939235443477,
105 0.393654052823306,
106 0.402407748998520,
107 0.411196583327596,
108 0.419329893917046,
109 0.428180314526271,
110 0.436380414469050,
111 0.445311711528396,
112 0.454294964705678,
113 0.462650937976521,
114 0.471757050335889,
115 0.480930016713931,
116 0.490177596952101,
117 0.499507550891852,
118 0.509614559626605,
119 0.519129332097892,
120 0.529425904805685,
121 0.539131693733156,
122 0.549621720283231,
123 0.560210336613821,
124 0.570219774106467,
125 0.581020791225554,
126 0.591909355273857,
127 0.602868354806121,
128 0.613880678377089,
129 0.624937372323546,
130 0.636061964882719,
131 0.646598972109041,
132 0.657953823040568,
133 0.668784162222337,
134 0.679793972609001,
135 0.690988775626207,
136 0.702382747907381,
137 0.713303244319125,
138 0.724451313004257,
139 0.735847049962440,
140 0.746811890694040,
141 0.758029423698604,
142 0.769496415708862,
143 0.780522562977852,
144 0.791780560381546,
145 0.802612337360557,
146 0.813079325993057,
147 0.823929780124040,
148 0.835225181574250,
149 0.845634267482597,
150 0.856481883918201,
151 0.867692173456598,
152 0.878502108708491,
153 0.888148910997447,
154 0.898640517466401,
155 0.907932280953237,
156 0.917425551604990,
157 0.925773944818251,
158 0.935065632506880,
159 0.943236567905124,
160 0.950906320820545,
161 0.958693118011219,
162 0.965841393473861,
163 0.972282552199726,
164 0.977992469040708,
165 0.983610660576306,
166 0.988346542031548,
167 0.992096449883431,
168 0.995443641860918,
169 0.997620215802517,
170 0.999345724088358,
171 1.000000000000000,
172 0.999649798070971,
173 0.999048794086766,
174 0.997535634478154,
175 0.995761525329390,
176 0.993014375646354,
177 0.989955936938867,
178 0.985874118212809,
179 0.981445295294584,
180 0.976688569332386,
181 0.970936319192731,
182 0.964894766246075,
183 0.958583260353477,
184 0.952011998742489,
185 0.944491622775044,
186 0.936708904475390,
187 0.929350665610349,
188 0.921042964190838,
189 0.912477248043005,
190 0.903660431384556,
191 0.894595846967911,
192 0.884599956036092,
193 0.875050033330603,
194 0.865945730653430,
195 0.855922407876719,
196 0.845684595123427,
197 0.835249901264545,
198 0.825322906165605,
199 0.815207983624290,
200 0.804220500547010,
201 0.794420922234228,
202 0.783746644454823,
203 0.773568077475167,
204 0.762780824836753,
205 0.752271069434583,
206 0.741754989619506,
207 0.731290980804024,
208 0.720798313160170,
209 0.710193918959030,
210 0.699636273302128,
211 0.689065687470055,
212 0.678559906736370,
213 0.668059341866812,
214 0.657569762999898,
215 0.647157872557888,
216 0.636820835214096,
217 0.626487173259215,
218 0.616154150851706,
219 0.605889614493019,
220 0.595700080460271,
221 0.585593706535502,
222 0.575441266250360,
223 0.565388301637279,
224 0.555374278353102,
225 0.545468087493321,
226 0.535597256497158,
227 0.525826697054231,
228 0.516015244478566,
229 0.506232237548814,
230 0.496559550172129,
231 0.486874671127568,
232 0.477329907437551,
233 0.467802847366283,
234 0.458370440306148,
235 0.448972251399137,
236 0.439760637410242,
237 0.430613136861096,
238 0.421544622781150,
239 0.412568127724641,
240 0.403755029915728,
241 0.395035990575763,
242 0.386410412793862,
243 0.377877749401719,
244 0.369440537270578,
245 0.361107481350787,
246 0.352859660514895,
247 0.344705630485531,
248 0.336647077772802,
249 0.328691712475589,
250 0.320841076613668,
251 0.313080884593691,
252 0.305410539504777,
253 0.297822525480953,
254 0.290302706156591,
255 0.282872778768479,
256 0.275531191822063,
257 0.268290082505259,
258 0.261147799838367,
259 0.254117629825878,
260 0.247188574621679,
261 0.240357052760484,
262 0.233605744351966,
263 0.226937937143361,
264 0.220352731030957,
265 0.213846544549470,
266 0.207394601159948,
267 0.200978993535962,
268 0.194581814351080,
269 0.188194308912381,
270 0.181822635824193,
271 0.175498734556038,
272 0.169247675364920,
273 0.163087659295321,
274 0.157025700050094,
275 0.151071000005320,
276 0.145246954751365,
277 0.139584565754938,
278 0.134108701934053,
279 0.128840802337855,
280 0.123766619272101,
281 0.118863181142645,
282 0.114107516355346,
283 0.109476653316060,
284 0.104961368330458,
285 0.100567919488016,
286 0.096292436342783,
287 0.092129674606303,
288 0.088077824596383,
289 0.084130597430525,
290 0.080288739247331,
291 0.076555990214584,
292 0.072936727678744,
293 0.069434592322446,
294 0.066049096194732,
295 0.062779244444135,
296 0.059627872397338,
297 0.056597078717201,
298 0.053689599245262,
299 0.050906885990927,
300 0.048244432277043,
301 0.045695095070067,
302 0.043251069286492,
303 0.040905236764061,
304 0.038653732504820,
305 0.036495591265975,
306 0.034428544786178,
307 0.032450118727706,
308 0.030557907444960,
309 0.028749627753821,
310 0.027023338509577,
311 0.025377681739976,
312 0.023811304447019,
313 0.022322652530592,
314 0.020908627975848,
315 0.019568807970913,
316 0.018305670643421,
317 0.017121625428881,
318 0.016019287839177,
319 0.014998624949462,
320 0.014053763109294,
321 0.013178438781201,
322 0.012366256017720,
323 0.011610755153519,
324 0.010909796310463,
325 0.010258783274767,
326 0.009647645070271,
327 0.009066521771446,
328 0.008505352350642,
329 0.007956703372438,
330 0.007422984272341,
331 0.006909491686943,
332 0.006421306227945,
333 0.005963729506196,
334 0.005537741450392,
335 0.005140198329894,
336 0.004770003226209,
337 0.004426333586668,
338 0.004108134205482,
339 0.003814898916435,
340 0.003545595063702,
341 0.003298484428587,
342 0.003071843028242,
343 0.002863947377246,
344 0.002673821526309,
345 0.002500026114851,
346 0.002340163148156,
347 0.002191847872506,
348 0.002052667559907,
349 0.001920775671288,
350 0.001795998699814,
351 0.001678462683692,
352 0.001568320640552,
353 0.001465704482962,
354 0.001370202034484,
355 0.001281000501467,
356 0.001197625742439,
357 0.001119582510866,
358 0.001046395670422,
359 0.000977644493684,
360 0.000913102154518,
361 0.000852563310843,
362 0.000795835861579,
363 0.000742713469792,
364 0.000692929112612,
365 0.000646294076190,
366 0.000602683198736,
367 0.000561985056886,
368 0.000524088227275,
369 0.000488865075198,
370 0.000456100902232,
371 0.000425592157031,
372 0.000397124984426,
373 0.000370486903095,
374 0.000345511126189,
375 0.000322107797301,
376 0.000300185818831,
377 0.000279651295749,
378 0.000260410283283,
379 0.000242354880318,
380 0.000225413417278,
381 0.000209548506700,
382 0.000194724821881,
383 0.000180904975355,
384 0.000168036678203,
385 0.000156055324297,
386 0.000144907947270,
387 0.000134542904857,
388 0.000124905757365,
389 0.000115947828132,
390 0.000107630246890,
391 0.000099921825045,
392 0.000092792011184,
393 0.000086209517226,
394 0.000080138556943,
395 0.000074542690348,
396 0.000069382092589,
397 0.000064618362399,
398 0.000060213148254,
399 0.000056133629529,
400 0.000052356318257,
401 0.000048854801130,
402 0.000045601913255,
403 0.000042571186609,
404 0.000039737093303,
405 0.000037085765108,
406 0.000034608253334,
407 0.000032294917398,
408 0.000030137485583,
409 0.000028122278208,
410 0.000026238700578,
411 0.000024479703696,
412 0.000022839057899,
413 0.000021310391162,
414 0.000019886198277,
415 0.000018558646686,
416 0.000017321059987,
417 0.000016166624394,
418 0.000015088526124,
419 0.000014080323512,
420 0.000013137863053,
421 0.000012257679587,
422 0.000011436518999,
423 0.000010671063462,
424 0.000009957265824,
425 0.000009291440160,
426 0.000008670655686,
427 0.000008091780515,
428 0.000007551893809,
429)
432class TestMesopicWeightingFunction:
433 """
434 Define :func:`colour.colorimetry.lefs.mesopic_weighting_function`
435 definition unit tests methods.
436 """
438 def test_mesopic_weighting_function(self) -> None:
439 """
440 Test :func:`colour.colorimetry.lefs.mesopic_weighting_function`
441 definition.
442 """
444 np.testing.assert_allclose(
445 mesopic_weighting_function(500, 0.2),
446 0.70522000,
447 atol=TOLERANCE_ABSOLUTE_TESTS,
448 )
450 np.testing.assert_allclose(
451 mesopic_weighting_function(500, 0.2, source="Red Heavy", method="LRC"),
452 0.90951000,
453 atol=TOLERANCE_ABSOLUTE_TESTS,
454 )
456 np.testing.assert_allclose(
457 mesopic_weighting_function(700, 10, source="Red Heavy", method="LRC"),
458 0.00410200,
459 atol=TOLERANCE_ABSOLUTE_TESTS,
460 )
462 def test_n_dimensional_mesopic_weighting_function(self) -> None:
463 """
464 Test :func:`colour.colorimetry.lefs.mesopic_weighting_function`
465 definition n-dimensional arrays support.
466 """
468 wl = 500
469 Vm = mesopic_weighting_function(wl, 0.2)
471 wl = np.tile(wl, 6)
472 Vm = np.tile(Vm, 6)
473 np.testing.assert_allclose(
474 mesopic_weighting_function(wl, 0.2),
475 Vm,
476 atol=TOLERANCE_ABSOLUTE_TESTS,
477 )
479 wl = np.reshape(wl, (2, 3))
480 Vm = np.reshape(Vm, (2, 3))
481 np.testing.assert_allclose(
482 mesopic_weighting_function(wl, 0.2),
483 Vm,
484 atol=TOLERANCE_ABSOLUTE_TESTS,
485 )
487 wl = np.reshape(wl, (2, 3, 1))
488 Vm = np.reshape(Vm, (2, 3, 1))
489 np.testing.assert_allclose(
490 mesopic_weighting_function(wl, 0.2),
491 Vm,
492 atol=TOLERANCE_ABSOLUTE_TESTS,
493 )
495 @ignore_numpy_errors
496 def test_nan_mesopic_weighting_function(self) -> None:
497 """
498 Test :func:`colour.colorimetry.lefs.mesopic_weighting_function`
499 definition nan support.
500 """
502 (
503 mesopic_weighting_function(
504 np.array([-1.0, 0.0, 1.0, -np.inf, np.inf, np.nan]), 0.2
505 ),
506 )
509class TestSdMesopicLuminousEfficiencyFunction:
510 """
511 Define :func:`colour.colorimetry.lefs.\
512sd_mesopic_luminous_efficiency_function` definition unit tests methods.
513 """
515 def test_sd_mesopic_luminous_efficiency_function(self) -> None:
516 """
517 Test :func:`colour.colorimetry.lefs.\
518sd_mesopic_luminous_efficiency_function` definition.
519 """
521 np.testing.assert_allclose(
522 sd_mesopic_luminous_efficiency_function(0.2).values,
523 DATA_MESOPIC_LEF,
524 atol=TOLERANCE_ABSOLUTE_TESTS,
525 )