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

1"""

2 Define the unit tests for the

3:mod:`colour.models.rgb.transfer_functions.gopro` 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_Protune,

11 log_encoding_Protune,

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

24 "TestLogDecoding_Protune",

25]

26

27

28 class TestLogEncoding_Protune:

29 """

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

31 log_encoding_Protune` definition unit tests methods.

32 """

33

34 def test_log_encoding_Protune(self) -> None:

35 """

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

37 log_encoding_Protune` definition.

38 """

39

40 np.testing.assert_allclose(

41 log_encoding_Protune(0.0), 0.0, atol=TOLERANCE_ABSOLUTE_TESTS

42 )

43

44 np.testing.assert_allclose(

45 log_encoding_Protune(0.18),

46 0.645623486803636,

47 atol=TOLERANCE_ABSOLUTE_TESTS,

48 )

49

50 np.testing.assert_allclose(

51 log_encoding_Protune(1.0), 1.0, atol=TOLERANCE_ABSOLUTE_TESTS

52 )

53

54 def test_n_dimensional_log_encoding_Protune(self) -> None:

55 """

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

57 log_encoding_Protune` definition n-dimensional arrays support.

58 """

59

60 x = 0.18

61 y = log_encoding_Protune(x)

62

63 x = np.tile(x, 6)

64 y = np.tile(y, 6)

65 np.testing.assert_allclose(

66 log_encoding_Protune(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_Protune(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_Protune(x), y, atol=TOLERANCE_ABSOLUTE_TESTS

79 )

80

81 def test_domain_range_scale_log_encoding_Protune(self) -> None:

82 """

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

84 log_encoding_Protune` definition domain and range scale support.

85 """

86

87 x = 0.18

88 y = log_encoding_Protune(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_Protune(x * factor),

95 y * factor,

96 atol=TOLERANCE_ABSOLUTE_TESTS,

97 )

98

99 @ignore_numpy_errors

100 def test_nan_log_encoding_Protune(self) -> None:

101 """

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

103 log_encoding_Protune` definition nan support.

104 """

105

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

107

108

109 class TestLogDecoding_Protune:

110 """

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

112 log_decoding_Protune` definition unit tests methods.

113 """

114

115 def test_log_decoding_Protune(self) -> None:

116 """

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

118 log_decoding_Protune` definition.

119 """

120

121 np.testing.assert_allclose(

122 log_decoding_Protune(0.0), 0.0, atol=TOLERANCE_ABSOLUTE_TESTS

123 )

124

125 np.testing.assert_allclose(

126 log_decoding_Protune(0.645623486803636),

127 0.18,

128 atol=TOLERANCE_ABSOLUTE_TESTS,

129 )

130

131 np.testing.assert_allclose(

132 log_decoding_Protune(1.0), 1.0, atol=TOLERANCE_ABSOLUTE_TESTS

133 )

134

135 def test_n_dimensional_log_decoding_Protune(self) -> None:

136 """

137 Test :func:`colour.models.rgb.transfer_functions.gopro.\

138 log_decoding_Protune` definition n-dimensional arrays support.

139 """

140

141 y = 0.645623486803636

142 x = log_decoding_Protune(y)

143

144 y = np.tile(y, 6)

145 x = np.tile(x, 6)

146 np.testing.assert_allclose(

147 log_decoding_Protune(y), x, atol=TOLERANCE_ABSOLUTE_TESTS

148 )

149

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

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

152 np.testing.assert_allclose(

153 log_decoding_Protune(y), x, atol=TOLERANCE_ABSOLUTE_TESTS

154 )

155

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

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

158 np.testing.assert_allclose(

159 log_decoding_Protune(y), x, atol=TOLERANCE_ABSOLUTE_TESTS

160 )

161

162 def test_domain_range_scale_log_decoding_Protune(self) -> None:

163 """

164 Test :func:`colour.models.rgb.transfer_functions.gopro.\

165 log_decoding_Protune` definition domain and range scale support.

166 """

167

168 y = 0.645623486803636

169 x = log_decoding_Protune(y)

170

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

172 for scale, factor in d_r:

173 with domain_range_scale(scale):

174 np.testing.assert_allclose(

175 log_decoding_Protune(y * factor),

176 x * factor,

177 atol=TOLERANCE_ABSOLUTE_TESTS,

178 )

179

180 @ignore_numpy_errors

181 def test_nan_log_decoding_Protune(self) -> None:

182 """

183 Test :func:`colour.models.rgb.transfer_functions.gopro.\

184 log_decoding_Protune` definition nan support.

185 """

186

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