day2/session3.tex
changeset 215 b69d0bdb136c
parent 171 29c0c504750c
child 219 f6725f6bee41
equal deleted inserted replaced
214:19592f802dde 215:b69d0bdb136c
       
     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 
       
   160 \begin{frame}
       
   161     \frametitle{Is this new?}    
       
   162     \begin{center}
       
   163     We have moved from:
       
   164     \end{center}
       
   165     \begin{columns}
       
   166     \column{}
       
   167     \hspace*{-1in}    
       
   168     \includegraphics[width=1.75in,height=1.75in, interpolate=true]{data/3832}      
       
   169     \column{}\hspace*{-0.25in}
       
   170     To
       
   171     \column{}
       
   172     \hspace*{-1in}
       
   173     \includegraphics[width=1.75in, height=1.75in, interpolate=true]{data/torus}  
       
   174     \end{columns}
       
   175 \end{frame}
       
   176 
       
   177 \begin{frame}
       
   178     \frametitle{3D visualization}
       
   179     \Large
       
   180     \begin{center}
       
   181         Harder but important
       
   182     \end{center}
       
   183 \end{frame}
       
   184 
       
   185 \begin{frame}
       
   186     \frametitle{Is this Graphics?}
       
   187     \Large
       
   188     \begin{center}
       
   189         Visualization is about data!
       
   190     \end{center}
       
   191 \end{frame}
       
   192 
       
   193 \begin{frame}
       
   194     \frametitle{Examples: trajectory in space}
       
   195     \Large
       
   196     \begin{center}
       
   197         \pgfimage[width=2.5in]{MEDIA/m2/mlab/plot3d_ex}
       
   198     \end{center}
       
   199 \end{frame}
       
   200 
       
   201 \begin{frame}
       
   202     \frametitle{Examples: Fire in a room}
       
   203     \Large
       
   204     \begin{center}
       
   205         Demo of data
       
   206     \end{center}
       
   207 \inctime{10}
       
   208 \end{frame}
       
   209 
       
   210 \section{Tools available}
       
   211 
       
   212 \subsection{mlab}
       
   213 
       
   214 \begin{frame}
       
   215     {Overview}
       
   216     \Large
       
   217     \begin{itemize}
       
   218         \item Simple
       
   219         \item Convenient
       
   220         \item Full-featured
       
   221     \end{itemize}
       
   222 \end{frame}
       
   223 
       
   224 \begin{frame}[fragile]
       
   225 
       
   226     \frametitle{Getting started}
       
   227     \myemph{\Large Vanilla:}
       
   228     \begin{lstlisting}[language=bash]
       
   229         $ ipython -wthread
       
   230     \end{lstlisting}
       
   231     \myemph{\Large with Pylab:}
       
   232     \begin{lstlisting}[language=bash]
       
   233         $ ipython -pylab -wthread
       
   234     \end{lstlisting}
       
   235 \end{frame}
       
   236 
       
   237 \begin{frame}[fragile]
       
   238     \frametitle{Using mlab}
       
   239 
       
   240     \begin{lstlisting}
       
   241 >>> from enthought.mayavi import mlab
       
   242     \end{lstlisting}
       
   243 
       
   244     \vspace*{0.5in}
       
   245 
       
   246     \myemph{\Large Try these}
       
   247 
       
   248     \vspace*{0.25in}
       
   249 
       
   250     \begin{lstlisting}
       
   251 >>> mlab.test_<TAB>
       
   252 >>> mlab.test_contour3d()
       
   253 >>> mlab.test_contour3d??
       
   254     \end{lstlisting}
       
   255 \end{frame}
       
   256 
       
   257 \begin{frame}
       
   258     {Exploring the view}
       
   259     \begin{columns}
       
   260         \column{0.6\textwidth}
       
   261     \pgfimage[width=3in]{MEDIA/m2/contour3d}
       
   262         \column{0.4\textwidth}
       
   263         \begin{itemize}
       
   264             \item Mouse
       
   265             \item Keyboard
       
   266             \item Toolbar
       
   267             \item Mayavi icon\pgfimage[width=0.2in]{MEDIA/m2/m2_icon}
       
   268         \end{itemize}
       
   269     \end{columns}
       
   270 \end{frame}
       
   271 
       
   272 \begin{frame}[fragile]
       
   273     \frametitle{\mlab\ plotting functions}
       
   274     \begin{columns}
       
   275         \column{0.25\textwidth}
       
   276         \myemph{\Large 0D data}
       
   277         \column{0.5\textwidth}
       
   278     \pgfimage[width=2in]{MEDIA/m2/mlab/points3d_ex}
       
   279     \end{columns}
       
   280 
       
   281     \begin{lstlisting}
       
   282 >>> from numpy import *
       
   283 >>> t = linspace(0, 2*pi, 50)
       
   284 >>> u = cos(t)*pi
       
   285 >>> x, y, z = sin(u), cos(u), sin(t)
       
   286     \end{lstlisting}
       
   287     \emphbar{\PythonCode{>>> mlab.points3d(x, y, z)}}
       
   288 \end{frame}
       
   289 
       
   290 \begin{frame}
       
   291   \begin{columns}
       
   292         \column{0.25\textwidth}
       
   293         \myemph{\Large 1D data}
       
   294         \column{0.5\textwidth}
       
   295         \pgfimage[width=2.5in]{MEDIA/m2/mlab/plot3d_ex}
       
   296   \end{columns}
       
   297   \emphbar{\PythonCode{>>> mlab.plot3d(x, y, z, t)}}
       
   298 
       
   299     Plots lines between the points
       
   300     
       
   301 \end{frame}
       
   302 
       
   303 \begin{frame}[fragile]
       
   304     \begin{columns}
       
   305         \column{0.25\textwidth}
       
   306         \myemph{\Large 2D data}
       
   307         \column{0.5\textwidth}
       
   308         \pgfimage[width=2in]{MEDIA/m2/mlab/surf_ex}
       
   309     \end{columns}            
       
   310     \begin{lstlisting}
       
   311 >>> x, y = mgrid[-3:3:100j,-3:3:100j]
       
   312 >>> z = sin(x*x + y*y)
       
   313     \end{lstlisting}
       
   314 
       
   315     \emphbar{\PythonCode{>>> mlab.surf(x, y, z)}}
       
   316 
       
   317     \alert{Assumes the points are rectilinear}
       
   318 
       
   319 \end{frame}
       
   320 
       
   321 \begin{frame}[fragile]
       
   322     \myemph{\Large 2D data: \texttt{mlab.mesh}}
       
   323     \vspace*{0.25in}
       
   324 
       
   325     \emphbar{\PythonCode{>>> mlab.mesh(x, y, z)}}
       
   326 
       
   327     \alert{Points needn't be regular}
       
   328 
       
   329     \vspace*{0.25in}
       
   330 \begin{lstlisting}
       
   331 >>> phi, theta = numpy.mgrid[0:pi:20j, 
       
   332 ...                         0:2*pi:20j]
       
   333 >>> x = sin(phi)*cos(theta)
       
   334 >>> y = sin(phi)*sin(theta)
       
   335 >>> z = cos(phi)
       
   336 >>> mlab.mesh(x, y, z, 
       
   337 ...           representation=
       
   338 ...           'wireframe')
       
   339 \end{lstlisting}
       
   340 
       
   341 \end{frame}
       
   342 
       
   343 \begin{frame}[fragile]
       
   344 
       
   345   \begin{columns}
       
   346         \column{0.25\textwidth}
       
   347         \myemph{\Large 3D data}
       
   348         \column{0.5\textwidth}
       
   349         \pgfimage[width=1.5in]{MEDIA/m2/mlab/contour3d}\\        
       
   350     \end{columns}
       
   351 \begin{lstlisting}
       
   352 >>> x, y, z = ogrid[-5:5:64j, 
       
   353 ...                -5:5:64j, 
       
   354 ...                -5:5:64j]
       
   355 >>> mlab.contour3d(x*x*0.5 + y*y + 
       
   356                    z*z*2)
       
   357 \end{lstlisting}
       
   358 \end{frame}
       
   359 
       
   360 \begin{frame}[fragile]
       
   361 
       
   362     \myemph{\Large 3D vector data: \PythonCode{mlab.quiver3d}}
       
   363     \vspace*{0.25in}
       
   364 
       
   365     \pgfimage[width=2in]{MEDIA/m2/mlab/quiver3d_ex}\\
       
   366     
       
   367 \begin{lstlisting}
       
   368 >>> mlab.test_quiver3d()
       
   369 \end{lstlisting}
       
   370 
       
   371 \emphbar{\PythonCode{obj = mlab.quiver3d(x, y, z, u, v, w)}}
       
   372 \inctime{20}
       
   373 \end{frame}
       
   374 
       
   375 
       
   376 \subsection{Mayavi2}
       
   377 
       
   378 \begin{frame}
       
   379   \frametitle{Introduction to Mayavi}
       
   380   \begin{itemize}
       
   381   \item Most scientists not interested in details of visualization
       
   382   \item Visualization of data files with a nice UI
       
   383   \item Interactive visualization of data (think Matlab)
       
   384   \item Embedding visualizations in applications
       
   385   \item Customization
       
   386   \end{itemize}
       
   387   \pause
       
   388   \begin{block}{The Goal}
       
   389       Provide a \alert{flexible} library/app for every one of these needs!
       
   390   \end{block}
       
   391 \end{frame}
       
   392 
       
   393 \begin{frame}
       
   394     {Overview of features}
       
   395       \vspace*{-0.3in}
       
   396   \begin{center}    
       
   397     \hspace*{-0.2in}\pgfimage[width=5in]{MEDIA/m2/m2_app3_3}
       
   398   \end{center}    
       
   399 \end{frame}
       
   400 
       
   401 
       
   402 \begin{frame}
       
   403     \frametitle{Mayavi in applications}
       
   404       \vspace*{-0.3in}
       
   405   \begin{center}    
       
   406     \hspace*{-0.2in}\pgfimage[width=4.5in]{MEDIA/m2/m2_envisage}
       
   407   \end{center}
       
   408 \end{frame}
       
   409 
       
   410 \begin{frame}
       
   411     \frametitle{Live in your dialogs}
       
   412       \vspace*{0.1in}
       
   413   \begin{center}    
       
   414     \hspace*{-0.2in}\pgfimage[width=2.5in]{MEDIA/m2/mlab_tui}
       
   415   \end{center}
       
   416 \end{frame}
       
   417 
       
   418 \begin{frame}
       
   419     {Exploring the documentation}
       
   420     \begin{center}
       
   421     \pgfimage[width=4in]{MEDIA/m2/m2_ug_doc}
       
   422     \end{center}
       
   423 \end{frame}
       
   424 
       
   425 
       
   426 \begin{frame}
       
   427   \frametitle{Summary}
       
   428       \begin{itemize}
       
   429           \item \url{http://code.enthought.com/projects/mayavi}
       
   430           \item Uses VTK (\url{www.vtk.org})
       
   431           \item BSD license
       
   432           \item Linux, win32 and Mac OS X
       
   433           \item Highly scriptable
       
   434           \item Embed in Traits UIs (wxPython and PyQt4)
       
   435           \item Envisage Plugins
       
   436           \item Debian/Ubuntu/Fedora
       
   437           \item \alert{Pythonic}
       
   438       \end{itemize}
       
   439     
       
   440       \inctime{10}
       
   441 
       
   442 \end{frame}
       
   443 
       
   444 \begin{frame}
       
   445     {Getting hands dirty!}
       
   446 
       
   447         \begin{block}{Motivational problem}
       
   448         Atmospheric data of temperature over the surface of the earth.
       
   449         Let temperature ($T$) vary linearly with height ($z$):
       
   450         \begin{center}            
       
   451         $T = 288.15 - 6.5z$
       
   452         \end{center}
       
   453         \end{block}
       
   454 \end{frame}
       
   455 
       
   456 \begin{frame}[fragile]
       
   457     \frametitle{Simple solution}
       
   458 
       
   459     \begin{lstlisting}
       
   460 lat = linspace(-89, 89, 37)
       
   461 lon = linspace(0, 360, 37)
       
   462 z = linspace(0, 100, 11)
       
   463     \end{lstlisting}
       
   464 \pause
       
   465     \begin{lstlisting}
       
   466 x, y, z = mgrid[0:360:37j,-89:89:37j,
       
   467                 0:100:11j]
       
   468 t = 288.15 - 6.5*z
       
   469 mlab.contour3d(x, y, z, t)
       
   470 mlab.outline()
       
   471 mlab.colorbar()
       
   472     \end{lstlisting}
       
   473 \end{frame}
       
   474 
       
   475 \begin{frame}[fragile]
       
   476     \frametitle{Exercise: Lorenz equation}
       
   477     \begin{columns}
       
   478         \column{0.25\textwidth}
       
   479         \begin{eqnarray*}
       
   480         \frac{d x}{dt} &=& s (y-x)\\
       
   481         \frac{d y}{d t} &=& rx -y -xz\\
       
   482         \frac{d z}{d t} &=& xy - bz\\
       
   483         \end{eqnarray*}
       
   484         \column{0.25\textwidth}
       
   485         Let $s=10,$
       
   486         $r=28,$ 
       
   487         $b=8./3.$
       
   488     \end{columns}
       
   489     \structure{\Large Region of interest}
       
   490   \begin{lstlisting}
       
   491 x, y, z = mgrid[-50:50:20j,-50:50:20j,
       
   492                 -10:60:20j]
       
   493   \end{lstlisting}
       
   494 \inctime{20}
       
   495 
       
   496 \end{frame}
       
   497 \begin{frame}[fragile]
       
   498     \frametitle{Solution}
       
   499   \begin{lstlisting}
       
   500 def lorenz(x,y,z,s=10.,r=28.,b=8./3.):
       
   501     u = s*(y-x)
       
   502     v = r*x-y-x*z
       
   503     w = x*y-b*z
       
   504     return u,v,w
       
   505 x,y,z = mgrid [-50:50:20j,-50:50:20j,
       
   506                     -10:60:20j ]
       
   507 u,v,w = lorenz( x , y , z )
       
   508 # Your plot here
       
   509 #
       
   510 mlab.show()
       
   511 
       
   512   \end{lstlisting}
       
   513 \end{frame}
       
   514   
       
   515 \end{document}
       
   516