Material for tutorial. Twitter: prabhu_r. Slides: http://goo.gl/5u7pv. Demos: http://goo.gl/mc0ea. www.enthought.com/~prabhu/m2_tutorial.

Similar documents
3D Data visualization with Mayavi


Mayavi User Guide. Release Prabhu Ramachandran, Gael Varoquaux

Visualization with ParaView

Visualization with ParaView. Greg Johnson

VisIt Visualization Tool

MayaVi: A free tool for CFD data visualization

Processing Data with rsmap3d Software Services Group Advanced Photon Source Argonne National Laboratory

Introduction to Paraview. H.D.Rajesh

Why are we teaching you VisIt?

Computational Fluid Dynamics. Department of Aerospace Engineering, IIT Bombay

Visualization Plugin for ParaView

Plotting: Customizing the Graph

Steady Flow: Laminar and Turbulent in an S-Bend

AMATH 352 Lecture 3 MATLAB Tutorial Starting MATLAB Entering Variables

Introduction to Visualization with VTK and ParaView

Scientific Visualization with ParaView

Finding Drag Coefficient using Solidworks Flow Simulation

Python. Python. 1 Python. M.Ulvrova, L.Pouilloux (ENS LYON) Informatique L3 Automne / 25

A Tutorial on dynamic networks. By Clement Levallois, Erasmus University Rotterdam

Visualizing molecular simulations

Quickstart for Desktop Version

ICEM CFD Tutorial. Simple Duct Grid

Cassandra 2.0: Tutorial

Gephi Tutorial Visualization

Creo Simulate 1.0 April 2011

DataPA OpenAnalytics End User Training

An introduction to 3D draughting & solid modelling using AutoCAD

Maple Quick Start. Introduction. Talking to Maple. Using [ENTER] 3 (2.1)

Microsoft PowerPoint 2011

version 3.0 tutorial - Turbulent mixing in a T-junction with CFDSTUDY in SALOME contact: saturne-support@edf.fr

TABLE OF CONTENTS. INTRODUCTION... 5 Advance Concrete... 5 Where to find information?... 6 INSTALLATION... 7 STARTING ADVANCE CONCRETE...

ParaView s Comparative Viewing, XY Plot, Spreadsheet View, Matrix View

Simulation of wireless ad-hoc sensor networks with QualNet

GeoGebra. 10 lessons. Gerrit Stols

OpenFOAM postprocessing and advanced running options

Activity: Using ArcGIS Explorer

Postprocessing with Python

Exercise 0. Although Python(x,y) comes already with a great variety of scientic Python packages, we might have to install additional dependencies:

0 Introduction to Data Analysis Using an Excel Spreadsheet

RVA: RESERVOIR VISUALIZATION AND ANALYSIS


Microsoft PowerPoint 2010

How is EnSight Uniquely Suited to FLOW-3D Data?

RAJALAKSHMI ENGINEERING COLLEGE MA 2161 UNIT I - ORDINARY DIFFERENTIAL EQUATIONS PART A

Microsoft Mathematics for Educators:

Working With Animation: Introduction to Flash

NaviCell Data Visualization Python API

Understand the Sketcher workbench of CATIA V5.

Customer Training Material. Shell Meshing Stamped Part ICEM CFD. ANSYS, Inc. Proprietary 2010 ANSYS, Inc. All rights reserved. WS3.

Visualization of Adaptive Mesh Refinement Data with VisIt

Getting more out of Matplotlib with GR

Visualisatie BMT. Introduction, visualization, visualization pipeline. Arjan Kok Huub van de Wetering

GUIDE TO POST-PROCESSING OF THE POINT CLOUD

Gerrit Stols

Microsoft PowerPoint 2008

Scripted Operator Shoulder

Applying a circular load. Immediate and consolidation settlement. Deformed contours. Query points and query lines. Graph query.

4VATARS PROJECT. Standard avatar specification for content creation in RealXtend

