Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PR: Ohno (2013) Correlated Colour Temperature Performance Improvements #951

Merged
merged 7 commits into from
Mar 2, 2022
2 changes: 1 addition & 1 deletion README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -1184,7 +1184,7 @@ Correlated Colour Temperature Computation Methods - ``colour.temperature``
>>> colour.uv_to_CCT([0.1978, 0.3122])
array([ 6.50751282e+03, 3.22335875e-03])
>>> sorted(colour.UV_TO_CCT_METHODS)
['Krystek 1985', 'Ohno 2013', 'Robertson 1968', 'ohno2013', 'robertson1968']
['Krystek 1985', 'Ohno 2013', 'Planck 1900', 'Robertson 1968', 'ohno2013', 'robertson1968']
>>> sorted(colour.XY_TO_CCT_METHODS)
['CIE Illuminant D Series',
'Hernandez 1999',
Expand Down
10 changes: 7 additions & 3 deletions colour/colorimetry/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,11 @@
sds_and_msds_to_sds,
sds_and_msds_to_msds,
)
from .blackbody import sd_blackbody, blackbody_spectral_radiance, planck_law
from .blackbody import (
planck_law,
blackbody_spectral_radiance,
sd_blackbody,
)
from .cmfs import (
LMS_ConeFundamentals,
RGB_ColourMatchingFunctions,
Expand Down Expand Up @@ -130,9 +134,9 @@
"sds_and_msds_to_msds",
]
__all__ += [
"sd_blackbody",
"blackbody_spectral_radiance",
"planck_law",
"blackbody_spectral_radiance",
"sd_blackbody",
]
__all__ += [
"LMS_ConeFundamentals",
Expand Down
437 changes: 23 additions & 414 deletions colour/colorimetry/blackbody.py

Large diffs are not rendered by default.

20 changes: 17 additions & 3 deletions colour/colorimetry/tests/test_blackbody.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,11 @@
import unittest
from itertools import permutations

from colour.colorimetry import SpectralShape, planck_law, sd_blackbody
from colour.colorimetry import (
SpectralShape,
planck_law,
sd_blackbody,
)
from colour.hints import Dict, NDArray
from colour.utilities import ignore_numpy_errors

Expand Down Expand Up @@ -4541,13 +4545,23 @@ def test_n_dimensional_planck_law(self):
np.testing.assert_almost_equal(planck_law(wl, 5500), p)

wl = np.reshape(wl, (2, 3))
p = np.reshape(p, (2, 3))
# The "colour.colorimetry.planck_law" definition behaviour with
# n-dimensional arrays is unusual.
# p = np.np.reshape(p, (2, 3))
np.testing.assert_almost_equal(planck_law(wl, 5500), p)

wl = np.reshape(wl, (2, 3, 1))
p = np.reshape(p, (2, 3, 1))
# The "colour.colorimetry.planck_law" definition behaviour with
# n-dimensional arrays is unusual.
# p = np.reshape(p, (2, 3, 1))
np.testing.assert_almost_equal(planck_law(wl, 5500), p)

# The "colour.colorimetry.planck_law" definition behaviour with
# n-dimensional arrays is unusual.
p = planck_law(500 * 1e-9, [5000, 5500, 6000])
p = np.tile(p, (6, 1))
np.testing.assert_almost_equal(planck_law(wl, [5000, 5500, 6000]), p)

@ignore_numpy_errors
def test_nan_planck_law(self):
"""
Expand Down
14 changes: 8 additions & 6 deletions colour/continuous/multi_signals.py
Original file line number Diff line number Diff line change
Expand Up @@ -1459,12 +1459,11 @@ def multi_signals_unpack_data(
):
data_sequence = list(data) # type: ignore[arg-type]

is_signal = all(
[
True if isinstance(i, Signal) else False
for i in data_sequence
]
)
is_signal = True
for i in data_sequence:
if not isinstance(i, Signal):
is_signal = False
break

if is_signal:
for signal in data_sequence:
Expand Down Expand Up @@ -1541,6 +1540,9 @@ def multi_signals_unpack_data(
'"signals"!',
)

if len(labels) != len(set(labels)):
labels = [f"{label} - {i}" for i, label in enumerate(labels)]

signals = {
str(labels[i]): signal
for i, signal in enumerate(signals.values())
Expand Down
10 changes: 5 additions & 5 deletions colour/examples/colorimetry/examples_blackbody.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@
message_box("Blackbody / Planckian Radiator Computations")

message_box(
"Computing the spectral distribution of a blackbody at temperature 5500K"
"Computing the spectral distribution of a blackbody at temperature 5000K"
'degrees and converting to "CIE XYZ" tristimulus values.'
)
cmfs = colour.MSDS_CMFS["CIE 1931 2 Degree Standard Observer"]
sd_blackbody = colour.sd_blackbody(5500, cmfs.shape)
sd_blackbody = colour.sd_blackbody(5000, cmfs.shape)
print(sd_blackbody)
XYZ = colour.sd_to_XYZ(sd_blackbody, cmfs)
print(XYZ)
Expand All @@ -19,7 +19,7 @@

message_box(
"Computing the spectral radiance of a blackbody at wavelength 500nm and "
"temperature 5500K degrees."
"temperature 5000K degrees."
)
print(colour.colorimetry.blackbody_spectral_radiance(500 * 1e-9, 5500))
print(colour.colorimetry.planck_law(500 * 1e-9, 5500))
print(colour.colorimetry.blackbody_spectral_radiance(500 * 1e-9, 5000))
print(colour.colorimetry.planck_law(500 * 1e-9, 5000))
9 changes: 9 additions & 0 deletions colour/examples/temperature/examples_cct.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,15 @@
print("\n")

CCT = 6503.49254150
message_box(
f'Converting to "CIE UCS" colourspace "uv" chromaticity coordinates from '
f'given "CCT" using "Planck (1900)" method:\n\n\t{CCT_D_uv}'
)
print(colour.CCT_to_uv(CCT, method="Planck 1900"))
print(colour.temperature.CCT_to_uv_Planck1900(CCT))

print("\n")

message_box(
f'Converting to "CIE UCS" colourspace "uv" chromaticity coordinates from '
f'given "CCT" using "Krystek (1985)" method:\n\n\t({CCT})'
Expand Down
40 changes: 28 additions & 12 deletions colour/temperature/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@
Development Kit (SDK) - 1.3.0.0 -
dng_sdk_1_3/dng_sdk/source/dng_temperature.cpp::dng_temperature::xy_coord.
https://www.adobe.com/support/downloads/dng/dng_sdk.html
- :cite:`CIETC1-482004i` : CIE TC 1-48. (2004). APPENDIX E. INFORMATION ON
THE USE OF PLANCK'S EQUATION FOR STANDARD AIR. In CIE 015:2004 Colorimetry,
3rd Edition (pp. 77-82). ISBN:978-3-901906-33-6
- :cite:`Hernandez-Andres1999a` : Hernández-Andrés, J., Lee, R. L., &
Romero, J. (1999). Calculating correlated color temperatures across the
entire gamut of daylight and skylight chromaticities. Applied Optics,
Expand Down Expand Up @@ -58,6 +61,7 @@
from .kang2002 import xy_to_CCT_Kang2002, CCT_to_xy_Kang2002
from .krystek1985 import uv_to_CCT_Krystek1985, CCT_to_uv_Krystek1985
from .mccamy1992 import xy_to_CCT_McCamy1992, CCT_to_xy_McCamy1992
from .planck1900 import uv_to_CCT_Planck1900, CCT_to_uv_Planck1900
from .ohno2013 import uv_to_CCT_Ohno2013, CCT_to_uv_Ohno2013
from .robertson1968 import uv_to_CCT_Robertson1968, CCT_to_uv_Robertson1968

Expand All @@ -81,6 +85,10 @@
"xy_to_CCT_McCamy1992",
"CCT_to_xy_McCamy1992",
]
__all__ += [
"uv_to_CCT_Planck1900",
"CCT_to_uv_Planck1900",
]
__all__ += [
"uv_to_CCT_Ohno2013",
"CCT_to_uv_Ohno2013",
Expand All @@ -94,6 +102,7 @@
{
"Krystek 1985": uv_to_CCT_Krystek1985,
"Ohno 2013": uv_to_CCT_Ohno2013,
"Planck 1900": uv_to_CCT_Planck1900,
"Robertson 1968": uv_to_CCT_Robertson1968,
}
)
Expand All @@ -103,8 +112,8 @@

References
----------
:cite:`AdobeSystems2013`, :cite:`AdobeSystems2013a`, :cite:`Krystek1985b`,
:cite:`Ohno2014a`, :cite:`Wyszecki2000y`
:cite:`AdobeSystems2013`, :cite:`AdobeSystems2013a`, :cite:`CIETC1-482004i`,
:cite:`Krystek1985b`, :cite:`Ohno2014a`, :cite:`Wyszecki2000y`

Aliases:

Expand All @@ -118,7 +127,8 @@
def uv_to_CCT(
uv: ArrayLike,
method: Union[
Literal["Krystek 1985", "Ohno 2013", "Robertson 1968"], str
Literal["Krystek 1985", "Ohno 2013", "Planck 1900", "Robertson 1968"],
str,
] = "Ohno 2013",
**kwargs: Any,
) -> NDArray:
Expand All @@ -137,7 +147,8 @@ def uv_to_CCT(
Other Parameters
----------------
cmfs
{:func:`colour.temperature.uv_to_CCT_Ohno2013`},
{:func:`colour.temperature.uv_to_CCT_Ohno2013`,
:func:`colour.temperature.uv_to_CCT_Planck1900`},
Standard observer colour matching functions.
count
{:func:`colour.temperature.uv_to_CCT_Ohno2013`},
Expand All @@ -162,8 +173,9 @@ def uv_to_CCT(

References
----------
:cite:`AdobeSystems2013`, :cite:`AdobeSystems2013a`, :cite:`Krystek1985b`,
:cite:`Ohno2014a`, :cite:`Wyszecki2000y`
:cite:`AdobeSystems2013`, :cite:`AdobeSystems2013a`,
:cite:`CIETC1-482004i`, :cite:`Krystek1985b`, :cite:`Ohno2014a`,
:cite:`Wyszecki2000y`

Examples
--------
Expand All @@ -184,6 +196,7 @@ def uv_to_CCT(
{
"Krystek 1985": CCT_to_uv_Krystek1985,
"Ohno 2013": CCT_to_uv_Ohno2013,
"Planck 1900": CCT_to_uv_Planck1900,
"Robertson 1968": CCT_to_uv_Robertson1968,
}
)
Expand All @@ -193,8 +206,8 @@ def uv_to_CCT(

References
----------
:cite:`AdobeSystems2013`, :cite:`AdobeSystems2013a`, :cite:`Krystek1985b`,
:cite:`Ohno2014a`, :cite:`Wyszecki2000y`
:cite:`AdobeSystems2013`, :cite:`AdobeSystems2013a`, :cite:`CIETC1-482004i`,
:cite:`Krystek1985b`, :cite:`Ohno2014a`, :cite:`Wyszecki2000y`

Aliases:

Expand All @@ -208,7 +221,8 @@ def uv_to_CCT(
def CCT_to_uv(
CCT_D_uv: ArrayLike,
method: Union[
Literal["Krystek 1985", "Ohno 2013", "Robertson 1968"], str
Literal["Krystek 1985", "Ohno 2013", "Planck 1900", "Robertson 1968"],
str,
] = "Ohno 2013",
**kwargs: Any,
) -> NDArray:
Expand All @@ -226,7 +240,8 @@ def CCT_to_uv(
Other Parameters
----------------
cmfs
{:func:`colour.temperature.CCT_to_uv_Ohno2013`},
{:func:`colour.temperature.CCT_to_uv_Ohno2013`,
:func:`colour.temperature.CCT_to_uv_Planck1900`},
Standard observer colour matching functions.

Returns
Expand All @@ -236,8 +251,9 @@ def CCT_to_uv(

References
----------
:cite:`AdobeSystems2013`, :cite:`AdobeSystems2013a`, :cite:`Krystek1985b`,
:cite:`Ohno2014a`, :cite:`Wyszecki2000y`
:cite:`AdobeSystems2013`, :cite:`AdobeSystems2013a`,
:cite:`CIETC1-482004i`, :cite:`Krystek1985b`, :cite:`Ohno2014a`,
:cite:`Wyszecki2000y`

Examples
--------
Expand Down
12 changes: 5 additions & 7 deletions colour/temperature/hernandez1999.py
Original file line number Diff line number Diff line change
Expand Up @@ -139,13 +139,11 @@ def CCT_to_xy_Hernandez1999(
"""

usage_warning(
'"Hernandez-Andres et al. (1999)" method for computing '
'"CIE xy" chromaticity coordinates from given correlated '
"colour temperature is not a bijective function and and"
"might produce unexpected results. It is given for "
"consistency with other correlated colour temperature "
"computation methods but should be avoided for practical "
"applications."
'"Hernandez-Andres et al. (1999)" method for computing "CIE xy" '
"chromaticity coordinates from given correlated colour temperature is "
"not a bijective function and might produce unexpected results. It is "
"given for consistency with other correlated colour temperature "
"computation methods but should be avoided for practical applications."
)

CCT = as_float_array(CCT)
Expand Down
11 changes: 5 additions & 6 deletions colour/temperature/mccamy1992.py
Original file line number Diff line number Diff line change
Expand Up @@ -122,12 +122,11 @@ def CCT_to_xy_McCamy1992(
"""

usage_warning(
'"McCamy (1992)" method for computing "CIE xy" '
"chromaticity coordinates from given correlated colour "
"temperature is not a bijective function and might produce "
"unexpected results. It is given for consistency with other "
"correlated colour temperature computation methods but "
"should be avoided for practical applications."
'"McCamy (1992)" method for computing "CIE xy" chromaticity '
"coordinates from given correlated colour temperature is not a "
"bijective function and might produce unexpected results. It is given "
"for consistency with other correlated colour temperature computation "
"methods but should be avoided for practical applications."
)

CCT = as_float_array(CCT)
Expand Down
Loading