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