Using MuPAD and JavaView to Visualize Mathematics on the Internet

Information Literacy Program

CHAPTER 8, GEOMETRY. 4. A circular cylinder has a circumference of 33 in. Use 22 as the approximate value of π and find the radius of this cylinder.

Norwegian Satellite Earth Observation Database for Marine and Polar Research USE CASES

KaleidaGraph Quick Start Guide

Visualization of 2D Domains

A QUICK OVERVIEW OF THE OMNeT++ IDE

GR Framework / MODBUS on Raspberry Pi

Advanced visualization with VisNow platform Case study #2 3D scalar data visualization

Plug-in Software Developer Kit (SDK)

Composite Surfaces Tutorial

Pro/ENGINEER Wildfire 4.0 Basic Design

Getting Started with EnSight 10.0

CATIA V5 Tutorials. Mechanism Design & Animation. Release 18. Nader G. Zamani. University of Windsor. Jonathan M. Weaver. University of Detroit Mercy

Last lecture... Computer Graphics:

Character Creation You can customize a character s look using Mixamo Fuse:

Blender Notes. Introduction to Digital Modelling and Animation in Design Blender Tutorial - week 9 The Game Engine

Running and Scheduling QGIS Processing Jobs

Derive 5: The Easiest... Just Got Better!

The following is an overview of lessons included in the tutorial.

Introduction to Measurement Tools

Learning Module 4 - Thermal Fluid Analysis Note: LM4 is still in progress. This version contains only 3 tutorials.

Introduction to COMSOL. The Navier-Stokes Equations

Data Mining. SPSS Clementine Clementine Overview. Spring 2010 Instructor: Dr. Masoud Yaghini. Clementine

PolyWorks V10 Beginner s Guide

James Ahrens, Berk Geveci, Charles Law. Technical Report

MAKERBOT DESKTOP. All instructions in this tutorial are for use with a Flashforge Creator X (replicator single) using Makerbot Desktop.

Introduction to ANSYS ICEM CFD

Twelve. Figure 12.1: 3D Curved MPR Viewer Window

SketchUp Instructions

CLOUD DIGITISER 2014!

Summary of important mathematical operations and formulas (from first tutorial):

Microsoft Excel 2010 Charts and Graphs

Signal Processing First Lab 01: Introduction to MATLAB. 3. Learn a little about advanced programming techniques for MATLAB, i.e., vectorization.

Nicolas P. Rougier PyConFr Conference 2014 Lyon, October 24 25

INSTRUCTIONS FOR MAKING 3D,.DWG CONTOUR LINES

Building a Python Plugin

Microsoft Access 2010 Part 1: Introduction to Access

Arena Tutorial 1. Installation STUDENT 2. Overall Features of Arena

User s Guide The SimSphere Biosphere/Atmosphere Modeling Tool

Transcription:

Material for tutorial Twitter: prabhu_r Slides: http://goo.gl/5u7pv www.enthought.com/~prabhu/m2_tutorial.pdf Demos: http://goo.gl/mc0ea www.enthought.com/~prabhu/demos.zip

3D Data visualization with Mayavi Prabhu Ramachandran Gaël Varoquaux Department of Aerospace Engineering IIT Bombay SciPy.in 2011, December 7, IIT Bombay. Prabhu Ramachandran, Gaël Varoquaux (IIT Bombay) Mayavi2 tutorial 2 / 72

Objectives At the end of this session you will be able to: 1 Use mlab effectively to visualize numpy array data of various kinds 2 Apply some of mayavi s advanced features 3 Embed mayavi visualizations in your dialogs 4 Create TVTK datasets for more effective visualization (if time permits)

Outline 1 Quick introduction to Mayavi 2 mlab 3 Embedding mayavi 4 Creating and working with datasets Prabhu Ramachandran, Gaël Varoquaux (IIT Bombay) Mayavi2 tutorial 4 / 72

