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

1"""

2 Define the unit tests for the

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

4"""

5

6 import numpy as np

7

8 from colour.constants import TOLERANCE_ABSOLUTE_TESTS

9 from colour.models.rgb.transfer_functions import (

10 oetf_ARIBSTDB67,

11 oetf_inverse_ARIBSTDB67,

12)

13 from 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

28 class TestOetf_ARIBSTDB67:

29 """

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

31 oetf_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.\

37 oetf_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.\

67 oetf_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.\

94 oetf_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.\

113 oetf_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

119 class TestOetf_inverse_ARIBSTDB67:

120 """

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

122 oetf_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.\

128 oetf_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.\

160 oetf_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.\

187 oetf_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.\

206 oetf_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]))