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

1"""

2 Define the unit tests for the

3:mod:`colour.models.rgb.transfer_functions.itur_bt_1361` 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 oetf_BT1361, oetf_inverse_BT1361

10 from colour.utilities import domain_range_scale, ignore_numpy_errors

11

12 __author__ = "Colour Developers"

13 __copyright__ = "Copyright 2013 Colour Developers"

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

15 __maintainer__ = "Colour Developers"

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

17 __status__ = "Production"

18

19 __all__ = [

20 "TestOetf_BT1361",

21 "TestOetf_inverse_BT1361",

22]

23

24

25 class TestOetf_BT1361:

26 """

27 Define :func:`colour.models.rgb.transfer_functions.itur_bt_1361.oetf_BT1361`

28 definition unit tests methods.

29 """

30

31 def test_oetf_BT1361(self) -> None:

32 """

33 Test :func:`colour.models.rgb.transfer_functions.itur_bt_1361.\

34 oetf_BT1361` definition.

35 """

36

37 np.testing.assert_allclose(

38 oetf_BT1361(-0.18),

39 -0.212243985492969,

40 atol=TOLERANCE_ABSOLUTE_TESTS,

41 )

42

43 np.testing.assert_allclose(oetf_BT1361(0.0), 0.0, atol=TOLERANCE_ABSOLUTE_TESTS)

44

45 np.testing.assert_allclose(

46 oetf_BT1361(0.015),

47 0.067500000000000,

48 atol=TOLERANCE_ABSOLUTE_TESTS,

49 )

50

51 np.testing.assert_allclose(

52 oetf_BT1361(0.18), 0.409007728864150, atol=TOLERANCE_ABSOLUTE_TESTS

53 )

54

55 np.testing.assert_allclose(oetf_BT1361(1.0), 1.0, atol=TOLERANCE_ABSOLUTE_TESTS)

56

57 def test_n_dimensional_oetf_BT1361(self) -> None:

58 """

59 Test :func:`colour.models.rgb.transfer_functions.itur_bt_1361.\

60 oetf_BT1361` definition n-dimensional arrays support.

61 """

62

63 L = 0.18

64 V = oetf_BT1361(L)

65

66 L = np.tile(L, 6)

67 V = np.tile(V, 6)

68 np.testing.assert_allclose(oetf_BT1361(L), V, atol=TOLERANCE_ABSOLUTE_TESTS)

69

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

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

72 np.testing.assert_allclose(oetf_BT1361(L), V, atol=TOLERANCE_ABSOLUTE_TESTS)

73

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

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

76 np.testing.assert_allclose(oetf_BT1361(L), V, atol=TOLERANCE_ABSOLUTE_TESTS)

77

78 def test_domain_range_scale_oetf_BT1361(self) -> None:

79 """

80 Test :func:`colour.models.rgb.transfer_functions.itur_bt_1361.\

81 oetf_BT1361` definition domain and range scale support.

82 """

83

84 L = 0.18

85 V = oetf_BT1361(L)

86

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

88 for scale, factor in d_r:

89 with domain_range_scale(scale):

90 np.testing.assert_allclose(

91 oetf_BT1361(L * factor),

92 V * factor,

93 atol=TOLERANCE_ABSOLUTE_TESTS,

94 )

95

96 @ignore_numpy_errors

97 def test_nan_oetf_BT1361(self) -> None:

98 """

99 Test :func:`colour.models.rgb.transfer_functions.itur_bt_1361.\

100 oetf_BT1361` definition nan support.

101 """

102

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

104

105

106 class TestOetf_inverse_BT1361:

107 """

108 Define :func:`colour.models.rgb.transfer_functions.itur_bt_1361.\

109 oetf_inverse_BT1361` definition unit tests methods.

110 """

111

112 def test_oetf_inverse_BT1361(self) -> None:

113 """

114 Test :func:`colour.models.rgb.transfer_functions.itur_bt_1361.\

115 oetf_inverse_BT1361` definition.

116 """

117

118 np.testing.assert_allclose(

119 oetf_inverse_BT1361(-0.212243985492969),

120 -0.18,

121 atol=TOLERANCE_ABSOLUTE_TESTS,

122 )

123

124 np.testing.assert_allclose(

125 oetf_inverse_BT1361(0.0), 0.0, atol=TOLERANCE_ABSOLUTE_TESTS

126 )

127

128 np.testing.assert_allclose(

129 oetf_inverse_BT1361(0.067500000000000),

130 0.015,

131 atol=TOLERANCE_ABSOLUTE_TESTS,

132 )

133

134 np.testing.assert_allclose(

135 oetf_inverse_BT1361(0.409007728864150),

136 0.18,

137 atol=TOLERANCE_ABSOLUTE_TESTS,

138 )

139

140 np.testing.assert_allclose(

141 oetf_inverse_BT1361(1.0), 1.0, atol=TOLERANCE_ABSOLUTE_TESTS

142 )

143

144 def test_n_dimensional_oetf_inverse_BT1361(self) -> None:

145 """

146 Test :func:`colour.models.rgb.transfer_functions.itur_bt_1361.\

147 oetf_inverse_BT1361` definition n-dimensional arrays support.

148 """

149

150 V = 0.409007728864150

151 L = oetf_inverse_BT1361(V)

152

153 V = np.tile(V, 6)

154 L = np.tile(L, 6)

155 np.testing.assert_allclose(

156 oetf_inverse_BT1361(V), L, atol=TOLERANCE_ABSOLUTE_TESTS

157 )

158

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

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

161 np.testing.assert_allclose(

162 oetf_inverse_BT1361(V), L, atol=TOLERANCE_ABSOLUTE_TESTS

163 )

164

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

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

167 np.testing.assert_allclose(

168 oetf_inverse_BT1361(V), L, atol=TOLERANCE_ABSOLUTE_TESTS

169 )

170

171 def test_domain_range_scale_oetf_inverse_BT1361(self) -> None:

172 """

173 Test :func:`colour.models.rgb.transfer_functions.itur_bt_1361.\

174 oetf_inverse_BT1361` definition domain and range scale support.

175 """

176

177 V = 0.409007728864150

178 L = oetf_inverse_BT1361(V)

179

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

181 for scale, factor in d_r:

182 with domain_range_scale(scale):

183 np.testing.assert_allclose(

184 oetf_inverse_BT1361(V * factor),

185 L * factor,

186 atol=TOLERANCE_ABSOLUTE_TESTS,

187 )

188

189 @ignore_numpy_errors

190 def test_nan_oetf_inverse_BT1361(self) -> None:

191 """

192 Test :func:`colour.models.rgb.transfer_functions.itur_bt_1361.\

193 oetf_inverse_BT1361` definition nan support.

194 """

195

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