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

1"""

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

3 nikon_n_log` 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 log_decoding_NLog, log_encoding_NLog

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

21 "TestLogDecoding_NLog",

22]

23

24

25 class TestLogEncoding_NLog:

26 """

27 Define :func:`colour.models.rgb.transfer_functions.nikon_n_log.\

28 log_encoding_NLog` definition unit tests methods.

29 """

30

31 def test_log_encoding_NLog(self) -> None:

32 """

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

34 log_encoding_NLog` definition.

35 """

36

37 np.testing.assert_allclose(

38 log_encoding_NLog(0.0),

39 0.124372627896372,

40 atol=TOLERANCE_ABSOLUTE_TESTS,

41 )

42

43 np.testing.assert_allclose(

44 log_encoding_NLog(0.18),

45 0.363667770117139,

46 atol=TOLERANCE_ABSOLUTE_TESTS,

47 )

48

49 np.testing.assert_allclose(

50 log_encoding_NLog(0.18, 12),

51 0.363667770117139,

52 atol=TOLERANCE_ABSOLUTE_TESTS,

53 )

54

55 np.testing.assert_allclose(

56 log_encoding_NLog(0.18, 10, False),

57 0.351634850262366,

58 atol=TOLERANCE_ABSOLUTE_TESTS,

59 )

60

61 np.testing.assert_allclose(

62 log_encoding_NLog(0.18, 10, False, False),

63 0.337584957293328,

64 atol=TOLERANCE_ABSOLUTE_TESTS,

65 )

66

67 np.testing.assert_allclose(

68 log_encoding_NLog(1.0),

69 0.605083088954056,

70 atol=TOLERANCE_ABSOLUTE_TESTS,

71 )

72

73 def test_n_dimensional_log_encoding_NLog(self) -> None:

74 """

75 Test :func:`colour.models.rgb.transfer_functions.nikon_n_log.\

76 log_encoding_NLog` definition n-dimensional arrays support.

77 """

78

79 y = 0.18

80 x = log_encoding_NLog(y)

81

82 y = np.tile(y, 6)

83 x = np.tile(x, 6)

84 np.testing.assert_allclose(

85 log_encoding_NLog(y), x, atol=TOLERANCE_ABSOLUTE_TESTS

86 )

87

88 y = np.reshape(y, (2, 3))

89 x = np.reshape(x, (2, 3))

90 np.testing.assert_allclose(

91 log_encoding_NLog(y), x, atol=TOLERANCE_ABSOLUTE_TESTS

92 )

93

94 y = np.reshape(y, (2, 3, 1))

95 x = np.reshape(x, (2, 3, 1))

96 np.testing.assert_allclose(

97 log_encoding_NLog(y), x, atol=TOLERANCE_ABSOLUTE_TESTS

98 )

99

100 def test_domain_range_scale_log_encoding_NLog(self) -> None:

101 """

102 Test :func:`colour.models.rgb.transfer_functions.nikon_n_log.\

103 log_encoding_NLog` definition domain and range scale support.

104 """

105

106 y = 0.18

107 x = log_encoding_NLog(y)

108

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

110 for scale, factor in d_r:

111 with domain_range_scale(scale):

112 np.testing.assert_allclose(

113 log_encoding_NLog(y * factor),

114 x * factor,

115 atol=TOLERANCE_ABSOLUTE_TESTS,

116 )

117

118 @ignore_numpy_errors

119 def test_nan_log_encoding_NLog(self) -> None:

120 """

121 Test :func:`colour.models.rgb.transfer_functions.nikon_n_log.\

122 log_encoding_NLog` definition nan support.

123 """

124

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

126

127

128 class TestLogDecoding_NLog:

129 """

130 Define :func:`colour.models.rgb.transfer_functions.nikon_n_log.\

131 log_decoding_NLog` definition unit tests methods.

132 """

133

134 def test_log_decoding_NLog(self) -> None:

135 """

136 Test :func:`colour.models.rgb.transfer_functions.nikon_n_log.\

137 log_decoding_NLog` definition.

138 """

139

140 np.testing.assert_allclose(

141 log_decoding_NLog(0.124372627896372),

142 0.0,

143 atol=TOLERANCE_ABSOLUTE_TESTS,

144 )

145

146 np.testing.assert_allclose(

147 log_decoding_NLog(0.363667770117139),

148 0.18,

149 atol=TOLERANCE_ABSOLUTE_TESTS,

150 )

151

152 np.testing.assert_allclose(

153 log_decoding_NLog(0.363667770117139, 12),

154 0.18,

155 atol=TOLERANCE_ABSOLUTE_TESTS,

156 )

157

158 np.testing.assert_allclose(

159 log_decoding_NLog(0.351634850262366, 10, False),

160 0.18,

161 atol=TOLERANCE_ABSOLUTE_TESTS,

162 )

163

164 np.testing.assert_allclose(

165 log_decoding_NLog(0.337584957293328, 10, False, False),

166 0.18,

167 atol=TOLERANCE_ABSOLUTE_TESTS,

168 )

169

170 np.testing.assert_allclose(

171 log_decoding_NLog(0.605083088954056),

172 1.0,

173 atol=TOLERANCE_ABSOLUTE_TESTS,

174 )

175

176 def test_n_dimensional_log_decoding_NLog(self) -> None:

177 """

178 Test :func:`colour.models.rgb.transfer_functions.nikon_n_log.\

179 log_decoding_NLog` definition n-dimensional arrays support.

180 """

181

182 x = 0.363667770117139

183 y = log_decoding_NLog(x)

184

185 x = np.tile(x, 6)

186 y = np.tile(y, 6)

187 np.testing.assert_allclose(

188 log_decoding_NLog(x), y, atol=TOLERANCE_ABSOLUTE_TESTS

189 )

190

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

192 y = np.reshape(y, (2, 3))

193 np.testing.assert_allclose(

194 log_decoding_NLog(x), y, atol=TOLERANCE_ABSOLUTE_TESTS

195 )

196

197 x = np.reshape(x, (2, 3, 1))

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

199 np.testing.assert_allclose(

200 log_decoding_NLog(x), y, atol=TOLERANCE_ABSOLUTE_TESTS

201 )

202

203 def test_domain_range_scale_log_decoding_NLog(self) -> None:

204 """

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

206 log_decoding_NLog` definition domain and range scale support.

207 """

208

209 x = 0.363667770117139

210 y = log_decoding_NLog(x)

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 log_decoding_NLog(x * factor),

217 y * factor,

218 atol=TOLERANCE_ABSOLUTE_TESTS,

219 )

220

221 @ignore_numpy_errors

222 def test_nan_log_decoding_NLog(self) -> None:

223 """

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

225 log_decoding_NLog` definition nan support.

226 """

227

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