Coverage for colour/temperature/tests/test_kang2002.py: 100%
51 statements
« prev ^ index » next coverage.py v7.11.0, created at 2025-11-15 19:01 +1300
« prev ^ index » next coverage.py v7.11.0, created at 2025-11-15 19:01 +1300
1"""Define the unit tests for the :mod:`colour.temperature.kang2002` 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_Kang2002, xy_to_CCT_Kang2002
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_Kang2002",
22 "TestCCT_to_xy_Kang2002",
23]
26class TestXy_to_CCT_Kang2002:
27 """
28 Define :func:`colour.temperature.kang2002.xy_to_CCT_Kang2002`
29 definition unit tests methods.
30 """
32 def test_xy_to_CCT_Kang2002(self) -> None:
33 """
34 Test :func:`colour.temperature.kang2002.xy_to_CCT_Kang2002`
35 definition.
36 """
38 np.testing.assert_allclose(
39 xy_to_CCT_Kang2002(
40 np.array([0.380528282812500, 0.376733530961114]),
41 {"method": "Nelder-Mead"},
42 ),
43 4000,
44 atol=TOLERANCE_ABSOLUTE_TESTS,
45 )
47 np.testing.assert_allclose(
48 xy_to_CCT_Kang2002(
49 np.array([0.306374019533528, 0.316552869726577]),
50 {"method": "Nelder-Mead"},
51 ),
52 7000,
53 atol=TOLERANCE_ABSOLUTE_TESTS,
54 )
56 np.testing.assert_allclose(
57 xy_to_CCT_Kang2002(
58 np.array([0.252472994438400, 0.252254791243654]),
59 {"method": "Nelder-Mead"},
60 ),
61 25000,
62 atol=TOLERANCE_ABSOLUTE_TESTS,
63 )
65 def test_n_dimensional_xy_to_CCT_Kang2002(self) -> None:
66 """
67 Test :func:`colour.temperature.kang2002.xy_to_CCT_Kang2002`
68 definition n-dimensional arrays support.
69 """
71 if not is_scipy_installed(): # pragma: no cover
72 return
74 uv = np.array([0.380528282812500, 0.376733530961114])
75 CCT = xy_to_CCT_Kang2002(uv)
77 uv = np.tile(uv, (6, 1))
78 CCT = np.tile(CCT, 6)
79 np.testing.assert_allclose(
80 xy_to_CCT_Kang2002(uv), CCT, atol=TOLERANCE_ABSOLUTE_TESTS
81 )
83 uv = np.reshape(uv, (2, 3, 2))
84 CCT = np.reshape(CCT, (2, 3))
85 np.testing.assert_allclose(
86 xy_to_CCT_Kang2002(uv), CCT, atol=TOLERANCE_ABSOLUTE_TESTS
87 )
89 @ignore_numpy_errors
90 def test_nan_xy_to_CCT_Kang2002(self) -> None:
91 """
92 Test :func:`colour.temperature.kang2002.xy_to_CCT_Kang2002`
93 definition nan support.
94 """
96 if not is_scipy_installed(): # pragma: no cover
97 return
99 cases = [-1.0, 0.0, 1.0, -np.inf, np.inf, np.nan]
100 cases = np.array(list(set(product(cases, repeat=2))))
101 xy_to_CCT_Kang2002(cases)
104class TestCCT_to_xy_Kang2002:
105 """
106 Define :func:`colour.temperature.kang2002.CCT_to_xy_Kang2002` definition
107 unit tests methods.
108 """
110 def test_CCT_to_xy_Kang2002(self) -> None:
111 """
112 Test :func:`colour.temperature.kang2002.CCT_to_xy_Kang2002`
113 definition.
114 """
116 np.testing.assert_allclose(
117 CCT_to_xy_Kang2002(4000),
118 np.array([0.380528282812500, 0.376733530961114]),
119 atol=TOLERANCE_ABSOLUTE_TESTS,
120 )
122 np.testing.assert_allclose(
123 CCT_to_xy_Kang2002(7000),
124 np.array([0.306374019533528, 0.316552869726577]),
125 atol=TOLERANCE_ABSOLUTE_TESTS,
126 )
128 np.testing.assert_allclose(
129 CCT_to_xy_Kang2002(25000),
130 np.array([0.252472994438400, 0.252254791243654]),
131 atol=TOLERANCE_ABSOLUTE_TESTS,
132 )
134 def test_n_dimensional_CCT_to_xy_Kang2002(self) -> None:
135 """
136 Test :func:`colour.temperature.kang2002.CCT_to_xy_Kang2002` definition
137 n-dimensional arrays support.
138 """
140 CCT = 4000
141 xy = CCT_to_xy_Kang2002(CCT)
143 CCT = np.tile(CCT, 6)
144 xy = np.tile(xy, (6, 1))
145 np.testing.assert_allclose(
146 CCT_to_xy_Kang2002(CCT), xy, atol=TOLERANCE_ABSOLUTE_TESTS
147 )
149 CCT = np.reshape(CCT, (2, 3))
150 xy = np.reshape(xy, (2, 3, 2))
151 np.testing.assert_allclose(
152 CCT_to_xy_Kang2002(CCT), xy, atol=TOLERANCE_ABSOLUTE_TESTS
153 )
155 @ignore_numpy_errors
156 def test_nan_CCT_to_xy_Kang2002(self) -> None:
157 """
158 Test :func:`colour.temperature.kang2002.CCT_to_xy_Kang2002` definition
159 nan support.
160 """
162 cases = [-1.0, 0.0, 1.0, -np.inf, np.inf, np.nan]
163 cases = np.array(list(set(product(cases, repeat=2))))
164 CCT_to_xy_Kang2002(cases)