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

1"""Define the unit tests for the :mod:`colour.temperature.krystek1985` 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_Krystek1985, uv_to_CCT_Krystek1985

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_Krystek1985",

22]

23

24

25 class TestUv_to_CCT_Krystek1985:

26 """

27 Define :func:`colour.temperature.krystek1985.uv_to_CCT_Krystek1985`

28 definition unit tests methods.

29 """

30

31 def test_uv_to_CCT_Krystek1985(self) -> None:

32 """

33 Test :func:`colour.temperature.krystek1985.uv_to_CCT_Krystek1985`

34 definition.

35 """

36

37 np.testing.assert_allclose(

38 uv_to_CCT_Krystek1985(

39 np.array([0.448087794140145, 0.354731965027727]),

40 {"method": "Nelder-Mead"},

41 ),

42 1000,

43 atol=TOLERANCE_ABSOLUTE_TESTS,

44 )

45

46 np.testing.assert_allclose(

47 uv_to_CCT_Krystek1985(

48 np.array([0.198152565091092, 0.307023596915037]),

49 {"method": "Nelder-Mead"},

50 ),

51 7000,

52 atol=TOLERANCE_ABSOLUTE_TESTS,

53 )

54

55 np.testing.assert_allclose(

56 uv_to_CCT_Krystek1985(

57 np.array([0.185675876767054, 0.282233658593898]),

58 {"method": "Nelder-Mead"},

59 ),

60 15000,

61 atol=TOLERANCE_ABSOLUTE_TESTS,

62 )

63

64 def test_n_dimensional_uv_to_CCT_Krystek1985(self) -> None:

65 """

66 Test :func:`colour.temperature.krystek1985.uv_to_CCT_Krystek1985`

67 definition n-dimensional arrays support.

68 """

69

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

71 return

72

73 uv = np.array([0.198152565091092, 0.307023596915037])

74 CCT = uv_to_CCT_Krystek1985(uv)

75

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

77 CCT = np.tile(CCT, 6)

78 np.testing.assert_allclose(

79 uv_to_CCT_Krystek1985(uv), CCT, atol=TOLERANCE_ABSOLUTE_TESTS

80 )

81

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

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

84 np.testing.assert_allclose(

85 uv_to_CCT_Krystek1985(uv), CCT, atol=TOLERANCE_ABSOLUTE_TESTS

86 )

87

88 @ignore_numpy_errors

89 def test_nan_uv_to_CCT_Krystek1985(self) -> None:

90 """

91 Test :func:`colour.temperature.krystek1985.uv_to_CCT_Krystek1985`

92 definition nan support.

93 """

94

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

96 return

97

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

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

100 uv_to_CCT_Krystek1985(cases)

101

102

103 class TestCCT_to_uv_Krystek1985:

104 """

105 Define :func:`colour.temperature.krystek1985.CCT_to_uv_Krystek1985`

106 definition unit tests methods.

107 """

108

109 def test_CCT_to_uv_Krystek1985(self) -> None:

110 """

111 Test :func:`colour.temperature.krystek1985.CCT_to_uv_Krystek1985`

112 definition.

113 """

114

115 np.testing.assert_allclose(

116 CCT_to_uv_Krystek1985(1000),

117 np.array([0.448087794140145, 0.354731965027727]),

118 atol=TOLERANCE_ABSOLUTE_TESTS,

119 )

120

121 np.testing.assert_allclose(

122 CCT_to_uv_Krystek1985(7000),

123 np.array([0.198152565091092, 0.307023596915037]),

124 atol=TOLERANCE_ABSOLUTE_TESTS,

125 )

126

127 np.testing.assert_allclose(

128 CCT_to_uv_Krystek1985(15000),

129 np.array([0.185675876767054, 0.282233658593898]),

130 atol=TOLERANCE_ABSOLUTE_TESTS,

131 )

132

133 def test_n_dimensional_CCT_to_uv_Krystek1985(self) -> None:

134 """

135 Test :func:`colour.temperature.krystek1985.CCT_to_uv_Krystek1985`

136 definition n-dimensional arrays support.

137 """

138

139 CCT = 7000

140 uv = CCT_to_uv_Krystek1985(CCT)

141

142 CCT = np.tile(CCT, 6)

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

144 np.testing.assert_allclose(

145 CCT_to_uv_Krystek1985(CCT), uv, atol=TOLERANCE_ABSOLUTE_TESTS

146 )

147

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

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

150 np.testing.assert_allclose(

151 CCT_to_uv_Krystek1985(CCT), uv, atol=TOLERANCE_ABSOLUTE_TESTS

152 )

153

154 @ignore_numpy_errors

155 def test_nan_CCT_to_uv_Krystek1985(self) -> None:

156 """

157 Test :func:`colour.temperature.krystek1985.CCT_to_uv_Krystek1985`

158 definition nan support.

159 """

160

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

162 CCT_to_uv_Krystek1985(cases)