3D Data visualization with Mayavi Prabhu Ramachandran Department of - - PowerPoint PPT Presentation

3d data visualization with mayavi
SMART_READER_LITE
LIVE PREVIEW

3D Data visualization with Mayavi Prabhu Ramachandran Department of - - PowerPoint PPT Presentation

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 In memory of John Hunter, Kenneth


slide-1
SLIDE 1

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

slide-2
SLIDE 2

In memory of John Hunter,

slide-3
SLIDE 3

Kenneth Gonsalves,

slide-4
SLIDE 4

and Raj Mathur.

slide-5
SLIDE 5

Objectives

At the end of this session you will be able to:

1

Use mlab effectively to visualize numpy array data

  • f various kinds

2

Apply some of mayavi’s advanced features

slide-6
SLIDE 6

Outline

1

Quick introduction to Mayavi

2

mlab

Prabhu Ramachandran (IIT Bombay) Mayavi2 tutorial 6 / 53

slide-7
SLIDE 7

Outline

1

Quick introduction to Mayavi

2

mlab

Prabhu Ramachandran (IIT Bombay) Mayavi2 tutorial 7 / 53

slide-8
SLIDE 8

Overview of features

slide-9
SLIDE 9
slide-10
SLIDE 10

Live in your dialogs

slide-11
SLIDE 11

Mayavi in applications

slide-12
SLIDE 12

Exploring the documentation

slide-13
SLIDE 13

Other features

Easy customization Offscreen animations Automatic script generation Powerful command line options

slide-14
SLIDE 14

Summary

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

Uses VTK (www.vtk.org) BSD license Linux, win32 and Mac OS X Highly scriptable Embed in Traits UIs (wxPython and PyQt4) Envisage Plugins Debian/Ubuntu/Fedora Pythonic

5

slide-15
SLIDE 15

Outline

1

Quick introduction to Mayavi

2

mlab

Prabhu Ramachandran (IIT Bombay) Mayavi2 tutorial 15 / 53

slide-16
SLIDE 16

Overview Simple Convenient Full-featured

Prabhu Ramachandran (IIT Bombay) Mayavi2 tutorial 16 / 53

slide-17
SLIDE 17

Getting started Vanilla:

$ ipython −−gui=wx

with Pylab:

$ ipython −−pylab=wx

slide-18
SLIDE 18

Using mlab:

>>> from enthought . mayavi import mlab

Try these:

>>> mlab . test_ <TAB> >>> mlab . test_contour3d ( ) >>> mlab . test_contour3d??

slide-19
SLIDE 19

Exploring the view

Mouse Keyboard Toolbar Mayavi icon

10

slide-20
SLIDE 20

mlab plotting functions

0D data

>>> from numpy import ∗ >>> t = linspace (0 , 2∗pi , 50) >>> u = cos ( t )∗ pi >>> x , y , z = sin ( u ) , cos ( u ) , sin ( t ) >>> mlab.points3d(x, y, z)

slide-21
SLIDE 21

Changing how things look

Clearing the view

>>> mlab.clf()

IPython is your friend!

>>> mlab.points3d? Extra argument: Scalars Keyword arguments UI >>> mlab . points3d ( x , y , z , t , scale_mode= ’ none ’ )

slide-22
SLIDE 22

Changing how things look

Clearing the view

>>> mlab.clf()

IPython is your friend!

>>> mlab.points3d? Extra argument: Scalars Keyword arguments UI >>> mlab . points3d ( x , y , z , t , scale_mode= ’ none ’ )

slide-23
SLIDE 23

Changing how things look

Clearing the view

>>> mlab.clf()

IPython is your friend!

>>> mlab.points3d? Extra argument: Scalars Keyword arguments UI >>> mlab . points3d ( x , y , z , t , scale_mode= ’ none ’ )

slide-24
SLIDE 24

1D data

>>> mlab.plot3d(x, y, z, t) Plots lines between the points

slide-25
SLIDE 25

2D data

>>> x , y = mgrid [ −3:3:100 j , −3:3:100 j ] >>> z = sin ( x∗x + y∗y ) >>> mlab.surf(x, y, z) Assumes the points are rectilinear

slide-26
SLIDE 26

2D data: mlab.mesh

>>> mlab.mesh(x, y, z) Points needn’t be regular >>> phi , theta = numpy . mgrid [ 0 : pi :20 j , . . . 0:2∗ pi :20 j ] >>> x = sin ( phi )∗ cos ( theta ) >>> y = sin ( phi )∗ sin ( theta ) >>> z = cos ( phi ) >>> mlab . mesh( x , y , z , . . . representation= ’ wireframe ’ )

slide-27
SLIDE 27

3D data

>>> x , y , z = ogrid [ −5:5:64 j , . . .

−5:5:64 j ,

. . .

−5:5:64 j ]

