Coverage for colorimetry/tests/test_photometry.py: 100%

1"""Define the unit tests for the :mod:`colour.colorimetry.photometry` module."""

2

3 from __future__ import annotations

4

5 import numpy as np

6

7 from colour.colorimetry import (

8 SDS_ILLUMINANTS,

9 SDS_LIGHT_SOURCES,

10 luminous_efficacy,

11 luminous_efficiency,

12 luminous_flux,

13 sd_zeros,

14)

15 from colour.constants import TOLERANCE_ABSOLUTE_TESTS

16

17 __author__ = "Colour Developers"

18 __copyright__ = "Copyright 2013 Colour Developers"

19 __license__ = "BSD-3-Clause - https://opensource.org/licenses/BSD-3-Clause"

20 __maintainer__ = "Colour Developers"

21 __email__ = "colour-developers@colour-science.org"

22 __status__ = "Production"

23

24 __all__ = [

25 "TestLuminousFlux",

26 "TestLuminousEfficiency",

27 "TestLuminousEfficacy",

28]

29

30

31 class TestLuminousFlux:

32 """

33 Define :func:`colour.colorimetry.photometry.luminous_flux` definition unit

34 tests methods.

35 """

36

37 def test_luminous_flux(self) -> None:

38 """Test :func:`colour.colorimetry.photometry.luminous_flux` definition."""

39

40 np.testing.assert_allclose(

41 luminous_flux(SDS_ILLUMINANTS["FL2"].copy().normalise()),

42 28588.73612977,

43 atol=TOLERANCE_ABSOLUTE_TESTS,

44 )

45

46 np.testing.assert_allclose(

47 luminous_flux(SDS_LIGHT_SOURCES["Neodimium Incandescent"]),

48 23807.65552737,

49 atol=TOLERANCE_ABSOLUTE_TESTS,

50 )

51

52 np.testing.assert_allclose(

53 luminous_flux(SDS_LIGHT_SOURCES["F32T8/TL841 (Triphosphor)"]),

54 13090.06759053,

55 atol=TOLERANCE_ABSOLUTE_TESTS,

56 )

57

58

59 class TestLuminousEfficiency:

60 """

61 Define :func:`colour.colorimetry.photometry.luminous_efficiency`

62 definition unit tests methods.

63 """

64

65 def test_luminous_efficiency(self) -> None:

66 """

67 Test :func:`colour.colorimetry.photometry.luminous_efficiency`

68 definition.

69 """

70

71 np.testing.assert_allclose(

72 luminous_efficiency(SDS_ILLUMINANTS["FL2"].copy().normalise()),

73 0.49317624,

74 atol=TOLERANCE_ABSOLUTE_TESTS,

75 )

76

77 np.testing.assert_allclose(

78 luminous_efficiency(SDS_LIGHT_SOURCES["Neodimium Incandescent"]),

79 0.19943936,

80 atol=TOLERANCE_ABSOLUTE_TESTS,

81 )

82

83 np.testing.assert_allclose(

84 luminous_efficiency(SDS_LIGHT_SOURCES["F32T8/TL841 (Triphosphor)"]),

85 0.51080919,

86 atol=TOLERANCE_ABSOLUTE_TESTS,

87 )

88

89

90 class TestLuminousEfficacy:

91 """

92 Define :func:`colour.colorimetry.photometry.luminous_efficacy`

93 definition unit tests methods.

94 """

95

96 def test_luminous_efficacy(self) -> None:

97 """

98 Test :func:`colour.colorimetry.photometry.luminous_efficacy`

99 definition.

100 """

101

102 np.testing.assert_allclose(

103 luminous_efficacy(SDS_ILLUMINANTS["FL2"].copy().normalise()),

104 336.83937176,

105 atol=TOLERANCE_ABSOLUTE_TESTS,

106 )

107

108 np.testing.assert_allclose(

109 luminous_efficacy(SDS_LIGHT_SOURCES["Neodimium Incandescent"]),

110 136.21708032,

111 atol=TOLERANCE_ABSOLUTE_TESTS,

112 )

113

114 np.testing.assert_allclose(

115 luminous_efficacy(SDS_LIGHT_SOURCES["F32T8/TL841 (Triphosphor)"]),

116 348.88267549,

117 atol=TOLERANCE_ABSOLUTE_TESTS,

118 )

119

120 sd = sd_zeros()

121 sd[555] = 1

122 np.testing.assert_allclose(

123 luminous_efficacy(sd), 683.00000000, atol=TOLERANCE_ABSOLUTE_TESTS

124 )