Coverage for colour/models/rgb/transfer_functions/tests/test_arib_std_b67.py: 100%

69 statements  

« prev     ^ index     » next       coverage.py v7.11.0, created at 2025-11-15 19:01 +1300

1""" 

2Define the unit tests for the 

3:mod:`colour.models.rgb.transfer_functions.arib_std_b67` module. 

4""" 

5 

6import numpy as np 

7 

8from colour.constants import TOLERANCE_ABSOLUTE_TESTS 

9from colour.models.rgb.transfer_functions import ( 

10 oetf_ARIBSTDB67, 

11 oetf_inverse_ARIBSTDB67, 

12) 

13from colour.utilities import domain_range_scale, ignore_numpy_errors 

14 

15__author__ = "Colour Developers" 

16__copyright__ = "Copyright 2013 Colour Developers" 

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

18__maintainer__ = "Colour Developers" 

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

20__status__ = "Production" 

21 

22__all__ = [ 

23 "TestOetf_ARIBSTDB67", 

24 "TestOetf_inverse_ARIBSTDB67", 

25] 

26 

27 

28class TestOetf_ARIBSTDB67: 

29 """ 

30 Define :func:`colour.models.rgb.transfer_functions.arib_std_b67.\ 

31oetf_ARIBSTDB67` definition unit tests methods. 

32 """ 

33 

34 def test_oetf_ARIBSTDB67(self) -> None: 

35 """ 

36 Test :func:`colour.models.rgb.transfer_functions.arib_std_b67.\ 

37oetf_ARIBSTDB67` definition. 

38 """ 

39 

40 np.testing.assert_allclose( 

41 oetf_ARIBSTDB67(-0.25), -0.25, atol=TOLERANCE_ABSOLUTE_TESTS 

42 ) 

43 

44 np.testing.assert_allclose( 

45 oetf_ARIBSTDB67(0.0), 0.0, atol=TOLERANCE_ABSOLUTE_TESTS 

46 ) 

47 

48 np.testing.assert_allclose( 

49 oetf_ARIBSTDB67(0.18), 

50 0.212132034355964, 

51 atol=TOLERANCE_ABSOLUTE_TESTS, 

52 ) 

53 

54 np.testing.assert_allclose( 

55 oetf_ARIBSTDB67(1.0), 0.5, atol=TOLERANCE_ABSOLUTE_TESTS 

56 ) 

57 

58 np.testing.assert_allclose( 

59 oetf_ARIBSTDB67(64.0), 

60 1.302858098046995, 

61 atol=TOLERANCE_ABSOLUTE_TESTS, 

62 ) 

63 

64 def test_n_dimensional_oetf_ARIBSTDB67(self) -> None: 

65 """ 

66 Test :func:`colour.models.rgb.transfer_functions.arib_std_b67.\ 

67oetf_ARIBSTDB67` definition n-dimensional arrays support. 

68 """ 

69 

70 E = 0.18 

71 E_p = oetf_ARIBSTDB67(E) 

72 

73 E = np.tile(E, 6) 

74 E_p = np.tile(E_p, 6) 

75 np.testing.assert_allclose( 

76 oetf_ARIBSTDB67(E), E_p, atol=TOLERANCE_ABSOLUTE_TESTS 

77 ) 

78 

79 E = np.reshape(E, (2, 3)) 

80 E_p = np.reshape(E_p, (2, 3)) 

81 np.testing.assert_allclose( 

82 oetf_ARIBSTDB67(E), E_p, atol=TOLERANCE_ABSOLUTE_TESTS 

83 ) 

84 

85 E = np.reshape(E, (2, 3, 1)) 

86 E_p = np.reshape(E_p, (2, 3, 1)) 

87 np.testing.assert_allclose( 

88 oetf_ARIBSTDB67(E), E_p, atol=TOLERANCE_ABSOLUTE_TESTS 

89 ) 

90 

91 def test_domain_range_scale_oetf_ARIBSTDB67(self) -> None: 

92 """ 

93 Test :func:`colour.models.rgb.transfer_functions.arib_std_b67.\ 

94oetf_ARIBSTDB67` definition domain and range scale support. 

95 """ 

96 

97 E = 0.18 

98 E_p = oetf_ARIBSTDB67(E) 

99 

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

101 for scale, factor in d_r: 

102 with domain_range_scale(scale): 

103 np.testing.assert_allclose( 

104 oetf_ARIBSTDB67(E * factor), 

105 E_p * factor, 

106 atol=TOLERANCE_ABSOLUTE_TESTS, 

107 ) 

108 

109 @ignore_numpy_errors 

