enthought / mayavi

3D visualization of scientific data in Python
http://docs.enthought.com/mayavi/mayavi/
Other
1.3k stars 284 forks source link

Intermittent error in traits #501

Open andrew2hart opened 7 years ago

andrew2hart commented 7 years ago

This code gives an intermittent error with vtk > 6.3

from mayavi import mlab
import numpy as np

my=np.array([[1,2,3],[4,5,6],[7,8,9]])
plotme=np.log(my)
plotme[np.isinf(plotme)]=0

mlab.figure(bgcolor=(0,0,0))
src=mlab.pipeline.scalar_field(plotme) 
mlab.pipeline.volume(src)
mlab.pipeline.image_plane_widget(src,plane_orientation='y_axes')
mlab.xlabel('E')
mlab.ylabel('mu')
mlab.zlabel('P')
mlab.outline()
mlab.show()

traits.trait_errors.TraitError: The 'vector_component' trait of a SmartVolumeMapper instance must be 0 <= a long integer <= 3, but a value of 1750425008 <class 'int'> was specified. The number is not always the same and some times there is no error. Changing to vtk 6.3 fixes the problem and it occurs in python 2 and 3. This is code cut down to show the error. I also tried similar code in fedora rawhide which is the only one with vtk7.1 as yet.

andrew2hart commented 7 years ago
from mayavi import mlab
import numpy as np
my=np.array([[1,2,3],[4,5,6],[7,8,9]])
src=mlab.pipeline.scalar_field(my) 
mlab.pipeline.volume(src)

Is enough to cause it.

HugoStrand commented 7 years ago

I am experiencing the same with VTK 7.1. Trying the volumetric rendering example of mayavi

import numpy as np
x,y,z = np.ogrid[-10:10:20j,-10:10:20j,-10:10:20j]
s = np.sin(x*y*z)/(x*y*z)

from mayavi import mlab
mlab.pipeline.volume(mlab.pipeline.scalar_field(s))
mlab.show()

produces

Generic Warning: In /opt/local/var/macports/build/_opt_bblocal_var_buildworker_ports_build_ports_graphics_vtk/vtk/work/VTK-7.1.0/Common/ExecutionModel/vtkAlgorithm.cxx, line 1808
vtkAlgorithm::SetUpdateExtent was deprecated for VTK 7.1 and will be removed in a future version.

Generic Warning: In /opt/local/var/macports/build/_opt_bblocal_var_buildworker_ports_build_ports_graphics_vtk/vtk/work/VTK-7.1.0/Common/ExecutionModel/vtkAlgorithm.cxx, line 1796
vtkAlgorithm::SetUpdateExtent was deprecated for VTK 7.1 and will be removed in a future version.

Generic Warning: In /opt/local/var/macports/build/_opt_bblocal_var_buildworker_ports_build_ports_graphics_vtk/vtk/work/VTK-7.1.0/Common/ExecutionModel/vtkStreamingDemandDrivenPipeline.cxx, line 1531
vtkStreamingDemandDrivenPipeline::SetUpdateExtent was deprecated for VTK 7.1 and will be removed in a future version.

Traceback (most recent call last):
  File "volume.py", line 7, in <module>
    mlab.pipeline.volume(mlab.pipeline.scalar_field(s))
  File "/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/mayavi/tools/pipe_base.py", line 38, in the_function
    factory = factory_class(*args, **kwargs)
  File "/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/mayavi/tools/pipe_base.py", line 146, in __init__
    if issubclass(self._target.__class__, Filter):
  File "/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/traits/trait_types.py", line 2801, in create_default_value
    return klass( *args[1:], **kw )
  File "/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/mayavi/core/module.py", line 58, in __init__
    self.setup_pipeline()
  File "/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/mayavi/modules/volume.py", line 318, in setup_pipeline
    available_mappers = find_volume_mappers()
  File "/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/mayavi/modules/volume.py", line 53, in find_volume_mappers
    inst = klass()
  File "tvtk_classes/smart_volume_mapper.py", line 108, in __init__
  File "/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/tvtk/tvtk_base.py", line 341, in __init__
    self.update_traits()
  File "/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/tvtk/tvtk_base.py", line 496, in update_traits
    setattr(self, name, val)
  File "/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/traits/trait_handlers.py", line 172, in error
    value )
