Coverage for models/tests/test_ragoo2021.py: 100%

65 statements  

« prev     ^ index     » next       coverage.py v7.11.0, created at 2025-11-16 22:49 +1300

1"""Define the unit tests for the :mod:`colour.models.ragoo2021` 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.models import IPT_Ragoo2021_to_XYZ, XYZ_to_IPT_Ragoo2021 

11from colour.utilities import domain_range_scale, ignore_numpy_errors 

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

22 "TestIPT_Ragoo2021_to_XYZ", 

23] 

24 

25 

26class TestXYZ_to_IPT_Ragoo2021: 

27 """ 

28 Define :func:`colour.models.ragoo2021.XYZ_to_IPT_Ragoo2021` definition 

29 unit tests methods. 

30 """ 

31 

32 def test_XYZ_to_IPT_Ragoo2021(self) -> None: 

33 """ 

34 Test :func:`colour.models.ragoo2021.XYZ_to_IPT_Ragoo2021` definition. 

35 """ 

36 

37 np.testing.assert_allclose( 

38 XYZ_to_IPT_Ragoo2021(np.array([0.20654008, 0.12197225, 0.05136952])), 

39 np.array([0.42248243, 0.29105140, 0.20410663]), 

40 atol=TOLERANCE_ABSOLUTE_TESTS, 

41 ) 

42 

43 np.testing.assert_allclose( 

44 XYZ_to_IPT_Ragoo2021(np.array([0.14222010, 0.23042768, 0.10495772])), 

45 np.array([0.54745257, -0.22795249, 0.10109646]), 

46 atol=TOLERANCE_ABSOLUTE_TESTS, 

47 ) 

48 

49 np.testing.assert_allclose( 

50 XYZ_to_IPT_Ragoo2021(np.array([0.07818780, 0.06157201, 0.28099326])), 

51 np.array([0.32151337, 0.06071424, -0.27388774]), 

52 atol=TOLERANCE_ABSOLUTE_TESTS, 

53 ) 

54 

55 def test_n_dimensional_XYZ_to_IPT_Ragoo2021(self) -> None: 

56 """ 

57 Test :func:`colour.models.ragoo2021.XYZ_to_IPT_Ragoo2021` definition 

58 n-dimensional support. 

59 """ 

60 

61 XYZ = np.array([0.20654008, 0.12197225, 0.05136952]) 

62 IPT = XYZ_to_IPT_Ragoo2021(XYZ) 

63 

64 XYZ = np.tile(XYZ, (6, 1)) 

65 IPT = np.tile(IPT, (6, 1)) 

66 np.testing.assert_allclose( 

67 XYZ_to_IPT_Ragoo2021(XYZ), IPT, atol=TOLERANCE_ABSOLUTE_TESTS 

68 ) 

69 

70 XYZ = np.reshape(XYZ, (2, 3, 3)) 

71 IPT = np.reshape(IPT, (2, 3, 3)) 

72 np.testing.assert_allclose( 

73 XYZ_to_IPT_Ragoo2021(XYZ), IPT, atol=TOLERANCE_ABSOLUTE_TESTS 

74 ) 

75 

76 def test_domain_range_scale_XYZ_to_IPT_Ragoo2021(self) -> None: 

77 """ 

78 Test :func:`colour.models.ragoo2021.XYZ_to_IPT_Ragoo2021` definition 

79 domain and range scale support. 

80 """ 

81 

82 XYZ = np.array([0.20654008, 0.12197225, 0.05136952]) 

83 IPT = XYZ_to_IPT_Ragoo2021(XYZ) 

84 

85 d_r = (("reference", 1), ("1", 1), ("100", 100)) 

86 for scale, factor in d_r: 

87 with domain_range_scale(scale): 

88 np.testing.assert_allclose( 

89 XYZ_to_IPT_Ragoo2021(XYZ * factor), 

90 IPT * factor, 

91 atol=TOLERANCE_ABSOLUTE_TESTS, 

92 ) 

93 

94 @ignore_numpy_errors 

95 def test_nan_XYZ_to_IPT_Ragoo2021(self) -> None: 

96 """ 

