+ All Categories
Home > Documents > 3D Data visualization with Mayavi

3D Data visualization with Mayavi

Date post: 09-Feb-2022
Category:
Upload: others
View: 4 times
Download: 0 times
Share this document with a friend
57
3D Data visualization with Mayavi Prabhu Ramachandran Department of Aerospace Engineering IIT Bombay SciPy.in 2012, December 27, IIT Bombay. Prabhu Ramachandran (IIT Bombay) Mayavi2 tutorial 1 / 53
Transcript
Page 1: 3D Data visualization with Mayavi

3D Data visualization with Mayavi

Prabhu Ramachandran

Department of Aerospace EngineeringIIT Bombay

SciPy.in 2012,December 27,IIT Bombay.

Prabhu Ramachandran (IIT Bombay) Mayavi2 tutorial 1 / 53

Page 2: 3D Data visualization with Mayavi

In memory of John Hunter,

Page 3: 3D Data visualization with Mayavi

Kenneth Gonsalves,

Page 4: 3D Data visualization with Mayavi

and Raj Mathur.

Page 5: 3D Data visualization with Mayavi

Objectives

At the end of this session you will be able to:1 Use mlab effectively to visualize numpy array data

of various kinds2 Apply some of mayavi’s advanced features

Page 6: 3D Data visualization with Mayavi

Outline

1 Quick introduction to Mayavi

2 mlab

Prabhu Ramachandran (IIT Bombay) Mayavi2 tutorial 6 / 53

Page 7: 3D Data visualization with Mayavi

Outline

1 Quick introduction to Mayavi

2 mlab

Prabhu Ramachandran (IIT Bombay) Mayavi2 tutorial 7 / 53

Page 8: 3D Data visualization with Mayavi

Overview of features

Page 9: 3D Data visualization with Mayavi
Page 10: 3D Data visualization with Mayavi

Live in your dialogs

Page 11: 3D Data visualization with Mayavi

Mayavi in applications

Page 12: 3D Data visualization with Mayavi

Exploring the documentation

Page 13: 3D Data visualization with Mayavi

Other features

Easy customizationOffscreen animationsAutomatic script generationPowerful command line options

Page 14: 3D Data visualization with Mayavi

Summary

http://code.enthought.com/projects/mayavi

Uses VTK (www.vtk.org)BSD licenseLinux, win32 and Mac OS XHighly scriptableEmbed in Traits UIs (wxPython and PyQt4)Envisage PluginsDebian/Ubuntu/FedoraPythonic

5

Page 15: 3D Data visualization with Mayavi

Outline

1 Quick introduction to Mayavi

2 mlab

Prabhu Ramachandran (IIT Bombay) Mayavi2 tutorial 15 / 53

Page 16: 3D Data visualization with Mayavi

Overview

SimpleConvenientFull-featured

Prabhu Ramachandran (IIT Bombay) Mayavi2 tutorial 16 / 53

Page 17: 3D Data visualization with Mayavi

Getting started

Vanilla:$ ipy thon −−gui=wx

with Pylab:$ ipy thon −−pylab=wx

Page 18: 3D Data visualization with Mayavi

Using mlab:

>>> from enthought . mayavi import mlab

Try these:

>>> mlab . tes t_ <TAB>>>> mlab . tes t_contour3d ( )>>> mlab . tes t_contour3d ??

Page 19: 3D Data visualization with Mayavi

Exploring the view

MouseKeyboardToolbarMayavi icon

10

Page 20: 3D Data visualization with Mayavi

mlab plotting functions

0D data

>>> from numpy import ∗>>> t = l inspace (0 , 2∗pi , 50)>>> u = cos ( t )∗ p i>>> x , y , z = s in ( u ) , cos ( u ) , s in ( t )

>>> mlab.points3d(x, y, z)

Page 21: 3D Data visualization with Mayavi

Changing how things look

Clearing the view>>> mlab.clf()

