Coverage for colour/temperature/tests/test_krystek1985.py: 100%
50 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.krystek1985` 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_uv_Krystek1985, uv_to_CCT_Krystek1985
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 "TestUv_to_CCT_Krystek1985",
22]
25class TestUv_to_CCT_Krystek1985:
26 """
27 Define :func:`colour.temperature.krystek1985.uv_to_CCT_Krystek1985`
28 definition unit tests methods.
29 """
31 def test_uv_to_CCT_Krystek1985(self) -> None:
32 """
33 Test :func:`colour.temperature.krystek1985.uv_to_CCT_Krystek1985`
34 definition.
35 """
37 np.testing.assert_allclose(
38 uv_to_CCT_Krystek1985(
39 np.array([0.448087794140145, 0.354731965027727]),
40 {"method": "Nelder-Mead"},
41 ),
42 1000,
43 atol=TOLERANCE_ABSOLUTE_TESTS,
44 )
46 np.testing.assert_allclose(
47 uv_to_CCT_Krystek1985(
48 np.array([0.198152565091092, 0.307023596915037]),
49 {"method": "Nelder-Mead"},
50 ),
51 7000,
52 atol=TOLERANCE_ABSOLUTE_TESTS,
53 )
55 np.testing.assert_allclose(
56 uv_to_CCT_Krystek1985(
57 np.array([0.185675876767054, 0.282233658593898]),
58 {"method": "Nelder-Mead"},
59 ),
60 15000,
61 atol=TOLERANCE_ABSOLUTE_TESTS,
62 )
64 def test_n_dimensional_uv_to_CCT_Krystek1985(self) -> None:
65 """
66 Test :func:`colour.temperature.krystek1985.uv_to_CCT_Krystek1985`
67 definition n-dimensional arrays support.
68 """
70 if not is_scipy_installed(): # pragma: no cover
71 return
73 uv = np.array([0.198152565091092, 0.307023596915037])
74 CCT = uv_to_CCT_Krystek1985(uv)
76 uv = np.tile(uv, (6, 1))
77 CCT = np.tile(CCT, 6)
78 np.testing.assert_allclose(
79 uv_to_CCT_Krystek1985(uv), CCT, atol=TOLERANCE_ABSOLUTE_TESTS
80 )
82 uv = np.reshape(uv, (2, 3, 2))
83 CCT = np.reshape(CCT, (2, 3))
84 np.testing.assert_allclose(
85 uv_to_CCT_Krystek1985(uv), CCT, atol=TOLERANCE_ABSOLUTE_TESTS
86 )
88 @ignore_numpy_errors
89 def test_nan_uv_to_CCT_Krystek1985(self) -> None:
90 """
91 Test :func:`colour.temperature.krystek1985.uv_to_CCT_Krystek1985`
92 definition nan support.
93 """
95 if not is_scipy_installed(): # pragma: no cover
96 return
98 cases = [-1.0, 0.0, 1.0, -np.inf, np.inf, np.nan]
99 cases = np.array(list(set(product(cases, repeat=2))))
100 uv_to_CCT_Krystek1985(cases)
103class TestCCT_to_uv_Krystek1985:
104 """
105 Define :func:`colour.temperature.krystek1985.CCT_to_uv_Krystek1985`
106 definition unit tests methods.
107 """
109 def test_CCT_to_uv_Krystek1985(self) -> None:
110 """
111 Test :func:`colour.temperature.krystek1985.CCT_to_uv_Krystek1985`
112 definition.
113 """
115 np.testing.assert_allclose(
116 CCT_to_uv_Krystek1985(1000),
117 np.array([0.448087794140145, 0.354731965027727]),
118 atol=TOLERANCE_ABSOLUTE_TESTS,
119 )
121 np.testing.assert_allclose(
122 CCT_to_uv_Krystek1985(7000),
123 np.array([0.198152565091092, 0.307023596915037]),
124 atol=TOLERANCE_ABSOLUTE_TESTS,
125 )
127 np.testing.assert_allclose(
128 CCT_to_uv_Krystek1985(15000),
129 np.array([0.185675876767054, 0.282233658593898]),
130 atol=TOLERANCE_ABSOLUTE_TESTS,
131 )
133 def test_n_dimensional_CCT_to_uv_Krystek1985(self) -> None:
134 """
135 Test :func:`colour.temperature.krystek1985.CCT_to_uv_Krystek1985`
136 definition n-dimensional arrays support.
137 """
139 CCT = 7000
140 uv = CCT_to_uv_Krystek1985(CCT)
142 CCT = np.tile(CCT, 6)
143 uv = np.tile(uv, (6, 1))
144 np.testing.assert_allclose(
145 CCT_to_uv_Krystek1985(CCT), uv, atol=TOLERANCE_ABSOLUTE_TESTS
146 )
148 CCT = np.reshape(CCT, (2, 3))
149 uv = np.reshape(uv, (2, 3, 2))
150 np.testing.assert_allclose(
151 CCT_to_uv_Krystek1985(CCT), uv, atol=TOLERANCE_ABSOLUTE_TESTS
152 )
154 @ignore_numpy_errors
155 def test_nan_CCT_to_uv_Krystek1985(self) -> None:
156 """
157 Test :func:`colour.temperature.krystek1985.CCT_to_uv_Krystek1985`
158 definition nan support.
159 """
161 cases = [-1.0, 0.0, 1.0, -np.inf, np.inf, np.nan]
162 CCT_to_uv_Krystek1985(cases)