Coverage for difference/tests/test_cam02_ucs.py: 100%

1"""Define the unit tests for the :mod:`colour.difference.cam02_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.difference import delta_E_CAM02LCD, delta_E_CAM02SCD, delta_E_CAM02UCS

11 from colour.difference.cam02_ucs import delta_E_Luo2006

12 from colour.models.cam02_ucs import COEFFICIENTS_UCS_LUO2006

13 from colour.utilities import ignore_numpy_errors

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

24]

25

26

27 class TestDelta_E_Luo2006:

28 """

29 Define :func:`colour.difference.cam02_ucs.delta_E_Luo2006` definition unit

30 tests methods.

31 """

32

33 def test_delta_E_Luo2006(self) -> None:

34 """Test :func:`colour.difference.cam02_ucs.delta_E_Luo2006` definition."""

35

36 np.testing.assert_allclose(

37 delta_E_Luo2006(

38 np.array([54.90433134, -0.08450395, -0.06854831]),

39 np.array([54.80352754, -3.96940084, -13.57591013]),

40 COEFFICIENTS_UCS_LUO2006["CAM02-LCD"],

41 ),

42 14.055546437777583,

43 atol=TOLERANCE_ABSOLUTE_TESTS,

44 )

45

46 np.testing.assert_allclose(

47 delta_E_Luo2006(

48 np.array([54.90433134, -0.08450395, -0.06854831]),

49 np.array([54.80352754, -3.96940084, -13.57591013]),

50 COEFFICIENTS_UCS_LUO2006["CAM02-LCD"],

51 ),

52 delta_E_CAM02LCD(

53 np.array([54.90433134, -0.08450395, -0.06854831]),

54 np.array([54.80352754, -3.96940084, -13.57591013]),

55 ),

56 atol=TOLERANCE_ABSOLUTE_TESTS,

57 )

58

59 np.testing.assert_allclose(

60 delta_E_Luo2006(

61 np.array([54.90433134, -0.08450395, -0.06854831]),

62 np.array([54.80352754, -3.96940084, -13.57591013]),

63 COEFFICIENTS_UCS_LUO2006["CAM02-SCD"],

64 ),

65 delta_E_CAM02SCD(

66 np.array([54.90433134, -0.08450395, -0.06854831]),

67 np.array([54.80352754, -3.96940084, -13.57591013]),

68 ),

69 atol=TOLERANCE_ABSOLUTE_TESTS,

70 )

71

72 np.testing.assert_allclose(

73 delta_E_Luo2006(

74 np.array([54.90433134, -0.08450395, -0.06854831]),

75 np.array([54.80352754, -3.96940084, -13.57591013]),

76 COEFFICIENTS_UCS_LUO2006["CAM02-UCS"],

77 ),

78 delta_E_CAM02UCS(

79 np.array([54.90433134, -0.08450395, -0.06854831]),

80 np.array([54.80352754, -3.96940084, -13.57591013]),

81 ),

82 atol=TOLERANCE_ABSOLUTE_TESTS,

83 )

84

85 def test_n_dimensional_delta_E_Luo2006(self) -> None:

86 """

87 Test :func:`colour.difference.cam02_ucs.delta_E_Luo2006` definition

88 n-dimensional arrays support.

89 """

90

91 Jpapbp_1 = np.array([54.90433134, -0.08450395, -0.06854831])

92 Jpapbp_2 = np.array([54.80352754, -3.96940084, -13.57591013])

93 delta_E_p = delta_E_Luo2006(

94 Jpapbp_1, Jpapbp_2, COEFFICIENTS_UCS_LUO2006["CAM02-LCD"]

95 )

96

97 Jpapbp_1 = np.tile(Jpapbp_1, (6, 1))

98 Jpapbp_2 = np.tile(Jpapbp_2, (6, 1))

99 delta_E_p = np.tile(delta_E_p, 6)

100 np.testing.assert_allclose(

101 delta_E_Luo2006(Jpapbp_1, Jpapbp_2, COEFFICIENTS_UCS_LUO2006["CAM02-LCD"]),

102 delta_E_p,

103 atol=TOLERANCE_ABSOLUTE_TESTS,

104 )

105

106 Jpapbp_1 = np.reshape(Jpapbp_1, (2, 3, 3))

107 Jpapbp_2 = np.reshape(Jpapbp_2, (2, 3, 3))

108 delta_E_p = np.reshape(delta_E_p, (2, 3))

109 np.testing.assert_allclose(

110 delta_E_Luo2006(Jpapbp_1, Jpapbp_2, COEFFICIENTS_UCS_LUO2006["CAM02-LCD"]),

111 delta_E_p,

112 atol=TOLERANCE_ABSOLUTE_TESTS,

113 )

114

115 @ignore_numpy_errors

116 def test_nan_delta_E_Luo2006(self) -> None:

117 """

118 Test :func:`colour.difference.cam02_ucs.delta_E_Luo2006`

119 definition nan support.

120 """

121

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

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

124 delta_E_Luo2006(cases, cases, COEFFICIENTS_UCS_LUO2006["CAM02-LCD"])