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

1"""

2 Define the unit tests for the :mod:`colour.models.rgb.transfer_functions.\

3 davinci_intermediate` 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_DaVinciIntermediate,

11 oetf_inverse_DaVinciIntermediate,

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

24 "TestOetf_inverse_DaVinciIntermediate",

25]

26

27

28 class TestOetf_DaVinciIntermediate:

29 """

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

31 oetf_DaVinciIntermediate` definition unit tests methods.

32 """

33

34 def test_oetf_DaVinciIntermediate(self) -> None:

35 """

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

37 davinci_intermediate.oetf_DaVinciIntermediate` definition.

38 """

39

40 np.testing.assert_allclose(

41 oetf_DaVinciIntermediate(-0.01),

42 -0.104442685500000,

43 atol=TOLERANCE_ABSOLUTE_TESTS,

44 )

45

46 np.testing.assert_allclose(

47 oetf_DaVinciIntermediate(0.0), 0.0, atol=TOLERANCE_ABSOLUTE_TESTS

48 )

49

50 np.testing.assert_allclose(

51 oetf_DaVinciIntermediate(0.18),

52 0.336043272384855,

53 atol=TOLERANCE_ABSOLUTE_TESTS,

54 )

55

56 np.testing.assert_allclose(

57 oetf_DaVinciIntermediate(1.0),

58 0.513837441116225,

59 atol=TOLERANCE_ABSOLUTE_TESTS,

60 )

61

62 np.testing.assert_allclose(

63 oetf_DaVinciIntermediate(100.0),

64 0.999999987016872,

65 atol=TOLERANCE_ABSOLUTE_TESTS,

66 )

67

68 def test_n_dimensional_oetf_DaVinciIntermediate(self) -> None:

69 """

70 Test :func:`colour.models.rgb.transfer_functions.\

71 davinci_intermediate.oetf_DaVinciIntermediate` definition n-dimensional arrays

72 support.

73 """

74

75 L = 0.18

76 V = oetf_DaVinciIntermediate(L)

77

78 L = np.tile(L, 6)

79 V = np.tile(V, 6)

80 np.testing.assert_allclose(

81 oetf_DaVinciIntermediate(L), V, atol=TOLERANCE_ABSOLUTE_TESTS

82 )

83

84 L = np.reshape(L, (2, 3))

85 V = np.reshape(V, (2, 3))

86 np.testing.assert_allclose(

87 oetf_DaVinciIntermediate(L), V, atol=TOLERANCE_ABSOLUTE_TESTS

88 )

89

90 L = np.reshape(L, (2, 3, 1))

91 V = np.reshape(V, (2, 3, 1))

92 np.testing.assert_allclose(

93 oetf_DaVinciIntermediate(L), V, atol=TOLERANCE_ABSOLUTE_TESTS

94 )

95

96 def test_domain_range_scale_oetf_DaVinciIntermediate(self) -> None:

97 """

98 Test :func:`colour.models.rgb.transfer_functions.\

99 davinci_intermediate.oetf_DaVinciIntermediate` definition domain and range

100 scale support.

101 """

102

103 L = 0.18

104 V = oetf_DaVinciIntermediate(L)

105

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

107 for scale, factor in d_r:

108 with domain_range_scale(scale):

109 np.testing.assert_allclose(

110 oetf_DaVinciIntermediate(L * factor),

111 V * factor,

112 atol=TOLERANCE_ABSOLUTE_TESTS,

113 )

114

115 @ignore_numpy_errors

116 def test_nan_oetf_DaVinciIntermediate(self) -> None:

117 """

118 Test :func:`colour.models.rgb.transfer_functions.\

119 davinci_intermediate.oetf_DaVinciIntermediate` definition nan support.

120 """

121

122 oetf_DaVinciIntermediate(np.array([-1.0, 0.0, 1.0, -np.inf, np.inf, np.nan]))

123

124

125 class TestOetf_inverse_DaVinciIntermediate:

126 """

