Coverage for temperature/tests/test_planck1900.py: 100%

1"""Define the unit tests for the :mod:`colour.temperature.planck1900` module."""

2

3 from __future__ import annotations

4

5 from itertools import product

6

7 import numpy as np

8

9 from colour.constants import TOLERANCE_ABSOLUTE_TESTS

10 from colour.temperature import CCT_to_uv_Planck1900, uv_to_CCT_Planck1900

11 from colour.utilities import ignore_numpy_errors, is_scipy_installed

12

13 __author__ = "Colour Developers"

14 __copyright__ = "Copyright 2013 Colour Developers"

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

16 __maintainer__ = "Colour Developers"

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

18 __status__ = "Production"

19

20 __all__ = [

21 "TestUv_to_CCT_Planck1900",

22 "TestCCT_to_uv_Planck1900",

23]

24

25

26 class TestUv_to_CCT_Planck1900:

27 """

28 Define :func:`colour.temperature.planck1900.uv_to_CCT_Planck1900`

29 definition unit tests methods.

30 """

31

32 def test_uv_to_CCT_Planck1900(self) -> None:

33 """

34 Test :func:`colour.temperature.planck1900.uv_to_CCT_Planck1900`

35 definition.

36 """

37

38 np.testing.assert_allclose(

39 uv_to_CCT_Planck1900(

40 np.array([0.225109670227493, 0.334387366663923]),

41 optimisation_kwargs={"method": "Nelder-Mead"},

42 ),

43 4000,

44 atol=TOLERANCE_ABSOLUTE_TESTS,

45 )

46

47 np.testing.assert_allclose(

48 uv_to_CCT_Planck1900(

49 np.array([0.198126929048352, 0.307025980523306]),

50 optimisation_kwargs={"method": "Nelder-Mead"},

51 ),

52 7000,

53 atol=TOLERANCE_ABSOLUTE_TESTS,

54 )

55

56 np.testing.assert_allclose(

57 uv_to_CCT_Planck1900(

58 np.array([0.182932683590136, 0.274073232217536]),

59 optimisation_kwargs={"method": "Nelder-Mead"},

60 ),

61 25000,

62 atol=TOLERANCE_ABSOLUTE_TESTS,

63 )

64

65 def test_n_dimensional_uv_to_CCT_Planck1900(self) -> None:

66 """

67 Test :func:`colour.temperature.planck1900.uv_to_CCT_Planck1900`

68 definition n-dimensional arrays support.

69 """

70

71 if not is_scipy_installed(): # pragma: no cover

72 return

73

74 uv = np.array([0.225109670227493, 0.334387366663923])

75 CCT = uv_to_CCT_Planck1900(uv)

76

77 uv = np.tile(uv, (6, 1))

78 CCT = np.tile(CCT, 6)

79 np.testing.assert_allclose(

80 uv_to_CCT_Planck1900(uv), CCT, atol=TOLERANCE_ABSOLUTE_TESTS

81 )

82

83 uv = np.reshape(uv, (2, 3, 2))

84 CCT = np.reshape(CCT, (2, 3))

85 np.testing.assert_allclose(

86 uv_to_CCT_Planck1900(uv), CCT, atol=TOLERANCE_ABSOLUTE_TESTS

87 )

88

89 @ignore_numpy_errors

90 def test_nan_uv_to_CCT_Planck1900(self) -> None:

91 """

92 Test :func:`colour.temperature.planck1900.uv_to_CCT_Planck1900`

93 definition nan support.

94 """

95

96 if not is_scipy_installed(): # pragma: no cover

97 return

98

99 cases = [-1.0, 0.0, 1.0, -np.inf, np.inf, np.nan]

100 cases = np.array(list(set(product(cases, repeat=2))))

101 uv_to_CCT_Planck1900(cases)

102

103

104 class TestCCT_to_uv_Planck1900:

105 """

106 Define :func:`colour.temperature.planck1900.CCT_to_uv_Planck1900` definition

107 unit tests methods.

108 """

109

110 def test_CCT_to_uv_Planck1900(self) -> None:

111 """

112 Test :func:`colour.temperature.planck1900.CCT_to_uv_Planck1900`

113 definition.

114 """

115

116 np.testing.assert_allclose(

117 CCT_to_uv_Planck1900(4000),

118 np.array([0.225109670227493, 0.334387366663923]),

119 atol=TOLERANCE_ABSOLUTE_TESTS,

120 )

121

122 np.testing.assert_allclose(

123 CCT_to_uv_Planck1900(7000),

124 np.array([0.198126929048352, 0.307025980523306]),

125 atol=TOLERANCE_ABSOLUTE_TESTS,

126 )

127

128 np.testing.assert_allclose(

129 CCT_to_uv_Planck1900(25000),

130 np.array([0.182932683590136, 0.274073232217536]),

131 atol=TOLERANCE_ABSOLUTE_TESTS,

132 )

133

134 def test_n_dimensional_CCT_to_uv_Planck1900(self) -> None:

135 """

136 Test :func:`colour.temperature.planck1900.CCT_to_uv_Planck1900` definition

137 n-dimensional arrays support.

138 """

139

140 CCT = 4000

141 uv = CCT_to_uv_Planck1900(CCT)

142

143 CCT = np.tile(CCT, 6)

144 uv = np.tile(uv, (6, 1))

145 np.testing.assert_allclose(

146 CCT_to_uv_Planck1900(CCT), uv, atol=TOLERANCE_ABSOLUTE_TESTS

147 )

148

149 CCT = np.reshape(CCT, (2, 3))

150 uv = np.reshape(uv, (2, 3, 2))

151 np.testing.assert_allclose(

152 CCT_to_uv_Planck1900(CCT), uv, atol=TOLERANCE_ABSOLUTE_TESTS

153 )

154

155 @ignore_numpy_errors

156 def test_nan_CCT_to_uv_Planck1900(self) -> None:

157 """

158 Test :func:`colour.temperature.planck1900.CCT_to_uv_Planck1900` definition

159 nan support.

160 """

161

162 cases = [-1.0, 0.0, 1.0, -np.inf, np.inf, np.nan]

163 cases = np.array(list(set(product(cases, repeat=2))))

164 CCT_to_uv_Planck1900(cases)