Coverage for adaptation/tests/test_li2025.py: 100%

1"""Define the unit tests for the :mod:`colour.adaptation.li2025` module."""

2

3 from __future__ import annotations

4

5 from itertools import product

6

7 import numpy as np

8

9 from colour.adaptation import chromatic_adaptation_Li2025

10 from colour.constants import TOLERANCE_ABSOLUTE_TESTS

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

22]

23

24

25 class TestChromaticAdaptationLi2025:

26 """

27 Define :func:`colour.adaptation.li2025.chromatic_adaptation_Li2025`

28 definition unit tests methods.

29 """

30

31 def test_chromatic_adaptation_Li2025(self) -> None:

32 """

33 Test :func:`colour.adaptation.li2025.chromatic_adaptation_Li2025`

34 definition.

35 """

36

37 np.testing.assert_allclose(

38 chromatic_adaptation_Li2025(

39 XYZ_s=np.array([48.900, 43.620, 6.250]),

40 XYZ_ws=np.array([109.850, 100, 35.585]),

41 XYZ_wd=np.array([95.047, 100, 108.883]),

42 L_A=318.31,

43 F_surround=1.0,

44 ),

45 np.array([40.00725815, 43.70148954, 21.32902932]),

46 atol=TOLERANCE_ABSOLUTE_TESTS,

47 )

48

49 np.testing.assert_allclose(

50 chromatic_adaptation_Li2025(

51 XYZ_s=np.array([52.034, 58.824, 23.703]),

52 XYZ_ws=np.array([92.288, 100, 38.775]),

53 XYZ_wd=np.array([105.432, 100, 137.392]),

54 L_A=318.31,

55 F_surround=1.0,

56 ),

57 np.array([59.99869086, 58.81067197, 83.41018242]),

58 atol=TOLERANCE_ABSOLUTE_TESTS,

59 )

60

61 np.testing.assert_allclose(

62 chromatic_adaptation_Li2025(

63 XYZ_s=np.array([48.900, 43.620, 6.250]),

64 XYZ_ws=np.array([109.850, 100, 35.585]),

65 XYZ_wd=np.array([95.047, 100, 108.883]),

66 L_A=20.0,

67 F_surround=1.0,

68 ),

69 np.array([41.22388901, 43.69034082, 19.26604215]),

70 atol=TOLERANCE_ABSOLUTE_TESTS,

71 )

72

73 np.testing.assert_allclose(

74 chromatic_adaptation_Li2025(

75 XYZ_s=np.array([48.900, 43.620, 6.250]),

76 XYZ_ws=np.array([109.850, 100, 35.585]),

77 XYZ_wd=np.array([95.047, 100, 108.883]),

78 L_A=318.31,

79 F_surround=1.0,

80 discount_illuminant=True,

81 ),

82 np.array([39.95779686, 43.70194278, 21.41289865]),

83 atol=TOLERANCE_ABSOLUTE_TESTS,

84 )

85

86 def test_n_dimensional_chromatic_adaptation_Li2025(self) -> None:

87 """

88 Test :func:`colour.adaptation.li2025.chromatic_adaptation_Li2025`

89 definition n-dimensional arrays support.

90 """

91

92 XYZ_s = np.array([48.900, 43.620, 6.250])

93 XYZ_ws = np.array([109.850, 100, 35.585])

94 XYZ_wd = np.array([95.047, 100, 108.883])

95 L_A = 318.31

96 F_surround = 1.0

97 XYZ_d = chromatic_adaptation_Li2025(XYZ_s, XYZ_ws, XYZ_wd, L_A, F_surround)

98

99 XYZ_s = np.tile(XYZ_s, (6, 1))

100 XYZ_d = np.tile(XYZ_d, (6, 1))

101 np.testing.assert_allclose(

102 chromatic_adaptation_Li2025(XYZ_s, XYZ_ws, XYZ_wd, L_A, F_surround),

103 XYZ_d,

104 atol=TOLERANCE_ABSOLUTE_TESTS,

105 )

106

107 XYZ_ws = np.tile(XYZ_ws, (6, 1))

108 XYZ_wd = np.tile(XYZ_wd, (6, 1))

109 L_A = np.tile(L_A, 6)

110 F_surround = np.tile(F_surround, 6)

111 np.testing.assert_allclose(

112 chromatic_adaptation_Li2025(XYZ_s, XYZ_ws, XYZ_wd, L_A, F_surround),

113 XYZ_d,

114 atol=TOLERANCE_ABSOLUTE_TESTS,

115 )

116

117 XYZ_s = np.reshape(XYZ_s, (2, 3, 3))

118 XYZ_ws = np.reshape(XYZ_ws, (2, 3, 3))

119 XYZ_wd = np.reshape(XYZ_wd, (2, 3, 3))

120 L_A = np.reshape(L_A, (2, 3))

121 F_surround = np.reshape(F_surround, (2, 3))

122 XYZ_d = np.reshape(XYZ_d, (2, 3, 3))

123 np.testing.assert_allclose(

124 chromatic_adaptation_Li2025(XYZ_s, XYZ_ws, XYZ_wd, L_A, F_surround),

125 XYZ_d,

126 atol=TOLERANCE_ABSOLUTE_TESTS,

127 )

128

129 def test_domain_range_scale_chromatic_adaptation_Li2025(self) -> None:

130 """

131 Test :func:`colour.adaptation.li2025.chromatic_adaptation_Li2025`

132 definition domain and range scale support.

133 """

134

135 XYZ_s = np.array([48.900, 43.620, 6.250])

136 XYZ_ws = np.array([109.850, 100, 35.585])

137 XYZ_wd = np.array([95.047, 100, 108.883])

138 L_A = 318.31

139 F_surround = 1.0

140 XYZ_d = chromatic_adaptation_Li2025(XYZ_s, XYZ_ws, XYZ_wd, L_A, F_surround)

141

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

143 for scale, factor in d_r:

144 with domain_range_scale(scale):

145 np.testing.assert_allclose(

146 chromatic_adaptation_Li2025(

147 XYZ_s * factor,

148 XYZ_ws * factor,

149 XYZ_wd * factor,

150 L_A,

151 F_surround,

152 ),

153 XYZ_d * factor,

154 atol=TOLERANCE_ABSOLUTE_TESTS,

155 )

156

157 @ignore_numpy_errors

158 def test_nan_chromatic_adaptation_Li2025(self) -> None:

159 """

160 Test :func:`colour.adaptation.li2025.chromatic_adaptation_Li2025`

161 definition nan support.

162 """

163

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

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

166 chromatic_adaptation_Li2025(cases, cases, cases, cases[0, 0], cases[0, 0])