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

119 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.arri` module. 

4""" 

5 

6import numpy as np 

7 

8from colour.constants import TOLERANCE_ABSOLUTE_TESTS 

9from colour.models.rgb.transfer_functions import ( 

10 log_decoding_ARRILogC3, 

11 log_decoding_ARRILogC4, 

12 log_encoding_ARRILogC3, 

13 log_encoding_ARRILogC4, 

14) 

15from colour.utilities import domain_range_scale, ignore_numpy_errors 

16 

17__author__ = "Colour Developers" 

18__copyright__ = "Copyright 2013 Colour Developers" 

19__license__ = "BSD-3-Clause - https://opensource.org/licenses/BSD-3-Clause" 

20__maintainer__ = "Colour Developers" 

21__email__ = "colour-developers@colour-science.org" 

22__status__ = "Production" 

23 

24__all__ = [ 

25 "TestLogEncoding_ARRILogC3", 

26 "TestLogDecoding_ARRILogC3", 

27 "TestLogEncoding_ARRILogC4", 

28 "TestLogDecoding_ARRILogC4", 

29] 

30 

31 

32class TestLogEncoding_ARRILogC3: 

33 """ 

34 Define :func:`colour.models.rgb.transfer_functions.arri.\ 

35log_encoding_ARRILogC3` definition unit tests methods. 

36 """ 

37 

38 def test_log_encoding_ARRILogC3(self) -> None: 

39 """ 

40 Test :func:`colour.models.rgb.transfer_functions.arri.\ 

41log_encoding_ARRILogC3` definition. 

42 """ 

43 

44 np.testing.assert_allclose( 

45 log_encoding_ARRILogC3(0.0), 

46 0.092809000000000, 

47 atol=TOLERANCE_ABSOLUTE_TESTS, 

48 ) 

49 

50 np.testing.assert_allclose( 

51 log_encoding_ARRILogC3(0.18), 

52 0.391006832034084, 

53 atol=TOLERANCE_ABSOLUTE_TESTS, 

54 ) 

55 

56 np.testing.assert_allclose( 

57 log_encoding_ARRILogC3(1.0), 

58 0.570631558120417, 

59 atol=TOLERANCE_ABSOLUTE_TESTS, 

60 ) 

61 

62 def test_n_dimensional_log_encoding_ARRILogC3(self) -> None: 

63 """ 

64 Test :func:`colour.models.rgb.transfer_functions.arri.\ 

65log_encoding_ARRILogC3` definition n-dimensional arrays support. 

66 """ 

67 

68 x = 0.18 

69 t = log_encoding_ARRILogC3(x) 

70 

71 x = np.tile(x, 6) 

72 t = np.tile(t, 6) 

73 np.testing.assert_allclose( 

74 log_encoding_ARRILogC3(x), t, atol=TOLERANCE_ABSOLUTE_TESTS 

75 ) 

76 

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

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

79 np.testing.assert_allclose( 

80 log_encoding_ARRILogC3(x), t, atol=TOLERANCE_ABSOLUTE_TESTS 

81 ) 

82 

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

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

85 np.testing.assert_allclose( 

86 log_encoding_ARRILogC3(x), t, atol=TOLERANCE_ABSOLUTE_TESTS 

87 ) 

88 

89 def test_domain_range_scale_log_encoding_ARRILogC3(self) -> None: 

90 """ 

91 Test :func:`colour.models.rgb.transfer_functions.arri.\ 

92log_encoding_ARRILogC3` definition domain and range scale support. 

93 """ 

94 

95 x = 0.18 

96 t = log_encoding_ARRILogC3(x) 

97 

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

99 for scale, factor in d_r: 

100 with domain_range_scale(scale): 

101 np.testing.assert_allclose( 

102 log_encoding_ARRILogC3(x * factor), 

103 t * factor, 

104 atol=TOLERANCE_ABSOLUTE_TESTS, 

105 ) 

106 

107 @ignore_numpy_errors 

108 def test_nan_log_encoding_ARRILogC3(self) -> None: 

109 """ 

110 Test :func:`colour.models.rgb.transfer_functions.arri.\ 

111log_encoding_ARRILogC3` definition nan support. 

112 """ 

113 

114 log_encoding_ARRILogC3(np.array([-1.0, 0.0, 1.0, -np.inf, np.inf, np.nan])) 

115 

116 

117class TestLogDecoding_ARRILogC3: 

118 """ 

119 Define :func:`colour.models.rgb.transfer_functions.arri.\ 

120log_decoding_ARRILogC3` definition unit tests methods. 

121 """ 

122 

123 def test_log_decoding_ARRILogC3(self) -> None: 

124 """ 

125 Test :func:`colour.models.rgb.transfer_functions.arri.\ 

