Coverage for io/luts/tests/test_iridas_cube.py: 100%

56 statements  

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

1"""Define the unit tests for the :mod:`colour.io.luts.iridas_cube` module.""" 

2 

3from __future__ import annotations 

4 

5import os 

6import shutil 

7import tempfile 

8 

9import numpy as np 

10 

11from colour.constants import TOLERANCE_ABSOLUTE_TESTS 

12from colour.hints import cast 

13from colour.io import LUT1D, LUTSequence, read_LUT_IridasCube, write_LUT_IridasCube 

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

24 "TestReadLUTIridasCube", 

25 "TestWriteLUTIridasCube", 

26] 

27 

28ROOT_LUTS: str = os.path.join(os.path.dirname(__file__), "resources", "iridas_cube") 

29 

30 

31class TestReadLUTIridasCube: 

32 """ 

33 Define :func:`colour.io.luts.iridas_cube.read_LUT_IridasCube` definition 

34 unit tests methods. 

35 """ 

36 

37 def test_read_LUT_IridasCube(self) -> None: 

38 """ 

39 Test :func:`colour.io.luts.iridas_cube.read_LUT_IridasCube` 

40 definition. 

41 """ 

42 

43 LUT_1 = read_LUT_IridasCube( 

44 os.path.join(ROOT_LUTS, "ACES_Proxy_10_to_ACES.cube") 

45 ) 

46 

47 np.testing.assert_allclose( 

48 LUT_1.table, 

49 np.array( 

50 [ 

51 [4.88300000e-04, 4.88300000e-04, 4.88300000e-04], 

52 [7.71400000e-04, 7.71400000e-04, 7.71400000e-04], 

53 [1.21900000e-03, 1.21900000e-03, 1.21900000e-03], 

54 [1.92600000e-03, 1.92600000e-03, 1.92600000e-03], 

55 [3.04400000e-03, 3.04400000e-03, 3.04400000e-03], 

56 [4.80900000e-03, 4.80900000e-03, 4.80900000e-03], 

57 [7.59900000e-03, 7.59900000e-03, 7.59900000e-03], 

58 [1.20100000e-02, 1.20100000e-02, 1.20100000e-02], 

59 [1.89700000e-02, 1.89700000e-02, 1.89700000e-02], 

60 [2.99800000e-02, 2.99800000e-02, 2.99800000e-02], 

61 [4.73700000e-02, 4.73700000e-02, 4.73700000e-02], 

62 [7.48400000e-02, 7.48400000e-02, 7.48400000e-02], 

63 [1.18300000e-01, 1.18300000e-01, 1.18300000e-01], 

64 [1.86900000e-01, 1.86900000e-01, 1.86900000e-01], 

65 [2.95200000e-01, 2.95200000e-01, 2.95200000e-01], 

66 [4.66500000e-01, 4.66500000e-01, 4.66500000e-01], 

67 [7.37100000e-01, 7.37100000e-01, 7.37100000e-01], 

68 [1.16500000e00, 1.16500000e00, 1.16500000e00], 

69 [1.84000000e00, 1.84000000e00, 1.84000000e00], 

70 [2.90800000e00, 2.90800000e00, 2.90800000e00], 

71 [4.59500000e00, 4.59500000e00, 4.59500000e00], 

72 [7.26000000e00, 7.26000000e00, 7.26000000e00], 

73 [1.14700000e01, 1.14700000e01, 1.14700000e01], 

74 [1.81300000e01, 1.81300000e01, 1.81300000e01], 

75 [2.86400000e01, 2.86400000e01, 2.86400000e01], 

76 [4.52500000e01, 4.52500000e01, 4.52500000e01], 

77 [7.15100000e01, 7.15100000e01, 7.15100000e01], 

78 [1.13000000e02, 1.13000000e02, 1.13000000e02], 

79 [1.78500000e02, 1.78500000e02, 1.78500000e02], 

80 [2.82100000e02, 2.82100000e02, 2.82100000e02], 

81 [4.45700000e02, 4.45700000e02, 4.45700000e02], 

82 [7.04300000e02, 7.04300000e02, 7.04300000e02], 

83 ] 

84 ), 

85 atol=TOLERANCE_ABSOLUTE_TESTS, 

86 ) 