Outline 1 Quick introduction to Mayavi 2 mlab 3 Embedding mayavi 4 Creating and working with datasets Prabhu Ramachandran, Gaël Varoquaux (IIT Bombay) Mayavi2 tutorial 5 / 72

Who are we? Prabhu Ramachandran 2001 Creator and lead Gaël Varoquaux 2007 mlab, documentation, usability Enthought Inc. ETS, Hosting, support, sprints, initial funding, distribution Prabhu Ramachandran, Gaël Varoquaux (IIT Bombay) Mayavi2 tutorial 6 / 72

History Mayavi-1.x: 2001 TVTK: 2004, Enthought Mayavi2: 2005, Enthought, IITB 2008: Mayavi sprint at Austin Prabhu Ramachandran, Gaël Varoquaux (IIT Bombay) Mayavi2 tutorial 7 / 72

Overview of features

Live in your dialogs

Mayavi in applications

Exploring the documentation

Other features Easy customization Offscreen animations Automatic script generation Powerful command line options

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 15

Outline 1 Quick introduction to Mayavi 2 mlab 3 Embedding mayavi 4 Creating and working with datasets Prabhu Ramachandran, Gaël Varoquaux (IIT Bombay) Mayavi2 tutorial 15 / 72

Overview Simple Convenient Full-featured Prabhu Ramachandran, Gaël Varoquaux (IIT Bombay) Mayavi2 tutorial 16 / 72

Getting started Vanilla: $ ipython wthread with Pylab: $ ipython pylab wthread

Using mlab: >>> from enthought. mayavi import mlab Try these: >>> mlab. test_ <TAB> >>> mlab. test_contour3d ( ) >>> mlab. test_contour3d??

Exploring the view Mouse Keyboard Toolbar Mayavi icon 20

mlab plotting functions 0D data >>> from numpy import >>> t = l i nspace ( 0, 2 pi, 50) >>> u = cos ( t ) p i >>> x, y, z = s i n ( u ), cos ( u ), s i n ( t ) >>> mlab.points3d(x, y, z)

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 )

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 )

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 )

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

2D data >>> x = mgrid [ 3:3:100 j, 3:3:100 j ] >>> z = s i n ( x x + y y ) >>> mlab.surf(x, y, z) Assumes the points are rectilinear

2D data: mlab.mesh >>> mlab.mesh(x, y, z) Points needn t be regular >>> phi, t h e t a = numpy. mgrid [ 0 : p i :20 j,... 0:2 p i :20 j ] >>> x = s i n ( phi ) cos ( t h e t a ) >>> y = s i n ( phi ) s i n ( t h e t a ) >>> z = cos ( phi ) >>> mlab. mesh( x, y, z,... r e p r e s e n t a t i o n = wireframe )

3D data >>> x, y, z = o g r i d [ 5:5:64 j,... 5:5:64 j,... 5:5:64 j ] >>> mlab. contour3d ( x x 0.5 + y y + z z 2)

3D vector data: mlab.quiver3d >>> mlab. t e s t _ q u i v e r 3 d ( ) obj = mlab.quiver3d(x, y, z, u, v, w) 50

Exercise: Lorenz equation dx dt dy dt dz dt = s(y x) = rx y xz = 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

mlab. quiver3d ( x, y, z, u, v, w, s c a l e _ f a c t o r =0.01, mask_points =5) mlab. show ( ) 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 )

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 60

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

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

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

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

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

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

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

Can we do more? Yes!

quiver3d ( x, y, z, u, v, w, s c a l e _ f a c t o r =0.01, mask_points =5)

Looking inside

The pipeline 70

Mayavi Engine TVTK Scene Source Filter ModuleManager Lookup tables List of Modules

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

Exercise >>> mlab. t e s t _ q u i v e r 3 d ( ) Hide vectors, add a Vector Cut Plane >>> mlab. t e s t _ f l o w ( ) Add a Vector Cut Plane Can also use the Lorenz example