126log_decoding_ARRILogC3` definition. 

127 """ 

128 

129 np.testing.assert_allclose( 

130 log_decoding_ARRILogC3(0.092809), 

131 0.0, 

132 atol=TOLERANCE_ABSOLUTE_TESTS, 

133 ) 

134 

135 np.testing.assert_allclose( 

136 log_decoding_ARRILogC3(0.391006832034084), 

137 0.18, 

138 atol=TOLERANCE_ABSOLUTE_TESTS, 

139 ) 

140 

141 np.testing.assert_allclose( 

142 log_decoding_ARRILogC3(0.570631558120417), 

143 1.0, 

144 atol=TOLERANCE_ABSOLUTE_TESTS, 

145 ) 

146 

147 def test_n_dimensional_log_decoding_ARRILogC3(self) -> None: 

148 """ 

149 Test :func:`colour.models.rgb.transfer_functions.arri.\ 

150log_decoding_ARRILogC3` definition n-dimensional arrays support. 

151 """ 

152 

153 t = 0.391006832034084 

154 x = log_decoding_ARRILogC3(t) 

155 

156 t = np.tile(t, 6) 

157 x = np.tile(x, 6) 

158 np.testing.assert_allclose( 

159 log_decoding_ARRILogC3(t), x, atol=TOLERANCE_ABSOLUTE_TESTS 

160 ) 

161 

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

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

164 np.testing.assert_allclose( 

165 log_decoding_ARRILogC3(t), x, atol=TOLERANCE_ABSOLUTE_TESTS 

166 ) 

167 

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

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

170 np.testing.assert_allclose( 

171 log_decoding_ARRILogC3(t), x, atol=TOLERANCE_ABSOLUTE_TESTS 

172 ) 

173 

174 def test_domain_range_scale_log_decoding_ARRILogC3(self) -> None: 

175 """ 

176 Test :func:`colour.models.rgb.transfer_functions.arri.\ 

177log_decoding_ARRILogC3` definition domain and range scale support. 

178 """ 

179 

180 t = 0.391006832034084 

181 x = log_decoding_ARRILogC3(t) 

182 

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

184 for scale, factor in d_r: 

185 with domain_range_scale(scale): 

186 np.testing.assert_allclose( 

187 log_decoding_ARRILogC3(t * factor), 

188 x * factor, 

189 atol=TOLERANCE_ABSOLUTE_TESTS, 

190 ) 

191 

192 @ignore_numpy_errors 

193 def test_nan_log_decoding_ARRILogC3(self) -> None: 

194 """ 

195 Test :func:`colour.models.rgb.transfer_functions.arri.\ 

196log_decoding_ARRILogC3` definition nan support. 

197 """ 

198 

199 log_decoding_ARRILogC3(np.array([-1.0, 0.0, 1.0, -np.inf, np.inf, np.nan])) 

200 

201 

202class TestLogEncoding_ARRILogC4: 

203 """ 

204 Define :func:`colour.models.rgb.transfer_functions.arri.\ 

205log_encoding_ARRILogC4` definition unit tests methods. 

206 """ 

207 

208 def test_log_encoding_ARRILogC4(self) -> None: 

209 """ 

210 Test :func:`colour.models.rgb.transfer_functions.arri.\ 

211log_encoding_ARRILogC4` definition. 

212 """ 

213 

214 np.testing.assert_allclose( 

215 log_encoding_ARRILogC4(0.0), 

216 0.092864125122190, 

217 atol=TOLERANCE_ABSOLUTE_TESTS, 

218 ) 

219 

220 np.testing.assert_allclose( 

221 log_encoding_ARRILogC4(0.18), 

222 0.278395836548265, 

223 atol=TOLERANCE_ABSOLUTE_TESTS, 

224 ) 

225 

226 np.testing.assert_allclose( 

227 log_encoding_ARRILogC4(1.0), 

228 0.427519364835306, 

229 atol=TOLERANCE_ABSOLUTE_TESTS, 

230 ) 

231 

232 def test_n_dimensional_log_encoding_ARRILogC4(self) -> None: 

233 """ 

234 Test :func:`colour.models.rgb.transfer_functions.arri.\ 

