day2/session5.tex
changeset 347 22e3480e4794
parent 339 8ac5fe07810f
child 354 5dc6c3673f9d
equal deleted inserted replaced
346:e9961fb16c58 347:22e3480e4794
     1 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
     1 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
     2 % Tutorial slides on Python.
     2 %Tutorial slides on Python.
     3 %
     3 %
     4 % Author: Prabhu Ramachandran <prabhu at aero.iitb.ac.in>
     4 % Author: Prabhu Ramachandran <prabhu at aero.iitb.ac.in>
     5 % Copyright (c) 2005-2009, Prabhu Ramachandran
     5 % Copyright (c) 2005-2009, Prabhu Ramachandran
     6 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
     6 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
     7 
     7 
     8 \documentclass[compress,14pt]{beamer}
     8 \documentclass[14pt,compress]{beamer}
     9 % \documentclass[handout]{beamer}
     9 %\documentclass[draft]{beamer}
    10 % \usepackage{pgfpages}
    10 %\documentclass[compress,handout]{beamer}
    11 % \pgfpagesuselayout{4 on 1}[a4paper,border, shrink=5mm,landscape]
    11 %\usepackage{pgfpages} 
    12 \usepackage{tikz}
    12 %\pgfpagesuselayout{2 on 1}[a4paper,border shrink=5mm]
    13 \newcommand{\hyperlinkmovie}{}
    13 
    14 %\usepackage{movie15}
    14 % Modified from: generic-ornate-15min-45min.de.tex
    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>
    15 \mode<presentation>
    24 {
    16 {
    25   \usetheme{Warsaw}
    17   \usetheme{Warsaw}
    26   %\usetheme{Boadilla}
       
    27   %\usetheme{default}
       
    28   \useoutertheme{infolines}
    18   \useoutertheme{infolines}
    29   \setbeamercovered{transparent}
    19   \setbeamercovered{transparent}
    30 }
    20 }
    31 
    21 
    32 % To remove navigation symbols
       
    33 \setbeamertemplate{navigation symbols}{}
       
    34 
       
    35 \usepackage{amsmath}
       
    36 \usepackage[english]{babel}
    22 \usepackage[english]{babel}
    37 \usepackage[latin1]{inputenc}
    23 \usepackage[latin1]{inputenc}
    38 \usepackage{times}
    24 %\usepackage{times}
    39 \usepackage[T1]{fontenc}
    25 \usepackage[T1]{fontenc}
    40 
    26 
    41 % Taken from Fernando's slides.
    27 % Taken from Fernando's slides.
    42 \usepackage{ae,aecompl}
    28 \usepackage{ae,aecompl}
    43 \usepackage{mathpazo,courier,euler}
    29 \usepackage{mathpazo,courier,euler}
    44 \usepackage[scaled=.95]{helvet}
    30 \usepackage[scaled=.95]{helvet}
    45 \usepackage{pgf}
       
    46 
    31 
    47 \definecolor{darkgreen}{rgb}{0,0.5,0}
    32 \definecolor{darkgreen}{rgb}{0,0.5,0}
    48 
    33 
    49 \usepackage{listings}
    34 \usepackage{listings}
    50 \lstset{language=Python,
    35 \lstset{language=Python,
    53   stringstyle=\color{darkgreen},
    38   stringstyle=\color{darkgreen},
    54   showstringspaces=false,
    39   showstringspaces=false,
    55   keywordstyle=\color{blue}\bfseries}
    40   keywordstyle=\color{blue}\bfseries}
    56 
    41 
    57 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    42 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    58 % My Macros
    43 % Macros
    59 \setbeamercolor{postit}{bg=yellow,fg=black}
       
    60 \setbeamercolor{emphbar}{bg=blue!20, fg=black}
    44 \setbeamercolor{emphbar}{bg=blue!20, fg=black}
    61 \newcommand{\emphbar}[1]
    45 \newcommand{\emphbar}[1]
    62 {\begin{beamercolorbox}[rounded=true]{emphbar} 
    46 {\begin{beamercolorbox}[rounded=true]{emphbar} 
    63       {#1}
    47       {#1}
    64  \end{beamercolorbox}
    48  \end{beamercolorbox}
    65 }
    49 }
    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}
    50 \newcounter{time}
    79 \setcounter{time}{0}
    51 \setcounter{time}{0}
    80 \newcommand{\inctime}[1]{\addtocounter{time}{#1}{\vspace*{0.1in}\tiny \thetime\ m}}
    52 \newcommand{\inctime}[1]{\addtocounter{time}{#1}{\tiny \thetime\ m}}
    81 
    53 
    82 \newcommand\BackgroundPicture[1]{%
    54 \newcommand{\typ}[1]{\texttt{#1}}
    83   \setbeamertemplate{background}{%
    55 
    84       \parbox[c][\paperheight]{\paperwidth}{%
    56 \newcommand{\kwrd}[1]{ \texttt{\textbf{\color{blue}{#1}}}  }
    85       \vfill \hfill
    57 
    86  \hfill \vfill
    58 %%% This is from Fernando's setup.
    87 }}}
    59 % \usepackage{color}
    88 
    60 % \definecolor{orange}{cmyk}{0,0.4,0.8,0.2}
    89 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    61 % % Use and configure listings package for nicely formatted code
    90 % Configuring the theme
    62 % \usepackage{listings}
    91 %\setbeamercolor{normal text}{fg=white}
    63 % \lstset{
    92 %\setbeamercolor{background canvas}{bg=black}
    64 %    language=Python,
    93 
    65 %    basicstyle=\small\ttfamily,
       
    66 %    commentstyle=\ttfamily\color{blue},
       
    67 %    stringstyle=\ttfamily\color{orange},
       
    68 %    showstringspaces=false,
       
    69 %    breaklines=true,
       
    70 %    postbreak = \space\dots
       
    71 % }
    94 
    72 
    95 
    73 
    96 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    74 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    97 % Title page
    75 % Title page
    98 \title[3D Plotting]{3D data Visualization}
    76 \title[Exercises]{Exercises}
    99 
    77 
   100 \author[FOSSEE] {FOSSEE}
    78 \author[FOSSEE] {FOSSEE}
   101 
    79 
   102 \institute[IIT Bombay] {Department of Aerospace Engineering\\IIT Bombay}
    80 \institute[IIT Bombay] {Department of Aerospace Engineering\\IIT Bombay}
   103 \date[] {12 January, 2010\\Day 2, Session 5}
    81 \date[] {12 January, 2010\\Day 2, Session 5}
   104 
    82 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
   105 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    83 
   106 
    84 %\pgfdeclareimage[height=0.75cm]{iitmlogo}{iitmlogo}
   107 %\pgfdeclareimage[height=0.75cm]{iitblogo}{iitblogo}
    85 %\logo{\pgfuseimage{iitmlogo}}
   108 %\logo{\pgfuseimage{iitblogo}}
    86 
   109 
       
   110 \AtBeginSection[]
       
   111 {
       
   112   \begin{frame}<beamer>
       
   113     \frametitle{Outline}      
       
   114     \tableofcontents[currentsection,currentsubsection]
       
   115   \end{frame}
       
   116 }
       
   117 
    87 
   118 %% Delete this, if you do not want the table of contents to pop up at
    88 %% Delete this, if you do not want the table of contents to pop up at
   119 %% the beginning of each subsection:
    89 %% the beginning of each subsection:
   120 \AtBeginSubsection[]
    90 \AtBeginSubsection[]
   121 {
    91 {
   123     \frametitle{Outline}
    93     \frametitle{Outline}
   124     \tableofcontents[currentsection,currentsubsection]
    94     \tableofcontents[currentsection,currentsubsection]
   125   \end{frame}
    95   \end{frame}
   126 }
    96 }
   127 
    97 
   128 \AtBeginSection[]
    98 
   129 {
    99 % If you wish to uncover everything in a step-wise fashion, uncomment
   130   \begin{frame}<beamer>
   100 % the following command: 
   131     \frametitle{Outline}
   101 %\beamerdefaultoverlayspecification{<+->}
   132     \tableofcontents[currentsection,currentsubsection]
   102 
   133   \end{frame}
   103 %\includeonlyframes{current,current1,current2,current3,current4,current5,current6}
   134 }
   104 
   135 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
   105 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
   136 % DOCUMENT STARTS
   106 % DOCUMENT STARTS
   137 \begin{document}
   107 \begin{document}
   138 
   108 
   139 \begin{frame}
   109 \begin{frame}
   140   \maketitle
   110   \titlepage
       
   111 \end{frame}
       
   112 
       
   113 \begin{frame}{Problem 1.1}
       
   114   The aliquot of a number is defined as: the sum of the \emph{proper} divisors of the number. For example:\\
       
   115 aliquot(12) = 1 + 2 + 3 + 4 + 6 = 16.\\
       
   116   Write a function that returns the aliquot number of a given number. 
       
   117 \end{frame}
       
   118 
       
   119 \begin{frame}{Problem 1.2}
       
   120   Pair of numbers (a, b) is said to be \alert{amicable} if aliquot number of a is b and aliquot number of b is a.\\
       
   121   Example: \texttt{220, 284}\\
       
   122   Write a program that prints all four digit amicable pairs.
       
   123   
       
   124 \inctime{20}
       
   125 \end{frame}
       
   126 
       
   127 %% \begin{frame}{Problem 2}
       
   128 %%   Given an empty chessboard and one Bishop placed in any s%quare, say (r, c), generate the list of all squares the Bi%shop could move to.
       
   129 
       
   130 %% \end{frame}
       
   131 
       
   132 \begin{frame}[fragile]
       
   133   \frametitle{Problem 2}
       
   134   Given a string of numbers like, ``1, 3-7, 12, 15, 18-21'', produce the following list \\
       
   135   \begin{lstlisting}
       
   136     [1,3,4,5,6,7,12,15,18,19,20,21]
       
   137   \end{lstlisting}
       
   138 \inctime{10}
       
   139 \end{frame}
       
   140 
       
   141 \begin{frame} 
       
   142   \frametitle{Problem 3}
       
   143   Count frequencies of words in a file.
       
   144 \inctime{25}
       
   145 \end{frame}
       
   146 
       
   147 \begin{frame}[fragile]
       
   148   \frametitle{Problem set 4}
       
   149   Central difference
       
   150   \begin{equation*}
       
   151   \frac{sin(x+h)-sin(x-h)}{2h}
       
   152   \end{equation*}
       
   153   \begin{lstlisting}
       
   154   In []: x = linspace(0, 2*pi, 100)
       
   155   In []: y = sin(x)
       
   156   In []: deltax = x[1] - x[0]
       
   157   \end{lstlisting}
       
   158   \pause
       
   159     \begin{enumerate}
       
   160       \item Given this, get the finite difference of sin in the range 0 to 2*pi
       
   161     \end{enumerate}
   141 \end{frame}
   162 \end{frame}
   142 
   163 
   143 \begin{frame}
   164 \begin{frame}
   144   \frametitle{Outline}
   165   \frametitle{Problem Set 5}
   145   \tableofcontents
   166   \begin{itemize}
   146   % You might wish to add the option [pausesections]
   167       \item[5.1] Write a function that plots any regular n-gon given \typ{n}.
   147 \end{frame}
   168       \item[5.2] Consider the logistic map, $f(x) = kx(1-x)$, plot it for
   148 
   169           $k=2.5, 3.5$ and $4$ in the same plot.
   149 \section{3D Data Visualization}
   170 \end{itemize}
       
   171 \end{frame}
       
   172 
       
   173 \begin{frame}[fragile] 
       
   174 \frametitle{Problem Set 5}
       
   175   \begin{columns}
       
   176     \column{0.6\textwidth}
       
   177     \small{
       
   178     \begin{itemize}
       
   179       \item[3] Consider the iteration $x_{n+1} = f(x_n)$ where $f(x) = kx(1-x)$.  Plot the successive iterates of this process as explained below. 
       
   180     \end{itemize}}
       
   181     \column{0.35\textwidth}
       
   182     \hspace*{-0.5in}
       
   183   \includegraphics[height=1.6in, interpolate=true]{data/cobweb}  
       
   184 \end{columns}
       
   185 \end{frame}
   150 
   186 
   151 \begin{frame}
   187 \begin{frame}
   152     \frametitle{What is visualization?}
   188   \frametitle{Problem Set 5.3}
   153     \Large
   189   Plot the cobweb plot as follows:
   154     \begin{center}
   190   \begin{enumerate}
   155     Visual representation of data
   191     \item Start at $(x_0, 0)$ ($\implies$ i=0)
   156     \end{center}
   192     \item Draw a line to $(x_i, f(x_i))$
   157 \end{frame}
   193     \item Set $x_{i+1} = f(x_i)$
   158 
   194     \item Draw a line to $(x_{i+1}, x_{i+1})$
   159 
   195     \item $(i\implies i+1)$ 
   160 %% \begin{frame}
   196     \item Repeat from 2 for as long as you want 
   161 %%     \frametitle{Is this new?}    
   197   \end{enumerate}
   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 In []: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 In []: mlab.test_<TAB>
       
   252 In []: mlab.test_contour3d()
       
   253 In []: 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 In []: t = linspace(0, 2*pi, 50)
       
   283 In []: u = cos(t) * pi
       
   284 In []: x, y, z = sin(u), cos(u), sin(t)
       
   285     \end{lstlisting}
       
   286     \emphbar{\PythonCode{In []: mlab.points3d(x, y, z)}}
       
   287 \end{frame}
       
   288 
       
   289 \begin{frame}
       
   290   \begin{columns}
       
   291         \column{0.25\textwidth}
       
   292         \myemph{\Large 1D data}
       
   293         \column{0.5\textwidth}
       
   294         \pgfimage[width=2.5in]{MEDIA/m2/mlab/plot3d_ex}
       
   295   \end{columns}
       
   296   \emphbar{\PythonCode{In []: mlab.plot3d(x, y, z, t)}}
       
   297 
       
   298     Plots lines between the points
       
   299     
       
   300 \end{frame}
       
   301 
       
   302 \begin{frame}[fragile]
       
   303     \begin{columns}
       
   304         \column{0.25\textwidth}
       
   305         \myemph{\Large 2D data}
       
   306         \column{0.5\textwidth}
       
   307         \pgfimage[width=2in]{MEDIA/m2/mlab/surf_ex}
       
   308     \end{columns}            
       
   309     \begin{lstlisting}
       
   310 In []: x, y = mgrid[-3:3:100j,-3:3:100j]
       
   311 In []: z = sin(x*x + y*y)
       
   312     \end{lstlisting}
       
   313 
       
   314     \emphbar{\PythonCode{In []: mlab.surf(x, y, z)}}
       
   315 
       
   316     \alert{Assumes the points are rectilinear}
       
   317 
       
   318 \end{frame}
       
   319 
       
   320 \begin{frame}[fragile]
       
   321   \frametitle{mgrid}
       
   322   \begin{lstlisting}
       
   323 In []: mgrid[0:3,0:3]
       
   324 Out[]: 
       
   325 array([[[0, 0, 0],
       
   326         [1, 1, 1],
       
   327         [2, 2, 2]],
       
   328 
       
   329        [[0, 1, 2],
       
   330         [0, 1, 2],
       
   331         [0, 1, 2]]])
       
   332 
       
   333 In []: mgrid[-1:1:5j]
       
   334 Out[]: array([-1., -0.5,  0.,  0.5,  1.])
       
   335 \end{lstlisting}
       
   336 \end{frame}
       
   337 
       
   338 \begin{frame}[fragile]
       
   339   \frametitle{Example}
       
   340   \begin{lstlisting}
       
   341 In []: x, y = mgrid[-1:1:5j, -1:1:5j]
       
   342 In []: z = x*x + y*y
       
   343 
       
   344 In []: z
       
   345 Out[]: 
       
   346 array([[ 2.  , 1.25, 1.  , 1.25, 2.  ],
       
   347        [ 1.25, 0.5 , 0.25, 0.5 , 1.25],
       
   348        [ 1.  , 0.25, 0.  , 0.25, 1.  ],
       
   349        [ 1.25, 0.5 , 0.25, 0.5 , 1.25],
       
   350        [ 2.  , 1.25, 1.  , 1.25, 2.  ]])
       
   351 \end{lstlisting}
       
   352 \end{frame}
       
   353 
       
   354 \begin{frame}[fragile]
       
   355     \myemph{\Large 2D data: \texttt{mlab.mesh}}
       
   356     \vspace*{0.25in}
       
   357 
       
   358     \emphbar{\PythonCode{In []: mlab.mesh(x, y, z)}}
       
   359 
       
   360     \alert{Points needn't be regular}
       
   361 
       
   362     \vspace*{0.25in}
       
   363 \begin{lstlisting}
       
   364 In []: phi, theta = mgrid[0:pi:20j, 
       
   365 ...                         0:2*pi:20j]
       
   366 In []: x = sin(phi)*cos(theta)
       
   367 In []: y = sin(phi)*sin(theta)
       
   368 In []: z = cos(phi)
       
   369 In []: mlab.mesh(x, y, z, 
       
   370 ...           representation=
       
   371 ...           'wireframe')
       
   372 \end{lstlisting}
       
   373 
       
   374 \end{frame}
       
   375 
       
   376 \begin{frame}[fragile]
       
   377 
       
   378   \begin{columns}
       
   379         \column{0.25\textwidth}
       
   380         \myemph{\Large 3D data}
       
   381         \column{0.5\textwidth}
       
   382         \pgfimage[width=1.5in]{MEDIA/m2/mlab/contour3d}\\        
       
   383     \end{columns}
       
   384 \begin{lstlisting}
       
   385 In []: x, y, z = mgrid[-5:5:64j, 
       
   386 ...                -5:5:64j, 
       
   387 ...                -5:5:64j]
       
   388 In []: mlab.contour3d(x*x*0.5 + y*y + 
       
   389                    z*z*2)
       
   390 \end{lstlisting}
       
   391 \end{frame}
       
   392 
       
   393 \begin{frame}[fragile]
       
   394 
       
   395     \myemph{\Large 3D vector data: \PythonCode{mlab.quiver3d}}
       
   396     \vspace*{0.25in}
       
   397 
       
   398     \pgfimage[width=2in]{MEDIA/m2/mlab/quiver3d_ex}\\
       
   399     
       
   400 \begin{lstlisting}
       
   401 In []: mlab.test_quiver3d()
       
   402 \end{lstlisting}
       
   403 
       
   404 \emphbar{\PythonCode{obj = mlab.quiver3d(x, y, z, u, v, w)}}
       
   405 \inctime{20}
   198 \inctime{20}
   406 \end{frame}
   199 \end{frame}
   407 
   200 
   408 
       
   409 \subsection{Mayavi2}
       
   410 
       
   411 \begin{frame}
       
   412   \frametitle{Introduction to Mayavi}
       
   413   \begin{itemize}
       
   414   \item Most scientists not interested in details of visualization
       
   415   \item Visualization of data files with a nice UI
       
   416   \item Interactive visualization of data (think Matlab)
       
   417   \item Embedding visualizations in applications
       
   418   \item Customization
       
   419   \end{itemize}
       
   420   \pause
       
   421   \begin{block}{The Goal}
       
   422       Provide a \alert{flexible} library/app for all of these needs!
       
   423   \end{block}
       
   424 \end{frame}
       
   425 
       
   426 \begin{frame}
       
   427     {Overview of features}
       
   428       \vspace*{-0.3in}
       
   429   \begin{center}    
       
   430     \hspace*{-0.2in}\pgfimage[width=5in]{MEDIA/m2/m2_app3_3}
       
   431   \end{center}    
       
   432 \end{frame}
       
   433 
       
   434 
       
   435 \begin{frame}
       
   436     \frametitle{Mayavi in applications}
       
   437       \vspace*{-0.3in}
       
   438   \begin{center}    
       
   439     \hspace*{-0.2in}\pgfimage[width=4.5in]{MEDIA/m2/m2_envisage}
       
   440   \end{center}
       
   441 \end{frame}
       
   442 
       
   443 \begin{frame}
       
   444     \frametitle{Live in your dialogs}
       
   445       \vspace*{0.1in}
       
   446   \begin{center}    
       
   447     \hspace*{-0.2in}\pgfimage[width=2.5in]{MEDIA/m2/mlab_tui}
       
   448   \end{center}
       
   449 \end{frame}
       
   450 
       
   451 \begin{frame}
       
   452     {Exploring the documentation}
       
   453     \begin{center}
       
   454     \pgfimage[width=4in]{MEDIA/m2/m2_ug_doc}
       
   455     \end{center}
       
   456 \end{frame}
       
   457 
       
   458 
       
   459 \begin{frame}
       
   460   \frametitle{Summary}
       
   461       \begin{itemize}
       
   462           \item \url{http://code.enthought.com/projects/mayavi}
       
   463           \item Uses VTK (\url{www.vtk.org})
       
   464           \item BSD license
       
   465           \item Linux, win32 and Mac OS X
       
   466           \item Highly scriptable
       
   467           \item Embed in Traits UIs (wxPython and PyQt4)
       
   468           \item Envisage Plugins
       
   469           \item Debian/Ubuntu/Fedora
       
   470           \item \alert{Pythonic}
       
   471       \end{itemize}
       
   472     
       
   473       \inctime{10}
       
   474 
       
   475 \end{frame}
       
   476 
       
   477 \begin{frame}
       
   478     {Getting hands dirty!}
       
   479 
       
   480         \begin{block}{Motivational problem}
       
   481         Atmospheric data of temperature over the surface of the earth.
       
   482         Let temperature ($T$) vary linearly with height ($z$):
       
   483         \begin{center}            
       
   484         $T = 288.15 - 6.5z$
       
   485         \end{center}
       
   486         \end{block}
       
   487 \end{frame}
       
   488 
       
   489 \begin{frame}[fragile]
       
   490     \frametitle{Simple solution}
       
   491 
       
   492     \begin{lstlisting}
       
   493 lat = linspace(-89, 89, 37)
       
   494 lon = linspace(0, 360, 37)
       
   495 z = linspace(0, 100, 11)
       
   496     \end{lstlisting}
       
   497 \pause
       
   498     \begin{lstlisting}
       
   499 x, y, z = mgrid[0:360:37j,-89:89:37j,
       
   500                 0:100:11j]
       
   501 t = 288.15 - 6.5*z
       
   502 mlab.contour3d(x, y, z, t)
       
   503 mlab.outline()
       
   504 mlab.colorbar()
       
   505     \end{lstlisting}
       
   506 \end{frame}
       
   507 
       
   508 \begin{frame}[fragile]
       
   509     \frametitle{Exercise: Lorenz equation}
       
   510     \begin{columns}
       
   511         \column{0.25\textwidth}
       
   512         \begin{eqnarray*}
       
   513         \frac{d x}{dt} &=& s (y-x)\\
       
   514         \frac{d y}{d t} &=& rx -y -xz\\
       
   515         \frac{d z}{d t} &=& xy - bz\\
       
   516         \end{eqnarray*}
       
   517         \column{0.25\textwidth}
       
   518         Let $s=10,$
       
   519         $r=28,$ 
       
   520         $b=8./3.$
       
   521     \end{columns}
       
   522     \structure{\Large Region of interest}
       
   523   \begin{lstlisting}
       
   524 x, y, z = mgrid[-50:50:20j,-50:50:20j,
       
   525                 -10:60:20j]
       
   526   \end{lstlisting}
       
   527 \inctime{20}
       
   528 
       
   529 \end{frame}
       
   530 \begin{frame}[fragile]
       
   531     \frametitle{Solution}
       
   532   \begin{lstlisting}
       
   533 def lorenz(x,y,z,s=10.,r=28.,b=8./3.):
       
   534     u = s*(y-x)
       
   535     v = r*x-y-x*z
       
   536     w = x*y-b*z
       
   537     return u,v,w
       
   538 x,y,z = mgrid [-50:50:20j,-50:50:20j,
       
   539                     -10:60:20j ]
       
   540 u,v,w = lorenz( x , y , z )
       
   541 # Your plot here
       
   542 #
       
   543 mlab.show()
       
   544 
       
   545   \end{lstlisting}
       
   546 \end{frame}
       
   547 
       
   548 \begin{frame}
       
   549   \frametitle{We have covered:}
       
   550   \begin{itemize}
       
   551   \item Need of visualization.
       
   552   \item Using mlab to create 3 D plots.
       
   553   \item Mayavi Toolkit.
       
   554   \end{itemize}
       
   555 \end{frame}
       
   556 
       
   557 \end{document}
   201 \end{document}
   558