191 \end{center} |
191 \end{center} |
192 \inctime{10} |
192 \inctime{10} |
193 \end{frame} |
193 \end{frame} |
194 |
194 |
195 \section{Tools at your disposal:} |
195 \section{Tools at your disposal:} |
196 |
|
197 \subsection{mlab} |
|
198 |
|
199 \begin{frame} |
|
200 {Overview} |
|
201 \Large |
|
202 \begin{itemize} |
|
203 \item Simple |
|
204 \item Convenient |
|
205 \item Full-featured |
|
206 \end{itemize} |
|
207 \end{frame} |
|
208 |
|
209 \begin{frame}[fragile] |
|
210 |
|
211 \frametitle{Getting started} |
|
212 \myemph{\Large Vanilla:} |
|
213 \begin{lstlisting}[language=bash] |
|
214 $ ipython -wthread |
|
215 \end{lstlisting} |
|
216 \myemph{\Large with Pylab:} |
|
217 \begin{lstlisting}[language=bash] |
|
218 $ ipython -pylab -wthread |
|
219 \end{lstlisting} |
|
220 \end{frame} |
|
221 |
|
222 \begin{frame}[fragile] |
|
223 \frametitle{Using mlab:} |
|
224 |
|
225 \begin{lstlisting} |
|
226 >>> from enthought.mayavi import mlab |
|
227 \end{lstlisting} |
|
228 |
|
229 \vspace*{0.5in} |
|
230 |
|
231 \myemph{\Large Try these:} |
|
232 |
|
233 \vspace*{0.25in} |
|
234 |
|
235 \begin{lstlisting} |
|
236 >>> mlab.test_<TAB> |
|
237 >>> mlab.test_contour3d() |
|
238 >>> mlab.test_contour3d?? |
|
239 \end{lstlisting} |
|
240 \end{frame} |
|
241 |
|
242 \begin{frame} |
|
243 {Exploring the view} |
|
244 \begin{columns} |
|
245 \column{0.6\textwidth} |
|
246 \pgfimage[width=3in]{MEDIA/m2/contour3d} |
|
247 \column{0.4\textwidth} |
|
248 \begin{itemize} |
|
249 \item Mouse |
|
250 \item Keyboard |
|
251 \item Toolbar |
|
252 \item Mayavi icon(wait for it...) \pgfimage[width=0.2in]{MEDIA/m2/m2_icon} |
|
253 \end{itemize} |
|
254 \end{columns} |
|
255 \end{frame} |
|
256 |
|
257 \begin{frame}[fragile] |
|
258 \frametitle{\mlab\ plotting functions} |
|
259 \begin{columns} |
|
260 \column{0.25\textwidth} |
|
261 \myemph{\Large 0D data} |
|
262 \column{0.5\textwidth} |
|
263 \pgfimage[width=2in]{MEDIA/m2/mlab/points3d_ex} |
|
264 \end{columns} |
|
265 |
|
266 \begin{lstlisting} |
|
267 >>> from numpy import * |
|
268 >>> t = linspace(0, 2*pi, 50) |
|
269 >>> u = cos(t)*pi |
|
270 >>> x, y, z = sin(u), cos(u), sin(t) |
|
271 \end{lstlisting} |
|
272 \emphbar{\PythonCode{>>> mlab.points3d(x, y, z)}} |
|
273 \end{frame} |
|
274 |
|
275 \begin{frame} |
|
276 \begin{columns} |
|
277 \column{0.25\textwidth} |
|
278 \myemph{\Large 1D data} |
|
279 \column{0.5\textwidth} |
|
280 \pgfimage[width=2.5in]{MEDIA/m2/mlab/plot3d_ex} |
|
281 \end{columns} |
|
282 \emphbar{\PythonCode{>>> mlab.plot3d(x, y, z, t)}} |
|
283 |
|
284 Plots lines between the points |
|
285 |
|
286 \end{frame} |
|
287 |
|
288 \begin{frame}[fragile] |
|
289 \begin{columns} |
|
290 \column{0.25\textwidth} |
|
291 \myemph{\Large 2D data} |
|
292 \column{0.5\textwidth} |
|
293 \pgfimage[width=2in]{MEDIA/m2/mlab/surf_ex} |
|
294 \end{columns} |
|
295 \begin{lstlisting} |
|
296 >>> x = mgrid[-3:3:100j,-3:3:100j] |
|
297 >>> z = sin(x*x + y*y) |
|
298 \end{lstlisting} |
|
299 |
|
300 \emphbar{\PythonCode{>>> mlab.surf(x, y, z)}} |
|
301 |
|
302 \alert{Assumes the points are rectilinear} |
|
303 |
|
304 \end{frame} |
|
305 |
|
306 \begin{frame}[fragile] |
|
307 \myemph{\Large 2D data: \texttt{mlab.mesh}} |
|
308 \vspace*{0.25in} |
|
309 |
|
310 \emphbar{\PythonCode{>>> mlab.mesh(x, y, z)}} |
|
311 |
|
312 \alert{Points needn't be regular} |
|
313 |
|
314 \vspace*{0.25in} |
|
315 \begin{lstlisting} |
|
316 >>> phi, theta = numpy.mgrid[0:pi:20j, |
|
317 ... 0:2*pi:20j] |
|
318 >>> x = sin(phi)*cos(theta) |
|
319 >>> y = sin(phi)*sin(theta) |
|
320 >>> z = cos(phi) |
|
321 >>> mlab.mesh(x, y, z, |
|
322 ... representation='wireframe') |
|
323 \end{lstlisting} |
|
324 |
|
325 \end{frame} |
|
326 |
|
327 \begin{frame}[fragile] |
|
328 |
|
329 \begin{columns} |
|
330 \column{0.25\textwidth} |
|
331 \myemph{\Large 3D data} |
|
332 \column{0.5\textwidth} |
|
333 \pgfimage[width=1.5in]{MEDIA/m2/mlab/contour3d}\\ |
|
334 \end{columns} |
|
335 \begin{lstlisting} |
|
336 >>> x, y, z = ogrid[-5:5:64j, |
|
337 ... -5:5:64j, |
|
338 ... -5:5:64j] |
|
339 >>> mlab.contour3d(x*x*0.5 + y*y + |
|
340 z*z*2) |
|
341 \end{lstlisting} |
|
342 \end{frame} |
|
343 |
|
344 \begin{frame}[fragile] |
|
345 |
|
346 \myemph{\Large 3D vector data: \PythonCode{mlab.quiver3d}} |
|
347 \vspace*{0.25in} |
|
348 |
|
349 \pgfimage[width=2in]{MEDIA/m2/mlab/quiver3d_ex}\\ |
|
350 |
|
351 \begin{lstlisting} |
|
352 >>> mlab.test_quiver3d() |
|
353 \end{lstlisting} |
|
354 |
|
355 \emphbar{\PythonCode{obj = mlab.quiver3d(x, y, z, u, v, w)}} |
|
356 \inctime{20} |
|
357 \end{frame} |
|
358 |
196 |
359 \subsection{Mayavi2.0} |
197 \subsection{Mayavi2.0} |
360 |
198 |
361 \begin{frame} |
199 \begin{frame} |
362 \frametitle{Introduction to Mayavi} |
200 \frametitle{Introduction to Mayavi} |
414 |
252 |
415 \inctime{10} |
253 \inctime{10} |
416 |
254 |
417 \end{frame} |
255 \end{frame} |
418 |
256 |
|
257 \subsection{mlab} |
|
258 |
|
259 \begin{frame} |
|
260 {Overview} |
|
261 \Large |
|
262 \begin{itemize} |
|
263 \item Simple |
|
264 \item Convenient |
|
265 \item Full-featured |
|
266 \end{itemize} |
|
267 \end{frame} |
|
268 |
|
269 \begin{frame}[fragile] |
|
270 |
|
271 \frametitle{Getting started} |
|
272 \myemph{\Large Vanilla:} |
|
273 \begin{lstlisting}[language=bash] |
|
274 $ ipython -wthread |
|
275 \end{lstlisting} |
|
276 \myemph{\Large with Pylab:} |
|
277 \begin{lstlisting}[language=bash] |
|
278 $ ipython -pylab -wthread |
|
279 \end{lstlisting} |
|
280 \end{frame} |
|
281 |
|
282 \begin{frame}[fragile] |
|
283 \frametitle{Using mlab:} |
|
284 |
|
285 \begin{lstlisting} |
|
286 >>> from enthought.mayavi import mlab |
|
287 \end{lstlisting} |
|
288 |
|
289 \vspace*{0.5in} |
|
290 |
|
291 \myemph{\Large Try these:} |
|
292 |
|
293 \vspace*{0.25in} |
|
294 |
|
295 \begin{lstlisting} |
|
296 >>> mlab.test_<TAB> |
|
297 >>> mlab.test_contour3d() |
|
298 >>> mlab.test_contour3d?? |
|
299 \end{lstlisting} |
|
300 \end{frame} |
|
301 |
|
302 \begin{frame} |
|
303 {Exploring the view} |
|
304 \begin{columns} |
|
305 \column{0.6\textwidth} |
|
306 \pgfimage[width=3in]{MEDIA/m2/contour3d} |
|
307 \column{0.4\textwidth} |
|
308 \begin{itemize} |
|
309 \item Mouse |
|
310 \item Keyboard |
|
311 \item Toolbar |
|
312 \item Mayavi icon\pgfimage[width=0.2in]{MEDIA/m2/m2_icon} |
|
313 \end{itemize} |
|
314 \end{columns} |
|
315 \end{frame} |
|
316 |
|
317 \begin{frame}[fragile] |
|
318 \frametitle{\mlab\ plotting functions} |
|
319 \begin{columns} |
|
320 \column{0.25\textwidth} |
|
321 \myemph{\Large 0D data} |
|
322 \column{0.5\textwidth} |
|
323 \pgfimage[width=2in]{MEDIA/m2/mlab/points3d_ex} |
|
324 \end{columns} |
|
325 |
|
326 \begin{lstlisting} |
|
327 >>> from numpy import * |
|
328 >>> t = linspace(0, 2*pi, 50) |
|
329 >>> u = cos(t)*pi |
|
330 >>> x, y, z = sin(u), cos(u), sin(t) |
|
331 \end{lstlisting} |
|
332 \emphbar{\PythonCode{>>> mlab.points3d(x, y, z)}} |
|
333 \end{frame} |
|
334 |
|
335 \begin{frame} |
|
336 \begin{columns} |
|
337 \column{0.25\textwidth} |
|
338 \myemph{\Large 1D data} |
|
339 \column{0.5\textwidth} |
|
340 \pgfimage[width=2.5in]{MEDIA/m2/mlab/plot3d_ex} |
|
341 \end{columns} |
|
342 \emphbar{\PythonCode{>>> mlab.plot3d(x, y, z, t)}} |
|
343 |
|
344 Plots lines between the points |
|
345 |
|
346 \end{frame} |
|
347 |
|
348 \begin{frame}[fragile] |
|
349 \begin{columns} |
|
350 \column{0.25\textwidth} |
|
351 \myemph{\Large 2D data} |
|
352 \column{0.5\textwidth} |
|
353 \pgfimage[width=2in]{MEDIA/m2/mlab/surf_ex} |
|
354 \end{columns} |
|
355 \begin{lstlisting} |
|
356 >>> x = mgrid[-3:3:100j,-3:3:100j] |
|
357 >>> z = sin(x*x + y*y) |
|
358 \end{lstlisting} |
|
359 |
|
360 \emphbar{\PythonCode{>>> mlab.surf(x, y, z)}} |
|
361 |
|
362 \alert{Assumes the points are rectilinear} |
|
363 |
|
364 \end{frame} |
|
365 |
|
366 \begin{frame}[fragile] |
|
367 \myemph{\Large 2D data: \texttt{mlab.mesh}} |
|
368 \vspace*{0.25in} |
|
369 |
|
370 \emphbar{\PythonCode{>>> mlab.mesh(x, y, z)}} |
|
371 |
|
372 \alert{Points needn't be regular} |
|
373 |
|
374 \vspace*{0.25in} |
|
375 \begin{lstlisting} |
|
376 >>> phi, theta = numpy.mgrid[0:pi:20j, |
|
377 ... 0:2*pi:20j] |
|
378 >>> x = sin(phi)*cos(theta) |
|
379 >>> y = sin(phi)*sin(theta) |
|
380 >>> z = cos(phi) |
|
381 >>> mlab.mesh(x, y, z, |
|
382 ... representation= |
|
383 ... 'wireframe') |
|
384 \end{lstlisting} |
|
385 |
|
386 \end{frame} |
|
387 |
|
388 \begin{frame}[fragile] |
|
389 |
|
390 \begin{columns} |
|
391 \column{0.25\textwidth} |
|
392 \myemph{\Large 3D data} |
|
393 \column{0.5\textwidth} |
|
394 \pgfimage[width=1.5in]{MEDIA/m2/mlab/contour3d}\\ |
|
395 \end{columns} |
|
396 \begin{lstlisting} |
|
397 >>> x, y, z = ogrid[-5:5:64j, |
|
398 ... -5:5:64j, |
|
399 ... -5:5:64j] |
|
400 >>> mlab.contour3d(x*x*0.5 + y*y + |
|
401 z*z*2) |
|
402 \end{lstlisting} |
|
403 \end{frame} |
|
404 |
|
405 \begin{frame}[fragile] |
|
406 |
|
407 \myemph{\Large 3D vector data: \PythonCode{mlab.quiver3d}} |
|
408 \vspace*{0.25in} |
|
409 |
|
410 \pgfimage[width=2in]{MEDIA/m2/mlab/quiver3d_ex}\\ |
|
411 |
|
412 \begin{lstlisting} |
|
413 >>> mlab.test_quiver3d() |
|
414 \end{lstlisting} |
|
415 |
|
416 \emphbar{\PythonCode{obj = mlab.quiver3d(x, y, z, u, v, w)}} |
|
417 \inctime{20} |
|
418 \end{frame} |
|
419 |
419 \begin{frame} |
420 \begin{frame} |
420 {Getting hands dirty!} |
421 {Getting hands dirty!} |
421 |
422 |
422 \begin{block}{Motivational problem} |
423 \begin{block}{Motivational problem} |
423 Atmospheric data of temperature over the surface of the earth. |
424 Atmospheric data of temperature over the surface of the earth. |
466 x, y, z = mgrid[-50:50:20j,-50:50:20j, |
467 x, y, z = mgrid[-50:50:20j,-50:50:20j, |
467 -10:60:20j] |
468 -10:60:20j] |
468 \end{lstlisting} |
469 \end{lstlisting} |
469 \inctime{20} |
470 \inctime{20} |
470 \end{frame} |
471 \end{frame} |
471 |
|
472 \section{Test Driven Approach} |
|
473 |
|
474 \begin{frame} |
|
475 \frametitle{Testing code with \typ{nosetests}} |
|
476 |
|
477 \begin{itemize} |
|
478 \item Writing tests is really simple! |
|
479 |
|
480 \item Using nose. |
|
481 |
|
482 \item Example! |
|
483 \end{itemize} |
|
484 \end{frame} |
|
485 |
|
486 \begin{frame} |
|
487 \frametitle{Need of Testing!} |
|
488 |
|
489 \begin{itemize} |
|
490 \item Quality |
|
491 |
|
492 \item Regression |
|
493 |
|
494 \item Documentation |
|
495 \end{itemize} |
|
496 \end{frame} |
|
497 |
|
498 \begin{frame}[fragile] |
|
499 \frametitle{Nosetest} |
|
500 \begin{lstlisting} |
|
501 def gcd(a, b): |
|
502 """Returns gcd of a and b, |
|
503 handles only positive numbers.""" |
|
504 if a%b == 0: return b |
|
505 return gcd(b, a%b) |
|
506 def lcm(a, b): |
|
507 return a*b/gcd(a, b) |
|
508 |
|
509 if __name__ == '__main__': |
|
510 import nose |
|
511 nose.main() |
|
512 \end{lstlisting} |
|
513 \inctime{10} |
|
514 \end{frame} |
|
515 |
|
516 \begin{frame}[fragile] |
|
517 \frametitle{Example} |
|
518 \begin{block}{Problem Statement:} |
|
519 Write a function to check whether a given input |
|
520 string is a palindrome. |
|
521 \end{block} |
|
522 \end{frame} |
|
523 |
|
524 \begin{frame}[fragile] |
|
525 \frametitle{Function: code.py} |
|
526 \begin{lstlisting} |
|
527 def is_palindrome(input_str): |
|
528 return input_str == input_str[::-1] |
|
529 \end{lstlisting} |
|
530 \end{frame} |
|
531 |
|
532 \begin{frame}[fragile] |
|
533 \frametitle{Test for the palindrome: code.py} |
|
534 \begin{lstlisting} |
|
535 from code import is_palindrome |
|
536 def test_function_normal_words(): |
|
537 input = "noon" |
|
538 assert is_palindrome(input) == True |
|
539 \end{lstlisting} |
|
540 \end{frame} |
|
541 |
|
542 \begin{frame}[fragile] |
|
543 \frametitle{Running the tests.} |
|
544 \begin{lstlisting} |
|
545 $ nosetests test.py |
|
546 . |
|
547 ---------------------------------------------- |
|
548 Ran 1 test in 0.001s |
|
549 |
|
550 OK |
|
551 \end{lstlisting} |
|
552 \end{frame} |
|
553 |
|
554 \begin{frame}[fragile] |
|
555 \frametitle{Exercise: Including new tests.} |
|
556 \begin{lstlisting} |
|
557 def test_function_ignore_cases_words(): |
|
558 input = "Noon" |
|
559 assert is_palindrome(input) == True |
|
560 \end{lstlisting} |
|
561 Check |
|
562 |
|
563 \PythonCode{$ nosetests test.py} |
|
564 |
|
565 Tweak the code to pass this test. |
|
566 \end{frame} |
|
567 |
|
568 \begin{frame}[fragile] |
|
569 \frametitle{Lets write some test!} |
|
570 \begin{lstlisting} |
|
571 #for form of equation y=mx+c |
|
572 #given m and c for two equation, |
|
573 #finding the intersection point. |
|
574 def intersect(m1,c1,m2,c2): |
|
575 x = (c2-c1)/(m1-m2) |
|
576 y = m1*x+c1 |
|
577 return (x,y) |
|
578 \end{lstlisting} |
|
579 |
|
580 Create a simple test for this |
|
581 |
|
582 function which will make it fail. |
|
583 |
|
584 \inctime{15} |
|
585 \end{frame} |
|
586 |
|
587 \section{Summary} |
|
588 \begin{frame}{So we have covered:} |
|
589 \begin{itemize} |
|
590 \item Need for vizualization. |
|
591 \item Tools available. |
|
592 \item How to follow Test Driven Approach. |
|
593 \end{itemize} |
|
594 \end{frame} |
|
595 \begin{frame} |
|
596 \begin{center} |
|
597 \Huge |
|
598 Thank you! |
|
599 \end{center} |
|
600 \end{frame} |
|
601 |
472 |
602 \end{document} |
473 \end{document} |
603 |
474 |