Coverage for colorimetry/lefs.py: 48%
27 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"""
2Luminous Efficiency Functions Spectral Distributions
3====================================================
5Define the luminous efficiency functions and their computation objects for
6photopic, scotopic, and mesopic vision conditions.
8References
9----------
10- :cite:`Wikipedia2005d` : Wikipedia. (2005). Mesopic weighting function.
11 Retrieved June 20, 2014, from
12 http://en.wikipedia.org/wiki/Mesopic_vision#Mesopic_weighting_function
13"""
15from __future__ import annotations
17import typing
19from colour.colorimetry import (
20 SDS_LEFS_PHOTOPIC,
21 SDS_LEFS_SCOTOPIC,
22 SpectralDistribution,
23 SpectralShape,
24)
25from colour.colorimetry.datasets.lefs import DATA_MESOPIC_X
27if typing.TYPE_CHECKING:
28 from colour.hints import ArrayLike, Literal, NDArrayFloat
30from colour.utilities import closest, optional, validate_method
32__author__ = "Colour Developers"
33__copyright__ = "Copyright 2013 Colour Developers"
34__license__ = "BSD-3-Clause - https://opensource.org/licenses/BSD-3-Clause"
35__maintainer__ = "Colour Developers"
36__email__ = "colour-developers@colour-science.org"
37__status__ = "Production"
39__all__ = [
40 "mesopic_weighting_function",
41 "sd_mesopic_luminous_efficiency_function",
42]
45def mesopic_weighting_function(
46 wavelength: ArrayLike,
47 L_p: float,
48 source: Literal["Blue Heavy", "Red Heavy"] | str = "Blue Heavy",
49 method: Literal["MOVE", "LRC"] | str = "MOVE",
50 photopic_lef: SpectralDistribution | None = None,
51 scotopic_lef: SpectralDistribution | None = None,
52) -> NDArrayFloat:
53 """
54 Calculate the mesopic weighting function factor :math:`V_m` at the specified
55 wavelength :math:`\\lambda` using the specified photopic luminance
56 :math:`L_p`.
58 The mesopic weighting function provides a transition between photopic and
59 scotopic vision, accounting for the combined response of rods and cones
60 under intermediate lighting conditions.
62 Parameters
63 ----------
64 wavelength
65 Wavelength :math:`\\lambda` to calculate the mesopic weighting function
66 factor.
67 L_p
68 Photopic luminance :math:`L_p`.
69 source
70 Light source colour temperature.
71 method
72 Method to calculate the weighting factor.
73 photopic_lef
74 :math:`V(\\lambda)` photopic luminous efficiency function, defaults to
75 the *CIE 1924 Photopic Standard Observer*.
76 scotopic_lef
77 :math:`V^\\prime(\\lambda)` scotopic luminous efficiency function,
78 defaults to the *CIE 1951 Scotopic Standard Observer*.
80 Returns
81 -------
82 :class:`numpy.ndarray`
83 Mesopic weighting function factor :math:`V_m`.
85 References
86 ----------
87 :cite:`Wikipedia2005d`
89 Examples
90 --------
91 >>> mesopic_weighting_function(500, 0.2) # doctest: +ELLIPSIS
92 0.7052...
93 """
95 photopic_lef = optional(
96 photopic_lef,
97 SDS_LEFS_PHOTOPIC["CIE 1924 Photopic Standard Observer"],
98 )
100 scotopic_lef = optional(
101 scotopic_lef,
102 SDS_LEFS_SCOTOPIC["CIE 1951 Scotopic Standard Observer"],
103 )
105 source = validate_method(
106 source,
107 ("Blue Heavy", "Red Heavy"),
108 '"{0}" light source colour temperature is invalid, it must be one of {1}!',
109 )
110 method = validate_method(method, ("MOVE", "LRC"))
112 mesopic_x_luminance_values = sorted(DATA_MESOPIC_X.keys())
113 index = mesopic_x_luminance_values.index(closest(mesopic_x_luminance_values, L_p))
114 x = DATA_MESOPIC_X[mesopic_x_luminance_values[index]][source][method]
116 return (1 - x) * scotopic_lef[wavelength] + x * photopic_lef[wavelength]
119def sd_mesopic_luminous_efficiency_function(
120 L_p: float,
121 source: Literal["Blue Heavy", "Red Heavy"] | str = "Blue Heavy",
122 method: Literal["MOVE", "LRC"] | str = "MOVE",
123 photopic_lef: SpectralDistribution | None = None,
124 scotopic_lef: SpectralDistribution | None = None,
125) -> SpectralDistribution:
126 """
127 Return the mesopic luminous efficiency function :math:`V_m(\\lambda)` for
128 the specified photopic luminance :math:`L_p`.
130 Parameters
131 ----------
132 L_p
133 Photopic luminance :math:`L_p`.
134 source
135 Light source colour temperature.
136 method
137 Method to calculate the weighting factor.
138 photopic_lef
139 :math:`V(\\lambda)` photopic luminous efficiency function, default to
140 the *CIE 1924 Photopic Standard Observer*.
141 scotopic_lef
142 :math:`V^\\prime(\\lambda)` scotopic luminous efficiency function,
143 default to the *CIE 1951 Scotopic Standard Observer*.
145 Returns
146 -------
147 :class:`colour.SpectralDistribution`
148 Mesopic luminous efficiency function :math:`V_m(\\lambda)`.
150 References
151 ----------
152 :cite:`Wikipedia2005d`
154 Examples
155 --------
156 >>> from colour.utilities import numpy_print_options
157 >>> with numpy_print_options(suppress=True):
158 ... sd_mesopic_luminous_efficiency_function(0.2) # doctest: +ELLIPSIS
159 SpectralDistribution([[ 380. , 0.000424 ...],
160 [ 381. , 0.0004781...],
161 [ 382. , 0.0005399...],
162 [ 383. , 0.0006122...],
163 [ 384. , 0.0006961...],
164 [ 385. , 0.0007929...],
165 [ 386. , 0.000907 ...],
166 [ 387. , 0.0010389...],
167 [ 388. , 0.0011923...],
168 [ 389. , 0.0013703...],
169 [ 390. , 0.0015771...],
170 [ 391. , 0.0018167...],
171 [ 392. , 0.0020942...],
172 [ 393. , 0.0024160...],
173 [ 394. , 0.0027888...],
174 [ 395. , 0.0032196...],
175 [ 396. , 0.0037222...],
176 [ 397. , 0.0042957...],
177 [ 398. , 0.0049531...],
178 [ 399. , 0.0057143...],
179 [ 400. , 0.0065784...],
180 [ 401. , 0.0075658...],
181 [ 402. , 0.0086912...],
182 [ 403. , 0.0099638...],
183 [ 404. , 0.0114058...],
184 [ 405. , 0.0130401...],
185 [ 406. , 0.0148750...],
186 [ 407. , 0.0169310...],
187 [ 408. , 0.0192211...],
188 [ 409. , 0.0217511...],
189 [ 410. , 0.0245342...],
190 [ 411. , 0.0275773...],
191 [ 412. , 0.0309172...],
192 [ 413. , 0.0345149...],
193 [ 414. , 0.0383998...],
194 [ 415. , 0.0425744...],
195 [ 416. , 0.0471074...],
196 [ 417. , 0.0519322...],
197 [ 418. , 0.0570541...],
198 [ 419. , 0.0625466...],
199 [ 420. , 0.0683463...],
200 [ 421. , 0.0745255...],
201 [ 422. , 0.0809440...],
202 [ 423. , 0.0877344...],
203 [ 424. , 0.0948915...],
204 [ 425. , 0.1022731...],
205 [ 426. , 0.109877 ...],
206 [ 427. , 0.1178421...],
207 [ 428. , 0.1260316...],
208 [ 429. , 0.1343772...],
209 [ 430. , 0.143017 ...],
210 [ 431. , 0.1518128...],
211 [ 432. , 0.1608328...],
212 [ 433. , 0.1700088...],
213 [ 434. , 0.1792726...],
214 [ 435. , 0.1886934...],
215 [ 436. , 0.1982041...],
216 [ 437. , 0.2078032...],
217 [ 438. , 0.2174184...],
218 [ 439. , 0.2271147...],
219 [ 440. , 0.2368196...],
220 [ 441. , 0.2464623...],
221 [ 442. , 0.2561153...],
222 [ 443. , 0.2657160...],
223 [ 444. , 0.2753387...],
224 [ 445. , 0.2848520...],
225 [ 446. , 0.2944648...],
226 [ 447. , 0.3034902...],
227 [ 448. , 0.3132347...],
228 [ 449. , 0.3223257...],
229 [ 450. , 0.3314513...],
230 [ 451. , 0.3406129...],
231 [ 452. , 0.3498117...],
232 [ 453. , 0.3583617...],
233 [ 454. , 0.3676377...],
234 [ 455. , 0.3762670...],
235 [ 456. , 0.3849392...],
236 [ 457. , 0.3936540...],
237 [ 458. , 0.4024077...],
238 [ 459. , 0.4111965...],
239 [ 460. , 0.4193298...],
240 [ 461. , 0.4281803...],
241 [ 462. , 0.4363804...],
242 [ 463. , 0.4453117...],
243 [ 464. , 0.4542949...],
244 [ 465. , 0.4626509...],
245 [ 466. , 0.4717570...],
246 [ 467. , 0.4809300...],
247 [ 468. , 0.4901776...],
248 [ 469. , 0.4995075...],
249 [ 470. , 0.5096145...],
250 [ 471. , 0.5191293...],
251 [ 472. , 0.5294259...],
252 [ 473. , 0.5391316...],
253 [ 474. , 0.5496217...],
254 [ 475. , 0.5602103...],
255 [ 476. , 0.5702197...],
256 [ 477. , 0.5810207...],
257 [ 478. , 0.5919093...],
258 [ 479. , 0.6028683...],
259 [ 480. , 0.6138806...],
260 [ 481. , 0.6249373...],
261 [ 482. , 0.6360619...],
262 [ 483. , 0.6465989...],
263 [ 484. , 0.6579538...],
264 [ 485. , 0.6687841...],
265 [ 486. , 0.6797939...],
266 [ 487. , 0.6909887...],
267 [ 488. , 0.7023827...],
268 [ 489. , 0.7133032...],
269 [ 490. , 0.7244513...],
270 [ 491. , 0.7358470...],
271 [ 492. , 0.7468118...],
272 [ 493. , 0.7580294...],
273 [ 494. , 0.7694964...],
274 [ 495. , 0.7805225...],
275 [ 496. , 0.7917805...],
276 [ 497. , 0.8026123...],
277 [ 498. , 0.8130793...],
278 [ 499. , 0.8239297...],
279 [ 500. , 0.8352251...],
280 [ 501. , 0.8456342...],
281 [ 502. , 0.8564818...],
282 [ 503. , 0.8676921...],
283 [ 504. , 0.8785021...],
284 [ 505. , 0.8881489...],
285 [ 506. , 0.8986405...],
286 [ 507. , 0.9079322...],
287 [ 508. , 0.9174255...],
288 [ 509. , 0.9257739...],
289 [ 510. , 0.9350656...],
290 [ 511. , 0.9432365...],
291 [ 512. , 0.9509063...],
292 [ 513. , 0.9586931...],
293 [ 514. , 0.9658413...],
294 [ 515. , 0.9722825...],
295 [ 516. , 0.9779924...],
296 [ 517. , 0.9836106...],
297 [ 518. , 0.9883465...],
298 [ 519. , 0.9920964...],
299 [ 520. , 0.9954436...],
300 [ 521. , 0.9976202...],
301 [ 522. , 0.9993457...],
302 [ 523. , 1. ...],
303 [ 524. , 0.9996498...],
304 [ 525. , 0.9990487...],
305 [ 526. , 0.9975356...],
306 [ 527. , 0.9957615...],
307 [ 528. , 0.9930143...],
308 [ 529. , 0.9899559...],
309 [ 530. , 0.9858741...],
310 [ 531. , 0.9814453...],
311 [ 532. , 0.9766885...],
312 [ 533. , 0.9709363...],
313 [ 534. , 0.9648947...],
314 [ 535. , 0.9585832...],
315 [ 536. , 0.952012 ...],
316 [ 537. , 0.9444916...],
317 [ 538. , 0.9367089...],
318 [ 539. , 0.9293506...],
319 [ 540. , 0.9210429...],
320 [ 541. , 0.9124772...],
321 [ 542. , 0.9036604...],
322 [ 543. , 0.8945958...],
323 [ 544. , 0.8845999...],
324 [ 545. , 0.8750500...],
325 [ 546. , 0.8659457...],
326 [ 547. , 0.8559224...],
327 [ 548. , 0.8456846...],
328 [ 549. , 0.8352499...],
329 [ 550. , 0.8253229...],
330 [ 551. , 0.8152079...],
331 [ 552. , 0.8042205...],
332 [ 553. , 0.7944209...],
333 [ 554. , 0.7837466...],
334 [ 555. , 0.7735680...],
335 [ 556. , 0.7627808...],
336 [ 557. , 0.7522710...],
337 [ 558. , 0.7417549...],
338 [ 559. , 0.7312909...],
339 [ 560. , 0.7207983...],
340 [ 561. , 0.7101939...],
341 [ 562. , 0.6996362...],
342 [ 563. , 0.6890656...],
343 [ 564. , 0.6785599...],
344 [ 565. , 0.6680593...],
345 [ 566. , 0.6575697...],
346 [ 567. , 0.6471578...],
347 [ 568. , 0.6368208...],
348 [ 569. , 0.6264871...],
349 [ 570. , 0.6161541...],
350 [ 571. , 0.6058896...],
351 [ 572. , 0.5957000...],
352 [ 573. , 0.5855937...],
353 [ 574. , 0.5754412...],
354 [ 575. , 0.5653883...],
355 [ 576. , 0.5553742...],
356 [ 577. , 0.5454680...],
357 [ 578. , 0.5355972...],
358 [ 579. , 0.5258267...],
359 [ 580. , 0.5160152...],
360 [ 581. , 0.5062322...],
361 [ 582. , 0.4965595...],
362 [ 583. , 0.4868746...],
363 [ 584. , 0.4773299...],
364 [ 585. , 0.4678028...],
365 [ 586. , 0.4583704...],
366 [ 587. , 0.4489722...],
367 [ 588. , 0.4397606...],
368 [ 589. , 0.4306131...],
369 [ 590. , 0.4215446...],
370 [ 591. , 0.4125681...],
371 [ 592. , 0.4037550...],
372 [ 593. , 0.3950359...],
373 [ 594. , 0.3864104...],
374 [ 595. , 0.3778777...],
375 [ 596. , 0.3694405...],
376 [ 597. , 0.3611074...],
377 [ 598. , 0.3528596...],
378 [ 599. , 0.3447056...],
379 [ 600. , 0.3366470...],
380 [ 601. , 0.3286917...],
381 [ 602. , 0.3208410...],
382 [ 603. , 0.3130808...],
383 [ 604. , 0.3054105...],
384 [ 605. , 0.2978225...],
385 [ 606. , 0.2903027...],
386 [ 607. , 0.2828727...],
387 [ 608. , 0.2755311...],
388 [ 609. , 0.2682900...],
389 [ 610. , 0.2611478...],
390 [ 611. , 0.2541176...],
391 [ 612. , 0.2471885...],
392 [ 613. , 0.2403570...],
393 [ 614. , 0.2336057...],
394 [ 615. , 0.2269379...],
395 [ 616. , 0.2203527...],
396 [ 617. , 0.2138465...],
397 [ 618. , 0.2073946...],
398 [ 619. , 0.2009789...],
399 [ 620. , 0.1945818...],
400 [ 621. , 0.1881943...],
401 [ 622. , 0.1818226...],
402 [ 623. , 0.1754987...],
403 [ 624. , 0.1692476...],
404 [ 625. , 0.1630876...],
405 [ 626. , 0.1570257...],
406 [ 627. , 0.151071 ...],
407 [ 628. , 0.1452469...],
408 [ 629. , 0.1395845...],
409 [ 630. , 0.1341087...],
410 [ 631. , 0.1288408...],
411 [ 632. , 0.1237666...],
412 [ 633. , 0.1188631...],
413 [ 634. , 0.1141075...],
414 [ 635. , 0.1094766...],
415 [ 636. , 0.1049613...],
416 [ 637. , 0.1005679...],
417 [ 638. , 0.0962924...],
418 [ 639. , 0.0921296...],
419 [ 640. , 0.0880778...],
420 [ 641. , 0.0841306...],
421 [ 642. , 0.0802887...],
422 [ 643. , 0.0765559...],
423 [ 644. , 0.0729367...],
424 [ 645. , 0.0694345...],
425 [ 646. , 0.0660491...],
426 [ 647. , 0.0627792...],
427 [ 648. , 0.0596278...],
428 [ 649. , 0.0565970...],
429 [ 650. , 0.0536896...],
430 [ 651. , 0.0509068...],
431 [ 652. , 0.0482444...],
432 [ 653. , 0.0456951...],
433 [ 654. , 0.0432510...],
434 [ 655. , 0.0409052...],
435 [ 656. , 0.0386537...],
436 [ 657. , 0.0364955...],
437 [ 658. , 0.0344285...],
438 [ 659. , 0.0324501...],
439 [ 660. , 0.0305579...],
440 [ 661. , 0.0287496...],
441 [ 662. , 0.0270233...],
442 [ 663. , 0.0253776...],
443 [ 664. , 0.0238113...],
444 [ 665. , 0.0223226...],
445 [ 666. , 0.0209086...],
446 [ 667. , 0.0195688...],
447 [ 668. , 0.0183056...],
448 [ 669. , 0.0171216...],
449 [ 670. , 0.0160192...],
450 [ 671. , 0.0149986...],
451 [ 672. , 0.0140537...],
452 [ 673. , 0.0131784...],
453 [ 674. , 0.0123662...],
454 [ 675. , 0.0116107...],
455 [ 676. , 0.0109098...],
456 [ 677. , 0.0102587...],
457 [ 678. , 0.0096476...],
458 [ 679. , 0.0090665...],
459 [ 680. , 0.0085053...],
460 [ 681. , 0.0079567...],
461 [ 682. , 0.0074229...],
462 [ 683. , 0.0069094...],
463 [ 684. , 0.0064213...],
464 [ 685. , 0.0059637...],
465 [ 686. , 0.0055377...],
466 [ 687. , 0.0051402...],
467 [ 688. , 0.00477 ...],
468 [ 689. , 0.0044263...],
469 [ 690. , 0.0041081...],
470 [ 691. , 0.0038149...],
471 [ 692. , 0.0035456...],
472 [ 693. , 0.0032984...],
473 [ 694. , 0.0030718...],
474 [ 695. , 0.0028639...],
475 [ 696. , 0.0026738...],
476 [ 697. , 0.0025000...],
477 [ 698. , 0.0023401...],
478 [ 699. , 0.0021918...],
479 [ 700. , 0.0020526...],
480 [ 701. , 0.0019207...],
481 [ 702. , 0.001796 ...],
482 [ 703. , 0.0016784...],
483 [ 704. , 0.0015683...],
484 [ 705. , 0.0014657...],
485 [ 706. , 0.0013702...],
486 [ 707. , 0.001281 ...],
487 [ 708. , 0.0011976...],
488 [ 709. , 0.0011195...],
489 [ 710. , 0.0010464...],
490 [ 711. , 0.0009776...],
491 [ 712. , 0.0009131...],
492 [ 713. , 0.0008525...],
493 [ 714. , 0.0007958...],
494 [ 715. , 0.0007427...],
495 [ 716. , 0.0006929...],
496 [ 717. , 0.0006462...],
497 [ 718. , 0.0006026...],
498 [ 719. , 0.0005619...],
499 [ 720. , 0.0005240...],
500 [ 721. , 0.0004888...],
501 [ 722. , 0.0004561...],
502 [ 723. , 0.0004255...],
503 [ 724. , 0.0003971...],
504 [ 725. , 0.0003704...],
505 [ 726. , 0.0003455...],
506 [ 727. , 0.0003221...],
507 [ 728. , 0.0003001...],
508 [ 729. , 0.0002796...],
509 [ 730. , 0.0002604...],
510 [ 731. , 0.0002423...],
511 [ 732. , 0.0002254...],
512 [ 733. , 0.0002095...],
513 [ 734. , 0.0001947...],
514 [ 735. , 0.0001809...],
515 [ 736. , 0.0001680...],
516 [ 737. , 0.0001560...],
517 [ 738. , 0.0001449...],
518 [ 739. , 0.0001345...],
519 [ 740. , 0.0001249...],
520 [ 741. , 0.0001159...],
521 [ 742. , 0.0001076...],
522 [ 743. , 0.0000999...],
523 [ 744. , 0.0000927...],
524 [ 745. , 0.0000862...],
525 [ 746. , 0.0000801...],
526 [ 747. , 0.0000745...],
527 [ 748. , 0.0000693...],
528 [ 749. , 0.0000646...],
529 [ 750. , 0.0000602...],
530 [ 751. , 0.0000561...],
531 [ 752. , 0.0000523...],
532 [ 753. , 0.0000488...],
533 [ 754. , 0.0000456...],
534 [ 755. , 0.0000425...],
535 [ 756. , 0.0000397...],
536 [ 757. , 0.0000370...],
537 [ 758. , 0.0000346...],
538 [ 759. , 0.0000322...],
539 [ 760. , 0.0000301...],
540 [ 761. , 0.0000281...],
541 [ 762. , 0.0000262...],
542 [ 763. , 0.0000244...],
543 [ 764. , 0.0000228...],
544 [ 765. , 0.0000213...],
545 [ 766. , 0.0000198...],
546 [ 767. , 0.0000185...],
547 [ 768. , 0.0000173...],
548 [ 769. , 0.0000161...],
549 [ 770. , 0.0000150...],
550 [ 771. , 0.0000140...],
551 [ 772. , 0.0000131...],
552 [ 773. , 0.0000122...],
553 [ 774. , 0.0000114...],
554 [ 775. , 0.0000106...],
555 [ 776. , 0.0000099...],
556 [ 777. , 0.0000092...],
557 [ 778. , 0.0000086...],
558 [ 779. , 0.0000080...],
559 [ 780. , 0.0000075...]],
560 SpragueInterpolator,
561 {},
562 Extrapolator,
563 {'method': 'Constant', 'left': None, 'right': None})
564 """
566 photopic_lef = optional(
567 photopic_lef,
568 SDS_LEFS_PHOTOPIC["CIE 1924 Photopic Standard Observer"],
569 )
571 scotopic_lef = optional(
572 scotopic_lef,
573 SDS_LEFS_SCOTOPIC["CIE 1951 Scotopic Standard Observer"],
574 )
576 shape = SpectralShape(
577 max([photopic_lef.shape.start, scotopic_lef.shape.start]),
578 min([photopic_lef.shape.end, scotopic_lef.shape.end]),
579 max([photopic_lef.shape.interval, scotopic_lef.shape.interval]),
580 )
582 sd = SpectralDistribution(
583 mesopic_weighting_function(
584 shape.wavelengths, L_p, source, method, photopic_lef, scotopic_lef
585 ),
586 shape.wavelengths,
587 name=f"{L_p} Lp Mesopic Luminous Efficiency Function",
588 )
590 return sd.normalise()