Coverage for colour/temperature/tests/test_hernandez1999.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.hernandez1999` 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_Hernandez1999, xy_to_CCT_Hernandez1999
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_Hernandez1999",
22 "TestCCT_to_xy_Hernandez1999",
23]
26class Testxy_to_CCT_Hernandez1999:
27 """
28 Define :func:`colour.temperature.hernandez1999.xy_to_CCT_Hernandez1999`
29 definition unit tests methods.
30 """
32 def test_xy_to_CCT_Hernandez1999(self) -> None:
33 """
34 Test :func:`colour.temperature.hernandez1999.xy_to_CCT_McCamy1992`
35 definition.
36 """
38 np.testing.assert_allclose(
39 xy_to_CCT_Hernandez1999(np.array([0.31270, 0.32900])),
40 6500.74204318,
41 atol=TOLERANCE_ABSOLUTE_TESTS,
42 )
44 np.testing.assert_allclose(
45 xy_to_CCT_Hernandez1999(np.array([0.44757, 0.40745])),
46 2790.64222533,
47 atol=TOLERANCE_ABSOLUTE_TESTS,
48 )
50 np.testing.assert_allclose(
51 xy_to_CCT_Hernandez1999(np.array([0.244162248213914, 0.240333674758318])),
52 64448.11092565,
53 atol=TOLERANCE_ABSOLUTE_TESTS,
54 )
56 def test_n_dimensional_xy_to_CCT_Hernandez1999(self) -> None:
57 """
58 Test :func:`colour.temperature.hernandez1999.xy_to_CCT_Hernandez1999`
59 definition n-dimensional arrays support.
60 """
62 if not is_scipy_installed(): # pragma: no cover
63 return
65 xy = np.array([0.31270, 0.32900])
66 CCT = xy_to_CCT_Hernandez1999(xy)
68 xy = np.tile(xy, (6, 1))
69 CCT = np.tile(CCT, 6)
70 np.testing.assert_allclose(
71 xy_to_CCT_Hernandez1999(xy), CCT, atol=TOLERANCE_ABSOLUTE_TESTS
72 )
74 xy = np.reshape(xy, (2, 3, 2))
75 CCT = np.reshape(CCT, (2, 3))
76 np.testing.assert_allclose(
77 xy_to_CCT_Hernandez1999(xy), CCT, atol=TOLERANCE_ABSOLUTE_TESTS
78 )
80 @ignore_numpy_errors
81 def test_nan_xy_to_CCT_Hernandez1999(self) -> None:
82 """
83 Test :func:`colour.temperature.hernandez1999.xy_to_CCT_Hernandez1999`
84 definition nan support.
85 """
87 if not is_scipy_installed(): # pragma: no cover
88 return
90 cases = [-1.0, 0.0, 1.0, -np.inf, np.inf, np.nan]
91 cases = np.array(list(set(product(cases, repeat=2))))
92 xy_to_CCT_Hernandez1999(cases)
95class TestCCT_to_xy_Hernandez1999:
96 """
97 Define :func:`colour.temperature.hernandez1999.CCT_to_xy_Hernandez1999`
98 definition unit tests methods.
99 """
101 def test_CCT_to_xy_Hernandez1999(self) -> None:
102 """
103 Test :func:`colour.temperature.hernandez1999.CCT_to_xy_Hernandez1999`
104 definition.
105 """
107 if not is_scipy_installed(): # pragma: no cover
108 return
110 np.testing.assert_allclose(
111 CCT_to_xy_Hernandez1999(6500.74204318, {"method": "Nelder-Mead"}),
112 np.array([0.31269943, 0.32900373]),
113 atol=TOLERANCE_ABSOLUTE_TESTS,
114 )
116 np.testing.assert_allclose(
117 CCT_to_xy_Hernandez1999(2790.64222533, {"method": "Nelder-Mead"}),
118 np.array([0.42864308, 0.36754776]),
119 atol=TOLERANCE_ABSOLUTE_TESTS,
120 )
122 np.testing.assert_allclose(
123 CCT_to_xy_Hernandez1999(64448.11092565, {"method": "Nelder-Mead"}),
124 np.array([0.08269106, 0.36612620]),
125 atol=TOLERANCE_ABSOLUTE_TESTS,
126 )
128 def test_n_dimensional_CCT_to_xy_Hernandez1999(self) -> None:
129 """
130 Test :func:`colour.temperature.hernandez1999.CCT_to_xy_Hernandez1999`
131 definition n-dimensional arrays support.
132 """
134 if not is_scipy_installed(): # pragma: no cover
135 return
137 CCT = 6500.74204318
138 xy = CCT_to_xy_Hernandez1999(CCT)
140 CCT = np.tile(CCT, 6)
141 xy = np.tile(xy, (6, 1))
142 np.testing.assert_allclose(
143 CCT_to_xy_Hernandez1999(CCT), xy, atol=TOLERANCE_ABSOLUTE_TESTS
144 )
146 CCT = np.reshape(CCT, (2, 3))
147 xy = np.reshape(xy, (2, 3, 2))
148 np.testing.assert_allclose(
149 CCT_to_xy_Hernandez1999(CCT), xy, atol=TOLERANCE_ABSOLUTE_TESTS
150 )
152 @ignore_numpy_errors
153 def test_nan_CCT_to_xy_Hernandez1999(self) -> None:
154 """
155 Test :func:`colour.temperature.hernandez1999.CCT_to_xy_Hernandez1999`
156 definition nan support.
157 """
159 if not is_scipy_installed(): # pragma: no cover
160 return
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_Hernandez1999(cases)