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

1"""

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

3 dji_d_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_DJIDLog,

11 log_encoding_DJIDLog,

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

24 "TestLogDecoding_DJIDLog",

25]

26

27

28 class TestLogEncoding_DJIDLog:

29 """

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

31 log_encoding_DJIDLog` definition unit tests methods.

32 """

33

34 def test_log_encoding_DJIDLog(self) -> None:

35 """

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

37 log_encoding_DJIDLog` definition.

38 """

39

40 np.testing.assert_allclose(

41 log_encoding_DJIDLog(0.0), 0.0929, atol=TOLERANCE_ABSOLUTE_TESTS

42 )

43

44 np.testing.assert_allclose(

45 log_encoding_DJIDLog(0.18),

46 0.398764556189331,

47 atol=TOLERANCE_ABSOLUTE_TESTS,

48 )

49

50 np.testing.assert_allclose(

51 log_encoding_DJIDLog(1.0), 0.584555, atol=TOLERANCE_ABSOLUTE_TESTS

52 )

53

54 def test_n_dimensional_log_encoding_DLog(self) -> None:

55 """

56 Test :func:`colour.models.rgb.transfer_functions.dji_d_log.\

57 log_encoding_DJIDLog` definition n-dimensional arrays support.

58 """

59

60 x = 0.18

61 y = log_encoding_DJIDLog(x)

62

63 x = np.tile(x, 6)

64 y = np.tile(y, 6)

65 np.testing.assert_allclose(

66 log_encoding_DJIDLog(x), y, atol=TOLERANCE_ABSOLUTE_TESTS

67 )

68

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

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

71 np.testing.assert_allclose(

72 log_encoding_DJIDLog(x), y, atol=TOLERANCE_ABSOLUTE_TESTS

73 )

74

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

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

77 np.testing.assert_allclose(

78 log_encoding_DJIDLog(x), y, atol=TOLERANCE_ABSOLUTE_TESTS

79 )

80

81 def test_domain_range_scale_log_encoding_DLog(self) -> None:

82 """

83 Test :func:`colour.models.rgb.transfer_functions.dji_d_log.\

84 log_encoding_DJIDLog` definition domain and range scale support.

85 """

86

87 x = 0.18

88 y = log_encoding_DJIDLog(x)

89

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

91 for scale, factor in d_r:

92 with domain_range_scale(scale):

93 np.testing.assert_allclose(

94 log_encoding_DJIDLog(x * factor),

95 y * factor,

96 atol=TOLERANCE_ABSOLUTE_TESTS,

97 )

98

99 @ignore_numpy_errors

100 def test_nan_log_encoding_DLog(self) -> None:

101 """

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

103 log_encoding_DJIDLog` definition nan support.

104 """

105

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

107

108

109 class TestLogDecoding_DJIDLog:

110 """

111 Define :func:`colour.models.rgb.transfer_functions.dji_d_log.\

112 log_decoding_DJIDLog` definition unit tests methods.

113 """

114

115 def test_log_decoding_DJIDLog(self) -> None:

116 """

117 Test :func:`colour.models.rgb.transfer_functions.dji_d_log.\

118 log_decoding_DJIDLog` definition.

119 """

120

121 np.testing.assert_allclose(

122 log_decoding_DJIDLog(0.0929), 0.0, atol=TOLERANCE_ABSOLUTE_TESTS

123 )

124

125 np.testing.assert_allclose(

126 log_decoding_DJIDLog(0.398764556189331), 0.18, atol=1e-6

127 )

128

129 np.testing.assert_allclose(log_decoding_DJIDLog(0.584555), 1.0, atol=1e-6)

130

131 def test_n_dimensional_log_decoding_DLog(self) -> None:

132 """

133 Test :func:`colour.models.rgb.transfer_functions.dji_d_log.\

134 log_decoding_DJIDLog` definition n-dimensional arrays support.

135 """

136

137 y = 0.398764556189331

138 x = log_decoding_DJIDLog(y)

139

140 y = np.tile(y, 6)

141 x = np.tile(x, 6)

142 np.testing.assert_allclose(

143 log_decoding_DJIDLog(y), x, atol=TOLERANCE_ABSOLUTE_TESTS

144 )

145

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

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

148 np.testing.assert_allclose(

149 log_decoding_DJIDLog(y), x, atol=TOLERANCE_ABSOLUTE_TESTS

150 )

151

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

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

154 np.testing.assert_allclose(

155 log_decoding_DJIDLog(y), x, atol=TOLERANCE_ABSOLUTE_TESTS

156 )

157

158 def test_domain_range_scale_log_decoding_DLog(self) -> None:

159 """

160 Test :func:`colour.models.rgb.transfer_functions.dji_d_log.\

161 log_decoding_DJIDLog` definition domain and range scale support.

162 """

163

164 y = 0.398764556189331

165 x = log_decoding_DJIDLog(y)

166

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

168 for scale, factor in d_r:

169 with domain_range_scale(scale):

170 np.testing.assert_allclose(

171 log_decoding_DJIDLog(y * factor),

172 x * factor,

173 atol=TOLERANCE_ABSOLUTE_TESTS,

174 )

175

176 @ignore_numpy_errors

177 def test_nan_log_decoding_DLog(self) -> None:

178 """

179 Test :func:`colour.models.rgb.transfer_functions.dji_d_log.\

180 log_decoding_DJIDLog` definition nan support.

181 """

182

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