From 16ae78784648615c5152d3b671769dda090bc29e Mon Sep 17 00:00:00 2001 From: Christian Greim <36072637+gutenzwerg@users.noreply.github.com> Date: Mon, 1 Feb 2021 20:38:00 +0100 Subject: [PATCH 01/46] Feature MacAdam_Limits This features calculates MacAdam_Limits according to a given brightness for every single whavelenght --- colour/volume/__init__.py | 4 + colour/volume/macadam_limits.py | 181 +++++++++++++++++++++++++++++++- 2 files changed, 184 insertions(+), 1 deletion(-) diff --git a/colour/volume/__init__.py b/colour/volume/__init__.py index 9871de1be..55fcfdfc7 100644 --- a/colour/volume/__init__.py +++ b/colour/volume/__init__.py @@ -1,6 +1,7 @@ from .datasets import * # noqa from . import datasets from .macadam_limits import is_within_macadam_limits +from .macadam_limits import macadam_limits from .mesh import is_within_mesh_volume from .pointer_gamut import is_within_pointer_gamut from .spectrum import ( @@ -22,6 +23,9 @@ __all__ += [ "is_within_macadam_limits", ] +__all__ += [ + 'macadam_limits' +] __all__ += [ "is_within_mesh_volume", ] diff --git a/colour/volume/macadam_limits.py b/colour/volume/macadam_limits.py index c7a8d7bf4..8a8added9 100644 --- a/colour/volume/macadam_limits.py +++ b/colour/volume/macadam_limits.py @@ -22,8 +22,9 @@ from colour.models import xyY_to_XYZ from colour.volume import OPTIMAL_COLOUR_STIMULI_ILLUMINANTS from colour.utilities import CACHE_REGISTRY, validate_method +from colour.colorimetry import MSDS_CMFS, SpectralShape, SDS_ILLUMINANTS -__author__ = "Colour Developers" +__author__ = "Colour Developers", "Christian Greim" __copyright__ = "Copyright 2013 Colour Developers" __license__ = "New BSD License - https://opensource.org/licenses/BSD-3-Clause" __maintainer__ = "Colour Developers" @@ -142,3 +143,181 @@ def is_within_macadam_limits( simplex = np.where(simplex >= 0, True, False) return simplex + + +def macadam_limits(target_brightness, illuminant=()): + """ + whavelenght reaches from 360 to 830 nm, in within the programm it is + handled as 0 to 470. Beyond the references this programm is very fast, + because the possible optimums are not simply tested step by step but + more effectively targeted by steps of power of two. The whavelenghts + left and right of a rough optimum are fited by a rule of proportion, + so that the wished brightness will be reached exactly. + + Parameters + ---------- + target_brightness : floating point + brightness has to be between 0 and 1 + + illuminant: object + illuminant must be out of colorimetry.MSDS_CMFS['XXX'] + If there is no illuminant or it has the wrong form, + the illuminant SDS_ILLUMINANTS['E'] + is choosen wich has no influence to the calculations, + because it is an equal-energy-spectrum + + if necessary a third parameter for the + colour-matching funciton could easily be implemented + + Returns + ------- + an array of CIE -X,Y,Z - Triples for every single whavelength + in single nm - Steps in the range from 360 to 830 nm + + References + ---------- + - cite: Wyszecki, G., & Stiles, W. S. (2000). + In Color Science: Concepts and Methods, + Quantitative Data and Formulae (pp. 181–184). Wiley. + ISBN:978-0-471-39918-6 + - cite: Francisco Martínez-Verdú, Esther Perales, + Elisabet Chorro, Dolores de Fez, + Valentín Viqueira, and Eduardo Gilabert, "Computation and + visualization of the MacAdam limits + for any lightness, hue angle, and light source," J. + Opt. Soc. Am. A 24, 1501-1515 (2007) + - cite: Kenichiro Masaoka. In OPTICS LETTERS, June 15, 2010 + / Vol. 35, No. 1 (pp. 2031 - 2033) + + Example + -------- + from matplotlib import pyplot as plt + import numpy as np + import math + fig = plt.figure(figsize=(7,7)) + ax = fig.add_axes([0,0,1,1]) + illuminant = colour.SDS_ILLUMINANTS['D65'] + + def plot_Narrowband_Spectra (Yxy_Narrowband_Spectra): + FirstColumn = 0 + SecondColumn = 1 + + x = Yxy_Narrowband_Spectra[...,FirstColumn] + y = Yxy_Narrowband_Spectra[...,SecondColumn] + ax.plot(x,y,'orange',label='Spectrum Loci') + + x = [Yxy_Narrowband_Spectra[-1][FirstColumn], + Yxy_Narrowband_Spectra[0][FirstColumn]] + y = [Yxy_Narrowband_Spectra[-1][SecondColumn], + Yxy_Narrowband_Spectra[0][SecondColumn]] + ax.plot(x,y,'purple',label='Purple Boundary') + return() + + for n in range(1, 20): + Yxy_Narrowband_Spectra = colour.XYZ_to_xy( + colour.macadam_limits(n/20, illuminant) / 100) + plot_Narrowband_Spectra (Yxy_Narrowband_Spectra) + + plt.show() + """ + target_bright = target_brightness + if target_bright > 1 or target_bright < 0: + raise TypeError('brightness of function macadam_limits( )' + 'has to be between 0 and 1') + standard_cfms = MSDS_CMFS['CIE 1931 2 Degree Standard Observer'] + X_cie31 = standard_cfms.values[..., 0] + Y_cie31 = standard_cfms.values[..., 1] + Z_cie31 = standard_cfms.values[..., 2] + try: + illuminant.interpolator + except AttributeError: + illuminant = SDS_ILLUMINANTS['E'] + + +# If there is no illuminant or it has the wrong form, +# an illuminant choosen with no influence +# If the illuminanats do not match the format of the Standard Observer, +# they have to be adaptet + illuminant.extrapolate(SpectralShape(360, 830)) + illuminant.interpolate(SpectralShape(360, 830, 1)) + # The cie31 cmfs are convolved with the given illuminant + X_illuminated = X_cie31 * illuminant.values + Y_illuminated = Y_cie31 * illuminant.values + Z_illuminated = Z_cie31 * illuminant.values + # Generate empty output-array + out_limits = np.zeros_like(standard_cfms.values) + # This Array has 471 entries for whavelenghts from 360 nm to 830 nm + opti_colour = np.zeros_like(Y_illuminated) + # The array of optimal colours has the same dimensions like Y_illuminated + # and all entries are initialy set to zero + middle_opti_colour = 235 + # is a constant and not be changed. At 595nm (360 + 235) + # in the middle of the center_opti_colour-array + # be aware that counting in array-positions starts at zero + # The first optimum color has its center initialy at zero + maximum_brightness = np.sum(Y_illuminated) + + # "integral" over Y_illuminated + + def optimum_colour(width, center): + opti_colour = np.zeros(471) + # creates array of 471 zeros and ones which represents optimum-colours + # All values of the opti_colour-array are intialy set to zero + half_width = width + center_opti_colour = center + middle_opti_colour = 235 + opti_colour[middle_opti_colour - half_width:middle_opti_colour + + half_width + 1] = 1 + # we start the construction of the optimum color + # at the center of the opti_colour-array + opti_colour = np.roll(opti_colour, + center_opti_colour - middle_opti_colour) + # the optimum colour is rolled to the right whavelenght + return opti_colour + + def bright_opti_colour(width, center, lightsource): + brightness = np.sum( + optimum_colour(width, center) * lightsource) / maximum_brightness + return brightness + + step_size = np.array([64, 32, 16, 8, 4, 2, 1]) + for whavelength in range(0, 471): + width = 127 + for n in step_size: + brightness = bright_opti_colour(width, whavelength, Y_illuminated) + if brightness > target_bright or width > 234: + width -= n + else: + width += n + + brightness = bright_opti_colour(width, whavelength, Y_illuminated) + if brightness < target_bright: + width += 1 + brightness = bright_opti_colour(width, whavelength, Y_illuminated) + + rough_optimum = optimum_colour(width, whavelength) + brightness = np.sum(rough_optimum * Y_illuminated) / maximum_brightness + + # in the following, the both borders of the found rough_optimum + # are reduced to get more exact results + bright_difference = (brightness - target_bright) * maximum_brightness + opti_colour = np.zeros(471) + opti_colour[middle_opti_colour - width:middle_opti_colour + width + + 1] = 1 + # instead rolling foreward the opti_colour, light is rolled backward + rolled_light = np.roll(Y_illuminated, middle_opti_colour - whavelength) + opti_colour_light = opti_colour * rolled_light + left_opti = opti_colour_light[middle_opti_colour - width] + right_opti = opti_colour_light[middle_opti_colour + width] + interpolation = 1 - (bright_difference / (left_opti + right_opti)) + opti_colour[middle_opti_colour - width] = interpolation + opti_colour[middle_opti_colour + width] = interpolation + # opti_colour is rolled to right possition + final_optimum = np.roll(opti_colour, whavelength - middle_opti_colour) + + out_X = np.sum(final_optimum * X_illuminated) + out_Y = target_bright * maximum_brightness + out_Z = np.sum(final_optimum * Z_illuminated) + triple = np.array([out_X, out_Y, out_Z]) + out_limits[whavelength] = triple + return (out_limits) From 47883a818fc40dca196573aee2822d2bf5000ad5 Mon Sep 17 00:00:00 2001 From: Christian Greim <36072637+gutenzwerg@users.noreply.github.com> Date: Mon, 1 Feb 2021 20:39:58 +0100 Subject: [PATCH 02/46] Feature MacAdam_Limits This features calculates MacAdam_Limits according to a given brightness for every single whavelenght --- colour/__init__.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/colour/__init__.py b/colour/__init__.py index 9d387282a..c85853545 100644 --- a/colour/__init__.py +++ b/colour/__init__.py @@ -435,6 +435,7 @@ is_within_mesh_volume, is_within_pointer_gamut, is_within_visible_spectrum, + macadam_limits, ) from .graph import describe_conversion_path, convert @@ -847,6 +848,7 @@ def __getattr__(self, attribute) -> Any: "RGB_colourspace_volume_MonteCarlo", "RGB_colourspace_volume_coverage_MonteCarlo", "is_within_macadam_limits", + "macadam_limits", "is_within_mesh_volume", "is_within_pointer_gamut", "is_within_visible_spectrum", From 9e27d7132da1d6cbd244e5c2140794942769ec13 Mon Sep 17 00:00:00 2001 From: Christian Greim <36072637+gutenzwerg@users.noreply.github.com> Date: Sat, 20 Feb 2021 12:09:25 +0100 Subject: [PATCH 03/46] Small change in the comments --- colour/volume/macadam_limits.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/colour/volume/macadam_limits.py b/colour/volume/macadam_limits.py index 8a8added9..89af83371 100644 --- a/colour/volume/macadam_limits.py +++ b/colour/volume/macadam_limits.py @@ -215,7 +215,7 @@ def plot_Narrowband_Spectra (Yxy_Narrowband_Spectra): for n in range(1, 20): Yxy_Narrowband_Spectra = colour.XYZ_to_xy( - colour.macadam_limits(n/20, illuminant) / 100) + colour.macadam_limits(n/20, illuminant)) plot_Narrowband_Spectra (Yxy_Narrowband_Spectra) plt.show() From f204568ce5810a4b0b31df9c741043ed2c8e38d0 Mon Sep 17 00:00:00 2001 From: Christian Greim <36072637+gutenzwerg@users.noreply.github.com> Date: Mon, 1 Feb 2021 20:38:00 +0100 Subject: [PATCH 04/46] Feature MacAdam_Limits This features calculates MacAdam_Limits according to a given brightness for every single whavelenght --- colour/volume/macadam_limits.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/colour/volume/macadam_limits.py b/colour/volume/macadam_limits.py index 89af83371..8a8added9 100644 --- a/colour/volume/macadam_limits.py +++ b/colour/volume/macadam_limits.py @@ -215,7 +215,7 @@ def plot_Narrowband_Spectra (Yxy_Narrowband_Spectra): for n in range(1, 20): Yxy_Narrowband_Spectra = colour.XYZ_to_xy( - colour.macadam_limits(n/20, illuminant)) + colour.macadam_limits(n/20, illuminant) / 100) plot_Narrowband_Spectra (Yxy_Narrowband_Spectra) plt.show() From 99872c351919b8bbc1a863b167ec689b6c825af0 Mon Sep 17 00:00:00 2001 From: Christian Greim <36072637+gutenzwerg@users.noreply.github.com> Date: Wed, 17 Feb 2021 17:54:39 +0100 Subject: [PATCH 05/46] Update macadam_limits.py A smaller change to support single-whavelenght-sprectra, especially for very dark colours. --- colour/volume/macadam_limits.py | 34 +++++++++++++++++++-------------- 1 file changed, 20 insertions(+), 14 deletions(-) diff --git a/colour/volume/macadam_limits.py b/colour/volume/macadam_limits.py index 8a8added9..ebcbb46b1 100644 --- a/colour/volume/macadam_limits.py +++ b/colour/volume/macadam_limits.py @@ -301,20 +301,26 @@ def bright_opti_colour(width, center, lightsource): # in the following, the both borders of the found rough_optimum # are reduced to get more exact results bright_difference = (brightness - target_bright) * maximum_brightness - opti_colour = np.zeros(471) - opti_colour[middle_opti_colour - width:middle_opti_colour + width + - 1] = 1 - # instead rolling foreward the opti_colour, light is rolled backward - rolled_light = np.roll(Y_illuminated, middle_opti_colour - whavelength) - opti_colour_light = opti_colour * rolled_light - left_opti = opti_colour_light[middle_opti_colour - width] - right_opti = opti_colour_light[middle_opti_colour + width] - interpolation = 1 - (bright_difference / (left_opti + right_opti)) - opti_colour[middle_opti_colour - width] = interpolation - opti_colour[middle_opti_colour + width] = interpolation - # opti_colour is rolled to right possition - final_optimum = np.roll(opti_colour, whavelength - middle_opti_colour) - + # discrimination for single-whavelenght-spectra + if width > 0: + opti_colour = np.zeros(471) + opti_colour[middle_opti_colour - width:middle_opti_colour + width + + 1] = 1 + # instead rolling foreward opti_colour, light is rolled backward + rolled_light = np.roll(Y_illuminated, + middle_opti_colour - whavelength) + opti_colour_light = opti_colour * rolled_light + left_opti = opti_colour_light[middle_opti_colour - width] + right_opti = opti_colour_light[middle_opti_colour + width] + interpolation = 1 - (bright_difference / (left_opti + right_opti)) + opti_colour[middle_opti_colour - width] = interpolation + opti_colour[middle_opti_colour + width] = interpolation + # opti_colour is rolled to right possition + final_optimum = np.roll(opti_colour, + whavelength - middle_opti_colour) + else: + final_optimum = rough_optimum / brightness * target_bright + out_X = np.sum(final_optimum * X_illuminated) out_Y = target_bright * maximum_brightness out_Z = np.sum(final_optimum * Z_illuminated) From 308712ed9f52022b328a3814aba31a6cdc4c1251 Mon Sep 17 00:00:00 2001 From: Christian Greim <36072637+gutenzwerg@users.noreply.github.com> Date: Wed, 17 Feb 2021 18:06:14 +0100 Subject: [PATCH 06/46] Update macadam_limits.py There was a blank line with some spaces --- colour/volume/macadam_limits.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/colour/volume/macadam_limits.py b/colour/volume/macadam_limits.py index ebcbb46b1..df97c9507 100644 --- a/colour/volume/macadam_limits.py +++ b/colour/volume/macadam_limits.py @@ -320,7 +320,7 @@ def bright_opti_colour(width, center, lightsource): whavelength - middle_opti_colour) else: final_optimum = rough_optimum / brightness * target_bright - + out_X = np.sum(final_optimum * X_illuminated) out_Y = target_bright * maximum_brightness out_Z = np.sum(final_optimum * Z_illuminated) From 6d345079aa19832e6ba008425c1ec697a90bf569 Mon Sep 17 00:00:00 2001 From: Zach Lewis Date: Wed, 17 Feb 2021 20:59:56 -0500 Subject: [PATCH 07/46] Adjust spelling --- colour/volume/macadam_limits.py | 55 ++++++++++++++++----------------- 1 file changed, 27 insertions(+), 28 deletions(-) diff --git a/colour/volume/macadam_limits.py b/colour/volume/macadam_limits.py index df97c9507..06a0f9919 100644 --- a/colour/volume/macadam_limits.py +++ b/colour/volume/macadam_limits.py @@ -147,11 +147,11 @@ def is_within_macadam_limits( def macadam_limits(target_brightness, illuminant=()): """ - whavelenght reaches from 360 to 830 nm, in within the programm it is - handled as 0 to 470. Beyond the references this programm is very fast, + wavelength reaches from 360 to 830 nm, in within the program it is + handled as 0 to 470. Beyond the references this program is very fast, because the possible optimums are not simply tested step by step but - more effectively targeted by steps of power of two. The whavelenghts - left and right of a rough optimum are fited by a rule of proportion, + more effectively targeted by steps of power of two. The wavelengths + left and right of a rough optimum are fitted by a rule of proportion, so that the wished brightness will be reached exactly. Parameters @@ -163,15 +163,15 @@ def macadam_limits(target_brightness, illuminant=()): illuminant must be out of colorimetry.MSDS_CMFS['XXX'] If there is no illuminant or it has the wrong form, the illuminant SDS_ILLUMINANTS['E'] - is choosen wich has no influence to the calculations, + is chosen which has no influence to the calculations, because it is an equal-energy-spectrum if necessary a third parameter for the - colour-matching funciton could easily be implemented + colour-matching function could easily be implemented Returns ------- - an array of CIE -X,Y,Z - Triples for every single whavelength + an array of CIE -X,Y,Z - Triples for every single wavelength in single nm - Steps in the range from 360 to 830 nm References @@ -233,11 +233,10 @@ def plot_Narrowband_Spectra (Yxy_Narrowband_Spectra): except AttributeError: illuminant = SDS_ILLUMINANTS['E'] - -# If there is no illuminant or it has the wrong form, -# an illuminant choosen with no influence -# If the illuminanats do not match the format of the Standard Observer, -# they have to be adaptet + # If there is no illuminant or it has the wrong form, + # an illuminant chosen with no influence + # If the illuminants do not match the format of the Standard Observer, + # they have to be adapted illuminant.extrapolate(SpectralShape(360, 830)) illuminant.interpolate(SpectralShape(360, 830, 1)) # The cie31 cmfs are convolved with the given illuminant @@ -246,15 +245,15 @@ def plot_Narrowband_Spectra (Yxy_Narrowband_Spectra): Z_illuminated = Z_cie31 * illuminant.values # Generate empty output-array out_limits = np.zeros_like(standard_cfms.values) - # This Array has 471 entries for whavelenghts from 360 nm to 830 nm + # This Array has 471 entries for wavelengths from 360 nm to 830 nm opti_colour = np.zeros_like(Y_illuminated) # The array of optimal colours has the same dimensions like Y_illuminated - # and all entries are initialy set to zero + # and all entries are initially set to zero middle_opti_colour = 235 # is a constant and not be changed. At 595nm (360 + 235) # in the middle of the center_opti_colour-array # be aware that counting in array-positions starts at zero - # The first optimum color has its center initialy at zero + # The first optimum color has its center initially at zero maximum_brightness = np.sum(Y_illuminated) # "integral" over Y_illuminated @@ -262,7 +261,7 @@ def plot_Narrowband_Spectra (Yxy_Narrowband_Spectra): def optimum_colour(width, center): opti_colour = np.zeros(471) # creates array of 471 zeros and ones which represents optimum-colours - # All values of the opti_colour-array are intialy set to zero + # All values of the opti_colour-array are initially set to zero half_width = width center_opti_colour = center middle_opti_colour = 235 @@ -272,7 +271,7 @@ def optimum_colour(width, center): # at the center of the opti_colour-array opti_colour = np.roll(opti_colour, center_opti_colour - middle_opti_colour) - # the optimum colour is rolled to the right whavelenght + # the optimum colour is rolled to the right wavelength return opti_colour def bright_opti_colour(width, center, lightsource): @@ -281,43 +280,43 @@ def bright_opti_colour(width, center, lightsource): return brightness step_size = np.array([64, 32, 16, 8, 4, 2, 1]) - for whavelength in range(0, 471): + for wavelength in range(0, 471): width = 127 for n in step_size: - brightness = bright_opti_colour(width, whavelength, Y_illuminated) + brightness = bright_opti_colour(width, wavelength, Y_illuminated) if brightness > target_bright or width > 234: width -= n else: width += n - brightness = bright_opti_colour(width, whavelength, Y_illuminated) + brightness = bright_opti_colour(width, wavelength, Y_illuminated) if brightness < target_bright: width += 1 - brightness = bright_opti_colour(width, whavelength, Y_illuminated) + brightness = bright_opti_colour(width, wavelength, Y_illuminated) - rough_optimum = optimum_colour(width, whavelength) + rough_optimum = optimum_colour(width, wavelength) brightness = np.sum(rough_optimum * Y_illuminated) / maximum_brightness # in the following, the both borders of the found rough_optimum # are reduced to get more exact results bright_difference = (brightness - target_bright) * maximum_brightness - # discrimination for single-whavelenght-spectra + # discrimination for single-wavelength-spectra if width > 0: opti_colour = np.zeros(471) opti_colour[middle_opti_colour - width:middle_opti_colour + width + 1] = 1 - # instead rolling foreward opti_colour, light is rolled backward + # instead rolling forward opti_colour, light is rolled backward rolled_light = np.roll(Y_illuminated, - middle_opti_colour - whavelength) + middle_opti_colour - wavelength) opti_colour_light = opti_colour * rolled_light left_opti = opti_colour_light[middle_opti_colour - width] right_opti = opti_colour_light[middle_opti_colour + width] interpolation = 1 - (bright_difference / (left_opti + right_opti)) opti_colour[middle_opti_colour - width] = interpolation opti_colour[middle_opti_colour + width] = interpolation - # opti_colour is rolled to right possition + # opti_colour is rolled to right position final_optimum = np.roll(opti_colour, - whavelength - middle_opti_colour) + wavelength - middle_opti_colour) else: final_optimum = rough_optimum / brightness * target_bright @@ -325,5 +324,5 @@ def bright_opti_colour(width, center, lightsource): out_Y = target_bright * maximum_brightness out_Z = np.sum(final_optimum * Z_illuminated) triple = np.array([out_X, out_Y, out_Z]) - out_limits[whavelength] = triple + out_limits[wavelength] = triple return (out_limits) From 5b8593ae71e5b15ad797d5b892290b9a2637242d Mon Sep 17 00:00:00 2001 From: Christian Greim <36072637+gutenzwerg@users.noreply.github.com> Date: Thu, 18 Feb 2021 10:44:05 +0100 Subject: [PATCH 08/46] Update colour/volume/macadam_limits Co-authored-by: zachlewis --- colour/volume/macadam_limits.py | 1 - 1 file changed, 1 deletion(-) diff --git a/colour/volume/macadam_limits.py b/colour/volume/macadam_limits.py index 06a0f9919..c5675e0be 100644 --- a/colour/volume/macadam_limits.py +++ b/colour/volume/macadam_limits.py @@ -292,7 +292,6 @@ def bright_opti_colour(width, center, lightsource): brightness = bright_opti_colour(width, wavelength, Y_illuminated) if brightness < target_bright: width += 1 - brightness = bright_opti_colour(width, wavelength, Y_illuminated) rough_optimum = optimum_colour(width, wavelength) brightness = np.sum(rough_optimum * Y_illuminated) / maximum_brightness From afc994611e62a98bc690a0bf50913a0707c4301e Mon Sep 17 00:00:00 2001 From: Christian Greim <36072637+gutenzwerg@users.noreply.github.com> Date: Fri, 19 Feb 2021 20:58:16 +0100 Subject: [PATCH 09/46] Update to get results between 0 and 1 --- colour/volume/macadam_limits.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/colour/volume/macadam_limits.py b/colour/volume/macadam_limits.py index c5675e0be..a71dbb568 100644 --- a/colour/volume/macadam_limits.py +++ b/colour/volume/macadam_limits.py @@ -319,9 +319,9 @@ def bright_opti_colour(width, center, lightsource): else: final_optimum = rough_optimum / brightness * target_bright - out_X = np.sum(final_optimum * X_illuminated) - out_Y = target_bright * maximum_brightness - out_Z = np.sum(final_optimum * Z_illuminated) + out_X = np.sum(final_optimum * X_illuminated) / maximum_brightness + out_Y = target_bright + out_Z = np.sum(final_optimum * Z_illuminated) / maximum_brightness triple = np.array([out_X, out_Y, out_Z]) out_limits[wavelength] = triple return (out_limits) From 170eb03a4cc88275ca85e72954733c98b3d3892f Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Mon, 23 May 2022 17:06:24 +0000 Subject: [PATCH 10/46] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- colour/volume/__init__.py | 4 +-- colour/volume/macadam_limits.py | 46 +++++++++++++++++++++------------ 2 files changed, 30 insertions(+), 20 deletions(-) diff --git a/colour/volume/__init__.py b/colour/volume/__init__.py index 55fcfdfc7..aa5ac5c7d 100644 --- a/colour/volume/__init__.py +++ b/colour/volume/__init__.py @@ -23,9 +23,7 @@ __all__ += [ "is_within_macadam_limits", ] -__all__ += [ - 'macadam_limits' -] +__all__ += ["macadam_limits"] __all__ += [ "is_within_mesh_volume", ] diff --git a/colour/volume/macadam_limits.py b/colour/volume/macadam_limits.py index a71dbb568..fd107091d 100644 --- a/colour/volume/macadam_limits.py +++ b/colour/volume/macadam_limits.py @@ -222,16 +222,18 @@ def plot_Narrowband_Spectra (Yxy_Narrowband_Spectra): """ target_bright = target_brightness if target_bright > 1 or target_bright < 0: - raise TypeError('brightness of function macadam_limits( )' - 'has to be between 0 and 1') - standard_cfms = MSDS_CMFS['CIE 1931 2 Degree Standard Observer'] + raise TypeError( + "brightness of function macadam_limits( )" + "has to be between 0 and 1" + ) + standard_cfms = MSDS_CMFS["CIE 1931 2 Degree Standard Observer"] X_cie31 = standard_cfms.values[..., 0] Y_cie31 = standard_cfms.values[..., 1] Z_cie31 = standard_cfms.values[..., 2] try: illuminant.interpolator except AttributeError: - illuminant = SDS_ILLUMINANTS['E'] + illuminant = SDS_ILLUMINANTS["E"] # If there is no illuminant or it has the wrong form, # an illuminant chosen with no influence @@ -265,18 +267,25 @@ def optimum_colour(width, center): half_width = width center_opti_colour = center middle_opti_colour = 235 - opti_colour[middle_opti_colour - half_width:middle_opti_colour + - half_width + 1] = 1 + opti_colour[ + middle_opti_colour + - half_width : middle_opti_colour + + half_width + + 1 + ] = 1 # we start the construction of the optimum color # at the center of the opti_colour-array - opti_colour = np.roll(opti_colour, - center_opti_colour - middle_opti_colour) + opti_colour = np.roll( + opti_colour, center_opti_colour - middle_opti_colour + ) # the optimum colour is rolled to the right wavelength return opti_colour def bright_opti_colour(width, center, lightsource): - brightness = np.sum( - optimum_colour(width, center) * lightsource) / maximum_brightness + brightness = ( + np.sum(optimum_colour(width, center) * lightsource) + / maximum_brightness + ) return brightness step_size = np.array([64, 32, 16, 8, 4, 2, 1]) @@ -302,11 +311,13 @@ def bright_opti_colour(width, center, lightsource): # discrimination for single-wavelength-spectra if width > 0: opti_colour = np.zeros(471) - opti_colour[middle_opti_colour - width:middle_opti_colour + width + - 1] = 1 + opti_colour[ + middle_opti_colour - width : middle_opti_colour + width + 1 + ] = 1 # instead rolling forward opti_colour, light is rolled backward - rolled_light = np.roll(Y_illuminated, - middle_opti_colour - wavelength) + rolled_light = np.roll( + Y_illuminated, middle_opti_colour - wavelength + ) opti_colour_light = opti_colour * rolled_light left_opti = opti_colour_light[middle_opti_colour - width] right_opti = opti_colour_light[middle_opti_colour + width] @@ -314,8 +325,9 @@ def bright_opti_colour(width, center, lightsource): opti_colour[middle_opti_colour - width] = interpolation opti_colour[middle_opti_colour + width] = interpolation # opti_colour is rolled to right position - final_optimum = np.roll(opti_colour, - wavelength - middle_opti_colour) + final_optimum = np.roll( + opti_colour, wavelength - middle_opti_colour + ) else: final_optimum = rough_optimum / brightness * target_bright @@ -324,4 +336,4 @@ def bright_opti_colour(width, center, lightsource): out_Z = np.sum(final_optimum * Z_illuminated) / maximum_brightness triple = np.array([out_X, out_Y, out_Z]) out_limits[wavelength] = triple - return (out_limits) + return out_limits From 5cbd91d868d4021b6d5bed08b988b37602495fb9 Mon Sep 17 00:00:00 2001 From: Christian Greim <36072637+gutenzwerg@users.noreply.github.com> Date: Mon, 23 May 2022 19:20:23 +0200 Subject: [PATCH 11/46] Update macadam_limits.py --- colour/volume/macadam_limits.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/colour/volume/macadam_limits.py b/colour/volume/macadam_limits.py index fd107091d..05da102b6 100644 --- a/colour/volume/macadam_limits.py +++ b/colour/volume/macadam_limits.py @@ -147,7 +147,7 @@ def is_within_macadam_limits( def macadam_limits(target_brightness, illuminant=()): """ - wavelength reaches from 360 to 830 nm, in within the program it is + Wavelength reaches from 360 to 830 nm, in within the program it is handled as 0 to 470. Beyond the references this program is very fast, because the possible optimums are not simply tested step by step but more effectively targeted by steps of power of two. The wavelengths From d6fe7eeeb6190b818f2405f31d4764b857ebc0ed Mon Sep 17 00:00:00 2001 From: Christian Greim <36072637+gutenzwerg@users.noreply.github.com> Date: Mon, 23 May 2022 19:36:34 +0200 Subject: [PATCH 12/46] Update macadam_limits.py --- colour/volume/macadam_limits.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/colour/volume/macadam_limits.py b/colour/volume/macadam_limits.py index 05da102b6..472ef5e82 100644 --- a/colour/volume/macadam_limits.py +++ b/colour/volume/macadam_limits.py @@ -239,7 +239,7 @@ def plot_Narrowband_Spectra (Yxy_Narrowband_Spectra): # an illuminant chosen with no influence # If the illuminants do not match the format of the Standard Observer, # they have to be adapted - illuminant.extrapolate(SpectralShape(360, 830)) + illuminant.extrapolate(SpectralShape(360, 830, 1)) illuminant.interpolate(SpectralShape(360, 830, 1)) # The cie31 cmfs are convolved with the given illuminant X_illuminated = X_cie31 * illuminant.values From b03eaf696097c62cfd94c641407db722f8a175e9 Mon Sep 17 00:00:00 2001 From: Roland Greim Date: Mon, 23 May 2022 20:15:02 +0200 Subject: [PATCH 13/46] Trigger ci From f3bc4fbc36b4073cb3cf6e1e90129e51f1f931c2 Mon Sep 17 00:00:00 2001 From: Christian Greim <36072637+gutenzwerg@users.noreply.github.com> Date: Thu, 16 Jun 2022 13:12:23 +0200 Subject: [PATCH 14/46] Update macadam_limits.py Several chages to meet the recommendations of KelSolaar --- colour/volume/macadam_limits.py | 155 ++++++++++++++++---------------- 1 file changed, 77 insertions(+), 78 deletions(-) diff --git a/colour/volume/macadam_limits.py b/colour/volume/macadam_limits.py index 472ef5e82..2009af461 100644 --- a/colour/volume/macadam_limits.py +++ b/colour/volume/macadam_limits.py @@ -1,7 +1,6 @@ """ Optimal Colour Stimuli - MacAdam Limits ======================================= - Defines the objects related to *Optimal Colour Stimuli* computations. """ @@ -19,10 +18,15 @@ Optional, Union, ) +from colour.colorimetry import ( + MSDS_CMFS, + reshape_sd, + SpectralShape, + SDS_ILLUMINANTS +) from colour.models import xyY_to_XYZ from colour.volume import OPTIMAL_COLOUR_STIMULI_ILLUMINANTS from colour.utilities import CACHE_REGISTRY, validate_method -from colour.colorimetry import MSDS_CMFS, SpectralShape, SDS_ILLUMINANTS __author__ = "Colour Developers", "Christian Greim" __copyright__ = "Copyright 2013 Colour Developers" @@ -52,12 +56,10 @@ def _XYZ_optimal_colour_stimuli( """ Return given illuminant *Optimal Colour Stimuli* in *CIE XYZ* tristimulus values and caches it if not existing. - Parameters ---------- illuminant Illuminant name. - Returns ------- :class:`numpy.ndarray` @@ -96,7 +98,6 @@ def is_within_macadam_limits( """ Return whether given *CIE xyY* colourspace array is within MacAdam limits of given illuminant. - Parameters ---------- xyY @@ -105,12 +106,10 @@ def is_within_macadam_limits( Illuminant name. tolerance Tolerance allowed in the inside-triangle check. - Returns ------- :class:`numpy.ndarray` Whether given *CIE xyY* colourspace array is within MacAdam limits. - Notes ----- +------------+-----------------------+---------------+ @@ -118,7 +117,6 @@ def is_within_macadam_limits( +============+=======================+===============+ | ``xyY`` | [0, 1] | [0, 1] | +------------+-----------------------+---------------+ - Examples -------- >>> is_within_macadam_limits(np.array([0.3205, 0.4131, 0.51]), 'A') @@ -145,36 +143,48 @@ def is_within_macadam_limits( return simplex -def macadam_limits(target_brightness, illuminant=()): +def macadam_limits( + luminance: Floating = 0.5, + illuminant: Optional[SpectralDistribution] = SDS_ILLUMINANTS["E"], + spectral_range: Optional[SpectralShape] = SpectralShape(360, 830, 1), + cmfs: Optional[MultiSpectralDistributions] = + MSDS_CMFS["CIE 1931 2 Degree Standard Observer"], +) -> NDArray: """ - Wavelength reaches from 360 to 830 nm, in within the program it is - handled as 0 to 470. Beyond the references this program is very fast, - because the possible optimums are not simply tested step by step but + Returns an array of CIE -X,Y,Z - Triples containing colour-coordinates + of the MacAdam-limit for the defined luminance for every + whavelength defined in spectral_range. + Target ist a fast running codey, by + not simply testing the possible optimums step by step but more effectively targeted by steps of power of two. The wavelengths left and right of a rough optimum are fitted by a rule of proportion, so that the wished brightness will be reached exactly. - + Parameters ---------- - target_brightness : floating point - brightness has to be between 0 and 1 - - illuminant: object - illuminant must be out of colorimetry.MSDS_CMFS['XXX'] - If there is no illuminant or it has the wrong form, - the illuminant SDS_ILLUMINANTS['E'] - is chosen which has no influence to the calculations, - because it is an equal-energy-spectrum - - if necessary a third parameter for the - colour-matching function could easily be implemented - + luminance + set the wanted luminance + has to be between 0 and 1 + illuminant + Illuminant spectral distribution, default to *CIE Illuminant E* + spectral_range + SpectralShape according to colour.SpectralShape + cmfs + Standard observer colour matching functions, default to the + *CIE 1931 2 Degree Standard Observer*. + Returns ------- - an array of CIE -X,Y,Z - Triples for every single wavelength - in single nm - Steps in the range from 360 to 830 nm - - References + :class:`numpy.ndarray` + an array of CIE -X,Y,Z - Triples containing colour-coordinates + of the MacAdam-limit for the definde luminance for every + whavelength defined in spectral_range + array([[ 3.83917134e-01, 5.00000000e-01, 3.55171511e-01], + [ 3.56913361e-01, 5.00000000e-01, 3.55215349e-01], + [ 3.32781985e-01, 5.00000000e-01, 3.55249953e-01], + ... + [ 4.44310989e-01, 5.00000000e-01, 3.55056751e-01], + [ 4.13165551e-01, 5.00000000e-01, 3.55118668e-01]]) ---------- - cite: Wyszecki, G., & Stiles, W. S. (2000). In Color Science: Concepts and Methods, @@ -188,7 +198,6 @@ def macadam_limits(target_brightness, illuminant=()): Opt. Soc. Am. A 24, 1501-1515 (2007) - cite: Kenichiro Masaoka. In OPTICS LETTERS, June 15, 2010 / Vol. 35, No. 1 (pp. 2031 - 2033) - Example -------- from matplotlib import pyplot as plt @@ -197,81 +206,69 @@ def macadam_limits(target_brightness, illuminant=()): fig = plt.figure(figsize=(7,7)) ax = fig.add_axes([0,0,1,1]) illuminant = colour.SDS_ILLUMINANTS['D65'] - def plot_Narrowband_Spectra (Yxy_Narrowband_Spectra): FirstColumn = 0 SecondColumn = 1 - x = Yxy_Narrowband_Spectra[...,FirstColumn] y = Yxy_Narrowband_Spectra[...,SecondColumn] ax.plot(x,y,'orange',label='Spectrum Loci') - x = [Yxy_Narrowband_Spectra[-1][FirstColumn], Yxy_Narrowband_Spectra[0][FirstColumn]] y = [Yxy_Narrowband_Spectra[-1][SecondColumn], Yxy_Narrowband_Spectra[0][SecondColumn]] ax.plot(x,y,'purple',label='Purple Boundary') return() - for n in range(1, 20): Yxy_Narrowband_Spectra = colour.XYZ_to_xy( - colour.macadam_limits(n/20, illuminant) / 100) + colour.macadam_limits(n/20, illuminant)) plot_Narrowband_Spectra (Yxy_Narrowband_Spectra) - plt.show() """ - target_bright = target_brightness + target_bright = luminance if target_bright > 1 or target_bright < 0: raise TypeError( "brightness of function macadam_limits( )" "has to be between 0 and 1" ) - standard_cfms = MSDS_CMFS["CIE 1931 2 Degree Standard Observer"] - X_cie31 = standard_cfms.values[..., 0] - Y_cie31 = standard_cfms.values[..., 1] - Z_cie31 = standard_cfms.values[..., 2] - try: - illuminant.interpolator - except AttributeError: - illuminant = SDS_ILLUMINANTS["E"] - - # If there is no illuminant or it has the wrong form, - # an illuminant chosen with no influence - # If the illuminants do not match the format of the Standard Observer, - # they have to be adapted - illuminant.extrapolate(SpectralShape(360, 830, 1)) - illuminant.interpolate(SpectralShape(360, 830, 1)) - # The cie31 cmfs are convolved with the given illuminant - X_illuminated = X_cie31 * illuminant.values - Y_illuminated = Y_cie31 * illuminant.values - Z_illuminated = Z_cie31 * illuminant.values + # workarround because illuminant and cmfs are rounded + # in a different way. + illuminant = reshape_sd(illuminant, cmfs.shape) + cmfs = reshape_sd(cmfs, spectral_range) + illuminant = reshape_sd(illuminant, spectral_range) + + # The cmfs are convolved with the given illuminant + X_illuminated = cmfs.values[..., 0] * illuminant.values + Y_illuminated = cmfs.values[..., 1] * illuminant.values + Z_illuminated = cmfs.values[..., 2] * illuminant.values # Generate empty output-array - out_limits = np.zeros_like(standard_cfms.values) - # This Array has 471 entries for wavelengths from 360 nm to 830 nm + out_limits = np.zeros_like(cmfs.values) + # For examle a SpectralShape(360, 830, 1) has 471 entries opti_colour = np.zeros_like(Y_illuminated) - # The array of optimal colours has the same dimensions like Y_illuminated - # and all entries are initially set to zero - middle_opti_colour = 235 - # is a constant and not be changed. At 595nm (360 + 235) - # in the middle of the center_opti_colour-array - # be aware that counting in array-positions starts at zero + # The array of optimal colours has the same dimensions + # like Y_illuminated, in our example: 471 + colour_range = illuminant.values.shape[0] + a = np.arange(12) + a = np.ceil(colour_range/2**(a+1)).astype(int) + step_sizes = np.append(np.flip(np.unique(a)), 1) + middle_opti_colour = step_sizes[0] -1 + # in our example: 235 + width = step_sizes[1] -1 + # in our example: 117 + step_sizes = np.delete(step_sizes,[0,1]) + # in our example: np.array([59 30 15 8 4 2 1]) # The first optimum color has its center initially at zero maximum_brightness = np.sum(Y_illuminated) - # "integral" over Y_illuminated - def optimum_colour(width, center): - opti_colour = np.zeros(471) + opti_colour = np.zeros(colour_range) # creates array of 471 zeros and ones which represents optimum-colours # All values of the opti_colour-array are initially set to zero half_width = width center_opti_colour = center - middle_opti_colour = 235 opti_colour[ middle_opti_colour - - half_width : middle_opti_colour + - half_width : middle_opti_colour + 1 + half_width - + 1 ] = 1 # we start the construction of the optimum color # at the center of the opti_colour-array @@ -288,18 +285,20 @@ def bright_opti_colour(width, center, lightsource): ) return brightness - step_size = np.array([64, 32, 16, 8, 4, 2, 1]) - for wavelength in range(0, 471): - width = 127 - for n in step_size: + # here we do some kind of Newton's Method to aproximate the + # wandted illuminance at the whavelengt. + # therefore the numbers 127, 64, 32 and so on + # step_size is in this case np.array([59 30 15 8 4 2 1]) + for wavelength in range(0, colour_range): + for n in step_sizes: brightness = bright_opti_colour(width, wavelength, Y_illuminated) - if brightness > target_bright or width > 234: + if brightness > target_bright or width >= middle_opti_colour: width -= n else: width += n brightness = bright_opti_colour(width, wavelength, Y_illuminated) - if brightness < target_bright: + if brightness < target_bright : width += 1 rough_optimum = optimum_colour(width, wavelength) @@ -310,7 +309,7 @@ def bright_opti_colour(width, center, lightsource): bright_difference = (brightness - target_bright) * maximum_brightness # discrimination for single-wavelength-spectra if width > 0: - opti_colour = np.zeros(471) + opti_colour = np.zeros(colour_range) opti_colour[ middle_opti_colour - width : middle_opti_colour + width + 1 ] = 1 From f5ee2a469dd6e14614dbf171ef8e9f854f978736 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Thu, 16 Jun 2022 11:14:56 +0000 Subject: [PATCH 15/46] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- colour/volume/macadam_limits.py | 30 ++++++++++++++++-------------- 1 file changed, 16 insertions(+), 14 deletions(-) diff --git a/colour/volume/macadam_limits.py b/colour/volume/macadam_limits.py index 2009af461..f0fde1274 100644 --- a/colour/volume/macadam_limits.py +++ b/colour/volume/macadam_limits.py @@ -22,7 +22,7 @@ MSDS_CMFS, reshape_sd, SpectralShape, - SDS_ILLUMINANTS + SDS_ILLUMINANTS, ) from colour.models import xyY_to_XYZ from colour.volume import OPTIMAL_COLOUR_STIMULI_ILLUMINANTS @@ -147,8 +147,9 @@ def macadam_limits( luminance: Floating = 0.5, illuminant: Optional[SpectralDistribution] = SDS_ILLUMINANTS["E"], spectral_range: Optional[SpectralShape] = SpectralShape(360, 830, 1), - cmfs: Optional[MultiSpectralDistributions] = - MSDS_CMFS["CIE 1931 2 Degree Standard Observer"], + cmfs: Optional[MultiSpectralDistributions] = MSDS_CMFS[ + "CIE 1931 2 Degree Standard Observer" + ], ) -> NDArray: """ Returns an array of CIE -X,Y,Z - Triples containing colour-coordinates @@ -159,7 +160,7 @@ def macadam_limits( more effectively targeted by steps of power of two. The wavelengths left and right of a rough optimum are fitted by a rule of proportion, so that the wished brightness will be reached exactly. - + Parameters ---------- luminance @@ -172,7 +173,7 @@ def macadam_limits( cmfs Standard observer colour matching functions, default to the *CIE 1931 2 Degree Standard Observer*. - + Returns ------- :class:`numpy.ndarray` @@ -231,7 +232,7 @@ def plot_Narrowband_Spectra (Yxy_Narrowband_Spectra): "has to be between 0 and 1" ) # workarround because illuminant and cmfs are rounded - # in a different way. + # in a different way. illuminant = reshape_sd(illuminant, cmfs.shape) cmfs = reshape_sd(cmfs, spectral_range) illuminant = reshape_sd(illuminant, spectral_range) @@ -242,19 +243,19 @@ def plot_Narrowband_Spectra (Yxy_Narrowband_Spectra): Z_illuminated = cmfs.values[..., 2] * illuminant.values # Generate empty output-array out_limits = np.zeros_like(cmfs.values) - # For examle a SpectralShape(360, 830, 1) has 471 entries + # For examle a SpectralShape(360, 830, 1) has 471 entries opti_colour = np.zeros_like(Y_illuminated) - # The array of optimal colours has the same dimensions + # The array of optimal colours has the same dimensions # like Y_illuminated, in our example: 471 colour_range = illuminant.values.shape[0] a = np.arange(12) - a = np.ceil(colour_range/2**(a+1)).astype(int) + a = np.ceil(colour_range / 2 ** (a + 1)).astype(int) step_sizes = np.append(np.flip(np.unique(a)), 1) - middle_opti_colour = step_sizes[0] -1 + middle_opti_colour = step_sizes[0] - 1 # in our example: 235 - width = step_sizes[1] -1 + width = step_sizes[1] - 1 # in our example: 117 - step_sizes = np.delete(step_sizes,[0,1]) + step_sizes = np.delete(step_sizes, [0, 1]) # in our example: np.array([59 30 15 8 4 2 1]) # The first optimum color has its center initially at zero maximum_brightness = np.sum(Y_illuminated) @@ -267,7 +268,8 @@ def optimum_colour(width, center): center_opti_colour = center opti_colour[ middle_opti_colour - - half_width : middle_opti_colour + 1 + - half_width : middle_opti_colour + + 1 + half_width ] = 1 # we start the construction of the optimum color @@ -298,7 +300,7 @@ def bright_opti_colour(width, center, lightsource): width += n brightness = bright_opti_colour(width, wavelength, Y_illuminated) - if brightness < target_bright : + if brightness < target_bright: width += 1 rough_optimum = optimum_colour(width, wavelength) From 388c0f61df34afcb572fba87303f78d785141687 Mon Sep 17 00:00:00 2001 From: Christian Greim <36072637+gutenzwerg@users.noreply.github.com> Date: Thu, 16 Jun 2022 13:38:55 +0200 Subject: [PATCH 16/46] Update macadam_limits.py Several updates to meet KelSolaars recommendations --- colour/volume/macadam_limits.py | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/colour/volume/macadam_limits.py b/colour/volume/macadam_limits.py index f0fde1274..bba6102dc 100644 --- a/colour/volume/macadam_limits.py +++ b/colour/volume/macadam_limits.py @@ -20,7 +20,9 @@ ) from colour.colorimetry import ( MSDS_CMFS, + MultiSpectralDistributions, reshape_sd, + SpectralDistributions SpectralShape, SDS_ILLUMINANTS, ) @@ -53,6 +55,7 @@ def _XYZ_optimal_colour_stimuli( illuminant: Union[Literal["A", "C", "D65"], str] = "D65" ) -> NDArray: + """ Return given illuminant *Optimal Colour Stimuli* in *CIE XYZ* tristimulus values and caches it if not existing. @@ -60,6 +63,7 @@ def _XYZ_optimal_colour_stimuli( ---------- illuminant Illuminant name. + Returns ------- :class:`numpy.ndarray` @@ -95,6 +99,7 @@ def is_within_macadam_limits( illuminant: Union[Literal["A", "C", "D65"], str] = "D65", tolerance: Optional[Floating] = None, ) -> NDArray: + """ Return whether given *CIE xyY* colourspace array is within MacAdam limits of given illuminant. @@ -150,9 +155,10 @@ def macadam_limits( cmfs: Optional[MultiSpectralDistributions] = MSDS_CMFS[ "CIE 1931 2 Degree Standard Observer" ], -) -> NDArray: + ) -> NDArray: + """ - Returns an array of CIE -X,Y,Z - Triples containing colour-coordinates + Return an array of CIE -X,Y,Z - Triples containing colour-coordinates of the MacAdam-limit for the defined luminance for every whavelength defined in spectral_range. Target ist a fast running codey, by From 91c45f74eae99dba9c24da5305cb21e1e3bbec37 Mon Sep 17 00:00:00 2001 From: Christian Greim <36072637+gutenzwerg@users.noreply.github.com> Date: Thu, 16 Jun 2022 14:14:42 +0200 Subject: [PATCH 17/46] Update macadam_limits.py Several updates to meet KelSolaars recommendations --- colour/volume/macadam_limits.py | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/colour/volume/macadam_limits.py b/colour/volume/macadam_limits.py index bba6102dc..b4434c892 100644 --- a/colour/volume/macadam_limits.py +++ b/colour/volume/macadam_limits.py @@ -22,7 +22,7 @@ MSDS_CMFS, MultiSpectralDistributions, reshape_sd, - SpectralDistributions + SpectralDistributions, SpectralShape, SDS_ILLUMINANTS, ) @@ -152,10 +152,9 @@ def macadam_limits( luminance: Floating = 0.5, illuminant: Optional[SpectralDistribution] = SDS_ILLUMINANTS["E"], spectral_range: Optional[SpectralShape] = SpectralShape(360, 830, 1), - cmfs: Optional[MultiSpectralDistributions] = MSDS_CMFS[ - "CIE 1931 2 Degree Standard Observer" - ], - ) -> NDArray: + cmfs: Optional[MultiSpectralDistributions] = + MSDS_CMFS["CIE 1931 2 Degree Standard Observer"], +) -> NDArray: """ Return an array of CIE -X,Y,Z - Triples containing colour-coordinates From 6eb76d58fd1d29c69f30a874f8de13b1b7b20ba0 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Thu, 16 Jun 2022 12:17:02 +0000 Subject: [PATCH 18/46] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- colour/volume/macadam_limits.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/colour/volume/macadam_limits.py b/colour/volume/macadam_limits.py index b4434c892..24f01f734 100644 --- a/colour/volume/macadam_limits.py +++ b/colour/volume/macadam_limits.py @@ -152,8 +152,9 @@ def macadam_limits( luminance: Floating = 0.5, illuminant: Optional[SpectralDistribution] = SDS_ILLUMINANTS["E"], spectral_range: Optional[SpectralShape] = SpectralShape(360, 830, 1), - cmfs: Optional[MultiSpectralDistributions] = - MSDS_CMFS["CIE 1931 2 Degree Standard Observer"], + cmfs: Optional[MultiSpectralDistributions] = MSDS_CMFS[ + "CIE 1931 2 Degree Standard Observer" + ], ) -> NDArray: """ From 41a277b71eb9adcae8c8fc3b3d95baeccd590190 Mon Sep 17 00:00:00 2001 From: Christian Greim <36072637+gutenzwerg@users.noreply.github.com> Date: Thu, 16 Jun 2022 14:49:40 +0200 Subject: [PATCH 19/46] Update macadam_limits.py Several updates to meet KelSolaars recommendations --- colour/volume/macadam_limits.py | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/colour/volume/macadam_limits.py b/colour/volume/macadam_limits.py index 24f01f734..8a9c97e03 100644 --- a/colour/volume/macadam_limits.py +++ b/colour/volume/macadam_limits.py @@ -22,7 +22,7 @@ MSDS_CMFS, MultiSpectralDistributions, reshape_sd, - SpectralDistributions, + SpectralDistribution, SpectralShape, SDS_ILLUMINANTS, ) @@ -55,10 +55,10 @@ def _XYZ_optimal_colour_stimuli( illuminant: Union[Literal["A", "C", "D65"], str] = "D65" ) -> NDArray: - """ Return given illuminant *Optimal Colour Stimuli* in *CIE XYZ* tristimulus values and caches it if not existing. + Parameters ---------- illuminant @@ -99,10 +99,10 @@ def is_within_macadam_limits( illuminant: Union[Literal["A", "C", "D65"], str] = "D65", tolerance: Optional[Floating] = None, ) -> NDArray: - """ Return whether given *CIE xyY* colourspace array is within MacAdam limits of given illuminant. + Parameters ---------- xyY @@ -111,10 +111,12 @@ def is_within_macadam_limits( Illuminant name. tolerance Tolerance allowed in the inside-triangle check. + Returns ------- :class:`numpy.ndarray` Whether given *CIE xyY* colourspace array is within MacAdam limits. + Notes ----- +------------+-----------------------+---------------+ @@ -122,6 +124,7 @@ def is_within_macadam_limits( +============+=======================+===============+ | ``xyY`` | [0, 1] | [0, 1] | +------------+-----------------------+---------------+ + Examples -------- >>> is_within_macadam_limits(np.array([0.3205, 0.4131, 0.51]), 'A') @@ -156,7 +159,6 @@ def macadam_limits( "CIE 1931 2 Degree Standard Observer" ], ) -> NDArray: - """ Return an array of CIE -X,Y,Z - Triples containing colour-coordinates of the MacAdam-limit for the defined luminance for every @@ -192,6 +194,8 @@ def macadam_limits( ... [ 4.44310989e-01, 5.00000000e-01, 3.55056751e-01], [ 4.13165551e-01, 5.00000000e-01, 3.55118668e-01]]) + + References ---------- - cite: Wyszecki, G., & Stiles, W. S. (2000). In Color Science: Concepts and Methods, @@ -205,7 +209,8 @@ def macadam_limits( Opt. Soc. Am. A 24, 1501-1515 (2007) - cite: Kenichiro Masaoka. In OPTICS LETTERS, June 15, 2010 / Vol. 35, No. 1 (pp. 2031 - 2033) - Example + + Examples -------- from matplotlib import pyplot as plt import numpy as np @@ -231,6 +236,7 @@ def plot_Narrowband_Spectra (Yxy_Narrowband_Spectra): plot_Narrowband_Spectra (Yxy_Narrowband_Spectra) plt.show() """ + target_bright = luminance if target_bright > 1 or target_bright < 0: raise TypeError( From 977be680ed4df7a411386ca62ccd77ffe4a649de Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Thu, 16 Jun 2022 12:52:08 +0000 Subject: [PATCH 20/46] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- colour/volume/macadam_limits.py | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/colour/volume/macadam_limits.py b/colour/volume/macadam_limits.py index 8a9c97e03..6e36dbf15 100644 --- a/colour/volume/macadam_limits.py +++ b/colour/volume/macadam_limits.py @@ -58,7 +58,7 @@ def _XYZ_optimal_colour_stimuli( """ Return given illuminant *Optimal Colour Stimuli* in *CIE XYZ* tristimulus values and caches it if not existing. - + Parameters ---------- illuminant @@ -102,7 +102,7 @@ def is_within_macadam_limits( """ Return whether given *CIE xyY* colourspace array is within MacAdam limits of given illuminant. - + Parameters ---------- xyY @@ -111,12 +111,12 @@ def is_within_macadam_limits( Illuminant name. tolerance Tolerance allowed in the inside-triangle check. - + Returns ------- :class:`numpy.ndarray` Whether given *CIE xyY* colourspace array is within MacAdam limits. - + Notes ----- +------------+-----------------------+---------------+ @@ -124,7 +124,7 @@ def is_within_macadam_limits( +============+=======================+===============+ | ``xyY`` | [0, 1] | [0, 1] | +------------+-----------------------+---------------+ - + Examples -------- >>> is_within_macadam_limits(np.array([0.3205, 0.4131, 0.51]), 'A') @@ -194,7 +194,7 @@ def macadam_limits( ... [ 4.44310989e-01, 5.00000000e-01, 3.55056751e-01], [ 4.13165551e-01, 5.00000000e-01, 3.55118668e-01]]) - + References ---------- - cite: Wyszecki, G., & Stiles, W. S. (2000). @@ -209,7 +209,7 @@ def macadam_limits( Opt. Soc. Am. A 24, 1501-1515 (2007) - cite: Kenichiro Masaoka. In OPTICS LETTERS, June 15, 2010 / Vol. 35, No. 1 (pp. 2031 - 2033) - + Examples -------- from matplotlib import pyplot as plt @@ -236,7 +236,7 @@ def plot_Narrowband_Spectra (Yxy_Narrowband_Spectra): plot_Narrowband_Spectra (Yxy_Narrowband_Spectra) plt.show() """ - + target_bright = luminance if target_bright > 1 or target_bright < 0: raise TypeError( From 9dc7145494b721e91fba5cb93f5e5b6148eaa0c1 Mon Sep 17 00:00:00 2001 From: Christian Greim <36072637+gutenzwerg@users.noreply.github.com> Date: Thu, 16 Jun 2022 17:12:15 +0200 Subject: [PATCH 21/46] Update macadam_limits.py Several updates to meet KelSolaars recommendations --- colour/volume/macadam_limits.py | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/colour/volume/macadam_limits.py b/colour/volume/macadam_limits.py index 6e36dbf15..82cd17e72 100644 --- a/colour/volume/macadam_limits.py +++ b/colour/volume/macadam_limits.py @@ -20,9 +20,9 @@ ) from colour.colorimetry import ( MSDS_CMFS, - MultiSpectralDistributions, reshape_sd, SpectralDistribution, + MultiSpectralDistributions, SpectralShape, SDS_ILLUMINANTS, ) @@ -153,11 +153,9 @@ def is_within_macadam_limits( def macadam_limits( luminance: Floating = 0.5, - illuminant: Optional[SpectralDistribution] = SDS_ILLUMINANTS["E"], - spectral_range: Optional[SpectralShape] = SpectralShape(360, 830, 1), - cmfs: Optional[MultiSpectralDistributions] = MSDS_CMFS[ - "CIE 1931 2 Degree Standard Observer" - ], + illuminant: Optional[SpectralDistribution] = None, + spectral_range: Optional[SpectralShape] = None, + cmfs: Optional[SpectralDistribution] = None, ) -> NDArray: """ Return an array of CIE -X,Y,Z - Triples containing colour-coordinates @@ -237,6 +235,12 @@ def plot_Narrowband_Spectra (Yxy_Narrowband_Spectra): plt.show() """ + if cmfs is None: + cmfs = MSDS_CMFS["CIE 1931 2 Degree Standard Observer"] + if illuminant is None: + illuminant = SDS_ILLUMINANTS["E"] + if spectral_range is None: + spectral_range = SpectralShape(360, 830, 1) target_bright = luminance if target_bright > 1 or target_bright < 0: raise TypeError( From 6f306dcffd4adcb34232caf7fecb6dba81fff525 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Thu, 16 Jun 2022 15:14:51 +0000 Subject: [PATCH 22/46] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- colour/volume/macadam_limits.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/colour/volume/macadam_limits.py b/colour/volume/macadam_limits.py index 82cd17e72..95e45a7fc 100644 --- a/colour/volume/macadam_limits.py +++ b/colour/volume/macadam_limits.py @@ -236,9 +236,9 @@ def plot_Narrowband_Spectra (Yxy_Narrowband_Spectra): """ if cmfs is None: - cmfs = MSDS_CMFS["CIE 1931 2 Degree Standard Observer"] + cmfs = MSDS_CMFS["CIE 1931 2 Degree Standard Observer"] if illuminant is None: - illuminant = SDS_ILLUMINANTS["E"] + illuminant = SDS_ILLUMINANTS["E"] if spectral_range is None: spectral_range = SpectralShape(360, 830, 1) target_bright = luminance From ac12a6bd6205693d44badf06e6f0baac39ffc244 Mon Sep 17 00:00:00 2001 From: Christian Greim <36072637+gutenzwerg@users.noreply.github.com> Date: Thu, 16 Jun 2022 17:21:04 +0200 Subject: [PATCH 23/46] Update macadam_limits.py Several updates to meet KelSolaars recommendations --- colour/volume/macadam_limits.py | 2 -- 1 file changed, 2 deletions(-) diff --git a/colour/volume/macadam_limits.py b/colour/volume/macadam_limits.py index 95e45a7fc..037da7b7d 100644 --- a/colour/volume/macadam_limits.py +++ b/colour/volume/macadam_limits.py @@ -21,8 +21,6 @@ from colour.colorimetry import ( MSDS_CMFS, reshape_sd, - SpectralDistribution, - MultiSpectralDistributions, SpectralShape, SDS_ILLUMINANTS, ) From 75ade266d9c1493077e8c1db1ec5bd2d4fe20a0e Mon Sep 17 00:00:00 2001 From: Christian Greim <36072637+gutenzwerg@users.noreply.github.com> Date: Thu, 16 Jun 2022 18:45:38 +0200 Subject: [PATCH 24/46] Update macadam_limits.py Several updates to meet KelSolaars recommendations --- colour/volume/macadam_limits.py | 1 + 1 file changed, 1 insertion(+) diff --git a/colour/volume/macadam_limits.py b/colour/volume/macadam_limits.py index 037da7b7d..db0de61c7 100644 --- a/colour/volume/macadam_limits.py +++ b/colour/volume/macadam_limits.py @@ -21,6 +21,7 @@ from colour.colorimetry import ( MSDS_CMFS, reshape_sd, + SpectralDistribution, SpectralShape, SDS_ILLUMINANTS, ) From 463a1b21a7cdd9dd592c8482e9269ba9a7fbbbd3 Mon Sep 17 00:00:00 2001 From: Christian Greim <36072637+gutenzwerg@users.noreply.github.com> Date: Thu, 16 Jun 2022 19:43:03 +0200 Subject: [PATCH 25/46] Update macadam_limits.py Several updates to meet KelSolaars recommendations --- colour/volume/macadam_limits.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/colour/volume/macadam_limits.py b/colour/volume/macadam_limits.py index db0de61c7..a8e814f74 100644 --- a/colour/volume/macadam_limits.py +++ b/colour/volume/macadam_limits.py @@ -160,11 +160,11 @@ def macadam_limits( Return an array of CIE -X,Y,Z - Triples containing colour-coordinates of the MacAdam-limit for the defined luminance for every whavelength defined in spectral_range. - Target ist a fast running codey, by - not simply testing the possible optimums step by step but - more effectively targeted by steps of power of two. The wavelengths - left and right of a rough optimum are fitted by a rule of proportion, - so that the wished brightness will be reached exactly. + Target ist a fast running codey, by not simply testing the possible + optimums step by step but more effectively targeted by steps of + power of two. The wavelengths left and right of a rough optimum are + fitted by a rule of proportion, so that the wished brightness will be + reached exactly. Parameters ---------- From 92a1cd124c234630318d43073b92482f7812f56e Mon Sep 17 00:00:00 2001 From: Roland Greim Date: Thu, 16 Jun 2022 20:22:15 +0200 Subject: [PATCH 26/46] Trigger CI From 78141ce8b6b3bd51b1784fe1ea1018ef762fd6ae Mon Sep 17 00:00:00 2001 From: Christian Greim <36072637+gutenzwerg@users.noreply.github.com> Date: Fri, 17 Jun 2022 08:38:27 +0200 Subject: [PATCH 27/46] Update macadam_limits.py Several updates to meet KelSolaars recommendations --- colour/volume/macadam_limits.py | 12 +++--------- 1 file changed, 3 insertions(+), 9 deletions(-) diff --git a/colour/volume/macadam_limits.py b/colour/volume/macadam_limits.py index a8e814f74..80e1bd37a 100644 --- a/colour/volume/macadam_limits.py +++ b/colour/volume/macadam_limits.py @@ -152,9 +152,9 @@ def is_within_macadam_limits( def macadam_limits( luminance: Floating = 0.5, - illuminant: Optional[SpectralDistribution] = None, - spectral_range: Optional[SpectralShape] = None, - cmfs: Optional[SpectralDistribution] = None, + illuminant: Optional = SDS_ILLUMINANTS["E"], + spectral_range: Optional = SpectralShape(360, 830, 1), + cmfs: Optional = MSDS_CMFS["CIE 1931 2 Degree Standard Observer"], ) -> NDArray: """ Return an array of CIE -X,Y,Z - Triples containing colour-coordinates @@ -234,12 +234,6 @@ def plot_Narrowband_Spectra (Yxy_Narrowband_Spectra): plt.show() """ - if cmfs is None: - cmfs = MSDS_CMFS["CIE 1931 2 Degree Standard Observer"] - if illuminant is None: - illuminant = SDS_ILLUMINANTS["E"] - if spectral_range is None: - spectral_range = SpectralShape(360, 830, 1) target_bright = luminance if target_bright > 1 or target_bright < 0: raise TypeError( From a190c00a64e6eb021ab4358db09056073161e888 Mon Sep 17 00:00:00 2001 From: Christian Greim <36072637+gutenzwerg@users.noreply.github.com> Date: Fri, 17 Jun 2022 08:42:13 +0200 Subject: [PATCH 28/46] Update macadam_limits.py Several updates to meet KelSolaars recommendations --- colour/volume/macadam_limits.py | 1 - 1 file changed, 1 deletion(-) diff --git a/colour/volume/macadam_limits.py b/colour/volume/macadam_limits.py index 80e1bd37a..3cc8f0444 100644 --- a/colour/volume/macadam_limits.py +++ b/colour/volume/macadam_limits.py @@ -21,7 +21,6 @@ from colour.colorimetry import ( MSDS_CMFS, reshape_sd, - SpectralDistribution, SpectralShape, SDS_ILLUMINANTS, ) From c67984df680fdc4e7eca437be75ae0aadc54ff02 Mon Sep 17 00:00:00 2001 From: Christian Greim <36072637+gutenzwerg@users.noreply.github.com> Date: Fri, 17 Jun 2022 09:11:35 +0200 Subject: [PATCH 29/46] Update macadam_limits.py Several updates to meet KelSolaars recommendations --- colour/volume/macadam_limits.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/colour/volume/macadam_limits.py b/colour/volume/macadam_limits.py index 3cc8f0444..f2d46a015 100644 --- a/colour/volume/macadam_limits.py +++ b/colour/volume/macadam_limits.py @@ -151,9 +151,10 @@ def is_within_macadam_limits( def macadam_limits( luminance: Floating = 0.5, - illuminant: Optional = SDS_ILLUMINANTS["E"], - spectral_range: Optional = SpectralShape(360, 830, 1), - cmfs: Optional = MSDS_CMFS["CIE 1931 2 Degree Standard Observer"], + illuminant: Optional[SDS_ILLUMINANTS] = SDS_ILLUMINANTS["E"], + spectral_range: Optional[SpectralShape] = SpectralShape(360, 830, 1), + cmfs: Optional[MSDS_CMFS] = + MSDS_CMFS["CIE 1931 2 Degree Standard Observer"], ) -> NDArray: """ Return an array of CIE -X,Y,Z - Triples containing colour-coordinates From a603c189407cd1b0af9b5aeb83bbae62b45c08a6 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Fri, 17 Jun 2022 07:14:08 +0000 Subject: [PATCH 30/46] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- colour/volume/macadam_limits.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/colour/volume/macadam_limits.py b/colour/volume/macadam_limits.py index f2d46a015..ae395b943 100644 --- a/colour/volume/macadam_limits.py +++ b/colour/volume/macadam_limits.py @@ -153,8 +153,9 @@ def macadam_limits( luminance: Floating = 0.5, illuminant: Optional[SDS_ILLUMINANTS] = SDS_ILLUMINANTS["E"], spectral_range: Optional[SpectralShape] = SpectralShape(360, 830, 1), - cmfs: Optional[MSDS_CMFS] = - MSDS_CMFS["CIE 1931 2 Degree Standard Observer"], + cmfs: Optional[MSDS_CMFS] = MSDS_CMFS[ + "CIE 1931 2 Degree Standard Observer" + ], ) -> NDArray: """ Return an array of CIE -X,Y,Z - Triples containing colour-coordinates From 0659c32251d925ef3e6a873bf4dfddffdbdfecdf Mon Sep 17 00:00:00 2001 From: Christian Greim <36072637+gutenzwerg@users.noreply.github.com> Date: Fri, 17 Jun 2022 10:27:26 +0200 Subject: [PATCH 31/46] Update macadam_limits.py Several updates to meet KelSolaars recommendations --- colour/volume/macadam_limits.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/colour/volume/macadam_limits.py b/colour/volume/macadam_limits.py index ae395b943..023eba4ba 100644 --- a/colour/volume/macadam_limits.py +++ b/colour/volume/macadam_limits.py @@ -21,6 +21,7 @@ from colour.colorimetry import ( MSDS_CMFS, reshape_sd, + SpectralDistribution, SpectralShape, SDS_ILLUMINANTS, ) @@ -151,9 +152,9 @@ def is_within_macadam_limits( def macadam_limits( luminance: Floating = 0.5, - illuminant: Optional[SDS_ILLUMINANTS] = SDS_ILLUMINANTS["E"], - spectral_range: Optional[SpectralShape] = SpectralShape(360, 830, 1), - cmfs: Optional[MSDS_CMFS] = MSDS_CMFS[ + illuminant: Optional[SpectralDistribution] = SDS_ILLUMINANTS["E"], + spectral_range: Optional[SpectralShape()] = SpectralShape(360, 830, 1), + cmfs: Optional[SpectralDistribution] = MSDS_CMFS[ "CIE 1931 2 Degree Standard Observer" ], ) -> NDArray: From f91801fa5b22e36d7b9bedaa6fec6a467830472d Mon Sep 17 00:00:00 2001 From: Christian Greim <36072637+gutenzwerg@users.noreply.github.com> Date: Fri, 17 Jun 2022 10:48:50 +0200 Subject: [PATCH 32/46] Update macadam_limits.py Several updates to meet KelSolaars recommendations --- colour/volume/macadam_limits.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/colour/volume/macadam_limits.py b/colour/volume/macadam_limits.py index 023eba4ba..c81030733 100644 --- a/colour/volume/macadam_limits.py +++ b/colour/volume/macadam_limits.py @@ -153,7 +153,7 @@ def is_within_macadam_limits( def macadam_limits( luminance: Floating = 0.5, illuminant: Optional[SpectralDistribution] = SDS_ILLUMINANTS["E"], - spectral_range: Optional[SpectralShape()] = SpectralShape(360, 830, 1), + spectral_range: Optional[SpectralShape] = SpectralShape(360, 830, 1), cmfs: Optional[SpectralDistribution] = MSDS_CMFS[ "CIE 1931 2 Degree Standard Observer" ], From 95a446eb4e30627ade45de41c57ef3e12ef4764d Mon Sep 17 00:00:00 2001 From: Christian Greim <36072637+gutenzwerg@users.noreply.github.com> Date: Tue, 21 Jun 2022 19:21:46 +0200 Subject: [PATCH 33/46] Update macadam_limits.py --- colour/volume/macadam_limits.py | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/colour/volume/macadam_limits.py b/colour/volume/macadam_limits.py index c81030733..dfbbe3115 100644 --- a/colour/volume/macadam_limits.py +++ b/colour/volume/macadam_limits.py @@ -152,11 +152,9 @@ def is_within_macadam_limits( def macadam_limits( luminance: Floating = 0.5, - illuminant: Optional[SpectralDistribution] = SDS_ILLUMINANTS["E"], - spectral_range: Optional[SpectralShape] = SpectralShape(360, 830, 1), - cmfs: Optional[SpectralDistribution] = MSDS_CMFS[ - "CIE 1931 2 Degree Standard Observer" - ], + illuminant: SDS_ILLUMINANTS = SDS_ILLUMINANTS["E"], + spectral_range: SpectralShape = SpectralShape(360, 830, 1), + cmfs: MSDS_CMFS = MSDS_CMFS["CIE 1931 2 Degree Standard Observer"], ) -> NDArray: """ Return an array of CIE -X,Y,Z - Triples containing colour-coordinates From 38b727af4ed35d70b36e39f93af9b4bb485823d6 Mon Sep 17 00:00:00 2001 From: Christian Greim <36072637+gutenzwerg@users.noreply.github.com> Date: Tue, 21 Jun 2022 19:28:29 +0200 Subject: [PATCH 34/46] Update macadam_limits.py Several updates to meet KelSolaars suggestions --- colour/volume/macadam_limits.py | 1 - 1 file changed, 1 deletion(-) diff --git a/colour/volume/macadam_limits.py b/colour/volume/macadam_limits.py index dfbbe3115..f613558bd 100644 --- a/colour/volume/macadam_limits.py +++ b/colour/volume/macadam_limits.py @@ -21,7 +21,6 @@ from colour.colorimetry import ( MSDS_CMFS, reshape_sd, - SpectralDistribution, SpectralShape, SDS_ILLUMINANTS, ) From fa6485b9b91f9b960b0c7d18ed663c8d5bbea4b3 Mon Sep 17 00:00:00 2001 From: Christian Greim <36072637+gutenzwerg@users.noreply.github.com> Date: Tue, 21 Jun 2022 19:59:42 +0200 Subject: [PATCH 35/46] Update macadam_limits.py Several updates to meet KelSolaars recommendations --- colour/volume/macadam_limits.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/colour/volume/macadam_limits.py b/colour/volume/macadam_limits.py index f613558bd..7c7071fc3 100644 --- a/colour/volume/macadam_limits.py +++ b/colour/volume/macadam_limits.py @@ -151,9 +151,9 @@ def is_within_macadam_limits( def macadam_limits( luminance: Floating = 0.5, - illuminant: SDS_ILLUMINANTS = SDS_ILLUMINANTS["E"], + illuminant: [SDS_ILLUMINANTS] = SDS_ILLUMINANTS["E"], spectral_range: SpectralShape = SpectralShape(360, 830, 1), - cmfs: MSDS_CMFS = MSDS_CMFS["CIE 1931 2 Degree Standard Observer"], + cmfs: [MSDS_CMFS] = MSDS_CMFS["CIE 1931 2 Degree Standard Observer"], ) -> NDArray: """ Return an array of CIE -X,Y,Z - Triples containing colour-coordinates From c1cd25ab57f65e3af9cef1297f7b0bd6f5d56ef2 Mon Sep 17 00:00:00 2001 From: Christian Greim <36072637+gutenzwerg@users.noreply.github.com> Date: Tue, 21 Jun 2022 20:24:01 +0200 Subject: [PATCH 36/46] Update macadam_limits.py Several updates to meet KelSolaars recommendations --- colour/volume/macadam_limits.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/colour/volume/macadam_limits.py b/colour/volume/macadam_limits.py index 7c7071fc3..3351d8280 100644 --- a/colour/volume/macadam_limits.py +++ b/colour/volume/macadam_limits.py @@ -151,9 +151,9 @@ def is_within_macadam_limits( def macadam_limits( luminance: Floating = 0.5, - illuminant: [SDS_ILLUMINANTS] = SDS_ILLUMINANTS["E"], - spectral_range: SpectralShape = SpectralShape(360, 830, 1), - cmfs: [MSDS_CMFS] = MSDS_CMFS["CIE 1931 2 Degree Standard Observer"], + illuminant = SDS_ILLUMINANTS["E"], + spectral_range = SpectralShape(360, 830, 1), + cmfs = MSDS_CMFS["CIE 1931 2 Degree Standard Observer"], ) -> NDArray: """ Return an array of CIE -X,Y,Z - Triples containing colour-coordinates From 9f28353c059898b73ca308a59c3303742353d7d5 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Tue, 21 Jun 2022 18:28:31 +0000 Subject: [PATCH 37/46] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- colour/volume/macadam_limits.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/colour/volume/macadam_limits.py b/colour/volume/macadam_limits.py index 3351d8280..fda2caf69 100644 --- a/colour/volume/macadam_limits.py +++ b/colour/volume/macadam_limits.py @@ -151,9 +151,9 @@ def is_within_macadam_limits( def macadam_limits( luminance: Floating = 0.5, - illuminant = SDS_ILLUMINANTS["E"], - spectral_range = SpectralShape(360, 830, 1), - cmfs = MSDS_CMFS["CIE 1931 2 Degree Standard Observer"], + illuminant=SDS_ILLUMINANTS["E"], + spectral_range=SpectralShape(360, 830, 1), + cmfs=MSDS_CMFS["CIE 1931 2 Degree Standard Observer"], ) -> NDArray: """ Return an array of CIE -X,Y,Z - Triples containing colour-coordinates From e58c32b5c342cdfb68c45d610d395c6d18b4b869 Mon Sep 17 00:00:00 2001 From: Christian Greim <36072637+gutenzwerg@users.noreply.github.com> Date: Wed, 22 Jun 2022 10:04:47 +0200 Subject: [PATCH 38/46] Update macadam_limits.py Several updates to meet the recommendations of KelSolaar --- colour/volume/macadam_limits.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/colour/volume/macadam_limits.py b/colour/volume/macadam_limits.py index fda2caf69..2975ac89b 100644 --- a/colour/volume/macadam_limits.py +++ b/colour/volume/macadam_limits.py @@ -160,9 +160,9 @@ def macadam_limits( of the MacAdam-limit for the defined luminance for every whavelength defined in spectral_range. Target ist a fast running codey, by not simply testing the possible - optimums step by step but more effectively targeted by steps of - power of two. The wavelengths left and right of a rough optimum are - fitted by a rule of proportion, so that the wished brightness will be + optimums step by step but more effectively targeted by steps of power + of two. The wavelengths left and right of a rough optimum are fitted + by a rule of proportion, so that the wished brightness will be reached exactly. Parameters From fd3a52fdd1d92c9078f328fffbac20ec621b6215 Mon Sep 17 00:00:00 2001 From: Christian Greim <36072637+gutenzwerg@users.noreply.github.com> Date: Thu, 7 Jul 2022 15:14:12 +0200 Subject: [PATCH 39/46] Update macadam_limits.py Some changes to meet KelSolaars recommendations. --- colour/volume/macadam_limits.py | 47 ++++++++++++++++++++++----------- 1 file changed, 31 insertions(+), 16 deletions(-) diff --git a/colour/volume/macadam_limits.py b/colour/volume/macadam_limits.py index 2975ac89b..7004c8dc7 100644 --- a/colour/volume/macadam_limits.py +++ b/colour/volume/macadam_limits.py @@ -7,14 +7,20 @@ from __future__ import annotations import numpy as np +from colour import ( + SDS_ILLUMINANTS, + MSDS_CMFS, + MultiSpectralDistributions, + SpectralDistribution +) from scipy.spatial import Delaunay - from colour.hints import ( ArrayLike, Dict, Floating, Literal, NDArray, + Sequence, Optional, Union, ) @@ -26,7 +32,12 @@ ) from colour.models import xyY_to_XYZ from colour.volume import OPTIMAL_COLOUR_STIMULI_ILLUMINANTS -from colour.utilities import CACHE_REGISTRY, validate_method +from colour.utilities import ( + CACHE_REGISTRY, + tsplit, + zeros, + validate_method +) __author__ = "Colour Developers", "Christian Greim" __copyright__ = "Copyright 2013 Colour Developers" @@ -151,19 +162,23 @@ def is_within_macadam_limits( def macadam_limits( luminance: Floating = 0.5, - illuminant=SDS_ILLUMINANTS["E"], - spectral_range=SpectralShape(360, 830, 1), - cmfs=MSDS_CMFS["CIE 1931 2 Degree Standard Observer"], + illuminant: Optional[SpectralDistribution] = SDS_ILLUMINANTS["E"], + spectral_range: Optional[SpectralShape] = SpectralShape(360, 830, 1), + cmfs: Optional[Union[ + MultiSpectralDistributions, + str, + Sequence[Union[MultiSpectralDistributions, str]], + ]] = MSDS_CMFS["CIE 1931 2 Degree Standard Observer"], ) -> NDArray: """ Return an array of CIE -X,Y,Z - Triples containing colour-coordinates of the MacAdam-limit for the defined luminance for every whavelength defined in spectral_range. - Target ist a fast running codey, by not simply testing the possible - optimums step by step but more effectively targeted by steps of power - of two. The wavelengths left and right of a rough optimum are fitted - by a rule of proportion, so that the wished brightness will be - reached exactly. + Target ist a fast running codey, by + not simply testing the possible optimums step by step but + more effectively targeted by steps of power of two. The wavelengths + left and right of a rough optimum are fitted by a rule of proportion, + so that the wished brightness will be reached exactly. Parameters ---------- @@ -232,7 +247,7 @@ def plot_Narrowband_Spectra (Yxy_Narrowband_Spectra): plot_Narrowband_Spectra (Yxy_Narrowband_Spectra) plt.show() """ - + target_bright = luminance if target_bright > 1 or target_bright < 0: raise TypeError( @@ -246,9 +261,9 @@ def plot_Narrowband_Spectra (Yxy_Narrowband_Spectra): illuminant = reshape_sd(illuminant, spectral_range) # The cmfs are convolved with the given illuminant - X_illuminated = cmfs.values[..., 0] * illuminant.values - Y_illuminated = cmfs.values[..., 1] * illuminant.values - Z_illuminated = cmfs.values[..., 2] * illuminant.values + X_illuminated,Y_illuminated,Z_illuminated = ( + tsplit(cmfs.values) * illuminant.values + ) # Generate empty output-array out_limits = np.zeros_like(cmfs.values) # For examle a SpectralShape(360, 830, 1) has 471 entries @@ -269,7 +284,7 @@ def plot_Narrowband_Spectra (Yxy_Narrowband_Spectra): maximum_brightness = np.sum(Y_illuminated) def optimum_colour(width, center): - opti_colour = np.zeros(colour_range) + opti_colour = zeros(colour_range) # creates array of 471 zeros and ones which represents optimum-colours # All values of the opti_colour-array are initially set to zero half_width = width @@ -319,7 +334,7 @@ def bright_opti_colour(width, center, lightsource): bright_difference = (brightness - target_bright) * maximum_brightness # discrimination for single-wavelength-spectra if width > 0: - opti_colour = np.zeros(colour_range) + opti_colour = zeros(colour_range) opti_colour[ middle_opti_colour - width : middle_opti_colour + width + 1 ] = 1 From 5d817da71a2577012107e5fe32ee1c74196928e6 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Thu, 7 Jul 2022 13:16:42 +0000 Subject: [PATCH 40/46] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- colour/volume/macadam_limits.py | 25 +++++++++++-------------- 1 file changed, 11 insertions(+), 14 deletions(-) diff --git a/colour/volume/macadam_limits.py b/colour/volume/macadam_limits.py index 7004c8dc7..edd955272 100644 --- a/colour/volume/macadam_limits.py +++ b/colour/volume/macadam_limits.py @@ -11,7 +11,7 @@ SDS_ILLUMINANTS, MSDS_CMFS, MultiSpectralDistributions, - SpectralDistribution + SpectralDistribution, ) from scipy.spatial import Delaunay from colour.hints import ( @@ -32,12 +32,7 @@ ) from colour.models import xyY_to_XYZ from colour.volume import OPTIMAL_COLOUR_STIMULI_ILLUMINANTS -from colour.utilities import ( - CACHE_REGISTRY, - tsplit, - zeros, - validate_method -) +from colour.utilities import CACHE_REGISTRY, tsplit, zeros, validate_method __author__ = "Colour Developers", "Christian Greim" __copyright__ = "Copyright 2013 Colour Developers" @@ -164,11 +159,13 @@ def macadam_limits( luminance: Floating = 0.5, illuminant: Optional[SpectralDistribution] = SDS_ILLUMINANTS["E"], spectral_range: Optional[SpectralShape] = SpectralShape(360, 830, 1), - cmfs: Optional[Union[ - MultiSpectralDistributions, - str, - Sequence[Union[MultiSpectralDistributions, str]], - ]] = MSDS_CMFS["CIE 1931 2 Degree Standard Observer"], + cmfs: Optional[ + Union[ + MultiSpectralDistributions, + str, + Sequence[Union[MultiSpectralDistributions, str]], + ] + ] = MSDS_CMFS["CIE 1931 2 Degree Standard Observer"], ) -> NDArray: """ Return an array of CIE -X,Y,Z - Triples containing colour-coordinates @@ -247,7 +244,7 @@ def plot_Narrowband_Spectra (Yxy_Narrowband_Spectra): plot_Narrowband_Spectra (Yxy_Narrowband_Spectra) plt.show() """ - + target_bright = luminance if target_bright > 1 or target_bright < 0: raise TypeError( @@ -261,7 +258,7 @@ def plot_Narrowband_Spectra (Yxy_Narrowband_Spectra): illuminant = reshape_sd(illuminant, spectral_range) # The cmfs are convolved with the given illuminant - X_illuminated,Y_illuminated,Z_illuminated = ( + X_illuminated, Y_illuminated, Z_illuminated = ( tsplit(cmfs.values) * illuminant.values ) # Generate empty output-array From c87523b49793e94f4983337e307a05025b040697 Mon Sep 17 00:00:00 2001 From: Christian Greim <36072637+gutenzwerg@users.noreply.github.com> Date: Thu, 7 Jul 2022 15:21:40 +0200 Subject: [PATCH 41/46] Update macadam_limits.py Some updates to meet KelSolaars recommendations --- colour/volume/macadam_limits.py | 2 -- 1 file changed, 2 deletions(-) diff --git a/colour/volume/macadam_limits.py b/colour/volume/macadam_limits.py index edd955272..a8e9470b7 100644 --- a/colour/volume/macadam_limits.py +++ b/colour/volume/macadam_limits.py @@ -8,8 +8,6 @@ import numpy as np from colour import ( - SDS_ILLUMINANTS, - MSDS_CMFS, MultiSpectralDistributions, SpectralDistribution, ) From 31f2dbda81aa82740dcc92225fd1cee7349a7747 Mon Sep 17 00:00:00 2001 From: Christian Greim <36072637+gutenzwerg@users.noreply.github.com> Date: Thu, 7 Jul 2022 16:43:38 +0200 Subject: [PATCH 42/46] Update macadam_limits.py Some updates to meet KelSolaars recommendations --- colour/volume/macadam_limits.py | 12 +++--------- 1 file changed, 3 insertions(+), 9 deletions(-) diff --git a/colour/volume/macadam_limits.py b/colour/volume/macadam_limits.py index a8e9470b7..67e33ce72 100644 --- a/colour/volume/macadam_limits.py +++ b/colour/volume/macadam_limits.py @@ -155,15 +155,9 @@ def is_within_macadam_limits( def macadam_limits( luminance: Floating = 0.5, - illuminant: Optional[SpectralDistribution] = SDS_ILLUMINANTS["E"], - spectral_range: Optional[SpectralShape] = SpectralShape(360, 830, 1), - cmfs: Optional[ - Union[ - MultiSpectralDistributions, - str, - Sequence[Union[MultiSpectralDistributions, str]], - ] - ] = MSDS_CMFS["CIE 1931 2 Degree Standard Observer"], + illuminant: Optional[ArrayLike] = SDS_ILLUMINANTS["E"], + spectral_range: Optional[ArrayLike] = SpectralShape(360, 830, 1), + cmfs: Optional[ArrayLike] = MSDS_CMFS["CIE 1931 2 Degree Standard Observer"], ) -> NDArray: """ Return an array of CIE -X,Y,Z - Triples containing colour-coordinates From 5ed84a09b87ce1b00026825bc478f3d790d78e5f Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Thu, 7 Jul 2022 14:46:41 +0000 Subject: [PATCH 43/46] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- colour/volume/macadam_limits.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/colour/volume/macadam_limits.py b/colour/volume/macadam_limits.py index 67e33ce72..9a82982df 100644 --- a/colour/volume/macadam_limits.py +++ b/colour/volume/macadam_limits.py @@ -157,7 +157,9 @@ def macadam_limits( luminance: Floating = 0.5, illuminant: Optional[ArrayLike] = SDS_ILLUMINANTS["E"], spectral_range: Optional[ArrayLike] = SpectralShape(360, 830, 1), - cmfs: Optional[ArrayLike] = MSDS_CMFS["CIE 1931 2 Degree Standard Observer"], + cmfs: Optional[ArrayLike] = MSDS_CMFS[ + "CIE 1931 2 Degree Standard Observer" + ], ) -> NDArray: """ Return an array of CIE -X,Y,Z - Triples containing colour-coordinates From cbdb8b494ca06151648d9494f87888337b055ab4 Mon Sep 17 00:00:00 2001 From: Christian Greim <36072637+gutenzwerg@users.noreply.github.com> Date: Thu, 7 Jul 2022 16:54:02 +0200 Subject: [PATCH 44/46] Update macadam_limits.py Some updates to meet KelSolaars recommendations --- colour/volume/macadam_limits.py | 5 ----- 1 file changed, 5 deletions(-) diff --git a/colour/volume/macadam_limits.py b/colour/volume/macadam_limits.py index 9a82982df..4fc4f156e 100644 --- a/colour/volume/macadam_limits.py +++ b/colour/volume/macadam_limits.py @@ -7,10 +7,6 @@ from __future__ import annotations import numpy as np -from colour import ( - MultiSpectralDistributions, - SpectralDistribution, -) from scipy.spatial import Delaunay from colour.hints import ( ArrayLike, @@ -18,7 +14,6 @@ Floating, Literal, NDArray, - Sequence, Optional, Union, ) From d1eca3ba035339792d631bf0aafcfc05af9515e7 Mon Sep 17 00:00:00 2001 From: Christian Greim <36072637+gutenzwerg@users.noreply.github.com> Date: Thu, 7 Jul 2022 17:55:17 +0200 Subject: [PATCH 45/46] Update macadam_limits.py An update to meet Kelsolaars recommendations --- colour/volume/macadam_limits.py | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/colour/volume/macadam_limits.py b/colour/volume/macadam_limits.py index 4fc4f156e..cc3eedd7c 100644 --- a/colour/volume/macadam_limits.py +++ b/colour/volume/macadam_limits.py @@ -150,11 +150,9 @@ def is_within_macadam_limits( def macadam_limits( luminance: Floating = 0.5, - illuminant: Optional[ArrayLike] = SDS_ILLUMINANTS["E"], - spectral_range: Optional[ArrayLike] = SpectralShape(360, 830, 1), - cmfs: Optional[ArrayLike] = MSDS_CMFS[ - "CIE 1931 2 Degree Standard Observer" - ], + illuminant = SDS_ILLUMINANTS["E"], + spectral_range = SpectralShape(360, 830, 1), + cmfs = MSDS_CMFS["CIE 1931 2 Degree Standard Observer"], ) -> NDArray: """ Return an array of CIE -X,Y,Z - Triples containing colour-coordinates From b5f06c8b00970c03a8812fc9dbae61eba366c078 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Thu, 7 Jul 2022 15:57:38 +0000 Subject: [PATCH 46/46] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- colour/volume/macadam_limits.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/colour/volume/macadam_limits.py b/colour/volume/macadam_limits.py index cc3eedd7c..f2d6df93a 100644 --- a/colour/volume/macadam_limits.py +++ b/colour/volume/macadam_limits.py @@ -150,9 +150,9 @@ def is_within_macadam_limits( def macadam_limits( luminance: Floating = 0.5, - illuminant = SDS_ILLUMINANTS["E"], - spectral_range = SpectralShape(360, 830, 1), - cmfs = MSDS_CMFS["CIE 1931 2 Degree Standard Observer"], + illuminant=SDS_ILLUMINANTS["E"], + spectral_range=SpectralShape(360, 830, 1), + cmfs=MSDS_CMFS["CIE 1931 2 Degree Standard Observer"], ) -> NDArray: """ Return an array of CIE -X,Y,Z - Triples containing colour-coordinates