Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

"colour.dominant_wavelength" definition seems to struggle with precise spectral locus CMF xy values?

See original GitHub issue

Issue Description

CMFS_1931 = colour.MSDS_CMFS["CIE 1931 2 Degree Standard Observer"]

CMFS_1931_xy = colour.XYZ_to_xy(CMFS_1931.values)
whitepoint = numpy.asarray([0.3101, 0.3163])

discard, locus_1931_samples_xy, discard = \
/usr/local/lib/python3.7/dist-packages/colour/algebra/ RuntimeWarning: invalid value encountered in true_divide
  u_a = numerator_a / denominator
/usr/local/lib/python3.7/dist-packages/colour/algebra/ RuntimeWarning: divide by zero encountered in true_divide
  u_b = numerator_b / denominator
/usr/local/lib/python3.7/dist-packages/colour/algebra/ RuntimeWarning: invalid value encountered in true_divide
  u_b = numerator_b / denominator
ValueError                                Traceback (most recent call last)
<ipython-input-40-2288142fce39> in <module>()
     10         CMFS_1931_xy,
     11         whitepoint,
---> 12         cmfs=CMFS_1931,
     14 )

3 frames
/usr/local/lib/python3.7/dist-packages/colour/colorimetry/ in dominant_wavelength(xy, xy_n, cmfs, inverse)
    194     xy_s = XYZ_to_xy(cmfs.values)
--> 196     i_wl, xy_wl = closest_spectral_locus_wavelength(xy, xy_n, xy_s, inverse)
    197     xy_cwl = xy_wl
    198     wl = cmfs.wavelengths[i_wl]

/usr/local/lib/python3.7/dist-packages/colour/colorimetry/ in closest_spectral_locus_wavelength(xy, xy_n, xy_s, inverse)
    117     i_wl = np.argmin(scipy.spatial.distance.cdist(xy_wl, xy_s), axis=-1)
--> 119     i_wl = np.reshape(i_wl, xy.shape[0:-1])
    120     xy_wl = np.reshape(xy_wl, xy.shape)

<__array_function__ internals> in reshape(*args, **kwargs)

/usr/local/lib/python3.7/dist-packages/numpy/core/ in reshape(a, newshape, order)
    297            [5, 6]])
    298     """
--> 299     return _wrapfunc(a, 'reshape', newshape, order=order)

/usr/local/lib/python3.7/dist-packages/numpy/core/ in _wrapfunc(obj, method, *args, **kwds)
     57     try:
---> 58         return bound(*args, **kwds)
     59     except TypeError:
     60         # A TypeError occurs if the object does have such a method in its

ValueError: cannot reshape array of size 6225 into shape (471,)

Issue Analytics

  • State:closed
  • Created a year ago
  • Comments:18 (18 by maintainers)

github_iconTop GitHub Comments

KelSolaarcommented, Feb 21, 2022

Nah, one liner change.

sobotkacommented, Feb 20, 2022

I arrived at one via Shapely. Not sure if it is relevant or if it could be viable for Colour, but it seems to work pretty well. Essentially create a Shapely polygon from the CMFS, then use the intersection to calculate.

spectral_locus_polygon = shapely.geometry.Polygon(
    CMFS_xyY[:, 0:2]
spectral_intersections = []
for line in xy_lines.geoms:
    intersection = spectral_locus_polygon.intersection(line)
Read more comments on GitHub >

github_iconTop Results From Across the Web

Dominant wavelength - Wikipedia
In color science, the dominant wavelength is a method of characterizing a color's hue. Along with purity, it makes up one half of...
Read more >
Chromaticity Diagram - an overview | ScienceDirect Topics
The spectrum locus is the set of chromaticity coordinates of pure monochromatic (single-wavelength) lights. All realizable colors fall within the spectrum ...
Read more >
LED Dominant vs Peak Wavelength - What is Going On?
My personal view is that dominant wavelength is a marketing-led simplification of colour specification. We go from CIE XYZ tristimulus (3 ...
Read more >
colour.dominant_wavelength — Colour 0.3.14 documentation
Returns the dominant wavelength λd for given colour stimulus xy and the related xywl first and xycw second intersection coordinates with the spectral...
Read more >
2.4 COLORIMETRY - 2.Concepts - Language of Light
The dominant wavelength (DW) of a colour is the wavelength of the spectrum colour whose chromaticity is on the same straight line as...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Post

No results found

github_iconTop Related Hashnode Post

No results found