Coverage for models/rgb/transfer_functions/tests/test_dcdm.py: 100%

1"""

2 Define the unit tests for the :mod:`colour.models.rgb.transfer_functions.dcdm`

3 module.

4"""

5

6 import numpy as np

7

8 from colour.constants import TOLERANCE_ABSOLUTE_TESTS

9 from colour.models.rgb.transfer_functions import eotf_DCDM, eotf_inverse_DCDM

10 from colour.utilities import domain_range_scale, ignore_numpy_errors

11

12 __author__ = "Colour Developers"

13 __copyright__ = "Copyright 2013 Colour Developers"

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

15 __maintainer__ = "Colour Developers"

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

17 __status__ = "Production"

18

19 __all__ = [

20 "TestEotf_inverse_DCDM",

21 "TestEotf_DCDM",

22]

23

24

25 class TestEotf_inverse_DCDM:

26 """

27 Define :func:`colour.models.rgb.transfer_functions.dcdm.eotf_inverse_DCDM`

28 definition unit tests methods.

29 """

30

31 def test_eotf_inverse_DCDM(self) -> None:

32 """

33 Test :func:`colour.models.rgb.transfer_functions.\

34 dcdm.eotf_inverse_DCDM` definition.

35 """

36

37 np.testing.assert_allclose(

38 eotf_inverse_DCDM(0.0), 0.0, atol=TOLERANCE_ABSOLUTE_TESTS

39 )

40

41 np.testing.assert_allclose(

42 eotf_inverse_DCDM(0.18), 0.11281861, atol=TOLERANCE_ABSOLUTE_TESTS

43 )

44

45 np.testing.assert_allclose(

46 eotf_inverse_DCDM(1.0), 0.21817973, atol=TOLERANCE_ABSOLUTE_TESTS

47 )

48

49 assert eotf_inverse_DCDM(0.18, out_int=True) == 462

50

51 def test_n_dimensional_eotf_inverse_DCDM(self) -> None:

52 """

53 Test :func:`colour.models.rgb.transfer_functions.dcdm.\

54 eotf_inverse_DCDM` definition n-dimensional arrays support.

55 """

56

57 XYZ = 0.18

58 XYZ_p = eotf_inverse_DCDM(XYZ)

59

60 XYZ = np.tile(XYZ, 6)

61 XYZ_p = np.tile(XYZ_p, 6)

62 np.testing.assert_allclose(

63 eotf_inverse_DCDM(XYZ), XYZ_p, atol=TOLERANCE_ABSOLUTE_TESTS

64 )

65

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

67 XYZ_p = np.reshape(XYZ_p, (2, 3))

68 np.testing.assert_allclose(

69 eotf_inverse_DCDM(XYZ), XYZ_p, atol=TOLERANCE_ABSOLUTE_TESTS

70 )

71

72 XYZ = np.reshape(XYZ, (2, 3, 1))

73 XYZ_p = np.reshape(XYZ_p, (2, 3, 1))

74 np.testing.assert_allclose(

75 eotf_inverse_DCDM(XYZ), XYZ_p, atol=TOLERANCE_ABSOLUTE_TESTS

76 )

77

78 def test_domain_range_scale_eotf_inverse_DCDM(self) -> None:

79 """

80 Test :func:`colour.models.rgb.transfer_functions.\

81 dcdm.eotf_inverse_DCDM` definition domain and range scale support.

82 """

83

84 XYZ = 0.18

85 XYZ_p = eotf_inverse_DCDM(XYZ)

86

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

88 for scale, factor in d_r:

89 with domain_range_scale(scale):

90 np.testing.assert_allclose(

91 eotf_inverse_DCDM(XYZ * factor),

92 XYZ_p * factor,

93 atol=TOLERANCE_ABSOLUTE_TESTS,

94 )

95

96 @ignore_numpy_errors

97 def test_nan_eotf_inverse_DCDM(self) -> None:

98 """

99 Test :func:`colour.models.rgb.transfer_functions.dcdm.\

100 eotf_inverse_DCDM` definition nan support.

101 """

102

103 eotf_inverse_DCDM(np.array([-1.0, 0.0, 1.0, -np.inf, np.inf, np.nan]))

104

105

106 class TestEotf_DCDM:

107 """

108 Define :func:`colour.models.rgb.transfer_functions.dcdm.eotf_DCDM`

109 definition unit tests methods.

110 """

111

112 def test_eotf_DCDM(self) -> None:

113 """

114 Test :func:`colour.models.rgb.transfer_functions.dcdm.eotf_DCDM`

115 definition.

116 """

117

118 np.testing.assert_allclose(eotf_DCDM(0.0), 0.0, atol=TOLERANCE_ABSOLUTE_TESTS)

119

120 np.testing.assert_allclose(

121 eotf_DCDM(0.11281861), 0.18, atol=TOLERANCE_ABSOLUTE_TESTS

122 )

123

124 np.testing.assert_allclose(

125 eotf_DCDM(0.21817973), 1.0, atol=TOLERANCE_ABSOLUTE_TESTS

126 )

127

128 np.testing.assert_allclose(eotf_DCDM(462, in_int=True), 0.18, atol=1e-5)

129

130 def test_n_dimensional_eotf_DCDM(self) -> None:

131 """

132 Test :func:`colour.models.rgb.transfer_functions.dcdm.eotf_DCDM`

133 definition n-dimensional arrays support.

134 """

135

136 XYZ_p = 0.11281861

137 XYZ = eotf_DCDM(XYZ_p)

138

139 XYZ_p = np.tile(XYZ_p, 6)

140 XYZ = np.tile(XYZ, 6)

141 np.testing.assert_allclose(eotf_DCDM(XYZ_p), XYZ, atol=TOLERANCE_ABSOLUTE_TESTS)

142

143 XYZ_p = np.reshape(XYZ_p, (2, 3))

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

145 np.testing.assert_allclose(eotf_DCDM(XYZ_p), XYZ, atol=TOLERANCE_ABSOLUTE_TESTS)

146

147 XYZ_p = np.reshape(XYZ_p, (2, 3, 1))

148 XYZ = np.reshape(XYZ, (2, 3, 1))

149 np.testing.assert_allclose(eotf_DCDM(XYZ_p), XYZ, atol=TOLERANCE_ABSOLUTE_TESTS)

150

151 def test_domain_range_scale_eotf_DCDM(self) -> None:

152 """

153 Test :func:`colour.models.rgb.transfer_functions.dcdm.eotf_DCDM`

154 definition domain and range scale support.

155 """

156

157 XYZ_p = 0.11281861

158 XYZ = eotf_DCDM(XYZ_p)

159

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

161 for scale, factor in d_r:

162 with domain_range_scale(scale):

163 np.testing.assert_allclose(

164 eotf_DCDM(XYZ_p * factor),

165 XYZ * factor,

166 atol=TOLERANCE_ABSOLUTE_TESTS,

167 )

168

169 @ignore_numpy_errors

170 def test_nan_eotf_DCDM(self) -> None:

171 """

172 Test :func:`colour.models.rgb.transfer_functions.dcdm.eotf_DCDM`

173 definition nan support.

174 """

175

176 eotf_DCDM(np.array([-1.0, 0.0, 1.0, -np.inf, np.inf, np.nan]))