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

1"""

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

3 blackmagic_design` 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_BlackmagicFilmGeneration5,

11 oetf_inverse_BlackmagicFilmGeneration5,

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

24 "TestOetf_inverse_BlackmagicFilmGeneration5",

25]

26

27

28 class TestOetf_BlackmagicFilmGeneration5:

29 """

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

31 oetf_BlackmagicFilmGeneration5` definition unit tests methods.

32 """

33

34 def test_oetf_BlackmagicFilmGeneration5(self) -> None:

35 """

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

37 blackmagic_design.oetf_BlackmagicFilmGeneration5` definition.

38 """

39

40 np.testing.assert_allclose(

41 oetf_BlackmagicFilmGeneration5(0.0),

42 0.092465753424658,

43 atol=TOLERANCE_ABSOLUTE_TESTS,

44 )

45

46 np.testing.assert_allclose(

47 oetf_BlackmagicFilmGeneration5(0.18),

48 0.383561643835617,

49 atol=TOLERANCE_ABSOLUTE_TESTS,

50 )

51

52 np.testing.assert_allclose(

53 oetf_BlackmagicFilmGeneration5(1.0),

54 0.530489624957305,

55 atol=TOLERANCE_ABSOLUTE_TESTS,

56 )

57

58 np.testing.assert_allclose(

59 oetf_BlackmagicFilmGeneration5(100.0),

60 0.930339851899973,

61 atol=TOLERANCE_ABSOLUTE_TESTS,

62 )

63

64 np.testing.assert_allclose(

65 oetf_BlackmagicFilmGeneration5(222.86),

66 0.999999631713769,

67 atol=TOLERANCE_ABSOLUTE_TESTS,

68 )

69

70 def test_n_dimensional_oetf_BlackmagicFilmGeneration5(self) -> None:

71 """

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

73 blackmagic_design.oetf_BlackmagicFilmGeneration5` definition n-dimensional

74 arrays support.

75 """

76

77 L = 0.18

78 V = oetf_BlackmagicFilmGeneration5(L)

79

80 L = np.tile(L, 6)

81 V = np.tile(V, 6)

82 np.testing.assert_allclose(

83 oetf_BlackmagicFilmGeneration5(L), V, atol=TOLERANCE_ABSOLUTE_TESTS

84 )

85

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

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

88 np.testing.assert_allclose(

89 oetf_BlackmagicFilmGeneration5(L), V, atol=TOLERANCE_ABSOLUTE_TESTS

90 )

91

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

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

94 np.testing.assert_allclose(

95 oetf_BlackmagicFilmGeneration5(L), V, atol=TOLERANCE_ABSOLUTE_TESTS

96 )

97

98 def test_domain_range_scale_oetf_BlackmagicFilmGeneration5(self) -> None:

99 """

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

101 blackmagic_design.oetf_BlackmagicFilmGeneration5` definition domain and range

102 scale support.

103 """

104

105 L = 0.18

106 V = oetf_BlackmagicFilmGeneration5(L)

107

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

109 for scale, factor in d_r:

110 with domain_range_scale(scale):

111 np.testing.assert_allclose(

112 oetf_BlackmagicFilmGeneration5(L * factor),

113 V * factor,

114 atol=TOLERANCE_ABSOLUTE_TESTS,

115 )

116

117 @ignore_numpy_errors

118 def test_nan_oetf_BlackmagicFilmGeneration5(self) -> None:

119 """

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

121 blackmagic_design.oetf_BlackmagicFilmGeneration5` definition nan support.

122 """

123

124 oetf_BlackmagicFilmGeneration5(

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

126 )

127

128

129 class TestOetf_inverse_BlackmagicFilmGeneration5:

130 """

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

132 blackmagic_design.oetf_inverse_BlackmagicFilmGeneration5` definition unit tests

133 methods.

134 """

135

136 def test_oetf_inverse_BlackmagicFilmGeneration5(self) -> None:

137 """

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

139 blackmagic_design.oetf_inverse_BlackmagicFilmGeneration5` definition.

140 """

141

142 np.testing.assert_allclose(

143 oetf_inverse_BlackmagicFilmGeneration5(0.092465753424658),

144 0.0,

145 atol=TOLERANCE_ABSOLUTE_TESTS,

146 )

147

148 np.testing.assert_allclose(

149 oetf_inverse_BlackmagicFilmGeneration5(0.383561643835617),

150 0.18,

151 atol=TOLERANCE_ABSOLUTE_TESTS,

152 )

153

154 np.testing.assert_allclose(

155 oetf_inverse_BlackmagicFilmGeneration5(0.530489624957305),

156 1.0,

157 atol=TOLERANCE_ABSOLUTE_TESTS,

158 )

159

160 np.testing.assert_allclose(

161 oetf_inverse_BlackmagicFilmGeneration5(0.930339851899973),

162 100.0,

163 atol=TOLERANCE_ABSOLUTE_TESTS,

164 )

165

166 np.testing.assert_allclose(

167 oetf_inverse_BlackmagicFilmGeneration5(0.999999631713769),

168 222.86,

169 atol=TOLERANCE_ABSOLUTE_TESTS,

170 )

171

172 def test_n_dimensional_oetf_inverse_BlackmagicFilmGeneration5(self) -> None:

173 """

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

175 blackmagic_design.oetf_inverse_BlackmagicFilmGeneration5` definition

176 n-dimensional arrays support.

177 """

178

179 V = 0.383561643835617

180 L = oetf_inverse_BlackmagicFilmGeneration5(V)

181

182 V = np.tile(V, 6)

183 L = np.tile(L, 6)

184 np.testing.assert_allclose(

185 oetf_inverse_BlackmagicFilmGeneration5(V),

186 L,

187 atol=TOLERANCE_ABSOLUTE_TESTS,

188 )

189

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

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

192 np.testing.assert_allclose(

193 oetf_inverse_BlackmagicFilmGeneration5(V),

194 L,

195 atol=TOLERANCE_ABSOLUTE_TESTS,

196 )

197

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

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

200 np.testing.assert_allclose(

201 oetf_inverse_BlackmagicFilmGeneration5(V),

202 L,

203 atol=TOLERANCE_ABSOLUTE_TESTS,

204 )

205

206 def test_domain_range_scale_oetf_inverse_BlackmagicFilmGeneration5(self) -> None:

207 """

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

209 blackmagic_design.oetf_inverse_BlackmagicFilmGeneration5` definition domain and

210 range scale support.

211 """

212

213 V = 0.383561643835617

214 L = oetf_inverse_BlackmagicFilmGeneration5(V)

215

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

217 for scale, factor in d_r:

218 with domain_range_scale(scale):

219 np.testing.assert_allclose(

220 oetf_inverse_BlackmagicFilmGeneration5(V * factor),

221 L * factor,

222 atol=TOLERANCE_ABSOLUTE_TESTS,

223 )

224

225 @ignore_numpy_errors

226 def test_nan_oetf_inverse_BlackmagicFilmGeneration5(self) -> None:

227 """

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

229 blackmagic_design.oetf_inverse_BlackmagicFilmGeneration5` definition nan

230 support.

231 """

232

233 oetf_inverse_BlackmagicFilmGeneration5(

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

235 )