Scientific Computing with Python Webinar March 19: 3D Visualization with Mayavi


Published on

In this webinar, Didrik Pinte provides an introduction to MayaVi, the 3D interactive visualization library for the open source Enthought Tool Suite. These tools provide scientists and engineers a sophisticated Python development framework for analysis and visualization.

Published in: Technology, Art & Photos
  • Be the first to comment

No Downloads
Total views
On SlideShare
From Embeds
Number of Embeds
Embeds 0
No embeds

No notes for slide
  • This begins the technical overview—this section of our presentation was interspersed with several live demos which I’ll not try to duplicate here.
  • [toc] level = 1 title = 3D Visualization with mlab # end config
  • Scientific Computing with Python Webinar March 19: 3D Visualization with Mayavi

    1. 1. 3D visualisation with Mayavi <ul><li>March 19, 2010 </li></ul>
    2. 2. What is Mayavi ? <ul><li>Mayavi is a general purpose, cross-platform tool for 3-D scientific data visualization </li></ul><ul><ul><li>Visualization of scalar, vector and tensor data in 2 and 3 dimensions. </li></ul></ul><ul><ul><li>Easy scriptability using Python. </li></ul></ul><ul><ul><li>Easy extendability via custom sources, modules, and data filters. </li></ul></ul><ul><ul><li>Reading several file formats: VTK, PLOT3D, etc. </li></ul></ul><ul><ul><li>Saving of visualizations. </li></ul></ul><ul><ul><li>Saving rendered visualization in a variety of image formats. </li></ul></ul><ul><ul><li>Convenient functionality for rapid scientific plotting via mlab </li></ul></ul><ul><ul><li>A very example of what you can build on top of ETS </li></ul></ul>
    3. 3. Enthought Tool Suite
    4. 4. Mayavi user interface
    5. 5. Mayavi user interface <ul><li>DataSource, Filter and Modules </li></ul><ul><li>Recording </li></ul><ul><li>Shell plugin and scripting </li></ul>
    6. 6. Mayavi user interface <ul><li>DataSource, Filter and Modules </li></ul><ul><li>Recording </li></ul><ul><li>Shell plugin and scripting </li></ul>
    7. 7. Mayavi user interface <ul><li>DataSource, Filter and Modules </li></ul><ul><li>Recording </li></ul><ul><li>Shell plugin and scripting </li></ul>
    8. 8. Mayavi “API” or scripting with mlab # Create the data. from numpy import pi, sin, cos, mgrid dphi, dtheta = pi/250.0, pi/250.0 [phi,theta] = mgrid[0:pi+dphi*1.5:dphi,0:2*pi+dtheta*1.5:dtheta] m0 = 4; m1 = 3; m2 = 2; m3 = 3; m4 = 6; m5 = 2; m6 = 6; m7 = 4; r = sin(m0*phi)**m1 + cos(m2*phi)**m3 + sin(m4*theta)**m5 + cos(m6*theta)**m7 x = r*sin(phi)*cos(theta) y = r*cos(phi) z = r*sin(phi)*sin(theta) # View it. from enthought.mayavi import mlab s = mlab.mesh(x, y, z)
    9. 9. Running mlab within ipython C: ipython –wthread >>> from enthought.mayavi import mlab matplotlib also has an mlab namespace. Be sure you are using the one from enthought.mayavi
    10. 10. Plotting commands <ul><li>0D data </li></ul><ul><li>mlab.points3d(x, y, z) </li></ul>1D data mlab.plot3d(x, y, z) 3D data mlab.contour3d(x, y, z) Vector field mlab.quiver(x, y, z, u, v, w) 2D data, y, z)
    11. 11. Example with points in 3D mlab.points3d(x, y, z, color=(1.0,0.0,1.0), mode=‘sphere’, scale_factor=0.1) { x.shape == y.shape == z.shape color = (R, G, B) 0.0 <= R, G, B <= 1.0 default is (1.0, 1.0, 1.0) mode = ‘sphere’ , ‘cone’, ‘cube’, ‘arrow’, ‘cylinder’, ‘point’, ‘2darrow’, ‘2dcircle’, ‘2dcross’, ‘2ddash’, ‘2ddiamond’, ‘2dhooked_arrow’, ‘2dsquare’, ‘2dthick_arrow’, ‘2dthick_cross’, ‘2dtriangle’, ‘2dvertex’ scaling applied from numpy.random import rand x,y,z = rand(30),rand(30),rand(30) mlab.axes()
    12. 12. Mlab decorations <ul><li>mlab.title('A title') </li></ul><ul><li>mlab.axes() </li></ul><ul><li>mlab.colorbar() </li></ul><ul><li>mlab.clf() </li></ul><ul><li>mlab.figure() </li></ul><ul><li>mlab.gcf() </li></ul>
    13. 13. Mlab helper functions and the engine pipeline >>> mlab.figure() >>> >>> mlab.axes() Array2DSource _ WarpScalar _ PolyDataNormals _ Colors and legends _ Surface Array2DSource _ WarpScalar _ PolyDataNormals _ Colors and leg _ Surface def complete_pipeline_call(data_array): src = mlab.pipeline.array2d_source(data_array) warp = mlab.pipeline.warp_scalar(src) normals = mlab.pipeline.poly_data_normals(warp) return mlab.pipeline.surface(normals)
    14. 14. Looking for help and demo’s <ul><li>mlab.test_points3d() </li></ul><ul><li>mlab.test_plot3d() </li></ul><ul><li>mlab.test_surf() </li></ul><ul><li>mlab.test_contour3d() </li></ul><ul><li>mlab.test_quiver3d() </li></ul><ul><li>mlab.test_molecule() </li></ul><ul><li>mlab.test_flow() </li></ul><ul><li>mlab.test_mesh() </li></ul>Use ?? in IPython to look at the source code of these examples. <ul><li>Documentation </li></ul><ul><li>Mayavi examples coming with EPD </li></ul><ul><li>enthought-dev mailing list </li></ul><ul><li>Mlab test functions : </li></ul>
    15. 15. Mlab and Traits ( class ActorViewer(HasTraits): scene = Instance(MlabSceneModel, ()) view = View(Item(name='scene‘, editor=SceneEditor(scene_class=MayaviScene), show_label=False, resizable=True, height=500, width=500), resizable=True) def __init__(self, **traits): HasTraits.__init__(self, **traits) self.generate_data() def generate_data(self): X, Y = mgrid[-2:2:100j, -2:2:100j] R = 10*sqrt(X**2 + Y**2) Z = sin(R)/R, Y, Z, colormap='gist_earth') if __name__ == '__main__': a = ActorViewer() a.configure_traits()
    16. 16. Mlab and Traits (
    17. 17. Traits, Mayavi and Chaco (Thanks to Travis Vaught for the example)
    18. 18. EPD Enthought Training: Webinars