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[]{11, October 2009} |
|
104 %\date[] % (optional) |
|
105 |
|
106 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
|
107 |
|
108 %\pgfdeclareimage[height=0.75cm]{iitblogo}{iitblogo} |
|
109 %\logo{\pgfuseimage{iitblogo}} |
|
110 |
|
111 \AtBeginSection[] |
|
112 { |
|
113 \begin{frame}<beamer> |
|
114 \frametitle{Outline} |
|
115 \tableofcontents[currentsection,currentsubsection] |
|
116 \end{frame} |
|
117 } |
|
118 |
|
119 %% Delete this, if you do not want the table of contents to pop up at |
|
120 %% the beginning of each subsection: |
|
121 \AtBeginSubsection[] |
|
122 { |
|
123 \begin{frame}<beamer> |
|
124 \frametitle{Outline} |
|
125 \tableofcontents[currentsection,currentsubsection] |
|
126 \end{frame} |
|
127 } |
|
128 |
|
129 \AtBeginSection[] |
|
130 { |
|
131 \begin{frame}<beamer> |
|
132 \frametitle{Outline} |
|
133 \tableofcontents[currentsection,currentsubsection] |
|
134 \end{frame} |
|
135 } |
|
136 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
|
137 % DOCUMENT STARTS |
|
138 \begin{document} |
|
139 |
|
140 \begin{frame} |
|
141 \maketitle |
|
142 \end{frame} |
|
143 |
|
144 \begin{frame} |
|
145 \frametitle{Outline} |
|
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{Mayavi2} |
|
196 |
|
197 \begin{frame} |
|
198 \frametitle{Introduction to Mayavi} |
|
199 \begin{itemize} |
|
200 \item Most scientists not interested in details of visualization |
|
201 \item Visualization of data files with a nice UI |
|
202 \item Interactive visualization of data (think Matlab) |
|
203 \item Embedding visualizations in applications |
|
204 \item Customization |
|
205 \end{itemize} |
|
206 \pause |
|
207 \begin{block}{The Goal} |
|
208 Provide a \alert{flexible} library/app for every one of these needs! |
|
209 \end{block} |
|
210 \end{frame} |
|
211 |
|
212 \begin{frame} |
|
213 {Overview of features} |
|
214 \vspace*{-0.3in} |
|
215 \begin{center} |
|
216 \hspace*{-0.2in}\pgfimage[width=5in]{MEDIA/m2/m2_app3_3} |
|
217 \end{center} |
|
218 \end{frame} |
|
219 |
|
220 |
|
221 \begin{frame} |
|
222 \frametitle{Mayavi in applications} |
|
223 \vspace*{-0.3in} |
|
224 \begin{center} |
|
225 \hspace*{-0.2in}\pgfimage[width=4.5in]{MEDIA/m2/m2_envisage} |
|
226 \end{center} |
|
227 \end{frame} |
|
228 |
|
229 \begin{frame} |
|
230 \frametitle{Live in your dialogs} |
|
231 \vspace*{0.1in} |
|
232 \begin{center} |
|
233 \hspace*{-0.2in}\pgfimage[width=2.5in]{MEDIA/m2/mlab_tui} |
|
234 \end{center} |
|
235 \end{frame} |
|
236 |
|
237 \begin{frame} |
|
238 {Exploring the documentation} |
|
239 \begin{center} |
|
240 \pgfimage[width=4in]{MEDIA/m2/m2_ug_doc} |
|
241 \end{center} |
|
242 \end{frame} |
|
243 |
|
244 |
|
245 \begin{frame} |
|
246 \frametitle{Summary} |
|
247 \begin{itemize} |
|
248 \item \url{http://code.enthought.com/projects/mayavi} |
|
249 \item Uses VTK (\url{www.vtk.org}) |
|
250 \item BSD license |
|
251 \item Linux, win32 and Mac OS X |
|
252 \item Highly scriptable |
|
253 \item Embed in Traits UIs (wxPython and PyQt4) |
|
254 \item Envisage Plugins |
|
255 \item Debian/Ubuntu/Fedora |
|
256 \item \alert{Pythonic} |
|
257 \end{itemize} |
|
258 |
|
259 \inctime{10} |
|
260 |
|
261 \end{frame} |
|
262 |
|
263 \subsection{mlab} |
|
264 |
|
265 \begin{frame} |
|
266 {Overview} |
|
267 \Large |
|
268 \begin{itemize} |
|
269 \item Simple |
|
270 \item Convenient |
|
271 \item Full-featured |
|
272 \end{itemize} |
|
273 \end{frame} |
|
274 |
|
275 \begin{frame}[fragile] |
|
276 |
|
277 \frametitle{Getting started} |
|
278 \myemph{\Large Vanilla:} |
|
279 \begin{lstlisting}[language=bash] |
|
280 $ ipython -wthread |
|
281 \end{lstlisting} |
|
282 \myemph{\Large with Pylab:} |
|
283 \begin{lstlisting}[language=bash] |
|
284 $ ipython -pylab -wthread |
|
285 \end{lstlisting} |
|
286 \end{frame} |
|
287 |
|
288 \begin{frame}[fragile] |
|
289 \frametitle{Using mlab} |
|
290 |
|
291 \begin{lstlisting} |
|
292 >>> from enthought.mayavi import mlab |
|
293 \end{lstlisting} |
|
294 |
|
295 \vspace*{0.5in} |
|
296 |
|
297 \myemph{\Large Try these} |
|
298 |
|
299 \vspace*{0.25in} |
|
300 |
|
301 \begin{lstlisting} |
|
302 >>> mlab.test_<TAB> |
|
303 >>> mlab.test_contour3d() |
|
304 >>> mlab.test_contour3d?? |
|
305 \end{lstlisting} |
|
306 \end{frame} |
|
307 |
|
308 \begin{frame} |
|
309 {Exploring the view} |
|
310 \begin{columns} |
|
311 \column{0.6\textwidth} |
|
312 \pgfimage[width=3in]{MEDIA/m2/contour3d} |
|
313 \column{0.4\textwidth} |
|
314 \begin{itemize} |
|
315 \item Mouse |
|
316 \item Keyboard |
|
317 \item Toolbar |
|
318 \item Mayavi icon\pgfimage[width=0.2in]{MEDIA/m2/m2_icon} |
|
319 \end{itemize} |
|
320 \end{columns} |
|
321 \end{frame} |
|
322 |
|
323 \begin{frame}[fragile] |
|
324 \frametitle{\mlab\ plotting functions} |
|
325 \begin{columns} |
|
326 \column{0.25\textwidth} |
|
327 \myemph{\Large 0D data} |
|
328 \column{0.5\textwidth} |
|
329 \pgfimage[width=2in]{MEDIA/m2/mlab/points3d_ex} |
|
330 \end{columns} |
|
331 |
|
332 \begin{lstlisting} |
|
333 >>> from numpy import * |
|
334 >>> t = linspace(0, 2*pi, 50) |
|
335 >>> u = cos(t)*pi |
|
336 >>> x, y, z = sin(u), cos(u), sin(t) |
|
337 \end{lstlisting} |
|
338 \emphbar{\PythonCode{>>> mlab.points3d(x, y, z)}} |
|
339 \end{frame} |
|
340 |
|
341 \begin{frame} |
|
342 \begin{columns} |
|
343 \column{0.25\textwidth} |
|
344 \myemph{\Large 1D data} |
|
345 \column{0.5\textwidth} |
|
346 \pgfimage[width=2.5in]{MEDIA/m2/mlab/plot3d_ex} |
|
347 \end{columns} |
|
348 \emphbar{\PythonCode{>>> mlab.plot3d(x, y, z, t)}} |
|
349 |
|
350 Plots lines between the points |
|
351 |
|
352 \end{frame} |
|
353 |
|
354 \begin{frame}[fragile] |
|
355 \begin{columns} |
|
356 \column{0.25\textwidth} |
|
357 \myemph{\Large 2D data} |
|
358 \column{0.5\textwidth} |
|
359 \pgfimage[width=2in]{MEDIA/m2/mlab/surf_ex} |
|
360 \end{columns} |
|
361 \begin{lstlisting} |
|
362 >>> x = mgrid[-3:3:100j,-3:3:100j] |
|
363 >>> z = sin(x*x + y*y) |
|
364 \end{lstlisting} |
|
365 |
|
366 \emphbar{\PythonCode{>>> mlab.surf(x, y, z)}} |
|
367 |
|
368 \alert{Assumes the points are rectilinear} |
|
369 |
|
370 \end{frame} |
|
371 |
|
372 \begin{frame}[fragile] |
|
373 \myemph{\Large 2D data: \texttt{mlab.mesh}} |
|
374 \vspace*{0.25in} |
|
375 |
|
376 \emphbar{\PythonCode{>>> mlab.mesh(x, y, z)}} |
|
377 |
|
378 \alert{Points needn't be regular} |
|
379 |
|
380 \vspace*{0.25in} |
|
381 \begin{lstlisting} |
|
382 >>> phi, theta = numpy.mgrid[0:pi:20j, |
|
383 ... 0:2*pi:20j] |
|
384 >>> x = sin(phi)*cos(theta) |
|
385 >>> y = sin(phi)*sin(theta) |
|
386 >>> z = cos(phi) |
|
387 >>> mlab.mesh(x, y, z, |
|
388 ... representation= |
|
389 ... 'wireframe') |
|
390 \end{lstlisting} |
|
391 |
|
392 \end{frame} |
|
393 |
|
394 \begin{frame}[fragile] |
|
395 |
|
396 \begin{columns} |
|
397 \column{0.25\textwidth} |
|
398 \myemph{\Large 3D data} |
|
399 \column{0.5\textwidth} |
|
400 \pgfimage[width=1.5in]{MEDIA/m2/mlab/contour3d}\\ |
|
401 \end{columns} |
|
402 \begin{lstlisting} |
|
403 >>> x, y, z = ogrid[-5:5:64j, |
|
404 ... -5:5:64j, |
|
405 ... -5:5:64j] |
|
406 >>> mlab.contour3d(x*x*0.5 + y*y + |
|
407 z*z*2) |
|
408 \end{lstlisting} |
|
409 \end{frame} |
|
410 |
|
411 \begin{frame}[fragile] |
|
412 |
|
413 \myemph{\Large 3D vector data: \PythonCode{mlab.quiver3d}} |
|
414 \vspace*{0.25in} |
|
415 |
|
416 \pgfimage[width=2in]{MEDIA/m2/mlab/quiver3d_ex}\\ |
|
417 |
|
418 \begin{lstlisting} |
|
419 >>> mlab.test_quiver3d() |
|
420 \end{lstlisting} |
|
421 |
|
422 \emphbar{\PythonCode{obj = mlab.quiver3d(x, y, z, u, v, w)}} |
|
423 \inctime{20} |
|
424 \end{frame} |
|
425 |
|
426 \begin{frame} |
|
427 {Getting hands dirty!} |
|
428 |
|
429 \begin{block}{Motivational problem} |
|
430 Atmospheric data of temperature over the surface of the earth. |
|
431 Let temperature ($T$) vary linearly with height ($z$): |
|
432 \begin{center} |
|
433 $T = 288.15 - 6.5z$ |
|
434 \end{center} |
|
435 \end{block} |
|
436 \end{frame} |
|
437 |
|
438 \begin{frame}[fragile] |
|
439 \frametitle{Simple solution} |
|
440 |
|
441 \begin{lstlisting} |
|
442 lat = linspace(-89, 89, 37) |
|
443 lon = linspace(0, 360, 37) |
|
444 z = linspace(0, 100, 11) |
|
445 \end{lstlisting} |
|
446 \pause |
|
447 \begin{lstlisting} |
|
448 x, y, z = mgrid[0:360:37j,-89:89:37j, |
|
449 0:100:11j] |
|
450 t = 288.15 - 6.5*z |
|
451 mlab.contour3d(x, y, z, t) |
|
452 mlab.outline() |
|
453 mlab.colorbar() |
|
454 \end{lstlisting} |
|
455 \end{frame} |
|
456 |
|
457 \begin{frame}[fragile] |
|
458 \frametitle{Exercise: Lorenz equation} |
|
459 \begin{columns} |
|
460 \column{0.25\textwidth} |
|
461 \begin{eqnarray*} |
|
462 \frac{d x}{dt} &=& s (y-x)\\ |
|
463 \frac{d y}{d t} &=& rx -y -xz\\ |
|
464 \frac{d z}{d t} &=& xy - bz\\ |
|
465 \end{eqnarray*} |
|
466 \column{0.25\textwidth} |
|
467 Let $s=10,$ |
|
468 $r=28,$ |
|
469 $b=8./3.$ |
|
470 \end{columns} |
|
471 \structure{\Large Region of interest} |
|
472 \begin{lstlisting} |
|
473 x, y, z = mgrid[-50:50:20j,-50:50:20j, |
|
474 -10:60:20j] |
|
475 \end{lstlisting} |
|
476 \inctime{20} |
|
477 |
|
478 \end{frame} |
|
479 \begin{frame}[fragile] |
|
480 \frametitle{Solution} |
|
481 \begin{lstlisting} |
|
482 def lorenz(x,y,z,s=10.,r=28.,b=8./3.): |
|
483 u = s*(y-x) |
|
484 v = r*x-y-x*z |
|
485 w = x*y-b*z |
|
486 return u,v,w |
|
487 x,y,z = mgrid [-50:50:20j,-50:50:20j, |
|
488 -10:60:20j ] |
|
489 u,v,w = lorenz( x , y , z ) |
|
490 # Your plot here |
|
491 # |
|
492 mlab.show() |
|
493 |
|
494 \end{lstlisting} |
|
495 \end{frame} |
|
496 |
|
497 \end{document} |
|
498 |
|