Coverage for temperature/tests/test_cie_d.py: 100%
51 statements
« prev ^ index » next coverage.py v7.11.0, created at 2025-11-16 22:49 +1300
« prev ^ index » next coverage.py v7.11.0, created at 2025-11-16 22:49 +1300
1"""Define the unit tests for the :mod:`colour.temperature.cie_d` module."""
3from __future__ import annotations
5from itertools import product
7import numpy as np
9from colour.constants import TOLERANCE_ABSOLUTE_TESTS
10from colour.temperature import CCT_to_xy_CIE_D, xy_to_CCT_CIE_D
11from colour.utilities import ignore_numpy_errors, is_scipy_installed
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"
20__all__ = [
21 "TestXy_to_CCT_CIE_D",
22 "TestCCT_to_xy_CIE_D",
23]
26class TestXy_to_CCT_CIE_D:
27 """
28 Define :func:`colour.temperature.cie_d.xy_to_CCT_CIE_D` definition unit
29 tests methods.
30 """
32 def test_xy_to_CCT_CIE_D(self) -> None:
33 """Test :func:`colour.temperature.cie_d.xy_to_CCT_CIE_D` definition."""
35 np.testing.assert_allclose(
36 xy_to_CCT_CIE_D(
37 np.array([0.382343625000000, 0.383766261015578]),
38 {"method": "Nelder-Mead"},
39 ),
40 4000,
41 atol=TOLERANCE_ABSOLUTE_TESTS,
42 )
44 np.testing.assert_allclose(
45 xy_to_CCT_CIE_D(
46 np.array([0.305357431486880, 0.321646345474552]),
47 {"method": "Nelder-Mead"},
48 ),
49 7000,
50 atol=TOLERANCE_ABSOLUTE_TESTS,
51 )
53 np.testing.assert_allclose(
54 xy_to_CCT_CIE_D(
55 np.array([0.24985367, 0.254799464210944]),
56 {"method": "Nelder-Mead"},
57 ),
58 25000,
59 atol=TOLERANCE_ABSOLUTE_TESTS,
60 )
62 def test_n_dimensional_xy_to_CCT_CIE_D(self) -> None:
63 """
64 Test :func:`colour.temperature.cie_d.xy_to_CCT_CIE_D` definition
65 n-dimensional arrays support.
66 """
68 if not is_scipy_installed(): # pragma: no cover
69 return
71 xy = np.array([0.382343625000000, 0.383766261015578])
72 CCT = xy_to_CCT_CIE_D(xy)
74 xy = np.tile(xy, (6, 1))
75 CCT = np.tile(CCT, 6)
76 np.testing.assert_allclose(
77 xy_to_CCT_CIE_D(xy), CCT, atol=TOLERANCE_ABSOLUTE_TESTS
78 )
80 xy = np.reshape(xy, (2, 3, 2))
81 CCT = np.reshape(CCT, (2, 3))
82 np.testing.assert_allclose(
83 xy_to_CCT_CIE_D(xy), CCT, atol=TOLERANCE_ABSOLUTE_TESTS
84 )
86 @ignore_numpy_errors
87 def test_nan_xy_to_CCT_CIE_D(self) -> None:
88 """
89 Test :func:`colour.temperature.cie_d.xy_to_CCT_CIE_D` definition nan
90 support.
91 """
93 if not is_scipy_installed(): # pragma: no cover
94 return
96 cases = [-1.0, 0.0, 1.0, -np.inf, np.inf, np.nan]
97 cases = np.array(list(set(product(cases, repeat=2))))
98 xy_to_CCT_CIE_D(cases)
101class TestCCT_to_xy_CIE_D:
102 """
103 Define :func:`colour.temperature.cie_d.CCT_to_xy_CIE_D` definition
104 unit tests methods.
105 """
107 def test_CCT_to_xy_CIE_D(self) -> None:
108 """Test :func:`colour.temperature.cie_d.CCT_to_xy_CIE_D` definition."""
110 np.testing.assert_allclose(
111 CCT_to_xy_CIE_D(4000),
112 np.array([0.382343625000000, 0.383766261015578]),
113 atol=TOLERANCE_ABSOLUTE_TESTS,
114 )
116 np.testing.assert_allclose(
117 CCT_to_xy_CIE_D(7000),
118 np.array([0.305357431486880, 0.321646345474552]),
119 atol=TOLERANCE_ABSOLUTE_TESTS,
120 )
122 np.testing.assert_allclose(
123 CCT_to_xy_CIE_D(25000),
124 np.array([0.24985367, 0.254799464210944]),
125 atol=TOLERANCE_ABSOLUTE_TESTS,
126 )
128 def test_n_dimensional_CCT_to_xy_CIE_D(self) -> None:
129 """
130 Test :func:`colour.temperature.cie_d.CCT_to_xy_CIE_D` definition
131 n-dimensional arrays support.
132 """
134 CCT = 4000
135 xy = CCT_to_xy_CIE_D(CCT)
137 CCT = np.tile(CCT, 6)
138 xy = np.tile(xy, (6, 1))
139 np.testing.assert_allclose(
140 CCT_to_xy_CIE_D(CCT), xy, atol=TOLERANCE_ABSOLUTE_TESTS
141 )
143 CCT = np.reshape(CCT, (2, 3))
144 xy = np.reshape(xy, (2, 3, 2))
145 np.testing.assert_allclose(
146 CCT_to_xy_CIE_D(CCT), xy, atol=TOLERANCE_ABSOLUTE_TESTS
147 )
149 @ignore_numpy_errors
150 def test_nan_CCT_to_xy_CIE_D(self) -> None:
151 """
152 Test :func:`colour.temperature.cie_d.CCT_to_xy_CIE_D` definition
153 nan support.
154 """
156 cases = [-1.0, 0.0, 1.0, -np.inf, np.inf, np.nan]
157 cases = np.array(list(set(product(cases, repeat=2))))
158 CCT_to_xy_CIE_D(cases)