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

1"""

2 Define the unit tests for the

3:mod:`colour.models.rgb.transfer_functions.itur_bt_2020` 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 oetf_BT2020, oetf_inverse_BT2020

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

21 "TestOetf_inverse_BT2020",

22]

23

24

25 class TestOetf_BT2020:

26 """

27 Define :func:`colour.models.rgb.transfer_functions.itur_bt_2020.\

28 oetf_BT2020` definition unit tests methods.

29 """

30

31 def test_oetf_BT2020(self) -> None:

32 """

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

34 oetf_BT2020` definition.

35 """

36

37 np.testing.assert_allclose(oetf_BT2020(0.0), 0.0, atol=TOLERANCE_ABSOLUTE_TESTS)

38

39 np.testing.assert_allclose(

40 oetf_BT2020(0.18), 0.409007728864150, atol=TOLERANCE_ABSOLUTE_TESTS

41 )

42

43 np.testing.assert_allclose(oetf_BT2020(1.0), 1.0, atol=TOLERANCE_ABSOLUTE_TESTS)

44

45 def test_n_dimensional_oetf_BT2020(self) -> None:

46 """

47 Test :func:`colour.models.rgb.transfer_functions.itur_bt_2020.\

48 oetf_BT2020` definition n-dimensional arrays support.

49 """

50

51 E = 0.18

52 E_p = oetf_BT2020(E)

53

54 E = np.tile(E, 6)

55 E_p = np.tile(E_p, 6)

56 np.testing.assert_allclose(oetf_BT2020(E), E_p, atol=TOLERANCE_ABSOLUTE_TESTS)

57

58 E = np.reshape(E, (2, 3))

59 E_p = np.reshape(E_p, (2, 3))

60 np.testing.assert_allclose(oetf_BT2020(E), E_p, atol=TOLERANCE_ABSOLUTE_TESTS)

61

62 E = np.reshape(E, (2, 3, 1))

63 E_p = np.reshape(E_p, (2, 3, 1))

64 np.testing.assert_allclose(oetf_BT2020(E), E_p, atol=TOLERANCE_ABSOLUTE_TESTS)

65

66 def test_domain_range_scale_oetf_BT2020(self) -> None:

67 """

68 Test :func:`colour.models.rgb.transfer_functions.itur_bt_2020.\

69 oetf_BT2020` definition domain and range scale support.

70 """

71

72 E = 0.18

73 E_p = oetf_BT2020(E)

74

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

76 for scale, factor in d_r:

77 with domain_range_scale(scale):

78 np.testing.assert_allclose(

79 oetf_BT2020(E * factor),

80 E_p * factor,

81 atol=TOLERANCE_ABSOLUTE_TESTS,

82 )

83

84 @ignore_numpy_errors

85 def test_nan_oetf_BT2020(self) -> None:

86 """

87 Test :func:`colour.models.rgb.transfer_functions.itur_bt_2020.\

88 oetf_BT2020` definition nan support.

89 """

90

91 oetf_BT2020(np.array([-1.0, 0.0, 1.0, -np.inf, np.inf, np.nan]))

92

93

94 class TestOetf_inverse_BT2020:

95 """

96 Define :func:`colour.models.rgb.transfer_functions.itur_bt_2020.\

97 oetf_inverse_BT2020` definition unit tests methods.

98 """

99

100 def test_oetf_inverse_BT2020(self) -> None:

101 """

102 Test :func:`colour.models.rgb.transfer_functions.itur_bt_2020.\

103 oetf_inverse_BT2020` definition.

104 """

105

106 np.testing.assert_allclose(

107 oetf_inverse_BT2020(0.0), 0.0, atol=TOLERANCE_ABSOLUTE_TESTS

108 )

109

110 np.testing.assert_allclose(

111 oetf_inverse_BT2020(0.409007728864150),

112 0.18,

113 atol=TOLERANCE_ABSOLUTE_TESTS,

114 )

115

116 np.testing.assert_allclose(

117 oetf_inverse_BT2020(1.0), 1.0, atol=TOLERANCE_ABSOLUTE_TESTS

118 )

119

120 def test_n_dimensional_oetf_inverse_BT2020(self) -> None:

121 """

122 Test :func:`colour.models.rgb.transfer_functions.itur_bt_2020.\

123 oetf_inverse_BT2020` definition n-dimensional arrays support.

124 """

125

126 E_p = 0.409007728864150

127 E = oetf_inverse_BT2020(E_p)

128

129 E_p = np.tile(E_p, 6)

130 E = np.tile(E, 6)

131 np.testing.assert_allclose(

132 oetf_inverse_BT2020(E_p), E, atol=TOLERANCE_ABSOLUTE_TESTS

133 )

134

135 E_p = np.reshape(E_p, (2, 3))

136 E = np.reshape(E, (2, 3))

137 np.testing.assert_allclose(

138 oetf_inverse_BT2020(E_p), E, atol=TOLERANCE_ABSOLUTE_TESTS

139 )

140

141 E_p = np.reshape(E_p, (2, 3, 1))

142 E = np.reshape(E, (2, 3, 1))

143 np.testing.assert_allclose(

144 oetf_inverse_BT2020(E_p), E, atol=TOLERANCE_ABSOLUTE_TESTS

145 )

146

147 def test_domain_range_scale_oetf_inverse_BT2020(self) -> None:

148 """

149 Test :func:`colour.models.rgb.transfer_functions.itur_bt_2020.\

150 oetf_inverse_BT2020` definition domain and range scale support.

151 """

152

153 E_p = 0.409007728864150

154 E = oetf_inverse_BT2020(E_p)

155

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

157 for scale, factor in d_r:

158 with domain_range_scale(scale):

159 np.testing.assert_allclose(

160 oetf_inverse_BT2020(E_p * factor),

161 E * factor,

162 atol=TOLERANCE_ABSOLUTE_TESTS,

163 )

164

165 @ignore_numpy_errors

166 def test_nan_oetf_inverse_BT2020(self) -> None:

167 """

168 Test :func:`colour.models.rgb.transfer_functions.itur_bt_2020.\

169 oetf_inverse_BT2020` definition nan support.

170 """

171

172 oetf_inverse_BT2020(np.array([-1.0, 0.0, 1.0, -np.inf, np.inf, np.nan]))