Coverage for volume/tests/test_rgb.py: 100%

1"""

2 Define the unit tests for the :mod:`colour.volume.rgb` module.

3

4 Notes

5-----

6 The MonteCarlo sampling based unit tests are assuming that

7:func:`np.random.RandomState` definition will return the same sequence no

8 matter which *OS* or *Python* version is used. There is however no formal

9 promise about the *prng* sequence reproducibility of either *Python* or *Numpy*

10 implementations:

11

12 References

13----------

14- :cite:`Laurent2012a` : Laurent. (2012). Reproducibility of python

15 pseudo-random numbers across systems and versions? Retrieved January 20,

16 2015, from

17 http://stackoverflow.com/questions/8786084/\

18 reproducibility-of-python-pseudo-random-numbers-across-systems-and-versions

19"""

20

21 from __future__ import annotations

22

23 import numpy as np

24

25 from colour.constants import TOLERANCE_ABSOLUTE_TESTS

26 from colour.models import (

27 RGB_COLOURSPACE_ACES2065_1,

28 RGB_COLOURSPACE_BT709,

29 RGB_COLOURSPACE_BT2020,

30)

31 from colour.utilities import disable_multiprocessing, is_scipy_installed

32 from colour.volume import (

33 RGB_colourspace_limits,

34 RGB_colourspace_pointer_gamut_coverage_MonteCarlo,

35 RGB_colourspace_visible_spectrum_coverage_MonteCarlo,

36 RGB_colourspace_volume_coverage_MonteCarlo,

37 RGB_colourspace_volume_MonteCarlo,

38 is_within_pointer_gamut,

39)

40

41 __author__ = "Colour Developers"

42 __copyright__ = "Copyright 2013 Colour Developers"

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

44 __maintainer__ = "Colour Developers"

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

46 __status__ = "Production"

47

48 __all__ = [

49 "TestRGB_colourspaceLimits",

50 "TestRGB_colourspaceVolumeMonteCarlo",

51 "TestRGB_colourspace_volume_coverage_MonteCarlo",

52 "TestRGB_colourspacePointerGamutCoverageMonteCarlo",

53 "TestRGB_colourspaceVisibleSpectrumCoverageMonteCarlo",

54]

55

56

57 class TestRGB_colourspaceLimits:

58 """

59 Define :func:`colour.volume.rgb.RGB_colourspace_limits` definition unit

60 tests methods.

61 """

62

63 def test_RGB_colourspace_limits(self) -> None:

64 """Test :func:`colour.volume.rgb.RGB_colourspace_limits` definition."""

65

66 np.testing.assert_allclose(

67 RGB_colourspace_limits(RGB_COLOURSPACE_BT709),

68 np.array(

69 [

70 [0.00000000, 100.00000000],

71 [-86.18159689, 98.23744381],

72 [-107.85546554, 94.48384002],

73 ]

74 ),

75 atol=TOLERANCE_ABSOLUTE_TESTS,

76 )

77

78 np.testing.assert_allclose(

79 RGB_colourspace_limits(RGB_COLOURSPACE_BT2020),

80 np.array(

81 [

82 [0.00000000, 100.00000000],

83 [-172.32005590, 130.52657313],

84 [-120.27412558, 136.88564561],

85 ]

86 ),

87 atol=TOLERANCE_ABSOLUTE_TESTS,

88 )

89

90 np.testing.assert_allclose(

91 RGB_colourspace_limits(RGB_COLOURSPACE_ACES2065_1),

92 np.array(

93 [

94 [-65.15706201, 102.72462756],

95 [-380.86283223, 281.23227495],

96 [-284.75355519, 177.11142683],

97 ]

98 ),

99 atol=TOLERANCE_ABSOLUTE_TESTS,

100 )

101

102

103 class TestRGB_colourspaceVolumeMonteCarlo:

104 """

105 Define :func:`colour.volume.rgb.RGB_colourspace_volume_MonteCarlo`

106 definition unit tests methods.

107

108 References

109 ----------

110 :cite:`Laurent2012a`

111 """

112

113 @disable_multiprocessing()

114 def test_RGB_colourspace_volume_MonteCarlo(self) -> None:

115 """

116 Test :func:`colour.volume.rgb.RGB_colourspace_volume_MonteCarlo`

117 definition.

118 """

119

120 np.testing.assert_allclose(

121 RGB_colourspace_volume_MonteCarlo(

122 RGB_COLOURSPACE_BT709,

123 int(10e3),

124 random_state=np.random.RandomState(2),

125 )

126 * 1e-6,

127 821700.0 * 1e-6,

128 atol=1,

129 )

130

131

132 class TestRGB_colourspace_volume_coverage_MonteCarlo:

133 """

134 Define :func:`colour.volume.rgb.\

135 RGB_colourspace_volume_coverage_MonteCarlo` definition unit tests methods.

136

137 References

138 ----------

139 :cite:`Laurent2012a`

140 """

141

142 def test_RGB_colourspace_volume_coverage_MonteCarlo(self) -> None:

143 """

144 Test :func:`colour.volume.rgb.\

145 RGB_colourspace_volume_coverage_MonteCarlo` definition.

146 """

147

148 if not is_scipy_installed(): # pragma: no cover

149 return

150

151 np.testing.assert_allclose(

152 RGB_colourspace_volume_coverage_MonteCarlo(

153 RGB_COLOURSPACE_BT709,

154 is_within_pointer_gamut,

155 int(10e3),

156 random_state=np.random.RandomState(2),

157 ),

158 81.044349070100140,

159 atol=TOLERANCE_ABSOLUTE_TESTS,

160 )

161

162

163 class TestRGB_colourspacePointerGamutCoverageMonteCarlo:

164 """

165 Define :func:`colour.volume.rgb.\

166 RGB_colourspace_pointer_gamut_coverage_MonteCarlo` definition unit tests

167 methods.

168

169 References

170 ----------

171 :cite:`Laurent2012a`

172 """

173

174 def test_RGB_colourspace_pointer_gamut_coverage_MonteCarlo(self) -> None:

175 """

176 Test :func:`colour.volume.rgb.\

177 RGB_colourspace_pointer_gamut_coverage_MonteCarlo` definition.

178 """

179

180 if not is_scipy_installed(): # pragma: no cover

181 return

182

183 np.testing.assert_allclose(

184 RGB_colourspace_pointer_gamut_coverage_MonteCarlo(

185 RGB_COLOURSPACE_BT709,

186 int(10e3),

187 random_state=np.random.RandomState(2),

188 ),

189 81.044349070100140,

190 atol=TOLERANCE_ABSOLUTE_TESTS,

191 )

192

193

194 class TestRGB_colourspaceVisibleSpectrumCoverageMonteCarlo:

195 """

196 Define :func:`colour.volume.rgb.\

197 RGB_colourspace_visible_spectrum_coverage_MonteCarlo` definition unit tests

198 methods.

199

200 References

201 ----------

202 :cite:`Laurent2012a`

203 """

204

205 def test_RGB_colourspace_visible_spectrum_coverage_MonteCarlo(self) -> None:

206 """

207 Test :func:`colour.volume.rgb.\

208 RGB_colourspace_visible_spectrum_coverage_MonteCarlo` definition.

209 """

210

211 if not is_scipy_installed(): # pragma: no cover

212 return

213

214 np.testing.assert_allclose(

215 RGB_colourspace_visible_spectrum_coverage_MonteCarlo(

216 RGB_COLOURSPACE_BT709,

217 int(10e3),

218 random_state=np.random.RandomState(2),

219 ),

220 46.931407942238266,

221 atol=TOLERANCE_ABSOLUTE_TESTS,

222 )