Skip to content

Commit 92067ee

Browse files
committed
CRI: Fix integration of TCS15
This commit fixes the TCS15 integration with the following steps: * Adding COLOUR_RENDERING_INDEX_METHODS to switch between "CIE 1995" and "CIE 2024" TCS sets * Introduce `SDS_TCS_SETS` to get the TCS set for the desired method * Introduce SDS_TCS_CIE_1995 (was SDS_TCS before) SDS_TCS_CIE_2024 * Add new parameter `method` to colour.colour_rendering_index to select the TCS set * Add a test for this new `method` parameter * Adjust the docs to reflect these changes with inspiration from the symbols exported by the CQS module Suggested-by: Thomas Mansencal <[email protected]> Signed-off-by: Christoph Müllner <[email protected]>
1 parent 901a609 commit 92067ee

File tree

9 files changed

+157
-11
lines changed

9 files changed

+157
-11
lines changed

README.rst

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1802,6 +1802,14 @@ Colour Rendering Index
18021802
18031803
64.233724121664793
18041804
1805+
.. code-block:: python
1806+
1807+
sorted(colour.COLOUR_RENDERING_INDEX_METHODS)
1808+
1809+
.. code-block:: text
1810+
1811+
['CIE 1995', 'CIE 2024']
1812+
18051813
Academy Spectral Similarity Index (SSI)
18061814
***************************************
18071815

colour/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -443,6 +443,7 @@
443443
from .quality import (
444444
COLOUR_FIDELITY_INDEX_METHODS,
445445
COLOUR_QUALITY_SCALE_METHODS,
446+
COLOUR_RENDERING_INDEX_METHODS,
446447
colour_fidelity_index,
447448
colour_quality_scale,
448449
colour_rendering_index,
@@ -838,6 +839,7 @@
838839
__all__ += [
839840
"COLOUR_FIDELITY_INDEX_METHODS",
840841
"COLOUR_QUALITY_SCALE_METHODS",
842+
"COLOUR_RENDERING_INDEX_METHODS",
841843
"colour_fidelity_index",
842844
"colour_quality_scale",
843845
"colour_rendering_index",

colour/quality/__init__.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,11 @@
1414
ColourRendering_Specification_CIE2017,
1515
colour_fidelity_index_CIE2017,
1616
)
17-
from .cri import ColourRendering_Specification_CRI, colour_rendering_index
17+
from .cri import (
18+
COLOUR_RENDERING_INDEX_METHODS,
19+
ColourRendering_Specification_CRI,
20+
colour_rendering_index,
21+
)
1822
from .cqs import (
1923
COLOUR_QUALITY_SCALE_METHODS,
2024
ColourRendering_Specification_CQS,
@@ -38,6 +42,7 @@
3842
"colour_fidelity_index_ANSIIESTM3018",
3943
]
4044
__all__ += [
45+
"COLOUR_RENDERING_INDEX_METHODS",
4146
"ColourRendering_Specification_CRI",
4247
"colour_rendering_index",
4348
]

colour/quality/cri.py

Lines changed: 37 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -40,9 +40,10 @@
4040

4141
from colour.hints import cast
4242
from colour.models import UCS_to_uv, XYZ_to_UCS, XYZ_to_xyY
43-
from colour.quality.datasets.tcs import INDEXES_TO_NAMES_TCS, SDS_TCS
43+
from colour.quality.datasets.tcs import INDEXES_TO_NAMES_TCS, SDS_TCS_SETS
4444
from colour.temperature import CCT_to_xy_CIE_D, uv_to_CCT_Robertson1968
45-
from colour.utilities import domain_range_scale
45+
from colour.utilities import domain_range_scale, validate_method
46+
from colour.utilities.documentation import DocstringTuple, is_documentation_building
4647

4748
__author__ = "Colour Developers"
4849
__copyright__ = "Copyright 2013 Colour Developers"
@@ -55,6 +56,7 @@
5556
"DataColorimetry_TCS",
5657
"DataColourQualityScale_TCS",
5758
"ColourRendering_Specification_CRI",
59+
"COLOUR_RENDERING_INDEX_METHODS",
5860
"colour_rendering_index",
5961
"tcs_colorimetry_data",
6062
"colour_rendering_indexes",
@@ -110,26 +112,47 @@ class ColourRendering_Specification_CRI:
110112
]
111113

112114