127 Define :func:`colour.models.rgb.transfer_functions.\

128 davinci_intermediate.oetf_inverse_DaVinciIntermediate` definition unit tests

129 methods.

130 """

131

132 def test_oetf_inverse_DaVinciIntermediate(self) -> None:

133 """

134 Test :func:`colour.models.rgb.transfer_functions.\

135 davinci_intermediate.oetf_inverse_DaVinciIntermediate` definition.

136 """

137

138 np.testing.assert_allclose(

139 oetf_inverse_DaVinciIntermediate(-0.104442685500000),

140 -0.01,

141 atol=TOLERANCE_ABSOLUTE_TESTS,

142 )

143

144 np.testing.assert_allclose(

145 oetf_inverse_DaVinciIntermediate(0.0),

146 0.0,

147 atol=TOLERANCE_ABSOLUTE_TESTS,

148 )

149

150 np.testing.assert_allclose(

151 oetf_inverse_DaVinciIntermediate(0.336043272384855),

152 0.18,

153 atol=TOLERANCE_ABSOLUTE_TESTS,

154 )

155

156 np.testing.assert_allclose(

157 oetf_inverse_DaVinciIntermediate(0.513837441116225),

158 1.0,

159 atol=TOLERANCE_ABSOLUTE_TESTS,

160 )

161

162 np.testing.assert_allclose(

163 oetf_inverse_DaVinciIntermediate(0.999999987016872),

164 100.0,

165 atol=TOLERANCE_ABSOLUTE_TESTS,

166 )

167

168 def test_n_dimensional_oetf_inverse_DaVinciIntermediate(self) -> None:

169 """

170 Test :func:`colour.models.rgb.transfer_functions.\

171 davinci_intermediate.oetf_inverse_DaVinciIntermediate` definition n-dimensional

172 arrays support.

173 """

174

175 V = 0.336043272384855

176 L = oetf_inverse_DaVinciIntermediate(V)

177

178 V = np.tile(V, 6)

179 L = np.tile(L, 6)

180 np.testing.assert_allclose(

181 oetf_inverse_DaVinciIntermediate(V),

182 L,

183 atol=TOLERANCE_ABSOLUTE_TESTS,

184 )

185

186 V = np.reshape(V, (2, 3))

187 L = np.reshape(L, (2, 3))

188 np.testing.assert_allclose(

189 oetf_inverse_DaVinciIntermediate(V),

190 L,

191 atol=TOLERANCE_ABSOLUTE_TESTS,

192 )

193

194 V = np.reshape(V, (2, 3, 1))

195 L = np.reshape(L, (2, 3, 1))

196 np.testing.assert_allclose(

197 oetf_inverse_DaVinciIntermediate(V),

198 L,

199 atol=TOLERANCE_ABSOLUTE_TESTS,

200 )

201

202 def test_domain_range_scale_oetf_inverse_DaVinciIntermediate(self) -> None:

203 """

204 Test :func:`colour.models.rgb.transfer_functions.\

205 davinci_intermediate.oetf_inverse_DaVinciIntermediate` definition domain and

206 range scale support.

207 """

208

209 V = 0.336043272384855

210 L = oetf_inverse_DaVinciIntermediate(V)

211

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

213 for scale, factor in d_r:

214 with domain_range_scale(scale):

215 np.testing.assert_allclose(

216 oetf_inverse_DaVinciIntermediate(V * factor),

217 L * factor,

218 atol=TOLERANCE_ABSOLUTE_TESTS,

219 )

220

221 @ignore_numpy_errors

222 def test_nan_oetf_inverse_DaVinciIntermediate(self) -> None:

223 """

224 Test :func:`colour.models.rgb.transfer_functions.\

225 davinci_intermediate.oetf_inverse_DaVinciIntermediate` definition nan support.

226 """

227

228 oetf_inverse_DaVinciIntermediate(

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

230 )