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

1"""Define the unit tests for the :mod:`colour.models.osa_ucs` 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 OSA_UCS_to_XYZ, XYZ_to_OSA_UCS

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

22 "TestOSA_UCS_to_XYZ",

23]

24

25

26 class TestXYZ_to_OSA_UCS:

27 """

28 Define :func:`colour.models.osa_ucs.XYZ_to_OSA_UCS` definition unit tests

29 methods.

30 """

31

32 def test_XYZ_to_OSA_UCS(self) -> None:

33 """Test :func:`colour.models.osa_ucs.XYZ_to_OSA_UCS` definition."""

34

35 np.testing.assert_allclose(

36 XYZ_to_OSA_UCS(np.array([0.20654008, 0.12197225, 0.05136952]) * 100),

37 np.array([-3.00499790, 2.99713697, -9.66784231]),

38 atol=TOLERANCE_ABSOLUTE_TESTS,

39 )

40

41 np.testing.assert_allclose(

42 XYZ_to_OSA_UCS(np.array([0.14222010, 0.23042768, 0.10495772]) * 100),

43 np.array([-1.64657491, 4.59201565, 5.31738757]),

44 atol=TOLERANCE_ABSOLUTE_TESTS,

45 )

46

47 np.testing.assert_allclose(

48 XYZ_to_OSA_UCS(np.array([0.07818780, 0.06157201, 0.28099326]) * 100),

49 np.array([-5.08589672, -7.91062749, 0.98107575]),

50 atol=TOLERANCE_ABSOLUTE_TESTS,

51 )

52

53 def test_n_dimensional_XYZ_to_OSA_UCS(self) -> None:

54 """

55 Test :func:`colour.models.osa_ucs.XYZ_to_OSA_UCS` definition

56 n-dimensional support.

57 """

58

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

60 Ljg = XYZ_to_OSA_UCS(XYZ)

61

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

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

64 np.testing.assert_allclose(

65 XYZ_to_OSA_UCS(XYZ), Ljg, atol=TOLERANCE_ABSOLUTE_TESTS

66 )

67

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

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

70 np.testing.assert_allclose(

71 XYZ_to_OSA_UCS(XYZ), Ljg, atol=TOLERANCE_ABSOLUTE_TESTS

72 )

73

74 def test_domain_range_scale_XYZ_to_OSA_UCS(self) -> None:

75 """

76 Test :func:`colour.models.osa_ucs.XYZ_to_OSA_UCS` definition domain

77 and range scale support.

78 """

79

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

81 Ljg = XYZ_to_OSA_UCS(XYZ)

82

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

84 for scale, factor in d_r:

85 with domain_range_scale(scale):

86 np.testing.assert_allclose(

87 XYZ_to_OSA_UCS(XYZ * factor),

88 Ljg * factor,

89 atol=TOLERANCE_ABSOLUTE_TESTS,

90 )

91

92 @ignore_numpy_errors

93 def test_nan_XYZ_to_OSA_UCS(self) -> None:

94 """

95 Test :func:`colour.models.osa_ucs.XYZ_to_OSA_UCS` 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_OSA_UCS(cases)

102

103

104 class TestOSA_UCS_to_XYZ:

105 """

106 Define :func:`colour.models.osa_ucs.OSA_UCS_to_XYZ` definition unit tests

107 methods.

108 """

109

110 def test_OSA_UCS_to_XYZ(self) -> None:

111 """Test :func:`colour.models.osa_ucs.OSA_UCS_to_XYZ` definition."""

112

113 np.testing.assert_allclose(

114 OSA_UCS_to_XYZ(

115 np.array([-3.00499790, 2.99713697, -9.66784231]),

116 {"disp": False},

117 ),

118 np.array([0.20654008, 0.12197225, 0.05136952]) * 100,

119 atol=5e-5,

120 )

121

122 np.testing.assert_allclose(

123 OSA_UCS_to_XYZ(

124 np.array([-1.64657491, 4.59201565, 5.31738757]),

125 {"disp": False},

126 ),

127 np.array([0.14222010, 0.23042768, 0.10495772]) * 100,

128 atol=5e-5,

129 )

130

131 np.testing.assert_allclose(

132 OSA_UCS_to_XYZ(

133 np.array([-5.08589672, -7.91062749, 0.98107575]),

134 {"disp": False},

135 ),

136 np.array([0.07818780, 0.06157201, 0.28099326]) * 100,

137 atol=5e-5,

138 )

139

140 def test_n_dimensional_OSA_UCS_to_XYZ(self) -> None:

141 """

142 Test :func:`colour.models.osa_ucs.OSA_UCS_to_XYZ` definition

143 n-dimensional support.

144 """

145

146 Ljg = np.array([-3.00499790, 2.99713697, -9.66784231])

147 XYZ = OSA_UCS_to_XYZ(Ljg)

148

149 Ljg = np.tile(Ljg, (6, 1))

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

151 np.testing.assert_allclose(

152 OSA_UCS_to_XYZ(Ljg), XYZ, atol=TOLERANCE_ABSOLUTE_TESTS

153 )

154

155 Ljg = np.reshape(Ljg, (2, 3, 3))

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

157 np.testing.assert_allclose(

158 OSA_UCS_to_XYZ(Ljg), XYZ, atol=TOLERANCE_ABSOLUTE_TESTS

159 )

160

161 def test_domain_range_scale_OSA_UCS_to_XYZ(self) -> None:

162 """

163 Test :func:`colour.models.osa_ucs.OSA_UCS_to_XYZ` definition domain

164 and range scale support.

165 """

166

167 Ljg = np.array([-3.00499790, 2.99713697, -9.66784231])

168 XYZ = OSA_UCS_to_XYZ(Ljg)

169

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

171 for scale, factor in d_r:

172 with domain_range_scale(scale):

173 np.testing.assert_allclose(

174 OSA_UCS_to_XYZ(Ljg * factor),

175 XYZ * factor,

176 atol=TOLERANCE_ABSOLUTE_TESTS,

177 )

178

179 @ignore_numpy_errors

180 def test_nan_OSA_UCS_to_XYZ(self) -> None:

181 """

182 Test :func:`colour.models.osa_ucs.OSA_UCS_to_XYZ` definition nan

183 support.

184 """

185

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

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

188 OSA_UCS_to_XYZ(cases)