115+
COLOUR_RENDERING_INDEX_METHODS: tuple = ("CIE 1995", "CIE 2024")
116+
if is_documentation_building(): # pragma: no cover
117+
COLOUR_RENDERING_INDEX_METHODS = DocstringTuple(COLOUR_RENDERING_INDEX_METHODS)
118+
COLOUR_RENDERING_INDEX_METHODS.__doc__ = """
119+
Supported *Colour Rendering Index* (CRI) computation methods.
120+
121+
References
122+
----------
123+
:cite:`Ohno2008a`
124+
"""
125+
126+
113127
@typing.overload
114128
def colour_rendering_index(
115-
sd_test: SpectralDistribution, additional_data: Literal[True] = True
129+
sd_test: SpectralDistribution,
130+
additional_data: Literal[True] = True,
131+
method: Literal["CIE 1995", "CIE 2024"] | str = ...,
116132
) -> ColourRendering_Specification_CRI: ...
117133

118134

119135
@typing.overload
120136
def colour_rendering_index(
121-
sd_test: SpectralDistribution, *, additional_data: Literal[False]
137+
sd_test: SpectralDistribution,
138+
*,
139+
additional_data: Literal[False],
140+
method: Literal["CIE 1995", "CIE 2024"] | str = ...,
122141
) -> float: ...
123142

124143

125144
@typing.overload
126145
def colour_rendering_index(
127-
sd_test: SpectralDistribution, additional_data: Literal[False]
146+
sd_test: SpectralDistribution,
147+
additional_data: Literal[False],
148+
method: Literal["CIE 1995", "CIE 2024"] | str = ...,
128149
) -> float: ...
129150

130151

131152
def colour_rendering_index(
132-
sd_test: SpectralDistribution, additional_data: bool = False
153+
sd_test: SpectralDistribution,
154+
additional_data: bool = False,
155+
method: Literal["CIE 1995", "CIE 2024"] | str = "CIE 1995",
133156
) -> float | ColourRendering_Specification_CRI:
134157
"""
135158
Return the *Colour Rendering Index* (CRI) :math:`Q_a` of given spectral
@@ -141,6 +164,8 @@ def colour_rendering_index(
141164
Test spectral distribution.
142165
additional_data
143166
Whether to output additional data.
167+
method
168+
Computation method.
144169
145170
Returns
146171
-------
@@ -160,6 +185,8 @@ def colour_rendering_index(
160185
64.2337241...
161186
"""
162187

188+
method = validate_method(method, tuple(COLOUR_RENDERING_INDEX_METHODS))
189+
163190
cmfs = reshape_msds(
164191
MSDS_CMFS["CIE 1931 2 Degree Standard Observer"],
165192
SPECTRAL_SHAPE_DEFAULT,
@@ -168,7 +195,8 @@ def colour_rendering_index(
168195

169196
shape = cmfs.shape
170197
sd_test = reshape_sd(sd_test, shape, copy=False)
171-
tcs_sds = {sd.name: reshape_sd(sd, shape, copy=False) for sd in SDS_TCS.values()}
198+
sds_tcs = SDS_TCS_SETS[method]
199+
tcs_sds = {sd.name: reshape_sd(sd, shape, copy=False) for sd in sds_tcs.values()}
172200

173201
with domain_range_scale("1"):
174202
XYZ = sd_to_XYZ(sd_test, cmfs)
@@ -250,6 +278,8 @@ def tcs_colorimetry_data(
250278

251279
tcs_data = []
252280
for _key, value in sorted(INDEXES_TO_NAMES_TCS.items()):
281+
if value not in sds_tcs:
282+
continue
253283
sd_tcs = sds_tcs[value]
254284
XYZ_tcs = sd_to_XYZ(sd_tcs, cmfs, sd_t)
255285
xyY_tcs = XYZ_to_xyY(XYZ_tcs)

colour/quality/datasets/__init__.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
1-
from .tcs import SDS_TCS
1+
from .tcs import SDS_TCS, SDS_TCS_SETS
22
from .vs import SDS_VS
33

44
__all__ = [
55
"SDS_TCS",
6+
"SDS_TCS_SETS",
67
"SDS_VS",
78
]

colour/quality/datasets/tcs.py

Lines changed: 64 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,9 @@
3434
"INDEXES_TO_NAMES_TCS",
3535
"APPROXIMATE_MUNSELL_NOTATIONS_TCS",
3636
"DATA_TCS",
37+
"SDS_TCS_CIE_1995",
38+
"SDS_TCS_CIE_2024",
39+
"SDS_TCS_SETS",
3740
"SDS_TCS",
3841
]
3942

@@ -1521,9 +1524,68 @@
15211524
},
15221525
}
15231526

