Coverage for temperature/__init__.py: 18%
57 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"""
2References
3----------
4- :cite:`AdobeSystems2013` : Adobe Systems. (2013). Adobe DNG Software
5 Development Kit (SDK) - 1.3.0.0 -
6 dng_sdk_1_3/dng_sdk/source/dng_temperature.cpp::dng_temperature::\
7Set_xy_coord. https://www.adobe.com/support/downloads/dng/dng_sdk.html
8- :cite:`CIETC1-482004i` : CIE TC 1-48. (2004). APPENDIX E. INFORMATION ON
9 THE USE OF PLANCK'S EQUATION FOR STANDARD AIR. In CIE 015:2004 Colorimetry,
10 3rd Edition (pp. 77-82). ISBN:978-3-901906-33-6
11- :cite:`Hernandez-Andres1999a` : Hernández-Andrés, J., Lee, R. L., &
12 Romero, J. (1999). Calculating correlated color temperatures across the
13 entire gamut of daylight and skylight chromaticities. Applied Optics,
14 38(27),
15 5703. doi:10.1364/AO.38.005703
16- :cite:`Kang2002a` : Kang, B., Moon, O., Hong, C., Lee, H., Cho, B., & Kim,
17 Y. (2002). Design of advanced color: Temperature control system for HDTV
18 applications. Journal of the Korean Physical Society, 41(6), 865-871.
19- :cite:`Krystek1985b` : Krystek, M. (1985). An algorithm to calculate
20 correlated colour temperature. Color Research & Application, 10(1), 38-40.
21 doi:10.1002/col.5080100109
22- :cite:`Ohno2014a` : Ohno, Yoshiro. (2014). Practical Use and Calculation of
23 CCT and Duv. LEUKOS, 10(1), 47-55. doi:10.1080/15502724.2014.839020
24- :cite:`Wikipedia2001` : Wikipedia. (2001). Approximation. Retrieved June
25 28, 2014, from http://en.wikipedia.org/wiki/Color_temperature#Approximation
26- :cite:`Wikipedia2001a` : Wikipedia. (2001). Color temperature. Retrieved
27 June 28, 2014, from http://en.wikipedia.org/wiki/Color_temperature
28- :cite:`Wyszecki2000y` : Wyszecki, Günther, & Stiles, W. S. (2000).
29 DISTRIBUTION TEMPERATURE, COLOR TEMPERATURE, AND CORRELATED COLOR
30 TEMPERATURE. In Color Science: Concepts and Methods, Quantitative Data and
31 Formulae (pp. 224-229). Wiley. ISBN:978-0-471-39918-6
32- :cite:`Wyszecki2000z` : Wyszecki, Günther, & Stiles, W. S. (2000). CIE
33 Method of Calculating D-Illuminants. In Color Science: Concepts and
34 Methods, Quantitative Data and Formulae (pp. 145-146). Wiley.
35 ISBN:978-0-471-39918-6
36"""
38from __future__ import annotations
40import typing
42if typing.TYPE_CHECKING:
43 from colour.hints import Any, ArrayLike, NDArrayFloat, Literal
45from colour.utilities import (
46 CanonicalMapping,
47 filter_kwargs,
48 validate_method,
49)
51from .cie_d import CCT_to_xy_CIE_D, xy_to_CCT_CIE_D
52from .hernandez1999 import CCT_to_xy_Hernandez1999, xy_to_CCT_Hernandez1999
53from .kang2002 import CCT_to_xy_Kang2002, xy_to_CCT_Kang2002
54from .krystek1985 import CCT_to_uv_Krystek1985, uv_to_CCT_Krystek1985
55from .mccamy1992 import CCT_to_xy_McCamy1992, xy_to_CCT_McCamy1992
56from .planck1900 import CCT_to_uv_Planck1900, uv_to_CCT_Planck1900
58# isort: split
60from .ohno2013 import (
61 CCT_to_uv_Ohno2013,
62 CCT_to_XYZ_Ohno2013,
63 XYZ_to_CCT_Ohno2013,
64 uv_to_CCT_Ohno2013,
65)
66from .robertson1968 import (
67 CCT_to_mired,
68 CCT_to_uv_Robertson1968,
69 mired_to_CCT,
70 uv_to_CCT_Robertson1968,
71)
73__all__ = [
74 "CCT_to_xy_CIE_D",
75 "xy_to_CCT_CIE_D",
76]
77__all__ += [
78 "CCT_to_xy_Hernandez1999",
79 "xy_to_CCT_Hernandez1999",
80]
81__all__ += [
82 "CCT_to_xy_Kang2002",
83 "xy_to_CCT_Kang2002",
84]
85__all__ += [
86 "CCT_to_uv_Krystek1985",
87 "uv_to_CCT_Krystek1985",
88]
89__all__ += [
90 "CCT_to_xy_McCamy1992",
91 "xy_to_CCT_McCamy1992",
92]
93__all__ += [
94 "CCT_to_uv_Planck1900",
95 "uv_to_CCT_Planck1900",
96]
97__all__ += [
98 "CCT_to_uv_Ohno2013",
99 "CCT_to_XYZ_Ohno2013",
100 "XYZ_to_CCT_Ohno2013",
101 "uv_to_CCT_Ohno2013",
102]
103__all__ += [
104 "CCT_to_mired",
105 "CCT_to_uv_Robertson1968",
106 "mired_to_CCT",
107 "uv_to_CCT_Robertson1968",
108]
110UV_TO_CCT_METHODS: CanonicalMapping = CanonicalMapping(
111 {
112 "Krystek 1985": uv_to_CCT_Krystek1985,
113 "Ohno 2013": uv_to_CCT_Ohno2013,
114 "Planck 1900": uv_to_CCT_Planck1900,
115 "Robertson 1968": uv_to_CCT_Robertson1968,
116 }
117)
118UV_TO_CCT_METHODS.__doc__ = """
119Supported *CIE UCS* colourspace *uv* chromaticity coordinates to correlated
120colour temperature :math:`T_{cp}` computation methods.
122References
123----------
124:cite:`AdobeSystems2013`,
125:cite:`CIETC1-482004i`, :cite:`Krystek1985b`, :cite:`Ohno2014a`,
126:cite:`Wyszecki2000y`
128Aliases:
130- 'ohno2013': 'Ohno 2013'
131- 'robertson1968': 'Robertson 1968'
132"""
133UV_TO_CCT_METHODS["ohno2013"] = UV_TO_CCT_METHODS["Ohno 2013"]
134UV_TO_CCT_METHODS["robertson1968"] = UV_TO_CCT_METHODS["Robertson 1968"]
137def uv_to_CCT(
138 uv: ArrayLike,
139 method: (
140 Literal["Krystek 1985", "Ohno 2013", "Planck 1900", "Robertson 1968"] | str
141 ) = "Ohno 2013",
142 **kwargs: Any,
143) -> NDArrayFloat:
144 """
145 Compute the correlated colour temperature :math:`T_{cp}` and
146 :math:`\\Delta_{uv}` from the specified *CIE UCS* colourspace *uv*
147 chromaticity coordinates using the specified method.
149 Parameters
150 ----------
151 uv
152 *CIE UCS* colourspace *uv* chromaticity coordinates.
153 method
154 Computation method.
156 Other Parameters
157 ----------------
158 cmfs
159 {:func:`colour.temperature.uv_to_CCT_Ohno2013`,
160 :func:`colour.temperature.uv_to_CCT_Planck1900`},
161 Standard observer colour matching functions.
162 count
163 {:func:`colour.temperature.uv_to_CCT_Ohno2013`},
164 Temperatures count in the planckian tables.
165 end
166 {:func:`colour.temperature.uv_to_CCT_Ohno2013`},
167 Temperature range end in kelvins.
168 iterations
169 {:func:`colour.temperature.uv_to_CCT_Ohno2013`},
170 Number of planckian tables to generate.
171 optimisation_kwargs
172 {:func:`colour.temperature.uv_to_CCT_Krystek1985`},
173 Parameters for :func:`scipy.optimize.minimize` definition.
174 start
175 {:func:`colour.temperature.uv_to_CCT_Ohno2013`},
176 Temperature range start in kelvins.
178 Returns
179 -------
180 :class:`numpy.ndarray`
181 Correlated colour temperature :math:`T_{cp}`, :math:`\\Delta_{uv}`.
183 References
184 ----------
185 :cite:`AdobeSystems2013`,
186 :cite:`CIETC1-482004i`, :cite:`Krystek1985b`, :cite:`Ohno2014a`,
187 :cite:`Wyszecki2000y`
189 Examples
190 --------
191 >>> import numpy as np
192 >>> uv = np.array([0.1978, 0.3122])
193 >>> uv_to_CCT(uv) # doctest: +ELLIPSIS
194 array([ 6.5074747...e+03, 3.2233463...e-03])
195 """
197 method = validate_method(method, tuple(UV_TO_CCT_METHODS))
199 function = UV_TO_CCT_METHODS[method]
201 return function(uv, **filter_kwargs(function, **kwargs))
204CCT_TO_UV_METHODS: CanonicalMapping = CanonicalMapping(
205 {
206 "Krystek 1985": CCT_to_uv_Krystek1985,
207 "Ohno 2013": CCT_to_uv_Ohno2013,
208 "Planck 1900": CCT_to_uv_Planck1900,
209 "Robertson 1968": CCT_to_uv_Robertson1968,
210 }
211)
212CCT_TO_UV_METHODS.__doc__ = """
213Supported correlated colour temperature :math:`T_{cp}` to *CIE UCS* colourspace
214*uv* chromaticity coordinates computation methods.
216References
217----------
218:cite:`AdobeSystems2013`,
219:cite:`CIETC1-482004i`, :cite:`Krystek1985b`, :cite:`Ohno2014a`,
220:cite:`Wyszecki2000y`
222Aliases:
224- 'ohno2013': 'Ohno 2013'
225- 'robertson1968': 'Robertson 1968'
226"""
227CCT_TO_UV_METHODS["ohno2013"] = CCT_TO_UV_METHODS["Ohno 2013"]
228CCT_TO_UV_METHODS["robertson1968"] = CCT_TO_UV_METHODS["Robertson 1968"]
231def CCT_to_uv(
232 CCT_D_uv: ArrayLike,
233 method: (
234 Literal["Krystek 1985", "Ohno 2013", "Planck 1900", "Robertson 1968"] | str
235 ) = "Ohno 2013",
236 **kwargs: Any,
237) -> NDArrayFloat:
238 """
239 Compute the *CIE UCS* colourspace *uv* chromaticity coordinates from the
240 specified correlated colour temperature :math:`T_{cp}` and
241 :math:`\\Delta_{uv}` using the specified method.
243 Parameters
244 ----------
245 CCT_D_uv
246 Correlated colour temperature :math:`T_{cp}`, :math:`\\Delta_{uv}`.
247 method
248 Computation method.
250 Other Parameters
251 ----------------
252 cmfs
253 {:func:`colour.temperature.CCT_to_uv_Ohno2013`,
254 :func:`colour.temperature.CCT_to_uv_Planck1900`},
255 Standard observer colour matching functions.
257 Returns
258 -------
259 :class:`numpy.ndarray`
260 *CIE UCS* colourspace *uv* chromaticity coordinates.
262 References
263 ----------
264 :cite:`AdobeSystems2013`,
265 :cite:`CIETC1-482004i`, :cite:`Krystek1985b`, :cite:`Ohno2014a`,
266 :cite:`Wyszecki2000y`
268 Examples
269 --------
270 >>> import numpy as np
271 >>> CCT_D_uv = np.array([6507.47380460, 0.00322335])
272 >>> CCT_to_uv(CCT_D_uv) # doctest: +ELLIPSIS
273 array([ 0.1977999..., 0.3121999...])
274 """
276 method = validate_method(method, tuple(CCT_TO_UV_METHODS))
278 function = CCT_TO_UV_METHODS[method]
280 return function(CCT_D_uv, **filter_kwargs(function, **kwargs))
283__all__ += [
284 "UV_TO_CCT_METHODS",
285 "uv_to_CCT",
286]
287__all__ += [
288 "CCT_TO_UV_METHODS",
289 "CCT_to_uv",
290]
292XY_TO_CCT_METHODS: CanonicalMapping = CanonicalMapping(
293 {
294 "CIE Illuminant D Series": xy_to_CCT_CIE_D,
295 "Hernandez 1999": xy_to_CCT_Hernandez1999,
296 "Kang 2002": xy_to_CCT_Kang2002,
297 "McCamy 1992": xy_to_CCT_McCamy1992,
298 }
299)
300XY_TO_CCT_METHODS.__doc__ = """
301Supported *CIE xy* chromaticity coordinates to correlated colour temperature
302:math:`T_{cp}` computation methods.
304References
305----------
306:cite:`Hernandez-Andres1999a`, :cite:`Kang2002a`, :cite:`Wikipedia2001`,
307:cite:`Wikipedia2001a`, :cite:`Wyszecki2000z`
309Aliases:
311- 'daylight': 'CIE Illuminant D Series'
312- 'kang2002': 'Kang 2002'
313- 'mccamy1992': 'McCamy 1992'
314- 'hernandez1999': 'Hernandez 1999'
315"""
316XY_TO_CCT_METHODS["daylight"] = XY_TO_CCT_METHODS["CIE Illuminant D Series"]
317XY_TO_CCT_METHODS["kang2002"] = XY_TO_CCT_METHODS["Kang 2002"]
318XY_TO_CCT_METHODS["mccamy1992"] = XY_TO_CCT_METHODS["McCamy 1992"]
319XY_TO_CCT_METHODS["hernandez1999"] = XY_TO_CCT_METHODS["Hernandez 1999"]
322def xy_to_CCT(
323 xy: ArrayLike,
324 method: (
325 Literal[
326 "CIE Illuminant D Series",
327 "Kang 2002",
328 "Hernandez 1999",
329 "McCamy 1992",
330 ]
331 | str
332 ) = "CIE Illuminant D Series",
333) -> NDArrayFloat:
334 """
335 Compute the correlated colour temperature :math:`T_{cp}` from the
336 specified *CIE xy* chromaticity coordinates using the specified method.
338 Parameters
339 ----------
340 xy
341 *CIE xy* chromaticity coordinates.
342 method
343 Computation method.
345 Other Parameters
346 ----------------
347 optimisation_kwargs
348 {:func:`colour.temperature.xy_to_CCT_CIE_D`,
349 :func:`colour.temperature.xy_to_CCT_Kang2002`},
350 Parameters for :func:`scipy.optimize.minimize` definition.
352 Returns
353 -------
354 :class:`numpy.ndarray`
355 Correlated colour temperature :math:`T_{cp}`.
357 References
358 ----------
359 :cite:`Hernandez-Andres1999a`, :cite:`Kang2002a`, :cite:`Wikipedia2001`,
360 :cite:`Wikipedia2001a`, :cite:`Wyszecki2000z`
362 Examples
363 --------
364 >>> import numpy as np
365 >>> xy_to_CCT(np.array([0.31270, 0.32900])) # doctest: +ELLIPSIS
366 6508.1175148...
367 >>> xy_to_CCT(np.array([0.31270, 0.32900]), "Hernandez 1999")
368 ... # doctest: +ELLIPSIS
369 6500.7420431...
370 """
372 method = validate_method(method, tuple(XY_TO_CCT_METHODS))
374 return XY_TO_CCT_METHODS[method](xy)
377CCT_TO_XY_METHODS: CanonicalMapping = CanonicalMapping(
378 {
379 "CIE Illuminant D Series": CCT_to_xy_CIE_D,
380 "Hernandez 1999": CCT_to_xy_Hernandez1999,
381 "Kang 2002": CCT_to_xy_Kang2002,
382 "McCamy 1992": CCT_to_xy_McCamy1992,
383 }
384)
385CCT_TO_XY_METHODS.__doc__ = """
386Supported correlated colour temperature :math:`T_{cp}` to *CIE xy* chromaticity
387coordinates computation methods.
389References
390----------
391:cite:`Hernandez-Andres1999a`, :cite:`Kang2002a`, :cite:`Wikipedia2001`,
392:cite:`Wikipedia2001a`, :cite:`Wyszecki2000z`
394Aliases:
396- 'daylight': 'CIE Illuminant D Series'
397- 'kang2002': 'Kang 2002'
398- 'mccamy1992': 'McCamy 1992'
399- 'hernandez1999': 'Hernandez 1999'
400"""
401CCT_TO_XY_METHODS["daylight"] = CCT_TO_XY_METHODS["CIE Illuminant D Series"]
402CCT_TO_XY_METHODS["kang2002"] = CCT_TO_XY_METHODS["Kang 2002"]
403CCT_TO_XY_METHODS["mccamy1992"] = CCT_TO_XY_METHODS["McCamy 1992"]
404CCT_TO_XY_METHODS["hernandez1999"] = CCT_TO_XY_METHODS["Hernandez 1999"]
407def CCT_to_xy(
408 CCT: ArrayLike,
409 method: (
410 Literal[
411 "CIE Illuminant D Series",
412 "Kang 2002",
413 "Hernandez 1999",
414 "McCamy 1992",
415 ]
416 | str
417 ) = "CIE Illuminant D Series",
418) -> NDArrayFloat:
419 """
420 Compute the *CIE xy* chromaticity coordinates from the specified
421 correlated colour temperature :math:`T_{cp}` using the specified method.
423 Parameters
424 ----------
425 CCT
426 Correlated colour temperature :math:`T_{cp}`.
427 method
428 Computation method.
430 Other Parameters
431 ----------------
432 optimisation_kwargs
433 {:func:`colour.temperature.CCT_to_xy_Hernandez1999`,
434 :func:`colour.temperature.CCT_to_xy_McCamy1992`},
435 Parameters for :func:`scipy.optimize.minimize` definition.
437 Returns
438 -------
439 :class:`numpy.ndarray`
440 *CIE xy* chromaticity coordinates.
442 References
443 ----------
444 :cite:`Hernandez-Andres1999a`, :cite:`Kang2002a`, :cite:`Wikipedia2001`,
445 :cite:`Wikipedia2001a`, :cite:`Wyszecki2000z`
447 Examples
448 --------
449 >>> CCT_to_xy(6504.38938305) # doctest: +ELLIPSIS
450 array([ 0.3127077..., 0.3291128...])
451 >>> CCT_to_xy(6504.38938305, "Kang 2002")
452 ... # doctest: +ELLIPSIS
453 array([ 0.313426 ..., 0.3235959...])
454 """
456 method = validate_method(method, tuple(CCT_TO_XY_METHODS))
458 return CCT_TO_XY_METHODS[method](CCT)
461__all__ += [
462 "XY_TO_CCT_METHODS",
463 "xy_to_CCT",
464]
465__all__ += [
466 "CCT_TO_XY_METHODS",
467 "CCT_to_xy",
468]