110 def test_nan_oetf_ARIBSTDB67(self) -> None: 

111 """ 

112 Test :func:`colour.models.rgb.transfer_functions.arib_std_b67.\ 

113oetf_ARIBSTDB67` definition nan support. 

114 """ 

115 

116 oetf_ARIBSTDB67(np.array([-1.0, 0.0, 1.0, -np.inf, np.inf, np.nan])) 

117 

118 

119class TestOetf_inverse_ARIBSTDB67: 

120 """ 

121 Define :func:`colour.models.rgb.transfer_functions.arib_std_b67.\ 

122oetf_inverse_ARIBSTDB67` definition unit tests methods. 

123 """ 

124 

125 def test_oetf_inverse_ARIBSTDB67(self) -> None: 

126 """ 

127 Test :func:`colour.models.rgb.transfer_functions.arib_std_b67.\ 

128oetf_inverse_ARIBSTDB67` definition. 

129 """ 

130 

131 np.testing.assert_allclose( 

132 oetf_inverse_ARIBSTDB67(-0.25), 

133 -0.25, 

134 atol=TOLERANCE_ABSOLUTE_TESTS, 

135 ) 

136 

137 np.testing.assert_allclose( 

138 oetf_inverse_ARIBSTDB67(0.0), 0.0, atol=TOLERANCE_ABSOLUTE_TESTS 

139 ) 

140 

141 np.testing.assert_allclose( 

142 oetf_inverse_ARIBSTDB67(0.212132034355964), 

143 0.18, 

144 atol=TOLERANCE_ABSOLUTE_TESTS, 

145 ) 

146 

147 np.testing.assert_allclose( 

148 oetf_inverse_ARIBSTDB67(0.5), 1.0, atol=TOLERANCE_ABSOLUTE_TESTS 

149 ) 

150 

151 np.testing.assert_allclose( 

152 oetf_inverse_ARIBSTDB67(1.302858098046995), 

153 64.0, 

154 atol=TOLERANCE_ABSOLUTE_TESTS, 

155 ) 

156 

157 def test_n_dimensional_oetf_inverse_ARIBSTDB67(self) -> None: 

158 """ 

159 Test :func:`colour.models.rgb.transfer_functions.arib_std_b67.\ 

160oetf_inverse_ARIBSTDB67` definition n-dimensional arrays support. 

161 """ 

162 

163 E_p = 0.212132034355964 

164 E = oetf_inverse_ARIBSTDB67(E_p) 

165 

166 E_p = np.tile(E_p, 6) 

167 E = np.tile(E, 6) 

168 np.testing.assert_allclose( 

169 oetf_inverse_ARIBSTDB67(E_p), E, atol=TOLERANCE_ABSOLUTE_TESTS 

170 ) 

171 

172 E_p = np.reshape(E_p, (2, 3)) 

173 E = np.reshape(E, (2, 3)) 

174 np.testing.assert_allclose( 

175 oetf_inverse_ARIBSTDB67(E_p), E, atol=TOLERANCE_ABSOLUTE_TESTS 

176 ) 

177 

178 E_p = np.reshape(E_p, (2, 3, 1)) 

179 E = np.reshape(E, (2, 3, 1)) 

180 np.testing.assert_allclose( 

181 oetf_inverse_ARIBSTDB67(E_p), E, atol=TOLERANCE_ABSOLUTE_TESTS 

182 ) 

183 

184 def test_domain_range_scale_oetf_inverse_ARIBSTDB67(self) -> None: 

185 """ 

186 Test :func:`colour.models.rgb.transfer_functions.arib_std_b67.\ 

187oetf_inverse_ARIBSTDB67` definition domain and range scale support. 

188 """ 

189 

190 E_p = 0.212132034355964 

191 E = oetf_inverse_ARIBSTDB67(E_p) 

192 

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

194 for scale, factor in d_r: 

195 with domain_range_scale(scale): 

196 np.testing.assert_allclose( 

197 oetf_inverse_ARIBSTDB67(E_p * factor), 

198 E * factor, 

199 atol=TOLERANCE_ABSOLUTE_TESTS, 

200 ) 

201 

202 @ignore_numpy_errors 

203 def test_nan_oetf_inverse_ARIBSTDB67(self) -> None: 

204 """ 

205 Test :func:`colour.models.rgb.transfer_functions.arib_std_b67.\ 

206oetf_inverse_ARIBSTDB67` definition nan support. 

207 """ 

208 

209 oetf_inverse_ARIBSTDB67(np.array([-1.0, 0.0, 1.0, -np.inf, np.inf, np.nan]))