87 assert LUT_1.name == "ACES Proxy 10 to ACES" 

88 assert LUT_1.dimensions == 2 

89 np.testing.assert_array_equal(LUT_1.domain, np.array([[0, 0, 0], [1, 1, 1]])) 

90 assert LUT_1.size == 32 

91 assert LUT_1.comments == [] 

92 

93 LUT_2 = read_LUT_IridasCube(os.path.join(ROOT_LUTS, "Demo.cube")) 

94 assert LUT_2.comments == ["Comments can go anywhere"] 

95 np.testing.assert_array_equal(LUT_2.domain, np.array([[0, 0, 0], [1, 2, 3]])) 

96 

97 LUT_3 = read_LUT_IridasCube( 

98 os.path.join(ROOT_LUTS, "Three_Dimensional_Table.cube") 

99 ) 

100 assert LUT_3.dimensions == 3 

101 assert LUT_3.size == 2 

102 

103 

104class TestWriteLUTIridasCube: 

105 """ 

106 Define :func:`colour.io.luts.iridas_cube.write_LUT_IridasCube` definition 

107 unit tests methods. 

108 """ 

109 

110 def setup_method(self) -> None: 

111 """Initialise the common tests attributes.""" 

112 

113 self._temporary_directory = tempfile.mkdtemp() 

114 

115 def teardown_method(self) -> None: 

116 """After tests actions.""" 

117 

118 shutil.rmtree(self._temporary_directory) 

119 

120 def test_write_LUT_IridasCube(self) -> None: 

121 """ 

122 Test :func:`colour.io.luts.iridas_cube.write_LUT_IridasCube` 

123 definition. 

124 """ 

125 

126 LUT_1_r = read_LUT_IridasCube( 

127 os.path.join(ROOT_LUTS, "ACES_Proxy_10_to_ACES.cube") 

128 ) 

129 write_LUT_IridasCube( 

130 LUT_1_r, 

131 os.path.join(self._temporary_directory, "ACES_Proxy_10_to_ACES.cube"), 

132 ) 

133 LUT_1_t = read_LUT_IridasCube( 

134 os.path.join(self._temporary_directory, "ACES_Proxy_10_to_ACES.cube") 

135 ) 

136 assert LUT_1_r == LUT_1_t 

137 

138 write_LUT_IridasCube( 

139 LUTSequence(LUT_1_r), 

140 os.path.join(self._temporary_directory, "ACES_Proxy_10_to_ACES.cube"), 

141 ) 

142 assert LUT_1_r == LUT_1_t 

143 

144 LUT_2_r = read_LUT_IridasCube(os.path.join(ROOT_LUTS, "Demo.cube")) 

145 write_LUT_IridasCube( 

146 LUT_2_r, os.path.join(self._temporary_directory, "Demo.cube") 

147 ) 

148 LUT_2_t = read_LUT_IridasCube( 

149 os.path.join(self._temporary_directory, "Demo.cube") 

150 ) 

151 assert LUT_2_r == LUT_2_t 

152 assert LUT_2_r.comments == LUT_2_t.comments 

153 

154 LUT_3_r = read_LUT_IridasCube( 

155 os.path.join(ROOT_LUTS, "Three_Dimensional_Table.cube") 

156 ) 

157 write_LUT_IridasCube( 

158 LUT_3_r, 

159 os.path.join(self._temporary_directory, "Three_Dimensional_Table.cube"), 

160 ) 

161 LUT_3_t = read_LUT_IridasCube( 

162 os.path.join(self._temporary_directory, "Three_Dimensional_Table.cube") 

163 ) 

164 assert LUT_3_r == LUT_3_t 

165 

166 LUT_4_r = read_LUT_IridasCube( 

167 os.path.join(ROOT_LUTS, "ACES_Proxy_10_to_ACES.cube") 

168 ) 

169 write_LUT_IridasCube( 

170 cast("LUT1D", LUT_4_r.convert(LUT1D, force_conversion=True)), 

171 os.path.join(self._temporary_directory, "ACES_Proxy_10_to_ACES.cube"), 

172 ) 

173 LUT_4_t = read_LUT_IridasCube( 

174 os.path.join(self._temporary_directory, "ACES_Proxy_10_to_ACES.cube") 

175 ) 

176 assert LUT_4_r == LUT_4_t