Exercise >>> mlab. t e s t _ q u i v e r 3 d ( ) Hide vectors, add a Vector Cut Plane >>> mlab. t e s t _ f l o w ( ) Add a Vector Cut Plane Can also use the Lorenz example

Surprised?

So what is the problem?

Points?

Curve?

Surface?

Interior of sphere?

Datasets Quiver v/s Flow Get back to this later! 85

Recap mlab gets you started Pipeline and data flow Datasets are important

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

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

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 95 Prabhu Ramachandran, Gaël Varoquaux (IIT Bombay) Mayavi2 tutorial 48 / 72

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

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

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

Setting the view >>> p r i n t mlab. view ( ) >>> mlab. view ( azimuth=none, e l e v a t i o n =None, distance=none, f o c a l p o i n t =None ) 110

Outline 1 Quick introduction to Mayavi 2 mlab 3 Embedding mayavi 4 Creating and working with datasets Prabhu Ramachandran, Gaël Varoquaux (IIT Bombay) Mayavi2 tutorial 52 / 72

General approach Embed Mayavi into a dialog box Use traits to wire up everything Full power of mayavi at your disposal

Simple example 120

Exercise: Lorenz trajectory Use the provided skeleton script 1 Create a simple UI to show a trajectory 2 Create sliders to change the position of the initial condition 3 Create a UI element to change the integration time 125 Prabhu Ramachandran, Gaël Varoquaux (IIT Bombay) Mayavi2 tutorial 55 / 72

Outline 1 Quick introduction to Mayavi 2 mlab 3 Embedding mayavi 4 Creating and working with datasets Prabhu Ramachandran, Gaël Varoquaux (IIT Bombay) Mayavi2 tutorial 56 / 72

Motivation Datasets are fundamental to doing visualization correctly Motivational problem Atmospheric data of temperature over the surface of the earth. Let temperature (T ) vary linearly with height (z): T = 288.15 6.5z

Simple solution l a t = l inspace ( 89, 89, 37) lon = l i n space ( 0, 360, 37) z = l i n s p ace ( 0, 100, 11) x, y, z = mgrid [0:360:37 j, 89:89:37 j, 0:100:11 j ] t = 288.15 6.5 z mlab. contour3d ( x, y, z, t ) mlab. o u t l i n e ( ) mlab. c o l o r b a r ( )

Simple solution l a t = l inspace ( 89, 89, 37) lon = l i n space ( 0, 360, 37) z = l i n s p ace ( 0, 100, 11) x, y, z = mgrid [0:360:37 j, 89:89:37 j, 0:100:11 j ] t = 288.15 6.5 z mlab. contour3d ( x, y, z, t ) mlab. o u t l i n e ( ) mlab. c o l o r b a r ( )

What happens underneath? P = mlab. p i p e l i n e src = P. s c a l a r _ f i e l d ( x, y, z, t ) i s o = P. iso_surface ( src ) # Try t h i s. p r i n t src

The underlying dataset from enthought. t v t k. api import t v t k o r i g = ( 0, 90, 0) spacing = (10, 5, 10) dims = (37, 37, 11) i d = t v t k. ImageData ( o r i g i n = orig, spacing =spacing, dimensions=dims ) i d. point_data. s c a l a r s = t. T. f l a t t e n ( ) i d. point_data. s c a l a r s. name = T # View i t. src = P. add_dataset ( i d ) i s o = P. iso_surface ( src )

The general idea Specify the points (explicitly or implicitly) Specify the connectivity between the points (explicit/implicit) The connectivity lets you build cells that break the space into pieces Specify attribute data at the points or cells Points Rectangular cell Triangular cells Point data 40 30 10 20 Cell data 20 10

Types of datasets Implicit topology (structured): Image data (structured points) Rectilinear grids Structured grids Explicit topology (unstructured): Polygonal data (surfaces) Unstructured grids

