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

67 statements  

« prev     ^ index     » next       coverage.py v7.11.0, created at 2025-11-16 22:49 +1300

1""" 

2Define the unit tests for the 

3:mod:`colour.models.rgb.transfer_functions.st_2084` module. 

4""" 

5 

6import numpy as np 

7 

8from colour.constants import TOLERANCE_ABSOLUTE_TESTS 

9from colour.models.rgb.transfer_functions import eotf_inverse_ST2084, eotf_ST2084 

10from 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 "TestEotf_inverse_ST2084", 

21 "TestEotf_ST2084", 

22] 

23 

24 

25class TestEotf_inverse_ST2084: 

26 """ 

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

28eotf_inverse_ST2084` definition unit tests methods. 

29 """ 

30 

31 def test_eotf_inverse_ST2084(self) -> None: 

32 """ 

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

34eotf_inverse_ST2084` definition. 

35 """ 

36 

37 np.testing.assert_allclose( 

38 eotf_inverse_ST2084(0.0), 

39 0.000000730955903, 

40 atol=TOLERANCE_ABSOLUTE_TESTS, 

41 ) 

42 

43 np.testing.assert_allclose( 

44 eotf_inverse_ST2084(100), 

45 0.508078421517399, 

46 atol=TOLERANCE_ABSOLUTE_TESTS, 

47 ) 

48 

49 np.testing.assert_allclose( 

50 eotf_inverse_ST2084(400), 

51 0.652578597563067, 

52 atol=TOLERANCE_ABSOLUTE_TESTS, 

53 ) 

54 

55 np.testing.assert_allclose( 

56 eotf_inverse_ST2084(5000, 5000), 1.0, atol=TOLERANCE_ABSOLUTE_TESTS 

57 ) 

58 

59 def test_n_dimensional_eotf_inverse_ST2084(self) -> None: 

60 """ 

61 Test :func:`colour.models.rgb.transfer_functions.st_2084.\ 

62eotf_inverse_ST2084` definition n-dimensional arrays support. 

63 """ 

64 

65 C = 100 

66 N = eotf_inverse_ST2084(C) 

67 

68 C = np.tile(C, 6) 

69 N = np.tile(N, 6) 

70 np.testing.assert_allclose( 

71 eotf_inverse_ST2084(C), N, atol=TOLERANCE_ABSOLUTE_TESTS 

72 ) 

73 

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

75 N = np.reshape(N, (2, 3)) 

76 np.testing.assert_allclose( 

77 eotf_inverse_ST2084(C), N, atol=TOLERANCE_ABSOLUTE_TESTS 

78 ) 

79 

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

81 N = np.reshape(N, (2, 3, 1)) 

82 np.testing.assert_allclose( 

83 eotf_inverse_ST2084(C), N, atol=TOLERANCE_ABSOLUTE_TESTS 

84 ) 

85 

86 def test_domain_range_scale_eotf_inverse_ST2084(self) -> None: 

87 """ 

88 Test :func:`colour.models.rgb.transfer_functions.st_2084.\ 

89eotf_inverse_ST2084` definition domain and range scale support. 

90 """ 

91 

92 C = 100 

93 N = eotf_inverse_ST2084(C) 

94 

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

96 for scale, factor in d_r: 

97 with domain_range_scale(scale): 

98 np.testing.assert_allclose( 

99 eotf_inverse_ST2084(C * factor), 

100 N * factor, 

101 atol=TOLERANCE_ABSOLUTE_TESTS, 

102 ) 

103 

104 @ignore_numpy_errors 

105 def test_nan_eotf_inverse_ST2084(self) -> None: 

106 """ 

107 Test :func:`colour.models.rgb.transfer_functions.st_2084.\ 

108eotf_inverse_ST2084` definition nan support. 

109 """ 

110 

111 eotf_inverse_ST2084(np.array([-1.0, 0.0, 1.0, -np.inf, np.inf, np.nan])) 

112 

113 

114class TestEotf_ST2084: 

115 """ 

116 Define :func:`colour.models.rgb.transfer_functions.st_2084.eotf_ST2084` 

117 definition unit tests methods. 

118 """ 

119 

120 def test_eotf_ST2084(self) -> None: 

121 """ 

122 Test :func:`colour.models.rgb.transfer_functions.st_2084.\ 

123eotf_ST2084` definition. 

124 """ 

125 

126 np.testing.assert_allclose(eotf_ST2084(0.0), 0.0, atol=TOLERANCE_ABSOLUTE_TESTS) 

127 

128 np.testing.assert_allclose( 

129 eotf_ST2084(0.508078421517399), 100, atol=TOLERANCE_ABSOLUTE_TESTS 

130 ) 

131 

132 np.testing.assert_allclose( 

133 eotf_ST2084(0.652578597563067), 400, atol=TOLERANCE_ABSOLUTE_TESTS 

134 ) 

135 

136 np.testing.assert_allclose( 

137 eotf_ST2084(1.0, 5000), 5000.0, atol=TOLERANCE_ABSOLUTE_TESTS 

138 ) 

139 

140 def test_n_dimensional_eotf_ST2084(self) -> None: 

141 """ 

142 Test :func:`colour.models.rgb.transfer_functions.st_2084.\ 

143eotf_ST2084` definition n-dimensional arrays support. 

144 """ 

145 

146 N = 0.508078421517399 

147 C = eotf_ST2084(N) 

148 

149 N = np.tile(N, 6) 

150 C = np.tile(C, 6) 

151 np.testing.assert_allclose(eotf_ST2084(N), C, atol=TOLERANCE_ABSOLUTE_TESTS) 

152 

153 N = np.reshape(N, (2, 3)) 

154 C = np.reshape(C, (2, 3)) 

155 np.testing.assert_allclose(eotf_ST2084(N), C, atol=TOLERANCE_ABSOLUTE_TESTS) 

156 

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

158 C = np.reshape(C, (2, 3, 1)) 

159 np.testing.assert_allclose(eotf_ST2084(N), C, atol=TOLERANCE_ABSOLUTE_TESTS) 

160 

161 def test_domain_range_scale_eotf_ST2084(self) -> None: 

162 """ 

163 Test :func:`colour.models.rgb.transfer_functions.st_2084.\ 

164eotf_ST2084` definition domain and range scale support. 

165 """ 

166 

167 N = 0.508078421517399 

168 C = eotf_ST2084(N) 

169 

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

171 for scale, factor in d_r: 

172 with domain_range_scale(scale): 

173 np.testing.assert_allclose( 

174 eotf_ST2084(N * factor), 

175 C * factor, 

176 atol=TOLERANCE_ABSOLUTE_TESTS, 

177 ) 

178 

179 @ignore_numpy_errors 

180 def test_nan_eotf_ST2084(self) -> None: 

181 """ 

182 Test :func:`colour.models.rgb.transfer_functions.st_2084.\ 

183eotf_ST2084` definition nan support. 

184 """ 

185 

186 eotf_ST2084(np.array([-1.0, 0.0, 1.0, -np.inf, np.inf, np.nan]))