day2/3Dplotting.tex
changeset 154 66b117b7edc7
child 171 29c0c504750c
equal deleted inserted replaced
140:fe6a38572a65 154:66b117b7edc7
       
     1 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
       
     2 % Tutorial slides on Python.
       
     3 %
       
     4 % Author: Prabhu Ramachandran <prabhu at aero.iitb.ac.in>
       
     5 % Copyright (c) 2005-2009, Prabhu Ramachandran
       
     6 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
       
     7 
       
     8 \documentclass[compress,14pt]{beamer}
       
     9 % \documentclass[handout]{beamer}
       
    10 % \usepackage{pgfpages}
       
    11 % \pgfpagesuselayout{4 on 1}[a4paper,border, shrink=5mm,landscape]
       
    12 \usepackage{tikz}
       
    13 \newcommand{\hyperlinkmovie}{}
       
    14 %\usepackage{movie15}
       
    15 
       
    16 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
       
    17 % Note that in presentation mode 
       
    18 % \paperwidth  364.19536pt
       
    19 % \paperheight 273.14662pt
       
    20 % h/w = 0.888
       
    21 
       
    22 
       
    23 \mode<presentation>
       
    24 {
       
    25   \usetheme{Warsaw}
       
    26   %\usetheme{Boadilla}
       
    27   %\usetheme{default}
       
    28   \useoutertheme{split}
       
    29   \setbeamercovered{transparent}
       
    30 }
       
    31 
       
    32 % To remove navigation symbols
       
    33 \setbeamertemplate{navigation symbols}{}
       
    34 
       
    35 \usepackage{amsmath}
       
    36 \usepackage[english]{babel}
       
    37 \usepackage[latin1]{inputenc}
       
    38 \usepackage{times}
       
    39 \usepackage[T1]{fontenc}
       
    40 
       
    41 % Taken from Fernando's slides.
       
    42 \usepackage{ae,aecompl}
       
    43 \usepackage{mathpazo,courier,euler}
       
    44 \usepackage[scaled=.95]{helvet}
       
    45 \usepackage{pgf}
       
    46 
       
    47 \definecolor{darkgreen}{rgb}{0,0.5,0}
       
    48 
       
    49 \usepackage{listings}
       
    50 \lstset{language=Python,
       
    51     basicstyle=\ttfamily\bfseries,
       
    52     commentstyle=\color{red}\itshape,
       
    53   stringstyle=\color{darkgreen},
       
    54   showstringspaces=false,
       
    55   keywordstyle=\color{blue}\bfseries}
       
    56 
       
    57 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
       
    58 % My Macros
       
    59 \setbeamercolor{postit}{bg=yellow,fg=black}
       
    60 \setbeamercolor{emphbar}{bg=blue!20, fg=black}
       
    61 \newcommand{\emphbar}[1]
       
    62 {\begin{beamercolorbox}[rounded=true]{emphbar} 
       
    63       {#1}
       
    64  \end{beamercolorbox}
       
    65 }
       
    66 %{\centerline{\fcolorbox{gray!50} {blue!10}{
       
    67 %\begin{minipage}{0.9\linewidth}
       
    68 %    {#1} 
       
    69 %\end{minipage}
       
    70 %    }}}
       
    71 
       
    72 \newcommand{\myemph}[1]{\structure{\emph{#1}}}
       
    73 \newcommand{\PythonCode}[1]{\lstinline{#1}}
       
    74 
       
    75 \newcommand{\tvtk}{\texttt{tvtk}}
       
    76 \newcommand{\mlab}{\texttt{mlab}}
       
    77 
       
    78 \newcounter{time}
       
    79 \setcounter{time}{0}
       
    80 \newcommand{\inctime}[1]{\addtocounter{time}{#1}{\vspace*{0.1in}\tiny \thetime\ m}}
       
    81 
       
    82 \newcommand\BackgroundPicture[1]{%
       
    83   \setbeamertemplate{background}{%
       
    84       \parbox[c][\paperheight]{\paperwidth}{%
       
    85       \vfill \hfill
       
    86  \hfill \vfill
       
    87 }}}
       
    88 
       
    89 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
       
    90 % Configuring the theme
       
    91 %\setbeamercolor{normal text}{fg=white}
       
    92 %\setbeamercolor{background canvas}{bg=black}
       
    93 
       
    94 
       
    95 
       
    96 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
       
    97 % Title page
       
    98 \title[]{3D data Visualization}
       
    99 
       
   100 \author[FOSSEE Team] {FOSSEE}
       
   101 
       
   102 \institute[IIT Bombay] {Department of Aerospace Engineering\\IIT Bombay}
       
   103 \date[] {1, November 2009\\Day 2, Session 3}
       
   104 
       
   105 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
       
   106 
       
   107 %\pgfdeclareimage[height=0.75cm]{iitblogo}{iitblogo}
       
   108 %\logo{\pgfuseimage{iitblogo}}
       
   109 
       
   110 \AtBeginSection[]
       
   111 {
       
   112   \begin{frame}<beamer>
       
   113     \frametitle{Outline}      
       
   114     \tableofcontents[currentsection,currentsubsection]
       
   115   \end{frame}
       
   116 }
       
   117 
       
   118 %% Delete this, if you do not want the table of contents to pop up at
       
   119 %% the beginning of each subsection:
       
   120 \AtBeginSubsection[]
       
   121 {
       
   122   \begin{frame}<beamer>
       
   123     \frametitle{Outline}
       
   124     \tableofcontents[currentsection,currentsubsection]
       
   125   \end{frame}
       
   126 }
       
   127 
       
   128 \AtBeginSection[]
       
   129 {
       
   130   \begin{frame}<beamer>
       
   131     \frametitle{Outline}
       
   132     \tableofcontents[currentsection,currentsubsection]
       
   133   \end{frame}
       
   134 }
       
   135 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
       
   136 % DOCUMENT STARTS
       
   137 \begin{document}
       
   138 
       
   139 \begin{frame}
       
   140   \maketitle
       
   141 \end{frame}
       
   142 
       
   143 \begin{frame}
       
   144   \frametitle{Outline}
       
   145   \tableofcontents
       
   146   % You might wish to add the option [pausesections]
       
   147 \end{frame}
       
   148 
       
   149 \section{3D Data Visualization}
       
   150 
       
   151 \begin{frame}
       
   152     \frametitle{What is visualization?}
       
   153     \Large
       
   154     \begin{center}
       
   155     Visual representation of data
       
   156     \end{center}
       
   157 \end{frame}
       
   158 
       
   159 \begin{frame}
       
   160     \frametitle{3D visualization}
       
   161     \Large
       
   162     \begin{center}
       
   163         Harder but important
       
   164     \end{center}
       
   165 \end{frame}
       
   166 
       
   167 \begin{frame}
       
   168     \frametitle{Is this Graphics?}
       
   169     \Large
       
   170     \begin{center}
       
   171         Visualization is about data!
       
   172     \end{center}
       
   173 \end{frame}
       
   174 
       
   175 \begin{frame}
       
   176     \frametitle{Examples: trajectory in space}
       
   177     \Large
       
   178     \begin{center}
       
   179         \pgfimage[width=2.5in]{MEDIA/m2/mlab/plot3d_ex}
       
   180     \end{center}
       
   181 \end{frame}
       
   182 
       
   183 \begin{frame}
       
   184     \frametitle{Examples: Fire in a room}
       
   185     \Large
       
   186     \begin{center}
       
   187         Demo of data
       
   188     \end{center}
       
   189 \inctime{10}
       
   190 \end{frame}
       
   191 
       
   192 \section{Tools at your disposal}
       
   193 
       
   194 \subsection{Mayavi2}
       
   195 
       
   196 \begin{frame}
       
   197   \frametitle{Introduction to Mayavi}
       
   198   \begin{itemize}
       
   199   \item Most scientists not interested in details of visualization
       
   200   \item Visualization of data files with a nice UI
       
   201   \item Interactive visualization of data (think Matlab)
       
   202   \item Embedding visualizations in applications
       
   203   \item Customization
       
   204   \end{itemize}
       
   205   \pause
       
   206   \begin{block}{The Goal}
       
   207       Provide a \alert{flexible} library/app for every one of these needs!
       
   208   \end{block}
       
   209 \end{frame}
       
   210 
       
   211 \begin{frame}
       
   212     {Overview of features}
       
   213       \vspace*{-0.3in}
       
   214   \begin{center}    
       
   215     \hspace*{-0.2in}\pgfimage[width=5in]{MEDIA/m2/m2_app3_3}
       
   216   \end{center}    
       
   217 \end{frame}
       
   218 
       
   219 
       
   220 \begin{frame}
       
   221     \frametitle{Mayavi in applications}
       
   222       \vspace*{-0.3in}
       
   223   \begin{center}    
       
   224     \hspace*{-0.2in}\pgfimage[width=4.5in]{MEDIA/m2/m2_envisage}
       
   225   \end{center}
       
   226 \end{frame}
       
   227 
       
   228 \begin{frame}
       
   229     \frametitle{Live in your dialogs}
       
   230       \vspace*{0.1in}
       
   231   \begin{center}    
       
   232     \hspace*{-0.2in}\pgfimage[width=2.5in]{MEDIA/m2/mlab_tui}
       
   233   \end{center}
       
   234 \end{frame}
       
   235 
       
   236 \begin{frame}
       
   237     {Exploring the documentation}
       
   238     \begin{center}
       
   239     \pgfimage[width=4in]{MEDIA/m2/m2_ug_doc}
       
   240     \end{center}
       
   241 \end{frame}
       
   242 
       
   243 
       
   244 \begin{frame}
       
   245   \frametitle{Summary}
       
   246       \begin{itemize}
       
   247           \item \url{http://code.enthought.com/projects/mayavi}
       
   248           \item Uses VTK (\url{www.vtk.org})
       
   249           \item BSD license
       
   250           \item Linux, win32 and Mac OS X
       
   251           \item Highly scriptable
       
   252           \item Embed in Traits UIs (wxPython and PyQt4)
       
   253           \item Envisage Plugins
       
   254           \item Debian/Ubuntu/Fedora
       
   255           \item \alert{Pythonic}
       
   256       \end{itemize}
       
   257     
       
   258       \inctime{10}
       
   259 
       
   260 \end{frame}
       
   261 
       
   262 \subsection{mlab}
       
   263 
       
   264 \begin{frame}
       
   265     {Overview}
       
   266     \Large
       
   267     \begin{itemize}
       
   268         \item Simple
       
   269         \item Convenient
       
   270         \item Full-featured
       
   271     \end{itemize}
       
   272 \end{frame}
       
   273 
       
   274 \begin{frame}[fragile]
       
   275 
       
   276     \frametitle{Getting started}
       
   277     \myemph{\Large Vanilla:}
       
   278     \begin{lstlisting}[language=bash]
       
   279         $ ipython -wthread
       
   280     \end{lstlisting}
       
   281     \myemph{\Large with Pylab:}
       
   282     \begin{lstlisting}[language=bash]
       
   283         $ ipython -pylab -wthread
       
   284     \end{lstlisting}
       
   285 \end{frame}
       
   286 
       
   287 \begin{frame}[fragile]
       
   288     \frametitle{Using mlab}
       
   289 
       
   290     \begin{lstlisting}
       
   291 >>> from enthought.mayavi import mlab
       
   292     \end{lstlisting}
       
   293 
       
   294     \vspace*{0.5in}
       
   295 
       
   296     \myemph{\Large Try these}
       
   297 
       
   298     \vspace*{0.25in}
       
   299 
       
   300     \begin{lstlisting}
       
   301 >>> mlab.test_<TAB>
       
   302 >>> mlab.test_contour3d()
       
   303 >>> mlab.test_contour3d??
       
   304     \end{lstlisting}
       
   305 \end{frame}
       
   306 
       
   307 \begin{frame}
       
   308     {Exploring the view}
       
   309     \begin{columns}
       
   310         \column{0.6\textwidth}
       
   311     \pgfimage[width=3in]{MEDIA/m2/contour3d}
       
   312         \column{0.4\textwidth}
       
   313         \begin{itemize}
       
   314             \item Mouse
       
   315             \item Keyboard
       
   316             \item Toolbar
       
   317             \item Mayavi icon\pgfimage[width=0.2in]{MEDIA/m2/m2_icon}
       
   318         \end{itemize}
       
   319     \end{columns}
       
   320 \end{frame}
       
   321 
       
   322 \begin{frame}[fragile]
       
   323     \frametitle{\mlab\ plotting functions}
       
   324     \begin{columns}
       
   325         \column{0.25\textwidth}
       
   326         \myemph{\Large 0D data}
       
   327         \column{0.5\textwidth}
       
   328     \pgfimage[width=2in]{MEDIA/m2/mlab/points3d_ex}
       
   329     \end{columns}
       
   330 
       
   331     \begin{lstlisting}
       
   332 >>> from numpy import *
       
   333 >>> t = linspace(0, 2*pi, 50)
       
   334 >>> u = cos(t)*pi
       
   335 >>> x, y, z = sin(u), cos(u), sin(t)
       
   336     \end{lstlisting}
       
   337     \emphbar{\PythonCode{>>> mlab.points3d(x, y, z)}}
       
   338 \end{frame}
       
   339 
       
   340 \begin{frame}
       
   341   \begin{columns}
       
   342         \column{0.25\textwidth}
       
   343         \myemph{\Large 1D data}
       
   344         \column{0.5\textwidth}
       
   345         \pgfimage[width=2.5in]{MEDIA/m2/mlab/plot3d_ex}
       
   346   \end{columns}
       
   347   \emphbar{\PythonCode{>>> mlab.plot3d(x, y, z, t)}}
       
   348 
       
   349     Plots lines between the points
       
   350     
       
   351 \end{frame}
       
   352 
       
   353 \begin{frame}[fragile]
       
   354     \begin{columns}
       
   355         \column{0.25\textwidth}
       
   356         \myemph{\Large 2D data}
       
   357         \column{0.5\textwidth}
       
   358         \pgfimage[width=2in]{MEDIA/m2/mlab/surf_ex}
       
   359     \end{columns}            
       
   360     \begin{lstlisting}
       
   361 >>> x = mgrid[-3:3:100j,-3:3:100j]
       
   362 >>> z = sin(x*x + y*y)
       
   363     \end{lstlisting}
       
   364 
       
   365     \emphbar{\PythonCode{>>> mlab.surf(x, y, z)}}
       
   366 
       
   367     \alert{Assumes the points are rectilinear}
       
   368 
       
   369 \end{frame}
       
   370 
       
   371 \begin{frame}[fragile]
       
   372     \myemph{\Large 2D data: \texttt{mlab.mesh}}
       
   373     \vspace*{0.25in}
       
   374 
       
   375     \emphbar{\PythonCode{>>> mlab.mesh(x, y, z)}}
       
   376 
       
   377     \alert{Points needn't be regular}
       
   378 
       
   379     \vspace*{0.25in}
       
   380 \begin{lstlisting}
       
   381 >>> phi, theta = numpy.mgrid[0:pi:20j, 
       
   382 ...                         0:2*pi:20j]
       
   383 >>> x = sin(phi)*cos(theta)
       
   384 >>> y = sin(phi)*sin(theta)
       
   385 >>> z = cos(phi)
       
   386 >>> mlab.mesh(x, y, z, 
       
   387 ...           representation=
       
   388 ...           'wireframe')
       
   389 \end{lstlisting}
       
   390 
       
   391 \end{frame}
       
   392 
       
   393 \begin{frame}[fragile]
       
   394 
       
   395   \begin{columns}
       
   396         \column{0.25\textwidth}
       
   397         \myemph{\Large 3D data}
       
   398         \column{0.5\textwidth}
       
   399         \pgfimage[width=1.5in]{MEDIA/m2/mlab/contour3d}\\        
       
   400     \end{columns}
       
   401 \begin{lstlisting}
       
   402 >>> x, y, z = ogrid[-5:5:64j, 
       
   403 ...                -5:5:64j, 
       
   404 ...                -5:5:64j]
       
   405 >>> mlab.contour3d(x*x*0.5 + y*y + 
       
   406                    z*z*2)
       
   407 \end{lstlisting}
       
   408 \end{frame}
       
   409 
       
   410 \begin{frame}[fragile]
       
   411 
       
   412     \myemph{\Large 3D vector data: \PythonCode{mlab.quiver3d}}
       
   413     \vspace*{0.25in}
       
   414 
       
   415     \pgfimage[width=2in]{MEDIA/m2/mlab/quiver3d_ex}\\
       
   416     
       
   417 \begin{lstlisting}
       
   418 >>> mlab.test_quiver3d()
       
   419 \end{lstlisting}
       
   420 
       
   421 \emphbar{\PythonCode{obj = mlab.quiver3d(x, y, z, u, v, w)}}
       
   422 \inctime{20}
       
   423 \end{frame}
       
   424 
       
   425 \begin{frame}
       
   426     {Getting hands dirty!}
       
   427 
       
   428         \begin{block}{Motivational problem}
       
   429         Atmospheric data of temperature over the surface of the earth.
       
   430         Let temperature ($T$) vary linearly with height ($z$):
       
   431         \begin{center}            
       
   432         $T = 288.15 - 6.5z$
       
   433         \end{center}
       
   434         \end{block}
       
   435 \end{frame}
       
   436 
       
   437 \begin{frame}[fragile]
       
   438     \frametitle{Simple solution}
       
   439 
       
   440     \begin{lstlisting}
       
   441 lat = linspace(-89, 89, 37)
       
   442 lon = linspace(0, 360, 37)
       
   443 z = linspace(0, 100, 11)
       
   444     \end{lstlisting}
       
   445 \pause
       
   446     \begin{lstlisting}
       
   447 x, y, z = mgrid[0:360:37j,-89:89:37j,
       
   448                 0:100:11j]
       
   449 t = 288.15 - 6.5*z
       
   450 mlab.contour3d(x, y, z, t)
       
   451 mlab.outline()
       
   452 mlab.colorbar()
       
   453     \end{lstlisting}
       
   454 \end{frame}
       
   455 
       
   456 \begin{frame}[fragile]
       
   457     \frametitle{Exercise: Lorenz equation}
       
   458     \begin{columns}
       
   459         \column{0.25\textwidth}
       
   460         \begin{eqnarray*}
       
   461         \frac{d x}{dt} &=& s (y-x)\\
       
   462         \frac{d y}{d t} &=& rx -y -xz\\
       
   463         \frac{d z}{d t} &=& xy - bz\\
       
   464         \end{eqnarray*}
       
   465         \column{0.25\textwidth}
       
   466         Let $s=10,$
       
   467         $r=28,$ 
       
   468         $b=8./3.$
       
   469     \end{columns}
       
   470     \structure{\Large Region of interest}
       
   471   \begin{lstlisting}
       
   472 x, y, z = mgrid[-50:50:20j,-50:50:20j,
       
   473                 -10:60:20j]
       
   474   \end{lstlisting}
       
   475 \inctime{20}
       
   476 
       
   477 \end{frame}
       
   478 \begin{frame}[fragile]
       
   479     \frametitle{Solution}
       
   480   \begin{lstlisting}
       
   481 def lorenz(x,y,z,s=10.,r=28.,b=8./3.):
       
   482     u = s*(y-x)
       
   483     v = r*x-y-x*z
       
   484     w = x*y-b*z
       
   485     return u,v,w
       
   486 x,y,z = mgrid [-50:50:20j,-50:50:20j,
       
   487                     -10:60:20j ]
       
   488 u,v,w = lorenz( x , y , z )
       
   489 # Your plot here
       
   490 #
       
   491 mlab.show()
       
   492 
       
   493   \end{lstlisting}
       
   494 \end{frame}
       
   495   
       
   496 \end{document}
       
   497