Implicit versus explicit topology Implicit topology associated with points: The X co-ordinate increases first, Y next and Z last Easiest example: a rectangular mesh Non-rectangular mesh certainly possible Prabhu Ramachandran, Gaël Varoquaux (IIT Bombay) Mayavi2 tutorial 64 / 72

On a sphere? lon, l a t, ht = x p i /180, (90+y ) p i /180, z r = (1+0.005 ht ) tmp = r s i n ( l a t ) # Points on the sphere x, y, z = tmp cos ( lon ), tmp s i n ( lon ), r cos ( l a t ) pts = empty ( x. shape + ( 3, ), dtype= f l o a t ) pts [..., 0 ] = x pts [..., 1 ] = y pts [..., 2 ] = z # Reorder the p o i n t s / s c a l a r s f o r VTK pts = pts. transpose ( 2, 1, 0, 3 ). copy ( ) pts. shape = pts. size / 3, 3 t = t. T. copy ( )

sg = t v t k. S t r u c t u r e d G r i d ( ) sg. dimensions = x. shape sg. p o i n t s = pts sg. point_data. s c a l a r s = t. r a v e l ( ) sg. point_data. s c a l a r s. name = T P = mlab. p i p e l i n e src = P. add_dataset ( sg ) P. grid_plane ( src ) P. iso_surface ( src, contours =1) mlab. show ( )

# Save a dataset to disk. from enthought. t v t k. api import w r i t e _ d a t a w r i t e _ d a t a ( dataset, fname ) # Open back t h e data. mlab. p i p e l i n e. open ( fname ) Try right clicking a node!

Unstructured grids Explicit topology specification Specified via connectivity lists Different number of neighbors, different types of cells

PolyData from enthought. t v t k. api import t v t k # The p o i n t s i n 3D. p o i n t s = array ( [ [ 0, 0, 0 ], [ 1, 0, 0 ], [ 0, 1, 0 ], [ 0, 0, 1 ] ], f ) # C o n n e c t i v i t y v i a i n d i c e s to the p o i n t s. t r i a n g l e s = array ( [ [ 0, 1, 3 ], [ 0, 3, 2 ], [ 1, 2, 3 ], [ 0, 2, 1 ] ] ) # Creating the data o b j e c t. mesh = t v t k. PolyData ( ) mesh. p o i n t s = p o i n t s # the p o i n t s mesh. polys = t r i a n g l e s # t r i a n g l e s f o r c o n n e c t i v i t y # For l i n e s use : mesh. l i n e s = l i n e s # Now create some p o i n t data. temperature = array ( [ 1 0, 20,20, 30], f ) mesh. point_data. s c a l a r s = temperature mesh. point_data. s c a l a r s. name = temperature

PolyData from enthought. t v t k. api import t v t k # The p o i n t s i n 3D. p o i n t s = array ( [ [ 0, 0, 0 ], [ 1, 0, 0 ], [ 0, 1, 0 ], [ 0, 0, 1 ] ], f ) # C o n n e c t i v i t y v i a i n d i c e s to the p o i n t s. t r i a n g l e s = array ( [ [ 0, 1, 3 ], [ 0, 3, 2 ], [ 1, 2, 3 ], [ 0, 2, 1 ] ] ) # Creating the data o b j e c t. mesh = t v t k. PolyData ( ) mesh. p o i n t s = p o i n t s # the p o i n t s mesh. polys = t r i a n g l e s # t r i a n g l e s f o r c o n n e c t i v i t y # For l i n e s use : mesh. l i n e s = l i n e s # Now create some p o i n t data. temperature = array ( [ 1 0, 20,20, 30], f ) mesh. point_data. s c a l a r s = temperature mesh. point_data. s c a l a r s. name = temperature

Summary 140

Advanced features Command line arguments, timeseries, scripting

Thank you!