Coverage for models/tests/test_igpgtg.py: 100%

1"""Define the unit tests for the :mod:`colour.models.igpgtg` module."""

2

3 from __future__ import annotations

4

5 from itertools import product

6

7 import numpy as np

8

9 from colour.constants import TOLERANCE_ABSOLUTE_TESTS

10 from colour.models import IgPgTg_to_XYZ, XYZ_to_IgPgTg

11 from colour.utilities import domain_range_scale, ignore_numpy_errors

12

13 __author__ = "Colour Developers"

14 __copyright__ = "Copyright 2013 Colour Developers"

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

16 __maintainer__ = "Colour Developers"

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

18 __status__ = "Production"

19

20 __all__ = [

21 "TestXYZ_to_IgPgTg",

22 "TestIgPgTg_to_XYZ",

23]

24

25

26 class TestXYZ_to_IgPgTg:

27 """

28 Define :func:`colour.models.igpgtg.XYZ_to_IgPgTg` definition unit tests

29 methods.

30 """

31

32 def test_XYZ_to_IgPgTg(self) -> None:

33 """Test :func:`colour.models.igpgtg.XYZ_to_IgPgTg` definition."""

34

35 np.testing.assert_allclose(

36 XYZ_to_IgPgTg(np.array([0.20654008, 0.12197225, 0.05136952])),

37 np.array([0.42421258, 0.18632491, 0.10689223]),

38 atol=TOLERANCE_ABSOLUTE_TESTS,

39 )

40

41 np.testing.assert_allclose(

42 XYZ_to_IgPgTg(np.array([0.14222010, 0.23042768, 0.10495772])),

43 np.array([0.50912820, -0.14804331, 0.11921472]),

44 atol=TOLERANCE_ABSOLUTE_TESTS,

45 )

46

47 np.testing.assert_allclose(

48 XYZ_to_IgPgTg(np.array([0.07818780, 0.06157201, 0.28099326])),

49 np.array([0.29095152, -0.04057508, -0.18220795]),

50 atol=TOLERANCE_ABSOLUTE_TESTS,

51 )

52

53 def test_n_dimensional_XYZ_to_IgPgTg(self) -> None:

54 """

55 Test :func:`colour.models.igpgtg.XYZ_to_IgPgTg` definition

56 n-dimensional support.

57 """

58

59 XYZ = np.array([0.20654008, 0.12197225, 0.05136952])

60 IgPgTg = XYZ_to_IgPgTg(XYZ)

61

62 XYZ = np.tile(XYZ, (6, 1))

63 IgPgTg = np.tile(IgPgTg, (6, 1))

64 np.testing.assert_allclose(

65 XYZ_to_IgPgTg(XYZ), IgPgTg, atol=TOLERANCE_ABSOLUTE_TESTS

66 )

67

68 XYZ = np.reshape(XYZ, (2, 3, 3))

69 IgPgTg = np.reshape(IgPgTg, (2, 3, 3))

70 np.testing.assert_allclose(

71 XYZ_to_IgPgTg(XYZ), IgPgTg, atol=TOLERANCE_ABSOLUTE_TESTS

72 )

73

74 def test_domain_range_scale_XYZ_to_IgPgTg(self) -> None:

75 """

76 Test :func:`colour.models.igpgtg.XYZ_to_IgPgTg` definition domain and

77 range scale support.

78 """

79

80 XYZ = np.array([0.20654008, 0.12197225, 0.05136952])

81 IgPgTg = XYZ_to_IgPgTg(XYZ)

82

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

84 for scale, factor in d_r:

85 with domain_range_scale(scale):

86 np.testing.assert_allclose(

87 XYZ_to_IgPgTg(XYZ * factor),

88 IgPgTg * factor,

89 atol=TOLERANCE_ABSOLUTE_TESTS,

90 )

91

92 @ignore_numpy_errors

93 def test_nan_XYZ_to_IgPgTg(self) -> None:

94 """

95 Test :func:`colour.models.igpgtg.XYZ_to_IgPgTg` definition nan

96 support.

97 """

98

99 cases = [-1.0, 0.0, 1.0, -np.inf, np.inf, np.nan]

100 cases = np.array(list(set(product(cases, repeat=3))))

101 XYZ_to_IgPgTg(cases)

102

103

104 class TestIgPgTg_to_XYZ:

105 """

106 Define :func:`colour.models.igpgtg.IgPgTg_to_XYZ` definition unit tests

107 methods.

108 """

109

110 def test_IgPgTg_to_XYZ(self) -> None:

111 """Test :func:`colour.models.igpgtg.IgPgTg_to_XYZ` definition."""

112

113 np.testing.assert_allclose(

114 IgPgTg_to_XYZ(np.array([0.42421258, 0.18632491, 0.10689223])),

115 np.array([0.20654008, 0.12197225, 0.05136952]),

116 atol=TOLERANCE_ABSOLUTE_TESTS,

117 )

118

119 np.testing.assert_allclose(

120 IgPgTg_to_XYZ(np.array([0.50912820, -0.14804331, 0.11921472])),

121 np.array([0.14222010, 0.23042768, 0.10495772]),

122 atol=TOLERANCE_ABSOLUTE_TESTS,

123 )

124

125 np.testing.assert_allclose(

126 IgPgTg_to_XYZ(np.array([0.29095152, -0.04057508, -0.18220795])),

127 np.array([0.07818780, 0.06157201, 0.28099326]),

128 atol=TOLERANCE_ABSOLUTE_TESTS,

129 )

130

131 def test_n_dimensional_IgPgTg_to_XYZ(self) -> None:

132 """

133 Test :func:`colour.models.igpgtg.IgPgTg_to_XYZ` definition

134 n-dimensional support.

135 """

136

137 IgPgTg = np.array([0.42421258, 0.18632491, 0.10689223])

138 XYZ = IgPgTg_to_XYZ(IgPgTg)

139

140 IgPgTg = np.tile(IgPgTg, (6, 1))

141 XYZ = np.tile(XYZ, (6, 1))

142 np.testing.assert_allclose(

143 IgPgTg_to_XYZ(IgPgTg), XYZ, atol=TOLERANCE_ABSOLUTE_TESTS

144 )

145

146 IgPgTg = np.reshape(IgPgTg, (2, 3, 3))

147 XYZ = np.reshape(XYZ, (2, 3, 3))

148 np.testing.assert_allclose(

149 IgPgTg_to_XYZ(IgPgTg), XYZ, atol=TOLERANCE_ABSOLUTE_TESTS

150 )

151

152 def test_domain_range_scale_IgPgTg_to_XYZ(self) -> None:

153 """

154 Test :func:`colour.models.igpgtg.IgPgTg_to_XYZ` definition domain and

155 range scale support.

156 """

157

158 IgPgTg = np.array([0.42421258, 0.18632491, 0.10689223])

159 XYZ = IgPgTg_to_XYZ(IgPgTg)

160

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

162 for scale, factor in d_r:

163 with domain_range_scale(scale):

164 np.testing.assert_allclose(

165 IgPgTg_to_XYZ(IgPgTg * factor),

166 XYZ * factor,

167 atol=TOLERANCE_ABSOLUTE_TESTS,

168 )

169

170 @ignore_numpy_errors

171 def test_nan_IgPgTg_to_XYZ(self) -> None:

172 """

173 Test :func:`colour.models.igpgtg.IgPgTg_to_XYZ` definition nan

174 support.

175 """

176

177 cases = [-1.0, 0.0, 1.0, -np.inf, np.inf, np.nan]

178 cases = np.array(list(set(product(cases, repeat=3))))

179 IgPgTg_to_XYZ(cases)