Coverage for colour/quality/tests/test_tm3018.py: 100%
31 statements
« prev ^ index » next coverage.py v7.11.0, created at 2025-11-16 23:01 +1300
« prev ^ index » next coverage.py v7.11.0, created at 2025-11-16 23:01 +1300
1"""
2Define the unit tests for the :mod:`colour.quality.tm3018` module.
4Notes
5-----
6- Reference data was created using the official Excel spreadsheet, published
7 by the IES at this URL:
8 http://media.ies.org/docs/errata/TM-30-18_tools_etc.zip.
9"""
11from __future__ import annotations
13import numpy as np
15from colour.colorimetry import SDS_ILLUMINANTS
16from colour.quality.tm3018 import (
17 averages_area,
18 colour_fidelity_index_ANSIIESTM3018,
19)
20from colour.utilities import as_float_array
22__author__ = "Colour Developers"
23__copyright__ = "Copyright 2013 Colour Developers"
24__license__ = "BSD-3-Clause - https://opensource.org/licenses/BSD-3-Clause"
25__maintainer__ = "Colour Developers"
26__email__ = "colour-developers@colour-science.org"
27__status__ = "Production"
29__all__ = [
30 "TestColourFidelityIndexANSIIESTM3018",
31 "TestAveragesArea",
32]
35class TestColourFidelityIndexANSIIESTM3018:
36 """
37 Define :func:`colour.quality.tm3018.colour_fidelity_index_ANSIIESTM3018`
38 definition unit tests methods.
39 """
41 def test_colour_fidelity_index_ANSIIESTM3018(self) -> None:
42 """
43 Test :func:`colour.quality.tm3018.colour_fidelity_index_ANSIIESTM3018`
44 definition.
45 """
47 # Test without additional data (returns R_f only)
48 R_f = colour_fidelity_index_ANSIIESTM3018(
49 SDS_ILLUMINANTS["FL2"], additional_data=False
50 )
51 np.testing.assert_allclose(R_f, 70, atol=2e-1)
53 # Test with additional data (returns full specification)
54 specification = colour_fidelity_index_ANSIIESTM3018(
55 SDS_ILLUMINANTS["FL2"], additional_data=True
56 )
58 np.testing.assert_allclose(specification.R_f, 70, atol=2e-1)
59 np.testing.assert_allclose(specification.R_g, 86, atol=5e-1)
60 np.testing.assert_allclose(specification.CCT, 4225, atol=1)
61 np.testing.assert_allclose(specification.D_uv, 0.0019, atol=1e-3)
63 np.testing.assert_allclose(
64 specification.R_s,
65 [
66 79,
67 59,
68 67,
69 66,
70 36,
71 66,
72 40,
73 35,
74 95,
75 54,
76 48,
77 45,
78 64,
79 87,
80 72,
81 49,
82 56,
83 69,
84 57,
85 44,
86 47,
87 47,
88 80,
89 63,
90 48,
91 59,
92 82,
93 85,
94 62,
95 70,
96 68,
97 62,
98 74,
99 74,
100 86,
101 88,
102 80,
103 76,
104 97,
105 93,
106 91,
107 89,
108 83,
109 99,
110 83,
111 81,
112 87,
113 66,
114 80,
115 81,
116 81,
117 76,
118 69,
119 77,
120 77,
121 66,
122 66,
123 67,
124 79,
125 90,
126 78,
127 87,
128 77,
129 60,
130 61,
131 58,
132 56,
133 62,
134 73,
135 58,
136 64,
137 84,
138 53,
139 96,
140 67,
141 57,
142 76,
143 63,
144 82,
145 85,
146 74,
147 94,
148 91,
149 86,
150 81,
151 64,
152 74,
153 69,
154 66,
155 68,
156 93,
157 51,
158 70,
159 41,
160 62,
161 70,
162 80,
163 67,
164 45,
165 ],
166 atol=0.75,
167 )
169 np.testing.assert_allclose(
170 specification.R_fs,
171 [60, 61, 53, 68, 80, 88, 77, 73, 76, 62, 70, 77, 81, 71, 64, 65],
172 atol=0.75,
173 )
174 np.testing.assert_allclose(
175 specification.R_cs,
176 [-25, -18, -9, 5, 11, 4, -8, -15, -17, -15, -4, 5, 11, 7, -6, -16],
177 atol=0.75,
178 )
179 np.testing.assert_allclose(
180 specification.R_hs,
181 [
182 -0.02,
183 0.14,
184 0.24,
185 0.20,
186 0.09,
187 -0.07,
188 -0.12,
189 -0.08,
190 0.01,
191 0.17,
192 0.19,
193 0.11,
194 -0.08,
195 -0.15,
196 -0.26,
197 -0.17,
198 ],
199 atol=0.75,
200 )
203class TestAveragesArea:
204 """
205 Define :func:`colour.quality.tm3018.averages_area` definition unit tests
206 methods.
207 """
209 def test_averages_area(self) -> None:
210 """Test :func:`colour.quality.tm3018.averages_area` definition."""
212 # Simple 3 * sqrt(2) by sqrt(2) rectangle.
213 rectangle = as_float_array([[2, 1], [1, 2], [-2, -1], [-1, -2]])
214 np.allclose(averages_area(rectangle), 6)
216 # Concave polygon.
217 poly = np.array([[1.0, -1], [1, 1], [3, 1], [3, 3], [-1, 3], [-1, -1]])
218 np.allclose(averages_area(poly), 12)