1524-
SDS_TCS: CanonicalMapping = CanonicalMapping(
1525-
{key: SpectralDistribution(value, name=key) for key, value in DATA_TCS.items()}
1527+
SDS_TCS_CIE_1995: CanonicalMapping = CanonicalMapping(
1528+
{
1529+
key: SpectralDistribution(value, name=key)
1530+
for key, value in {
1531+
x: DATA_TCS[x]
1532+
for x in [
1533+
"TCS01",
1534+
"TCS02",
1535+
"TCS03",
1536+
"TCS04",
1537+
"TCS05",
1538+
"TCS06",
1539+
"TCS07",
1540+
"TCS08",
1541+
"TCS09",
1542+
"TCS10",
1543+
"TCS11",
1544+
"TCS12",
1545+
"TCS13",
1546+
"TCS14",
1547+
]
1548+
}.items()
1549+
}
15261550
)
1551+
1552+
SDS_TCS_CIE_2024: CanonicalMapping = CanonicalMapping(
1553+
{
1554+
key: SpectralDistribution(value, name=key)
1555+
for key, value in {
1556+
x: DATA_TCS[x]
1557+
for x in [
1558+
"TCS01",
1559+
"TCS02",
1560+
"TCS03",
1561+
"TCS04",
1562+
"TCS05",
1563+
"TCS06",
1564+
"TCS07",
1565+
"TCS08",
1566+
"TCS09",
1567+
"TCS10",
1568+
"TCS11",
1569+
"TCS12",
1570+
"TCS13",
1571+
"TCS14",
1572+
"TCS15",
1573+
]
1574+
}.items()
1575+
}
1576+
)
1577+
1578+
SDS_TCS_SETS: CanonicalMapping = CanonicalMapping(
1579+
{
1580+
"CIE 1995": SDS_TCS_CIE_1995,
1581+
"CIE 2024": SDS_TCS_CIE_2024,
1582+
}
1583+
)
1584+
1585+
# TODO: deprecate SDS_TCS (was renamed to SDS_TCS_CIE_1995)
1586+
SDS_TCS = SDS_TCS_CIE_1995
1587+
1588+
15271589
"""
15281590
Test colour samples spectral distributions.
15291591

colour/quality/tests/test_cri.py

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -348,6 +348,35 @@ def test_colour_rendering_index(self) -> None:
348348
),
349349
)
350350

351+
specification_t = colour_rendering_index(
352+
SDS_ILLUMINANTS["FL1"], additional_data=True, method="CIE 2024"
353+
)
354+
355+
np.testing.assert_allclose(
356+
[data.Q_a for _index, data in sorted(specification_r.Q_as.items())],
357+
[data.Q_a for _index, data in sorted(specification_t.Q_as.items())],
358+
atol=TOLERANCE_ABSOLUTE_TESTS,
359+
)
360+
361+
# Drop CIE 2024 results to get CIE 1995 results
362+
specification_r.Q_as.pop(15)
363+
specification_r.colorimetry_data[0] =
364+
specification_r.colorimetry_data[0][:-1]
365+
specification_r.colorimetry_data[1] =
366+
specification_r.colorimetry_data[1][:-1]
367+
368+
# Test for CIE 1995
369+
specification_t = colour_rendering_index(
370+
SDS_ILLUMINANTS["FL1"], additional_data=True, method="CIE 1995"
371+
)
372+
373+
np.testing.assert_allclose(
374+
[data.Q_a for _index, data in sorted(specification_r.Q_as.items())],
375+
[data.Q_a for _index, data in sorted(specification_t.Q_as.items())],
376+
atol=TOLERANCE_ABSOLUTE_TESTS,
377+
)
378+
379+
# If method not defined, then CIE 1995 is used
351380
specification_t = colour_rendering_index(
352381
SDS_ILLUMINANTS["FL1"], additional_data=True
353382
)

docs/colour.quality.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ Colour Rendering Index
3636
.. autosummary::
3737
:toctree: generated/
3838

39+
COLOUR_RENDERING_INDEX_METHODS
3940
colour_rendering_index
4041

4142
``colour.quality``

docs/index.rst

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1537,6 +1537,14 @@ Colour Rendering Index
15371537
15381538
64.233724121664793
15391539
1540+
.. code-block:: python
1541+
1542+
sorted(colour.COLOUR_RENDERING_INDEX_METHODS)
1543+
1544+
.. code-block:: text
1545+
1546+
['CIE 1995', 'CIE 2024']
1547+
15401548
Academy Spectral Similarity Index (SSI)
15411549
***************************************
15421550

0 commit comments

Comments
 (0)