Coverage for colour/temperature/tests/test_mccamy1992.py: 100%

51 statements  

« 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.temperature.mccamy1992` module.""" 

2 

3from __future__ import annotations 

4 

5from itertools import product 

6 

7import numpy as np 

8 

9from colour.constants import TOLERANCE_ABSOLUTE_TESTS 

10from colour.temperature import CCT_to_xy_McCamy1992, xy_to_CCT_McCamy1992 

11from 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 "Testxy_to_CCT_McCamy1992", 

22 "TestCCT_to_xy_McCamy1992", 

23] 

24 

25 

26class Testxy_to_CCT_McCamy1992: 

27 """ 

28 Define :func:`colour.temperature.mccamy1992.xy_to_CCT_McCamy1992` 

29 definition unit tests methods. 

30 """ 

31 

32 def test_xy_to_CCT_McCamy1992(self) -> None: 

33 """ 

34 Test :func:`colour.temperature.mccamy1992.xy_to_CCT_McCamy1992` 

35 definition. 

36 """ 

37 

38 np.testing.assert_allclose( 

39 xy_to_CCT_McCamy1992(np.array([0.31270, 0.32900])), 

40 6505.08059131, 

41 atol=TOLERANCE_ABSOLUTE_TESTS, 

42 ) 

43 

44 np.testing.assert_allclose( 

45 xy_to_CCT_McCamy1992(np.array([0.44757, 0.40745])), 

46 2857.28961266, 

47 atol=TOLERANCE_ABSOLUTE_TESTS, 

48 ) 

49 

50 np.testing.assert_allclose( 

51 xy_to_CCT_McCamy1992(np.array([0.252520939374083, 0.252220883926284])), 

52 19501.61953130, 

53 atol=TOLERANCE_ABSOLUTE_TESTS, 

54 ) 

55 

56 def test_n_dimensional_xy_to_CCT_McCamy1992(self) -> None: 

57 """ 

58 Test :func:`colour.temperature.mccamy1992.xy_to_CCT_McCamy1992` 

59 definition n-dimensional arrays support. 

60 """ 

61 

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

63 return 

64 

65 xy = np.array([0.31270, 0.32900]) 

66 CCT = xy_to_CCT_McCamy1992(xy) 

67 

68 xy = np.tile(xy, (6, 1)) 

69 CCT = np.tile(CCT, 6) 

70 np.testing.assert_allclose( 

71 xy_to_CCT_McCamy1992(xy), CCT, atol=TOLERANCE_ABSOLUTE_TESTS 

72 ) 

73 

74 xy = np.reshape(xy, (2, 3, 2)) 

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

76 np.testing.assert_allclose( 

77 xy_to_CCT_McCamy1992(xy), CCT, atol=TOLERANCE_ABSOLUTE_TESTS 

78 ) 

79 

80 @ignore_numpy_errors 

81 def test_nan_xy_to_CCT_McCamy1992(self) -> None: 

82 """ 

83 Test :func:`colour.temperature.mccamy1992.xy_to_CCT_McCamy1992` 

84 definition nan support. 

85 """ 

86 

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

88 return 

89 

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

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

92 xy_to_CCT_McCamy1992(cases) 

93 

94 

95class TestCCT_to_xy_McCamy1992: 

96 """ 

97 Define :func:`colour.temperature.mccamy1992.CCT_to_xy_McCamy1992` 

98 definition unit tests methods. 

99 """ 

100 

101 def test_CCT_to_xy_McCamy1992(self) -> None: 

102 """ 

103 Test :func:`colour.temperature.mccamy1992.CCT_to_xy_McCamy1992` 

104 definition. 

105 """ 

106 

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

108 return 

109 

110 np.testing.assert_allclose( 

111 CCT_to_xy_McCamy1992(6505.08059131, {"method": "Nelder-Mead"}), 

112 np.array([0.31269945, 0.32900411]), 

113 atol=TOLERANCE_ABSOLUTE_TESTS, 

114 ) 

115 

116 np.testing.assert_allclose( 

117 CCT_to_xy_McCamy1992(2857.28961266, {"method": "Nelder-Mead"}), 

118 np.array([0.42350314, 0.36129253]), 

119 atol=TOLERANCE_ABSOLUTE_TESTS, 

120 ) 

121 

122 np.testing.assert_allclose( 

123 CCT_to_xy_McCamy1992(19501.61953130, {"method": "Nelder-Mead"}), 

124 np.array([0.11173782, 0.36987375]), 

125 atol=TOLERANCE_ABSOLUTE_TESTS, 

126 ) 

127 

128 def test_n_dimensional_CCT_to_xy_McCamy1992(self) -> None: 

129 """ 

130 Test :func:`colour.temperature.mccamy1992.CCT_to_xy_McCamy1992` 

131 definition n-dimensional arrays support. 

132 """ 

133 

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

135 return 

136 

137 CCT = 6505.08059131 

138 xy = CCT_to_xy_McCamy1992(CCT) 

139 

140 CCT = np.tile(CCT, 6) 

141 xy = np.tile(xy, (6, 1)) 

142 np.testing.assert_allclose( 

143 CCT_to_xy_McCamy1992(CCT), xy, atol=TOLERANCE_ABSOLUTE_TESTS 

144 ) 

145 

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

147 xy = np.reshape(xy, (2, 3, 2)) 

148 np.testing.assert_allclose( 

149 CCT_to_xy_McCamy1992(CCT), xy, atol=TOLERANCE_ABSOLUTE_TESTS 

150 ) 

151 

152 @ignore_numpy_errors 

153 def test_nan_CCT_to_xy_McCamy1992(self) -> None: 

154 """ 

155 Test :func:`colour.temperature.mccamy1992.CCT_to_xy_McCamy1992` 

156 definition nan support. 

157 """ 

158 

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

160 return 

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_xy_McCamy1992(cases)