97 Test :func:`colour.models.ragoo2021.XYZ_to_IPT_Ragoo2021` definition 

98 nan support. 

99 """ 

100 

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

102 cases = np.array(list(set(product(cases, repeat=3)))) 

103 XYZ_to_IPT_Ragoo2021(cases) 

104 

105 

106class TestIPT_Ragoo2021_to_XYZ: 

107 """ 

108 Define :func:`colour.models.ragoo2021.IPT_Ragoo2021_to_XYZ` definition 

109 unit tests methods. 

110 """ 

111 

112 def test_IPT_Ragoo2021_to_XYZ(self) -> None: 

113 """ 

114 Test :func:`colour.models.ragoo2021.IPT_Ragoo2021_to_XYZ` definition. 

115 """ 

116 

117 np.testing.assert_allclose( 

118 IPT_Ragoo2021_to_XYZ(np.array([0.42248243, 0.29105140, 0.20410663])), 

119 np.array([0.20654008, 0.12197225, 0.05136952]), 

120 atol=TOLERANCE_ABSOLUTE_TESTS, 

121 ) 

122 

123 np.testing.assert_allclose( 

124 IPT_Ragoo2021_to_XYZ(np.array([0.54745257, -0.22795249, 0.10109646])), 

125 np.array([0.14222010, 0.23042768, 0.10495772]), 

126 atol=TOLERANCE_ABSOLUTE_TESTS, 

127 ) 

128 

129 np.testing.assert_allclose( 

130 IPT_Ragoo2021_to_XYZ(np.array([0.32151337, 0.06071424, -0.27388774])), 

131 np.array([0.07818780, 0.06157201, 0.28099326]), 

132 atol=TOLERANCE_ABSOLUTE_TESTS, 

133 ) 

134 

135 def test_n_dimensional_IPT_Ragoo2021_to_XYZ(self) -> None: 

136 """ 

137 Test :func:`colour.models.ragoo2021.IPT_Ragoo2021_to_XYZ` definition 

138 n-dimensional support. 

139 """ 

140 

141 IPT = np.array([0.42248243, 0.29105140, 0.20410663]) 

142 XYZ = IPT_Ragoo2021_to_XYZ(IPT) 

143 

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

145 XYZ = np.tile(XYZ, (6, 1)) 

146 np.testing.assert_allclose( 

147 IPT_Ragoo2021_to_XYZ(IPT), XYZ, atol=TOLERANCE_ABSOLUTE_TESTS 

148 ) 

149 

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

151 XYZ = np.reshape(XYZ, (2, 3, 3)) 

152 np.testing.assert_allclose( 

153 IPT_Ragoo2021_to_XYZ(IPT), XYZ, atol=TOLERANCE_ABSOLUTE_TESTS 

154 ) 

155 

156 def test_domain_range_scale_IPT_Ragoo2021_to_XYZ(self) -> None: 

157 """ 

158 Test :func:`colour.models.ragoo2021.IPT_Ragoo2021_to_XYZ` definition 

159 domain and range scale support. 

160 """ 

161 

162 IPT = np.array([0.42248243, 0.29105140, 0.20410663]) 

163 XYZ = IPT_Ragoo2021_to_XYZ(IPT) 

164 

165 d_r = (("reference", 1), ("1", 1), ("100", 100)) 

166 for scale, factor in d_r: 

167 with domain_range_scale(scale): 

168 np.testing.assert_allclose( 

169 IPT_Ragoo2021_to_XYZ(IPT * factor), 

170 XYZ * factor, 

171 atol=TOLERANCE_ABSOLUTE_TESTS, 

172 ) 

173 

174 @ignore_numpy_errors 

175 def test_nan_IPT_Ragoo2021_to_XYZ(self) -> None: 

176 """ 

177 Test :func:`colour.models.ragoo2021.IPT_Ragoo2021_to_XYZ` definition 

178 nan support. 

179 """ 

180 

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

182 cases = np.array(list(set(product(cases, repeat=3)))) 

183 IPT_Ragoo2021_to_XYZ(cases)