235log_encoding_ARRILogC4` definition n-dimensional arrays support. 

236 """ 

237 

238 x = 0.18 

239 t = log_encoding_ARRILogC4(x) 

240 

241 x = np.tile(x, 6) 

242 t = np.tile(t, 6) 

243 np.testing.assert_allclose( 

244 log_encoding_ARRILogC4(x), t, atol=TOLERANCE_ABSOLUTE_TESTS 

245 ) 

246 

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

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

249 np.testing.assert_allclose( 

250 log_encoding_ARRILogC4(x), t, atol=TOLERANCE_ABSOLUTE_TESTS 

251 ) 

252 

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

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

255 np.testing.assert_allclose( 

256 log_encoding_ARRILogC4(x), t, atol=TOLERANCE_ABSOLUTE_TESTS 

257 ) 

258 

259 def test_domain_range_scale_log_encoding_ARRILogC4(self) -> None: 

260 """ 

261 Test :func:`colour.models.rgb.transfer_functions.arri.\ 

262log_encoding_ARRILogC4` definition domain and range scale support. 

263 """ 

264 

265 x = 0.18 

266 t = log_encoding_ARRILogC4(x) 

267 

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

269 for scale, factor in d_r: 

270 with domain_range_scale(scale): 

271 np.testing.assert_allclose( 

272 log_encoding_ARRILogC4(x * factor), 

273 t * factor, 

274 atol=TOLERANCE_ABSOLUTE_TESTS, 

275 ) 

276 

277 @ignore_numpy_errors 

278 def test_nan_log_encoding_ARRILogC4(self) -> None: 

279 """ 

280 Test :func:`colour.models.rgb.transfer_functions.arri.\ 

281log_encoding_ARRILogC4` definition nan support. 

282 """ 

283 

284 log_encoding_ARRILogC4(np.array([-1.0, 0.0, 1.0, -np.inf, np.inf, np.nan])) 

285 

286 

287class TestLogDecoding_ARRILogC4: 

288 """ 

289 Define :func:`colour.models.rgb.transfer_functions.arri.\ 

290log_decoding_ARRILogC4` definition unit tests methods. 

291 """ 

292 

293 def test_log_decoding_ARRILogC4(self) -> None: 

294 """ 

295 Test :func:`colour.models.rgb.transfer_functions.arri.\ 

296log_decoding_ARRILogC4` definition. 

297 """ 

298 

299 np.testing.assert_allclose( 

300 log_decoding_ARRILogC4(0.092864125122190), 

301 0.0, 

302 atol=TOLERANCE_ABSOLUTE_TESTS, 

303 ) 

304 

305 np.testing.assert_allclose( 

306 log_decoding_ARRILogC4(0.278395836548265), 

307 0.18, 

308 atol=TOLERANCE_ABSOLUTE_TESTS, 

309 ) 

310 

311 np.testing.assert_allclose( 

312 log_decoding_ARRILogC4(0.427519364835306), 

313 1.0, 

314 atol=TOLERANCE_ABSOLUTE_TESTS, 

315 ) 

316 

317 def test_n_dimensional_log_decoding_ARRILogC4(self) -> None: 

318 """ 

319 Test :func:`colour.models.rgb.transfer_functions.arri.\ 

320log_decoding_ARRILogC4` definition n-dimensional arrays support. 

321 """ 

322 

323 t = 0.278395836548265 

324 x = log_decoding_ARRILogC4(t) 

325 

326 t = np.tile(t, 6) 

327 x = np.tile(x, 6) 

328 np.testing.assert_allclose( 

329 log_decoding_ARRILogC4(t), x, atol=TOLERANCE_ABSOLUTE_TESTS 

330 ) 

331 

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

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

334 np.testing.assert_allclose( 

335 log_decoding_ARRILogC4(t), x, atol=TOLERANCE_ABSOLUTE_TESTS 

336 ) 

337 

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

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

340 np.testing.assert_allclose( 

341 log_decoding_ARRILogC4(t), x, atol=TOLERANCE_ABSOLUTE_TESTS 

342 ) 

343 

344 def test_domain_range_scale_log_decoding_ARRILogC4(self) -> None: 

345 """ 

346 Test :func:`colour.models.rgb.transfer_functions.arri.\ 

347log_decoding_ARRILogC4` definition domain and range scale support. 

348 """ 

349 

350 t = 0.278395836548265 

351 x = log_decoding_ARRILogC4(t) 

352 

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

354 for scale, factor in d_r: 

355 with domain_range_scale(scale): 

356 np.testing.assert_allclose( 

357 log_decoding_ARRILogC4(t * factor), 

358 x * factor, 

359 atol=TOLERANCE_ABSOLUTE_TESTS, 

360 ) 

361 

362 @ignore_numpy_errors 

363 def test_nan_log_decoding_ARRILogC4(self) -> None: 

364 """ 

365 Test :func:`colour.models.rgb.transfer_functions.arri.\ 

366log_decoding_ARRILogC4` definition nan support. 

367 """ 

368 

369 log_decoding_ARRILogC4(np.array([-1.0, 0.0, 1.0, -np.inf, np.inf, np.nan]))