IPython is your friend!>>> mlab.points3d?

Extra argument: ScalarsKeyword argumentsUI

>>> mlab . po in ts3d ( x , y , z , t ,scale_mode= ’ none ’ )

Page 22: 3D Data visualization with Mayavi

Changing how things look

Clearing the view>>> mlab.clf()

IPython is your friend!>>> mlab.points3d?

Extra argument: ScalarsKeyword argumentsUI

>>> mlab . po in ts3d ( x , y , z , t ,scale_mode= ’ none ’ )

Page 23: 3D Data visualization with Mayavi

Changing how things look

Clearing the view>>> mlab.clf()

IPython is your friend!>>> mlab.points3d?

Extra argument: ScalarsKeyword argumentsUI

>>> mlab . po in ts3d ( x , y , z , t ,scale_mode= ’ none ’ )

Page 24: 3D Data visualization with Mayavi

1D data

>>> mlab.plot3d(x, y, z, t )

Plots lines between the points

Page 25: 3D Data visualization with Mayavi

2D data

>>> x , y = mgrid [−3:3:100 j ,−3:3:100 j ]>>> z = s in ( x∗x + y∗y )

>>> mlab.surf(x, y, z)

Assumes the points are rectilinear

Page 26: 3D Data visualization with Mayavi

2D data: mlab.mesh

>>> mlab.mesh(x, y, z)

Points needn’t be regular

>>> phi , the ta = numpy . mgrid [ 0 : p i :20 j ,. . . 0:2∗ p i :20 j ]>>> x = s in ( ph i )∗ cos ( the ta )>>> y = s in ( ph i )∗ s in ( the ta )>>> z = cos ( ph i )>>> mlab . mesh( x , y , z ,. . . r ep resen ta t i on = ’ wireframe ’ )

Page 27: 3D Data visualization with Mayavi

3D data

>>> x , y , z = ogr id [−5:5:64 j ,. . . −5:5:64 j ,. . . −5:5:64 j ]>>> mlab . contour3d ( x∗x∗0.5 + y∗y +

z∗z∗2)

Page 28: 3D Data visualization with Mayavi

3D vector data: mlab.quiver3d

>>> mlab . tes t_qu ive r3d ( )

obj = mlab.quiver3d(x, y, z, u, v, w)

40

Page 29: 3D Data visualization with Mayavi

3D vector data: mlab.flow

>>> x , y , z = mgrid [−2:3 , −2:3 , −2:3]>>> r = s q r t ( x∗∗2 + y∗∗2 + z∗∗4)>>> u = y∗ s in ( r ) / ( r +0.001)>>> v = −x∗ s in ( r ) / ( r +0.001)>>> w = ze ros_ l i ke ( z )>>> ob j = mlab . f low ( x , y , z , u , v , w,

seedtype= ’ plane ’ )>>> ob j . s t ream_t racer . i n t e g r a t o r _ t y p e = \

’ runge_kutta45 ’

Page 30: 3D Data visualization with Mayavi

Exercise: Lorenz equationdxdt

= s(y − x)

dydt

= rx − y − xz

dzdt

= xy − bz

Let s = 10, r = 28, b = 8./3.

Region of interestx , y , z = mgrid [−50:50:20 j ,−50:50:20 j ,

−10:60:20 j ]

Use mlab.quiver3d

Page 31: 3D Data visualization with Mayavi

Solutiondef l o renz ( x , y , z , s =10. , r =28. , b = 8 . / 3 . ) :

u = s ∗ ( y−x )v = r ∗x −y − x∗zw = x∗y − b∗zreturn u , v , w

x , y , z = mgrid [−50:50:20 j ,−50:50:20 j ,−10:60:20 j ]

u , v , w = lo renz ( x , y , z )

mlab . quiver3d ( x , y , z , u , v , w,sca l e_ fac t o r =0.01 ,mask_points =5)

mlab . show ( )

