question-mark
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.

IndexError when running the "textured gyroid shape" example

See original GitHub issue

Running this example:

vedo -r gyroid

gives me IndexError: list index out of range error:

gyroid - A textured gyroid shape cut by a sphere from vedo import..
(/Users/matus/miniconda3/envs/3d-vis/lib/python3.9/site-packages/vedo/examples/advanced/gyroid.py)
Traceback (most recent call last):
  File "/Users/matus/miniconda3/envs/3d-vis/lib/python3.9/site-packages/vedo/examples/advanced/gyroid.py", line 10, in <module>
    gyr = Volume(U).isosurface(0).smoothLaplacian().subdivide()
  File "/Users/matus/miniconda3/envs/3d-vis/lib/python3.9/site-packages/vedo/volume.py", line 1025, in __init__
    self.mode(mode).color(c).alpha(alpha).alphaGradient(alphaGradient)
  File "/Users/matus/miniconda3/envs/3d-vis/lib/python3.9/site-packages/vedo/base.py", line 1466, in color
    r,g,b = colors.colorMap(x, name=col, vmin=smin, vmax=smax)
  File "/Users/matus/miniconda3/envs/3d-vis/lib/python3.9/site-packages/vedo/colors.py", line 651, in colorMap
    return hex2rgb(cmap[n-iv])
IndexError: list index out of range

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:7 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
MatusGasparikcommented, Jun 29, 2021

I am on macOS:

os.uname()
posix.uname_result(sysname='Darwin', nodename='Foo-MacBook-Pro.local', release='20.5.0', version='Darwin Kernel Version 20.5.0: Sat May  8 05:10:33 PDT 2021; root:xnu-7195.121.3~9/RELEASE_X86_64', machine='x86_64')

with python==3.9.5. I haven’t checked all examples, but most of them work as expected.

I ran the script with the pdb:

python -m pdb -c continue /Users/matus/miniconda3/envs/3d-vis/lib/python3.9/site-packages/vedo/examples/advanced/gyroid.py

Here is the output:

(Pdb) ll
587  	def colorMap(value, name="jet", vmin=None, vmax=None):
588  	    """Map a real value in range [vmin, vmax] to a (r,g,b) color scale.
589
590  	    :param value: scalar value to transform into a color
591  	    :type value: float, list
592  	    :param name: color map name
593  	    :type name: str, matplotlib.colors.LinearSegmentedColormap
594
595  	    :return: (r,g,b) color, or a list of (r,g,b) colors.
596
597  	    .. note:: Most frequently used color maps:
598
599  	        |colormaps|
600
601  	        Color maps list:
602
603  	        .. image:: https://matplotlib.org/1.2.1/_images/show_colormaps.png
604
605  	    .. tip:: Can also use directly a matplotlib color map:
606
607  	        :Example:
608  	            .. code-block:: python
609
610  	                from vedo import colorMap
611  	                import matplotlib.cm as cm
612  	                print( colorMap(0.2, cm.flag, 0, 1) )
613
614  	                (1.0, 0.809016994374948, 0.6173258487801733)
615  	    """
616  	    value_isSequence = False
617  	    if _isSequence(value):
618  	        value_isSequence = True
619  	        values = np.array(value)
620  	        if vmin is None:
621  	            vmin = np.min(values)
622  	        if vmax is None:
623  	            vmax = np.max(values)
624  	        values = np.clip(values, vmin, vmax)
625  	        values -= vmin
626  	        values = values / (vmax - vmin)
627
628  	    # matplotlib not available #######################
629  	    if not _has_matplotlib:
630  	        invert=False
631  	        if name.endswith('_r'):
632  	            invert=True
633  	            name = name.replace('_r', "")
634  	        cmap = cmaps[name]
635
636  	        n = len(cmap)-1
637  	        if value_isSequence:
638  	            outs = []
639  	            for v in values:
640  	                iv = min(255, int(v*n))
641  	                if invert:
642  	                    rgb = hex2rgb(cmap[n-iv])
643  	                else:
644  	                    rgb = hex2rgb(cmap[iv])
645  	                outs.append(rgb)
646  	            return outs
647
648  	        else:
649  	            iv = min(255, int(value*n))
650  	            if invert:
651  ->	                return hex2rgb(cmap[n-iv])
652  	            else:
653  	                return hex2rgb(cmap[iv])
654
655  	    # matplotlib is available, use it! #######################
656  	    if isinstance(name, matplotlib.colors.LinearSegmentedColormap):
657  	        mp = name
658  	    else:
659  	        mp = cm_mpl.get_cmap(name=name)
660
661  	    if value_isSequence:
662  	        mp = cm_mpl.get_cmap(name=name)
663  	        return mp(values)[:,[0,1,2]]
664  	    else:
665  	        value -= vmin
666  	        dv = vmax - vmin
667  	        if dv:
668  	            value /= dv
669  	        if value > 0.999:
670  	            value = 0.999
671  	        elif value < 0:
672  	            value = 0
673  	        return mp(value)[0:3]
(Pdb) p iv
-381
(Pdb) p n
255

The iv value seem to be the issue…

0reactions
marcomusycommented, Jun 29, 2021

Ahhh !! Right I will add a more meaningful error message…

Read more comments on GitHub >

github_iconTop Results From Across the Web

film thickness ranging: Topics by Science.gov
Then, microstructure of thin films was determined using X-ray diffraction. To investigate the influence of temperature on the texture development in the Ag ......
Read more >
Untitled
Famiglia asburgo albero genealogico, Mother earth india website, Phd thesis latex template dtu, Indexerror index out of range 1 python.
Read more >
Untitled
And found wanting, Figure skating warm up exercises, Billy houghland, ... Fiesta mall mesa az fair, Index pivot table excel, Elsa cape template, ......
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 Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found