traits.trait_errors.TraitError: The 'vector_component' trait of a SmartVolumeMapper instance must be 0 <= an integer <= 3, but a value of 557520968 <type 'int'> was specified.
andrew2hart commented 7 years ago

Yes, your code crashed the third time I ran it.(python 3.5.1, vtk 7.1.1, linux)

HugoStrand commented 7 years ago

Ok. I should maybe add that I am on Mac OS X, Sierra (10.12.4) with MacPorts py27-mayavi.

[~] $ python
Python 2.7.13 (default, Dec 18 2016, 05:36:03) 
[GCC 4.2.1 Compatible Apple LLVM 8.0.0 (clang-800.0.38)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> 
[~] $ python -c "import mayavi.version; print mayavi.version.version"
4.5.0
[~] $ port installed | grep vtk
  vtk @7.1.0_0+python27 (active)

But as far as I understand this seems to be an issue with the VTK 7.1 library?

Any developer out there?

braidedlogix commented 7 years ago

This is an issue for me under Python 3.6, VTK 7.1 with certain failure under OSX, and Linux. Under Windows, the problem is intermittent. On Linux, changing the definition of vector_component in tvtk.tvtk_classes.smart_volume_mapper.py of the install directory from

-vector_component = traits.Trait(2037150581, 2037150581, traits.Range(0, 3, enter_set=True, auto_set=False), help=\
+vector_component = traits.Trait(-1, help=\

allows it to run with (so far) no failures. It's not desirable, nor an easy change to make if the folder is zipped, but it might shed some light on the source of the problem.

heroxbd commented 7 years ago

I can reproduce it with VTK 7.1, Python 2.7 on GNU/Linux.

bond-anton commented 7 years ago

I added a while loop to your test code and for me it works after some (2 to 7) failures. My configuration: Linux, python 3.6 (virtualenv) + git version of mayavi + vtk 8.1.0 (git verion).

import numpy as np
x,y,z = np.ogrid[-10:10:20j,-10:10:20j,-10:10:20j]
s = np.sin(x*y*z)/(x*y*z)

from mayavi import mlab
while 1:
    try:
        mlab.pipeline.volume(mlab.pipeline.scalar_field(s))
        break
    except:
        print('Nope :(')
mlab.show()
bond-anton commented 7 years ago

Same script fails on MacOS Sierra + python 3.5 + mayavi 4.5.0 + vtk 7.1.1

bond-anton commented 6 years ago

MacOS mayavi-master python 3.6 VTK-8.0.1 raises TypeError

Traceback (most recent call last):
  File "/opt/local/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/mayavi/tools/pipe_base.py", line 38, in the_function
    factory = factory_class(*args, **kwargs)
  File "/opt/local/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/mayavi/tools/pipe_base.py", line 146, in __init__
    if issubclass(self._target.__class__, Filter):
  File "/opt/local/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/traits/trait_types.py", line 2800, in create_default_value
    return klass( *args[1:], **kw )
  File "/opt/local/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/mayavi/core/module.py", line 58, in __init__
    self.setup_pipeline()
  File "/opt/local/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/mayavi/modules/volume.py", line 307, in setup_pipeline
    self._ctf = ctf = default_CTF(0, 255)
  File "/opt/local/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/mayavi/modules/volume.py", line 125, in default_CTF
    mode='sqrt')
  File "/opt/local/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/mayavi/modules/volume.py", line 103, in make_CTF
    ctf.add_rgb_point(mins+x*ds, r, g, b)
  File "/opt/local/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/tvtk/util/ctf.py", line 210, in add_rgb_point
    self.nodes.sort()
  File "/opt/local/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/traits/trait_handlers.py", line 2566, in sort
    list.sort( self, cmp = cmp, key = key, reverse = reverse )
TypeError: sort() takes at most 2 arguments (3 given)
rdecharette commented 6 years ago

I'm facing the same issue when using the mlab.pipeline.volume() Setup: Win 10 64bits, Python 2.7, VTK 7.1, mayavi 4.5.0

The workaround proposed by @braidedlogix is working well for me. Thanks very much.

junyiphys commented 6 years ago

I'm facing exactly the same issue when using mlab.pipeline.volume() Setup: Fedora27, Python3.6, VTK7.1, mayavi 4.5.0, virtualenv

@braidedlogix's method also works for me. Thx.