Hi all!

I have a strange problem with the atomic_orbitals.py example. I edited the 
code to read in the numpy array Phi from a hdf5 file and it stopped working, 
saying

TraitError: The 'point_scalars_name' trait of a SetActiveAttribute instance 
must be one of ['scalar', ''], but a value of 'angle' <type 'str'> was 
specified.

I have several other codes, where the corresponding structure works, but 
copying those over does not work either. It is as if there is some internal 
structure which needs to be initialised (or reset?) and which my other codes 
and unmodified atomic_orbitals.py do.

Edited script is attached.

Any help appreciated!

Cheers,
Juha
from enthought.mayavi import mlab
import numpy,h5py

# open the input files
fil=h5py.File("world_%09d.hdf5"%(-1-99905),"r")
dat=fil["world"]
wf=h5py.File("world_%09d.hdf5"%(99905),"r")
wd=wf["world"]


# Create the data ############################################################

phi_r,phi_i=1,2
Phi = wd[:,:,:,phi_r]+1j*wd[:,:,:,phi_i]

# Plot it ####################################################################
from enthought.mayavi import mlab
mlab.figure(1, fgcolor=(1, 1, 1), bgcolor=(0, 0, 0))
# We create a scalar field with the module of Phi as the scalar
src = mlab.pipeline.scalar_field(numpy.abs(Phi))

# And we add the phase of Phi as an additional array
# This is a tricky part: the layout of the new array needs to be the same
# as the existing dataset, and no checks are performed. The shape needs
# to be the same, and so should the data. Failure to do so can result in 
# segfaults.
src.image_data.point_data.add_array(numpy.angle(Phi).T.ravel())
# We need to give a name to our new dataset.
src.image_data.point_data.get_array(1).name = 'angle'

# We select the 'scalar' attribute, ie the norm of Phi
src2 = mlab.pipeline.set_active_attribute(src,
                                    point_scalars='scalar')

# Cut isosurfaces of the norm
contour = mlab.pipeline.contour(src2)

# Now we select the 'angle' attribute, ie the phase of Phi
contour2 = mlab.pipeline.set_active_attribute(contour,
                                    point_scalars='angle')

# And we display the surface. The colormap is the current attribute: the phase.
mlab.pipeline.surface(contour2, colormap='hsv')

mlab.colorbar(title='Phase', orientation='vertical', nb_labels=3)

mlab.show()
------------------------------------------------------------------------------
All of the data generated in your IT infrastructure is seriously valuable.
Why? It contains a definitive record of application performance, security 
threats, fraudulent activity, and more. Splunk takes this data and makes 
sense of it. IT sense. And common sense.
http://p.sf.net/sfu/splunk-d2d-c2
_______________________________________________
MayaVi-users mailing list
MayaVi-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/mayavi-users

Reply via email to