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

1"""

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

3 filmlight_t_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 (

10 log_decoding_FilmLightTLog,

11 log_encoding_FilmLightTLog,

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

24 "TestLogDecoding_FilmLightTLog",

25]

26

27

28 class TestLogEncoding_FilmLightTLog:

29 """

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

31 log_encoding_FilmLightTLog` definition unit tests methods.

32 """

33

34 def test_log_encoding_FilmLightTLog(self) -> None:

35 """

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

37 log_encoding_FilmLightTLog` definition.

38 """

39

40 np.testing.assert_allclose(

41 log_encoding_FilmLightTLog(0.0),

42 0.075,

43 atol=TOLERANCE_ABSOLUTE_TESTS,

44 )

45

46 np.testing.assert_allclose(

47 log_encoding_FilmLightTLog(0.18),

48 0.396567801298332,

49 atol=TOLERANCE_ABSOLUTE_TESTS,

50 )

51

52 np.testing.assert_allclose(

53 log_encoding_FilmLightTLog(1.0),

54 0.552537881005859,

55 atol=TOLERANCE_ABSOLUTE_TESTS,

56 )

57

58 def test_n_dimensional_log_encoding_TLog(self) -> None:

59 """

60 Test :func:`colour.models.rgb.transfer_functions.filmlight_t_log.\

61 log_encoding_FilmLightTLog` definition n-dimensional arrays support.

62 """

63

64 x = 0.18

65 t = log_encoding_FilmLightTLog(x)

66

67 x = np.tile(x, 6)

68 t = np.tile(t, 6)

69 np.testing.assert_allclose(

70 log_encoding_FilmLightTLog(x), t, atol=TOLERANCE_ABSOLUTE_TESTS

71 )

72

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

74 t = np.reshape(t, (2, 3))

75 np.testing.assert_allclose(

76 log_encoding_FilmLightTLog(x), t, atol=TOLERANCE_ABSOLUTE_TESTS

77 )

78

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

80 t = np.reshape(t, (2, 3, 1))

81 np.testing.assert_allclose(

82 log_encoding_FilmLightTLog(x), t, atol=TOLERANCE_ABSOLUTE_TESTS

83 )

84

85 def test_domain_range_scale_log_encoding_TLog(self) -> None:

86 """

87 Test :func:`colour.models.rgb.transfer_functions.filmlight_t_log.\

88 log_encoding_FilmLightTLog` definition domain and range scale support.

89 """

90

91 x = 0.18

92 t = log_encoding_FilmLightTLog(x)

93

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

95 for scale, factor in d_r:

96 with domain_range_scale(scale):

97 np.testing.assert_allclose(

98 log_encoding_FilmLightTLog(x * factor),

99 t * factor,

100 atol=TOLERANCE_ABSOLUTE_TESTS,

101 )

102

103 @ignore_numpy_errors

104 def test_nan_log_encoding_TLog(self) -> None:

105 """

106 Test :func:`colour.models.rgb.transfer_functions.filmlight_t_log.\

107 log_encoding_FilmLightTLog` definition nan support.

108 """

109

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

111

112

113 class TestLogDecoding_FilmLightTLog:

114 """

115 Define :func:`colour.models.rgb.transfer_functions.filmlight_t_log.\

116 log_decoding_FilmLightTLog` definition unit tests methods.

117 """

118

119 def test_log_decoding_FilmLightTLog(self) -> None:

120 """

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

122 log_decoding_FilmLightTLog` definition.

123 """

124

125 np.testing.assert_allclose(

126 log_decoding_FilmLightTLog(0.075),

127 0.0,

128 atol=TOLERANCE_ABSOLUTE_TESTS,

129 )

130

131 np.testing.assert_allclose(

132 log_decoding_FilmLightTLog(0.396567801298332),

133 0.18,

134 atol=TOLERANCE_ABSOLUTE_TESTS,

135 )

136

137 np.testing.assert_allclose(

138 log_decoding_FilmLightTLog(0.552537881005859),

139 1.0,

140 atol=TOLERANCE_ABSOLUTE_TESTS,

141 )

142

143 def test_n_dimensional_log_decoding_TLog(self) -> None:

144 """

145 Test :func:`colour.models.rgb.transfer_functions.filmlight_t_log.\

146 log_decoding_FilmLightTLog` definition n-dimensional arrays support.

147 """

148

149 t = 0.396567801298332

150 x = log_decoding_FilmLightTLog(t)

151

152 t = np.tile(t, 6)

153 x = np.tile(x, 6)

154 np.testing.assert_allclose(

155 log_decoding_FilmLightTLog(t), x, atol=TOLERANCE_ABSOLUTE_TESTS

156 )

157

158 t = np.reshape(t, (2, 3))

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

160 np.testing.assert_allclose(

161 log_decoding_FilmLightTLog(t), x, atol=TOLERANCE_ABSOLUTE_TESTS

162 )

163

164 t = np.reshape(t, (2, 3, 1))

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

166 np.testing.assert_allclose(

167 log_decoding_FilmLightTLog(t), x, atol=TOLERANCE_ABSOLUTE_TESTS

168 )

169

170 def test_domain_range_scale_log_decoding_TLog(self) -> None:

171 """

172 Test :func:`colour.models.rgb.transfer_functions.filmlight_t_log.\

173 log_decoding_FilmLightTLog` definition domain and range scale support.

174 """

175

176 t = 0.396567801298332

177 x = log_decoding_FilmLightTLog(t)

178

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

180 for scale, factor in d_r:

181 with domain_range_scale(scale):

182 np.testing.assert_allclose(

183 log_decoding_FilmLightTLog(t * factor),

184 x * factor,

185 atol=TOLERANCE_ABSOLUTE_TESTS,

186 )

187

188 @ignore_numpy_errors

189 def test_nan_log_decoding_TLog(self) -> None:

190 """

191 Test :func:`colour.models.rgb.transfer_functions.filmlight_t_log.\

192 log_decoding_FilmLightTLog` definition nan support.

193 """

194

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