Page 32: 3D Data visualization with Mayavi

Issues and solutions

Basic visualization: not very usefulTweak parameters:mask_points, scale_factorExplore parameters on UImlab.flow is a lot better!

Good visualization involves work

50

Page 33: 3D Data visualization with Mayavi

Other utility functions

gcf: get current figuresavefig, figureaxes, outlinetitle , xlabel , ylabel , zlabel

colorbar, scalarbar, vectorbarshow: Standalone mlab scriptsOthers, see UG

Page 34: 3D Data visualization with Mayavi

Can we do more?

Yes!

Page 35: 3D Data visualization with Mayavi

quiver3d ( x , y , z ,u , v , w,sca l e_ fac t o r =0.01 ,mask_points =5)

Page 36: 3D Data visualization with Mayavi

Looking inside

Page 37: 3D Data visualization with Mayavi

The pipeline

60

Page 38: 3D Data visualization with Mayavi

Lookup tables

List of Modules

TVTK Scene

Filter

Source

Mayavi Engine

ModuleManager

Page 39: 3D Data visualization with Mayavi

Changing the pipeline

On UIRight click on nodedrag drop

Script

Or use mlab.pipelineExample: mlab.pipeline. outline ()obj.remove()

Page 40: 3D Data visualization with Mayavi

Exercise

>>> mlab . tes t_qu ive r3d ( )

Hide vectors, add a Vector Cut Plane

>>> mlab . t e s t _ f l o w ( )

Add a Vector Cut PlaneCan also use the Lorenz example

Page 41: 3D Data visualization with Mayavi

Exercise

>>> mlab . tes t_qu ive r3d ( )

Hide vectors, add a Vector Cut Plane

>>> mlab . t e s t _ f l o w ( )

Add a Vector Cut PlaneCan also use the Lorenz example

Page 42: 3D Data visualization with Mayavi

Surprised?

Page 43: 3D Data visualization with Mayavi

So what is the problem?

Page 44: 3D Data visualization with Mayavi

Points?

Page 45: 3D Data visualization with Mayavi

Curve?

Page 46: 3D Data visualization with Mayavi

Surface?

Page 47: 3D Data visualization with Mayavi

Interior of sphere?

Page 48: 3D Data visualization with Mayavi

Datasets

Quiver v/s Flow

75

Page 49: 3D Data visualization with Mayavi

Recap

mlab gets you startedPipeline and data flowDatasets are important

Page 50: 3D Data visualization with Mayavi

Changing the pipeline

On UIRight click on nodedrag drop

Script

Or use mlab.pipelineExample: mlab.pipeline. outline ()obj.remove()

Page 51: 3D Data visualization with Mayavi

mlab and Mayavi2?

mlab is just a thin layer over the Mayavi OO APImlab commands return mayavi objects

Page 52: 3D Data visualization with Mayavi

Exercise

1 Start with flow for the Lorenz system2 Now extract the vector norm (use a filter)3 Plot iso-contours of this4 Figure out how to do this from the UI and

mlab.pipeline

85

Prabhu Ramachandran (IIT Bombay) Mayavi2 tutorial 49 / 53

Page 53: 3D Data visualization with Mayavi

So how do you make a fancier script?

Use script recordingDemo

Page 54: 3D Data visualization with Mayavi

So how do you make a fancier script?

Use script recordingDemo

Page 55: 3D Data visualization with Mayavi

Animating data

>>> s = mlab . f low ( x , y , z , u , v , w)>>> s . mlab_source . u = u∗z

mlab_source.set: multiple attributesIf you change the shape of the arrays use the resetmethod

Page 56: 3D Data visualization with Mayavi

Setting the view

>>> pr in t mlab . view ( )>>> mlab . view ( azimuth=None ,

e l ev a t i on =None ,d is tance=None ,f o c a l p o i n t =None )

100

Page 57: 3D Data visualization with Mayavi

Thank you!


Recommended