Coverage for colour/temperature/tests/test_planck1900.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.planck1900` 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_Planck1900, uv_to_CCT_Planck1900
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_Planck1900",
22 "TestCCT_to_uv_Planck1900",
23]
26class TestUv_to_CCT_Planck1900:
27 """
28 Define :func:`colour.temperature.planck1900.uv_to_CCT_Planck1900`
29 definition unit tests methods.
30 """
32 def test_uv_to_CCT_Planck1900(self) -> None:
33 """
34 Test :func:`colour.temperature.planck1900.uv_to_CCT_Planck1900`
35 definition.
36 """
38 np.testing.assert_allclose(
39 uv_to_CCT_Planck1900(
40 np.array([0.225109670227493, 0.334387366663923]),
41 optimisation_kwargs={"method": "Nelder-Mead"},
42 ),
43 4000,
44 atol=TOLERANCE_ABSOLUTE_TESTS,
45 )
47 np.testing.assert_allclose(
48 uv_to_CCT_Planck1900(
49 np.array([0.198126929048352, 0.307025980523306]),
50 optimisation_kwargs={"method": "Nelder-Mead"},
51 ),
52 7000,
53 atol=TOLERANCE_ABSOLUTE_TESTS,
54 )
56 np.testing.assert_allclose(
57 uv_to_CCT_Planck1900(
58 np.array([0.182932683590136, 0.274073232217536]),
59 optimisation_kwargs={"method": "Nelder-Mead"},
60 ),
61 25000,
62 atol=TOLERANCE_ABSOLUTE_TESTS,
63 )
65 def test_n_dimensional_uv_to_CCT_Planck1900(self) -> None:
66 """
67 Test :func:`colour.temperature.planck1900.uv_to_CCT_Planck1900`
68 definition n-dimensional arrays support.
69 """
71 if not is_scipy_installed(): # pragma: no cover
72 return
74 uv = np.array([0.225109670227493, 0.334387366663923])
75 CCT = uv_to_CCT_Planck1900(uv)
77 uv = np.tile(uv, (6, 1))
78 CCT = np.tile(CCT, 6)
79 np.testing.assert_allclose(
80 uv_to_CCT_Planck1900(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 uv_to_CCT_Planck1900(uv), CCT, atol=TOLERANCE_ABSOLUTE_TESTS
87 )
89 @ignore_numpy_errors
90 def test_nan_uv_to_CCT_Planck1900(self) -> None:
91 """
92 Test :func:`colour.temperature.planck1900.uv_to_CCT_Planck1900`
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 uv_to_CCT_Planck1900(cases)
104class TestCCT_to_uv_Planck1900:
105 """
106 Define :func:`colour.temperature.planck1900.CCT_to_uv_Planck1900` definition
107 unit tests methods.
108 """
110 def test_CCT_to_uv_Planck1900(self) -> None:
111 """
112 Test :func:`colour.temperature.planck1900.CCT_to_uv_Planck1900`
113 definition.
114 """
116 np.testing.assert_allclose(
117 CCT_to_uv_Planck1900(4000),
118 np.array([0.225109670227493, 0.334387366663923]),
119 atol=TOLERANCE_ABSOLUTE_TESTS,
120 )
122 np.testing.assert_allclose(
123 CCT_to_uv_Planck1900(7000),
124 np.array([0.198126929048352, 0.307025980523306]),
125 atol=TOLERANCE_ABSOLUTE_TESTS,
126 )
128 np.testing.assert_allclose(
129 CCT_to_uv_Planck1900(25000),
130 np.array([0.182932683590136, 0.274073232217536]),
131 atol=TOLERANCE_ABSOLUTE_TESTS,
132 )
134 def test_n_dimensional_CCT_to_uv_Planck1900(self) -> None:
135 """
136 Test :func:`colour.temperature.planck1900.CCT_to_uv_Planck1900` definition
137 n-dimensional arrays support.
138 """
140 CCT = 4000
141 uv = CCT_to_uv_Planck1900(CCT)
143 CCT = np.tile(CCT, 6)
144 uv = np.tile(uv, (6, 1))
145 np.testing.assert_allclose(
146 CCT_to_uv_Planck1900(CCT), uv, atol=TOLERANCE_ABSOLUTE_TESTS
147 )
149 CCT = np.reshape(CCT, (2, 3))
150 uv = np.reshape(uv, (2, 3, 2))
151 np.testing.assert_allclose(
152 CCT_to_uv_Planck1900(CCT), uv, atol=TOLERANCE_ABSOLUTE_TESTS
153 )
155 @ignore_numpy_errors
156 def test_nan_CCT_to_uv_Planck1900(self) -> None:
157 """
158 Test :func:`colour.temperature.planck1900.CCT_to_uv_Planck1900` 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_uv_Planck1900(cases)