>>> mlab . contour3d ( x∗x∗0.5 + y∗y + z∗z∗2)

slide-28
SLIDE 28

3D vector data: mlab.quiver3d

>>> mlab . test_quiver3d ( )

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

40

slide-29
SLIDE 29

3D vector data: mlab.flow

>>> x , y , z = mgrid [ −2:3 , −2:3, −2:3] >>> r = sqrt ( x∗∗2 + y∗∗2 + z∗∗4) >>> u = y∗ sin ( r ) / ( r +0.001) >>> v = −x∗ sin ( r ) / ( r +0.001) >>> w = zeros_like ( z ) >>> obj = mlab . flow ( x , y , z , u , v , w, seedtype= ’ plane ’ ) >>> obj . stream_tracer . integrator_type = \ ’ runge_kutta45 ’

slide-30
SLIDE 30

Exercise: Lorenz equation

dx dt

= s(y − x)

dy dt

= rx − y − xz

dz dt

= xy − bz

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

Region of interest

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

−10:60:20 j ]

Use mlab.quiver3d

slide-31
SLIDE 31

Solution

def lorenz ( x , y , z , s =10. , r =28. , b = 8 . / 3 . ) : u = s ∗(y−x ) v = r ∗x −y − x∗z w = x∗y − b∗z return u , v , w x , y , z = mgrid [ −50:50:20 j , −50:50:20 j ,

−10:60:20 j ]

u , v , w = lorenz ( x , y , z ) mlab . quiver3d ( x , y , z , u , v , w, scale_factor =0.01 , mask_points =5) mlab . show ( )

slide-32
SLIDE 32

Issues and solutions Basic visualization: not very useful Tweak parameters: mask_points, scale_factor Explore parameters on UI mlab.flow is a lot better! Good visualization involves work

50

slide-33
SLIDE 33

Other utility functions gcf: get current figure savefig, figure axes, outline title , xlabel, ylabel, zlabel colorbar, scalarbar, vectorbar show: Standalone mlab scripts Others, see UG

slide-34
SLIDE 34

Can we do more? Yes!

slide-35
SLIDE 35

quiver3d ( x , y , z , u , v , w, scale_factor =0.01 , mask_points =5)

slide-36
SLIDE 36

Looking inside

slide-37
SLIDE 37

The pipeline

60

slide-38
SLIDE 38

Lookup tables List of Modules TVTK Scene Filter Source

Mayavi Engine

ModuleManager

slide-39
SLIDE 39

Changing the pipeline On UI Right click on node drag drop Script Or use mlab.pipeline Example: mlab.pipeline. outline ()

  • bj.remove()
slide-40
SLIDE 40

Exercise >>> mlab . test_quiver3d ( ) Hide vectors, add a Vector Cut Plane >>> mlab . test_flow ( ) Add a Vector Cut Plane Can also use the Lorenz example

slide-41
SLIDE 41

Exercise >>> mlab . test_quiver3d ( ) Hide vectors, add a Vector Cut Plane >>> mlab . test_flow ( ) Add a Vector Cut Plane Can also use the Lorenz example

slide-42
SLIDE 42

Surprised?

slide-43
SLIDE 43

So what is the problem?

slide-44
SLIDE 44

Points?

slide-45
SLIDE 45

Curve?

slide-46
SLIDE 46

Surface?

slide-47
SLIDE 47

Interior of sphere?

slide-48
SLIDE 48

Datasets Quiver v/s Flow

75

slide-49
SLIDE 49

Recap

mlab gets you started

Pipeline and data flow Datasets are important

slide-50
SLIDE 50

Changing the pipeline On UI Right click on node drag drop Script Or use mlab.pipeline Example: mlab.pipeline. outline ()

  • bj.remove()
slide-51
SLIDE 51

mlab and Mayavi2?

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

slide-52
SLIDE 52

Exercise

1

Start with flow for the Lorenz system

2

Now extract the vector norm (use a filter)

3

Plot iso-contours of this

4

Figure out how to do this from the UI and mlab.pipeline

85 Prabhu Ramachandran (IIT Bombay) Mayavi2 tutorial 49 / 53

slide-53
SLIDE 53

So how do you make a fancier script? Use script recording Demo

slide-54
SLIDE 54

So how do you make a fancier script? Use script recording Demo

slide-55
SLIDE 55

Animating data

>>> s = mlab . flow ( x , y , z , u , v , w) >>> s . mlab_source . u = u∗z mlab_source.set: multiple attributes If you change the shape of the arrays use the reset method

slide-56
SLIDE 56

Setting the view

>>> print mlab . view ( ) >>> mlab . view ( azimuth=None , elevation=None , distance=None , f o c a l p o i n t =None)

100

slide-57
SLIDE 57

Thank you!