day2/session5.tex
changeset 298 df494695e061
parent 289 884d42eff66d
child 330 46533051b9d3
equal deleted inserted replaced
294:f05b1c457120 298:df494695e061
     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[14pt,compress]{beamer}
     8 \documentclass[compress,14pt]{beamer}
     9 %\documentclass[draft]{beamer}
     9 % \documentclass[handout]{beamer}
    10 %\documentclass[compress,handout]{beamer}
    10 % \usepackage{pgfpages}
    11 %\usepackage{pgfpages} 
    11 % \pgfpagesuselayout{4 on 1}[a4paper,border, shrink=5mm,landscape]
    12 %\pgfpagesuselayout{2 on 1}[a4paper,border shrink=5mm]
    12 \usepackage{tikz}
    13 
    13 \newcommand{\hyperlinkmovie}{}
    14 % Modified from: generic-ornate-15min-45min.de.tex
    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 
    15 \mode<presentation>
    23 \mode<presentation>
    16 {
    24 {
    17   \usetheme{Warsaw}
    25   \usetheme{Warsaw}
       
    26   %\usetheme{Boadilla}
       
    27   %\usetheme{default}
    18   \useoutertheme{infolines}
    28   \useoutertheme{infolines}
    19   \setbeamercovered{transparent}
    29   \setbeamercovered{transparent}
    20 }
    30 }
    21 
    31 
       
    32 % To remove navigation symbols
       
    33 \setbeamertemplate{navigation symbols}{}
       
    34 
       
    35 \usepackage{amsmath}
    22 \usepackage[english]{babel}
    36 \usepackage[english]{babel}
    23 \usepackage[latin1]{inputenc}
    37 \usepackage[latin1]{inputenc}
    24 %\usepackage{times}
    38 \usepackage{times}
    25 \usepackage[T1]{fontenc}
    39 \usepackage[T1]{fontenc}
    26 
    40 
    27 % Taken from Fernando's slides.
    41 % Taken from Fernando's slides.
    28 \usepackage{ae,aecompl}
    42 \usepackage{ae,aecompl}
    29 \usepackage{mathpazo,courier,euler}
    43 \usepackage{mathpazo,courier,euler}
    30 \usepackage[scaled=.95]{helvet}
    44 \usepackage[scaled=.95]{helvet}
       
    45 \usepackage{pgf}
    31 
    46 
    32 \definecolor{darkgreen}{rgb}{0,0.5,0}
    47 \definecolor{darkgreen}{rgb}{0,0.5,0}
    33 
    48 
    34 \usepackage{listings}
    49 \usepackage{listings}
    35 \lstset{language=Python,
    50 \lstset{language=Python,
    38   stringstyle=\color{darkgreen},
    53   stringstyle=\color{darkgreen},
    39   showstringspaces=false,
    54   showstringspaces=false,
    40   keywordstyle=\color{blue}\bfseries}
    55   keywordstyle=\color{blue}\bfseries}
    41 
    56 
    42 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    57 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    43 % Macros
    58 % My Macros
       
    59 \setbeamercolor{postit}{bg=yellow,fg=black}
    44 \setbeamercolor{emphbar}{bg=blue!20, fg=black}
    60 \setbeamercolor{emphbar}{bg=blue!20, fg=black}
    45 \newcommand{\emphbar}[1]
    61 \newcommand{\emphbar}[1]
    46 {\begin{beamercolorbox}[rounded=true]{emphbar} 
    62 {\begin{beamercolorbox}[rounded=true]{emphbar} 
    47       {#1}
    63       {#1}
    48  \end{beamercolorbox}
    64  \end{beamercolorbox}
    49 }
    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 
    50 \newcounter{time}
    78 \newcounter{time}
    51 \setcounter{time}{0}
    79 \setcounter{time}{0}
    52 \newcommand{\inctime}[1]{\addtocounter{time}{#1}{\tiny \thetime\ m}}
    80 \newcommand{\inctime}[1]{\addtocounter{time}{#1}{\vspace*{0.1in}\tiny \thetime\ m}}
    53 
    81 
    54 \newcommand{\typ}[1]{\texttt{#1}}
    82 \newcommand\BackgroundPicture[1]{%
    55 
    83   \setbeamertemplate{background}{%
    56 \newcommand{\kwrd}[1]{ \texttt{\textbf{\color{blue}{#1}}}  }
    84       \parbox[c][\paperheight]{\paperwidth}{%
    57 
    85       \vfill \hfill
    58 %%% This is from Fernando's setup.
    86  \hfill \vfill
    59 % \usepackage{color}
    87 }}}
    60 % \definecolor{orange}{cmyk}{0,0.4,0.8,0.2}
    88 
    61 % % Use and configure listings package for nicely formatted code
    89 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    62 % \usepackage{listings}
    90 % Configuring the theme
    63 % \lstset{
    91 %\setbeamercolor{normal text}{fg=white}
    64 %    language=Python,
    92 %\setbeamercolor{background canvas}{bg=black}
    65 %    basicstyle=\small\ttfamily,
    93 
    66 %    commentstyle=\ttfamily\color{blue},
       
    67 %    stringstyle=\ttfamily\color{orange},
       
    68 %    showstringspaces=false,
       
    69 %    breaklines=true,
       
    70 %    postbreak = \space\dots
       
    71 % }
       
    72 
    94 
    73 
    95 
    74 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    96 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    75 % Title page
    97 % Title page
    76 \title[Exercises]{Exercises}
    98 \title[3D Plotting]{3D data Visualization}
    77 
    99 
    78 \author[FOSSEE] {FOSSEE}
   100 \author[FOSSEE] {FOSSEE}
    79 
   101 
    80 \institute[IIT Bombay] {Department of Aerospace Engineering\\IIT Bombay}
   102 \institute[IIT Bombay] {Department of Aerospace Engineering\\IIT Bombay}
    81 \date[] {8 November, 2009\\Day 2, Session 5}
   103 \date[] {8 November, 2009\\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 }
    87 
   117 
    88 %% Delete this, if you do not want the table of contents to pop up at
   118 %% Delete this, if you do not want the table of contents to pop up at
    89 %% the beginning of each subsection:
   119 %% the beginning of each subsection:
    90 \AtBeginSubsection[]
   120 \AtBeginSubsection[]
    91 {
   121 {
    93     \frametitle{Outline}
   123     \frametitle{Outline}
    94     \tableofcontents[currentsection,currentsubsection]
   124     \tableofcontents[currentsection,currentsubsection]
    95   \end{frame}
   125   \end{frame}
    96 }
   126 }
    97 
   127 
    98 
   128 \AtBeginSection[]
    99 % If you wish to uncover everything in a step-wise fashion, uncomment
   129 {
   100 % the following command: 
   130   \begin{frame}<beamer>
   101 %\beamerdefaultoverlayspecification{<+->}
   131     \frametitle{Outline}
   102 
   132     \tableofcontents[currentsection,currentsubsection]
   103 %\includeonlyframes{current,current1,current2,current3,current4,current5,current6}
   133   \end{frame}
   104 
   134 }
   105 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
   135 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
   106 % DOCUMENT STARTS
   136 % DOCUMENT STARTS
   107 \begin{document}
   137 \begin{document}
   108 
   138 
   109 \begin{frame}
   139 \begin{frame}
   110   \titlepage
   140   \maketitle
   111 \end{frame}
   141 \end{frame}
   112 
   142 
   113 \begin{frame}{Problem 1.1}
   143 \begin{frame}
   114   The aliquot of a number is defined as: the sum of the \emph{proper} divisors of the number. \\For example: 
   144   \frametitle{Outline}
   115 \center{aliquot(12) = 1 + 2 + 3 + 4 + 6 = 16.}\\
   145   \tableofcontents
   116   Write a function that returns the aliquot number of a given number. 
   146   % You might wish to add the option [pausesections]
   117 \end{frame}
   147 \end{frame}
   118 
   148 
   119 \begin{frame}{Problem 1.2}
   149 \section{3D Data Visualization}
   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.\\
   150 
   121   Example: \texttt{220, 284}\\
   151 \begin{frame}
   122   Write a program that prints all four digit amicable pairs.
   152     \frametitle{What is visualization?}
   123   
   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 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)}}
   124 \inctime{20}
   405 \inctime{20}
   125 \end{frame}
   406 \end{frame}
   126 
   407 
   127 %% \begin{frame}{Problem 2}
   408 
   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.
   409 \subsection{Mayavi2}
   129 
   410 
   130 %% \end{frame}
   411 \begin{frame}
   131 
   412   \frametitle{Introduction to Mayavi}
   132 \begin{frame}[fragile]
   413   \begin{itemize}
   133   \frametitle{Problem Set 2}
   414   \item Most scientists not interested in details of visualization
   134   Given a string like, ``1, 3-7, 12, 15, 18-21'', produce the list \\
   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}
   135   \begin{lstlisting}
   523   \begin{lstlisting}
   136     [1,3,4,5,6,7,12,15,18,19,20,21]
   524 x, y, z = mgrid[-50:50:20j,-50:50:20j,
       
   525                 -10:60:20j]
   137   \end{lstlisting}
   526   \end{lstlisting}
   138 \inctime{10}
   527 \inctime{20}
   139 \end{frame}
   528 
   140 
   529 \end{frame}
   141 \begin{frame} 
   530 \begin{frame}[fragile]
   142   \frametitle{Problem Set 3}
   531     \frametitle{Solution}
   143   \begin{description}
       
   144     \item[3.1] Count word frequencies in a file.
       
   145 \end{description}
       
   146 \inctime{5}
       
   147 \end{frame}
       
   148 
       
   149 \begin{frame}[fragile]
       
   150   \frametitle{Problem set 4}
       
   151   Central difference
       
   152   \begin{equation*}
       
   153   \frac{sin(x+h)-sin(x-h)}{2h}
       
   154   \end{equation*}
       
   155   \begin{lstlisting}
   532   \begin{lstlisting}
   156   In []: x = linspace(0, 2*pi, 100)
   533 def lorenz(x,y,z,s=10.,r=28.,b=8./3.):
   157   In []: y = sin(x)
   534     u = s*(y-x)
   158   In []: deltax = x[1] - x[0]
   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 
   159   \end{lstlisting}
   545   \end{lstlisting}
   160   \pause
   546 \end{frame}
   161     \begin{enumerate}
   547 
   162       \item Given this, get the finite difference of sin in the range 0 to 2*pi
   548 \begin{frame}
   163     \end{enumerate}
   549   \frametitle{We have covered:}
   164 \end{frame}
       
   165 
       
   166 \begin{frame}
       
   167   \frametitle{Problem Set 5}
       
   168   \begin{itemize}
   550   \begin{itemize}
   169       \item[5.1] Write a function that plots any regular n-gon given \typ{n}.
   551   \item Need of visualization.
   170       \item[5.2] Consider the logistic map, $f(x) = kx(1-x)$, plot it for
   552   \item Using mlab to create 3 D plots.
   171           $k=2.5, 3.5$ and $4$ in the same plot.
   553   \item Mayavi Toolkit.
   172 \end{itemize}
   554   \end{itemize}
   173 \end{frame}
       
   174 
       
   175 \begin{frame}[fragile] 
       
   176 \frametitle{Problem Set 5}
       
   177   \begin{columns}
       
   178     \column{0.6\textwidth}
       
   179     \small{
       
   180     \begin{itemize}
       
   181       \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. 
       
   182     \end{itemize}}
       
   183     \column{0.35\textwidth}
       
   184     \hspace*{-0.5in}
       
   185   \includegraphics[height=1.6in, interpolate=true]{data/cobweb}  
       
   186 \end{columns}
       
   187 \end{frame}
       
   188 
       
   189 \begin{frame}
       
   190   \frametitle{Problem Set 5.3}
       
   191   Plot the cobweb plot as follows:
       
   192   \begin{enumerate}
       
   193     \item Start at $(x_0, 0)$ ($\implies$ i=0)
       
   194     \item Draw a line to $(x_i, f(x_i))$
       
   195     \item Set $x_{i+1} = f(x_i)$
       
   196     \item Draw a line to $(x_{i+1}, x_{i+1})$
       
   197     \item $(i\implies i+1)$ 
       
   198     \item Repeat from 2 for as long as you want 
       
   199   \end{enumerate}
       
   200 \inctime{20}
       
   201 \end{frame}
   555 \end{frame}
   202 
   556 
   203 \end{document}
   557 \end{document}
       
   558