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{plotting 3-D Surface: $x^2+y^2-z^2=1$} |
|
274 \begin{lstlisting} |
|
275 u,v = mgrid[-2:2:100j, -pi:pi:100j] |
|
276 x=sqrt(u*u+1)*cos(v) |
|
277 y=sqrt(u*u+1)*sin(v) |
|
278 z=u |
|
279 mlab.mesh(x,y,z) |
|
280 \end{lstlisting} |
|
281 \begin{figure} |
|
282 \includegraphics[width=1in, height=1in, interpolate=true]{data/hyperboloid} |
|
283 \end{figure} |
|
284 \end{frame} |
|
285 |
|
286 \begin{frame}[fragile] |
|
287 \frametitle{mgrid} |
|
288 \begin{itemize} |
|
289 \item Creates a multidimensional ``meshgrid'' |
|
290 |
|
291 \item In this particular case, creates 2 2D arrays: u,v. |
|
292 \end{itemize} |
|
293 \begin{lstlisting} |
|
294 In []: mgrid[0:3,0:3] |
|
295 Out[]: |
|
296 array([[[0, 0, 0], |
|
297 [1, 1, 1], |
|
298 [2, 2, 2]], |
|
299 |
|
300 [[0, 1, 2], |
|
301 [0, 1, 2], |
|
302 [0, 1, 2]]]) |
|
303 \end{lstlisting} |
|
304 \end{frame} |
|
305 |
|
306 \begin{frame}[fragile] |
|
307 \frametitle{mesh} |
|
308 \begin{itemize} |
|
309 \item Plots a surface from data supplied as 2D arrays. |
|
310 \end{itemize} |
|
311 \end{frame} |
|
312 |
|
313 \begin{frame}[fragile] |
|
314 \frametitle{\mlab\ plotting functions} |
|
315 \begin{columns} |
|
316 \column{0.25\textwidth} |
|
317 \myemph{Points in 3D space} |
|
318 \column{0.5\textwidth} |
|
319 \pgfimage[width=2in]{MEDIA/m2/mlab/points3d_ex} |
|
320 \end{columns} |
|
321 |
|
322 \begin{lstlisting} |
|
323 >>> from numpy import * |
|
324 >>> t = linspace(0, 2*pi, 50) |
|
325 >>> u = cos(t)*pi |
|
326 >>> x, y, z = sin(u), cos(u), sin(t) |
|
327 \end{lstlisting} |
|
328 \emphbar{\PythonCode{>>> mlab.points3d(x, y, z)}} |
|
329 \end{frame} |
|
330 |
|
331 \begin{frame} |
|
332 \begin{columns} |
|
333 \column{0.25\textwidth} |
|
334 \myemph{Connected points in 3D space} |
|
335 \column{0.5\textwidth} |
|
336 \pgfimage[width=2.5in]{MEDIA/m2/mlab/plot3d_ex} |
|
337 \end{columns} |
|
338 \emphbar{\PythonCode{>>> mlab.plot3d(x, y, z, t)}} |
|
339 |
|
340 Plots lines between the points |
|
341 |
|
342 \end{frame} |
|
343 |
|
344 \begin{frame}[fragile] |
|
345 \begin{columns} |
|
346 \column{0.25\textwidth} |
|
347 \myemph{\Large 2D data} |
|
348 \column{0.5\textwidth} |
|
349 \pgfimage[width=2in]{MEDIA/m2/mlab/surf_ex} |
|
350 \end{columns} |
|
351 \begin{lstlisting} |
|
352 >>> x, y = mgrid[-3:3:100j,-3:3:100j] |
|
353 >>> z = sin(x*x + y*y) |
|
354 \end{lstlisting} |
|
355 |
|
356 \emphbar{\PythonCode{>>> mlab.surf(x, y, z)}} |
|
357 |
|
358 \alert{Assumes the points are rectilinear} |
|
359 |
|
360 \end{frame} |
|
361 |
|
362 \begin{frame}[fragile] |
|
363 \myemph{\Large 2D data: \texttt{mlab.mesh}} |
|
364 \vspace*{0.25in} |
|
365 |
|
366 \emphbar{\PythonCode{>>> mlab.mesh(x, y, z)}} |
|
367 |
|
368 \alert{Points needn't be regular} |
|
369 |
|
370 \vspace*{0.25in} |
|
371 \begin{lstlisting} |
|
372 >>> phi, theta = numpy.mgrid[0:pi:20j, |
|
373 ... 0:2*pi:20j] |
|
374 >>> x = sin(phi)*cos(theta) |
|
375 >>> y = sin(phi)*sin(theta) |
|
376 >>> z = cos(phi) |
|
377 >>> mlab.mesh(x, y, z, |
|
378 ... representation= |
|
379 ... 'wireframe') |
|
380 \end{lstlisting} |
|
381 |
|
382 \end{frame} |
|
383 |
|
384 \begin{frame}[fragile] |
|
385 |
|
386 \begin{columns} |
|
387 \column{0.25\textwidth} |
|
388 \myemph{\Large 3D data} |
|
389 \column{0.5\textwidth} |
|
390 \pgfimage[width=1.5in]{MEDIA/m2/mlab/contour3d}\\ |
|
391 \end{columns} |
|
392 \begin{lstlisting} |
|
393 >>> x, y, z = ogrid[-5:5:64j, |
|
394 ... -5:5:64j, |
|
395 ... -5:5:64j] |
|
396 >>> mlab.contour3d(x*x*0.5 + y*y + |
|
397 z*z*2) |
|
398 \end{lstlisting} |
|
399 \end{frame} |
|
400 |
|
401 \begin{frame}[fragile] |
|
402 |
|
403 \myemph{\Large 3D vector data: \PythonCode{mlab.quiver3d}} |
|
404 \vspace*{0.25in} |
|
405 |
|
406 \pgfimage[width=2in]{MEDIA/m2/mlab/quiver3d_ex}\\ |
|
407 |
|
408 \begin{lstlisting} |
|
409 >>> mlab.test_quiver3d() |
|
410 \end{lstlisting} |
|
411 |
|
412 \emphbar{\PythonCode{obj = mlab.quiver3d(x, y, z, u, v, w)}} |
|
413 \inctime{20} |
|
414 \end{frame} |
|
415 |
|
416 |
|
417 \subsection{Mayavi2} |
|
418 |
|
419 \begin{frame} |
|
420 \frametitle{Introduction to Mayavi} |
|
421 \begin{itemize} |
|
422 \item Most scientists not interested in details of visualization |
|
423 \item Visualization of data files with a nice UI |
|
424 \item Interactive visualization of data (think Matlab) |
|
425 \item Embedding visualizations in applications |
|
426 \item Customization |
|
427 \end{itemize} |
|
428 \pause |
|
429 \begin{block}{The Goal} |
|
430 Provide a \alert{flexible} library/app for every one of these needs! |
|
431 \end{block} |
|
432 \end{frame} |
|
433 |
|
434 \begin{frame} |
|
435 {Overview of features} |
|
436 \vspace*{-0.3in} |
|
437 \begin{center} |
|
438 \hspace*{-0.2in}\pgfimage[width=5in]{MEDIA/m2/m2_app3_3} |
|
439 \end{center} |
|
440 \end{frame} |
|
441 |
|
442 |
|
443 \begin{frame} |
|
444 \frametitle{Mayavi in applications} |
|
445 \vspace*{-0.3in} |
|
446 \begin{center} |
|
447 \hspace*{-0.2in}\pgfimage[width=4.5in]{MEDIA/m2/m2_envisage} |
|
448 \end{center} |
|
449 \end{frame} |
|
450 |
|
451 \begin{frame} |
|
452 \frametitle{Live in your dialogs} |
|
453 \vspace*{0.1in} |
|
454 \begin{center} |
|
455 \hspace*{-0.2in}\pgfimage[width=2.5in]{MEDIA/m2/mlab_tui} |
|
456 \end{center} |
|
457 \end{frame} |
|
458 |
|
459 \begin{frame} |
|
460 {Exploring the documentation} |
|
461 \begin{center} |
|
462 \pgfimage[width=4in]{MEDIA/m2/m2_ug_doc} |
|
463 \end{center} |
|
464 \end{frame} |
|
465 |
|
466 |
|
467 \begin{frame} |
|
468 \frametitle{Summary} |
|
469 \begin{itemize} |
|
470 \item \url{http://code.enthought.com/projects/mayavi} |
|
471 \item Uses VTK (\url{www.vtk.org}) |
|
472 \item BSD license |
|
473 \item Linux, win32 and Mac OS X |
|
474 \item Highly scriptable |
|
475 \item Embed in Traits UIs (wxPython and PyQt4) |
|
476 \item Envisage Plugins |
|
477 \item Debian/Ubuntu/Fedora |
|
478 \item \alert{Pythonic} |
|
479 \end{itemize} |
|
480 |
|
481 \inctime{10} |
|
482 |
|
483 \end{frame} |
|
484 |
|
485 \begin{frame} |
|
486 {Getting hands dirty!} |
|
487 |
|
488 \begin{block}{Motivational problem} |
|
489 Atmospheric data of temperature over the surface of the earth. |
|
490 Let temperature ($T$) vary linearly with height ($z$): |
|
491 \begin{center} |
|
492 $T = 288.15 - 6.5z$ |
|
493 \end{center} |
|
494 \end{block} |
|
495 \end{frame} |
|
496 |
|
497 \begin{frame}[fragile] |
|
498 \frametitle{Simple solution} |
|
499 |
|
500 \begin{lstlisting} |
|
501 lat = linspace(-89, 89, 37) |
|
502 lon = linspace(0, 360, 37) |
|
503 z = linspace(0, 100, 11) |
|
504 \end{lstlisting} |
|
505 \pause |
|
506 \begin{lstlisting} |
|
507 x, y, z = mgrid[0:360:37j,-89:89:37j, |
|
508 0:100:11j] |
|
509 t = 288.15 - 6.5*z |
|
510 mlab.contour3d(x, y, z, t) |
|
511 mlab.outline() |
|
512 mlab.colorbar() |
|
513 \end{lstlisting} |
|
514 \end{frame} |
|
515 |
|
516 \begin{frame}[fragile] |
|
517 \frametitle{Exercise: Lorenz equation} |
|
518 \begin{columns} |
|
519 \column{0.25\textwidth} |
|
520 \begin{eqnarray*} |
|
521 \frac{d x}{dt} &=& s (y-x)\\ |
|
522 \frac{d y}{d t} &=& rx -y -xz\\ |
|
523 \frac{d z}{d t} &=& xy - bz\\ |
|
524 \end{eqnarray*} |
|
525 \column{0.25\textwidth} |
|
526 Let $s=10,$ |
|
527 $r=28,$ |
|
528 $b=8./3.$ |
|
529 \end{columns} |
|
530 \structure{\Large Region of interest} |
|
531 \begin{lstlisting} |
|
532 x, y, z = mgrid[-50:50:20j,-50:50:20j, |
|
533 -10:60:20j] |
|
534 \end{lstlisting} |
|
535 \inctime{20} |
|
536 |
|
537 \end{frame} |
|
538 \begin{frame}[fragile] |
|
539 \frametitle{Solution} |
|
540 \begin{lstlisting} |
|
541 def lorenz(x,y,z,s=10.,r=28.,b=8./3.): |
|
542 u = s*(y-x) |
|
543 v = r*x-y-x*z |
|
544 w = x*y-b*z |
|
545 return u,v,w |
|
546 x,y,z = mgrid [-50:50:20j,-50:50:20j, |
|
547 -10:60:20j ] |
|
548 u,v,w = lorenz( x , y , z ) |
|
549 # Your plot here |
|
550 # |
|
551 mlab.show() |
|
552 |
|
553 \end{lstlisting} |
|
554 \end{frame} |
|
555 |
|
556 \end{document} |
|
557 |
|