From abdd88fb72a7db3ba3b4a09218d6ba2fbc78b688 Mon Sep 17 00:00:00 2001 From: Thomas Mansencal Date: Fri, 23 Dec 2022 17:15:47 +1300 Subject: [PATCH] Ensure that "colour.colorimetry.sds_and_msds_to_sds" and "colour.colorimetry.sds_and_msds_to_msds" definitions can take a "colour.SpectralDistribution" argument. --- colour/colorimetry/spectrum.py | 12 ++++++++---- colour/colorimetry/tests/test_spectrum.py | 3 +++ colour/colorimetry/uniformity.py | 1 + colour/plotting/colorimetry.py | 1 + colour/plotting/diagrams.py | 1 + colour/plotting/quality.py | 2 ++ 6 files changed, 16 insertions(+), 4 deletions(-) diff --git a/colour/colorimetry/spectrum.py b/colour/colorimetry/spectrum.py index 2900cc35de..3a7c52f3be 100644 --- a/colour/colorimetry/spectrum.py +++ b/colour/colorimetry/spectrum.py @@ -30,7 +30,6 @@ import numpy as np from collections.abc import Mapping - from colour.algebra import ( Extrapolator, CubicSplineInterpolator, @@ -2757,7 +2756,6 @@ def strict_labels(self, value): # pragma: no cover # noqa: D102 f"{__name__}._CACHE_RESHAPED_SDS_AND_MSDS" ) - TypeSpectralDistribution = TypeVar( "TypeSpectralDistribution", bound="SpectralDistribution" ) @@ -2884,6 +2882,7 @@ def reshape_msds( def sds_and_msds_to_sds( sds: Union[ Sequence[Union[SpectralDistribution, MultiSpectralDistributions]], + SpectralDistribution, MultiSpectralDistributions, ] ) -> List[SpectralDistribution]: @@ -2929,7 +2928,9 @@ def sds_and_msds_to_sds( 8 """ - if isinstance(sds, MultiSpectralDistributions): + if isinstance(sds, SpectralDistribution): + return sds_and_msds_to_sds([sds]) + elif isinstance(sds, MultiSpectralDistributions): sds_converted = sds.to_sds() else: sds_converted = [] @@ -2946,6 +2947,7 @@ def sds_and_msds_to_sds( def sds_and_msds_to_msds( sds: Union[ Sequence[Union[SpectralDistribution, MultiSpectralDistributions]], + SpectralDistribution, MultiSpectralDistributions, ] ) -> MultiSpectralDistributions: @@ -3028,7 +3030,9 @@ def sds_and_msds_to_msds( extrapolator_kwargs={...}) """ - if isinstance(sds, MultiSpectralDistributions): + if isinstance(sds, SpectralDistribution): + return sds_and_msds_to_msds([sds]) + elif isinstance(sds, MultiSpectralDistributions): msds_converted = sds else: sds_converted = sds_and_msds_to_sds(sds) diff --git a/colour/colorimetry/tests/test_spectrum.py b/colour/colorimetry/tests/test_spectrum.py index 974a2db3f3..9472f763bb 100644 --- a/colour/colorimetry/tests/test_spectrum.py +++ b/colour/colorimetry/tests/test_spectrum.py @@ -1950,6 +1950,7 @@ def test_sds_and_msds_to_sds(self): multi_sds_1 = MultiSpectralDistributions(DATA_MULTI_SAMPLE_ABRIDGED) multi_sds_2 = MultiSpectralDistributions(DATA_MULTI_SAMPLE_ABRIDGED) + self.assertEqual(sds_and_msds_to_sds(sd_1), [sd_1]) self.assertEqual( len( sds_and_msds_to_sds( @@ -1984,6 +1985,8 @@ def test_sds_and_msds_to_msds(self): multi_sds_1 = MultiSpectralDistributions(DATA_MULTI_SAMPLE_ABRIDGED) multi_sds_2 = MultiSpectralDistributions(DATA_MULTI_SAMPLE_ABRIDGED) + self.assertEqual(len(sds_and_msds_to_msds(sd_1)), 6) + self.assertEqual(sds_and_msds_to_msds(multi_sds_1), multi_sds_1) multi_sds_0 = sds_and_msds_to_msds([multi_sds_1]) diff --git a/colour/colorimetry/uniformity.py b/colour/colorimetry/uniformity.py index fd70348ce3..34fecd896e 100644 --- a/colour/colorimetry/uniformity.py +++ b/colour/colorimetry/uniformity.py @@ -39,6 +39,7 @@ def spectral_uniformity( sds: Union[ Sequence[Union[SpectralDistribution, MultiSpectralDistributions]], + SpectralDistribution, MultiSpectralDistributions, ], use_second_order_derivatives: bool = False, diff --git a/colour/plotting/colorimetry.py b/colour/plotting/colorimetry.py index a7ca291cee..a2012e1ad0 100644 --- a/colour/plotting/colorimetry.py +++ b/colour/plotting/colorimetry.py @@ -271,6 +271,7 @@ def plot_single_sd( def plot_multi_sds( sds: Union[ Sequence[Union[SpectralDistribution, MultiSpectralDistributions]], + SpectralDistribution, MultiSpectralDistributions, ], plot_kwargs: Optional[Union[dict, List[dict]]] = None, diff --git a/colour/plotting/diagrams.py b/colour/plotting/diagrams.py index f03219cabc..c47c4454b6 100644 --- a/colour/plotting/diagrams.py +++ b/colour/plotting/diagrams.py @@ -797,6 +797,7 @@ def plot_chromaticity_diagram_CIE1976UCS( def plot_sds_in_chromaticity_diagram( sds: Union[ Sequence[Union[SpectralDistribution, MultiSpectralDistributions]], + SpectralDistribution, MultiSpectralDistributions, ], cmfs: Union[ diff --git a/colour/plotting/quality.py b/colour/plotting/quality.py index 10e83108ba..58e40f57e1 100644 --- a/colour/plotting/quality.py +++ b/colour/plotting/quality.py @@ -290,6 +290,7 @@ def plot_single_sd_colour_rendering_index_bars( def plot_multi_sds_colour_rendering_indexes_bars( sds: Union[ Sequence[Union[SpectralDistribution, MultiSpectralDistributions]], + SpectralDistribution, MultiSpectralDistributions, ], **kwargs: Any, @@ -428,6 +429,7 @@ def plot_single_sd_colour_quality_scale_bars( def plot_multi_sds_colour_quality_scales_bars( sds: Union[ Sequence[Union[SpectralDistribution, MultiSpectralDistributions]], + SpectralDistribution, MultiSpectralDistributions, ], method: Union[