day1/session1.tex
changeset 379 682b6f66fe11
parent 378 2299700a8b97
child 381 b797cd67982b
equal deleted inserted replaced
378:2299700a8b97 379:682b6f66fe11
   152 \section{Checklist}
   152 \section{Checklist}
   153 \begin{frame}
   153 \begin{frame}
   154 \frametitle{Checklist}
   154 \frametitle{Checklist}
   155   \begin{enumerate}
   155   \begin{enumerate}
   156     \item IPython
   156     \item IPython
   157     \item Editor
   157     \item Editor - we recommend \alert{scite}
   158     \item Data files: 
   158     \item Data files: 
   159       \begin{itemize}
   159       \begin{itemize}
   160       \item \typ{sslc1.txt}
   160       \item \typ{sslc/sslc1.txt}
   161       \item \typ{pendulum.txt}
   161       \item \typ{pendulum/pendulum.txt}
   162       \item \typ{points.txt}
   162       \item \typ{motion-plot/pos.txt}
   163       \item \typ{pos.txt}
   163       \item \typ{word-freq/holmes.txt}
   164       \item \typ{holmes.txt}
   164       \item \typ{anagrams/anag.txt}
   165       \end{itemize}
   165       \end{itemize}
   166     \item Python scripts: 
   166     \item Python scripts: 
   167       \begin{itemize}
   167       \begin{itemize}
   168       \item \typ{sslc_allreg.py}
   168       \item \typ{sslc/sslc_allreg.py}
   169       \item \typ{sslc_science.py}
   169       \item \typ{sslc/sslc_science.py}
   170       \end{itemize}
   170       \end{itemize}
   171     \item Images
   171     \item Images
   172       \begin{itemize}
   172       \begin{itemize}
   173       \item \typ{lena.png}
   173       \item \typ{lena/lena.png}
   174       \item \typ{smoothing.gif}
   174       \item \typ{smoothing/smoothing.gif}
   175       \end{itemize}
   175       \end{itemize}
   176   \end{enumerate}
   176   \end{enumerate}
   177 \end{frame}
   177 \end{frame}
   178 
   178 
   179 \begin{frame}
   179 \begin{frame}
   208 Exiting
   208 Exiting
   209 \begin{lstlisting}     
   209 \begin{lstlisting}     
   210   >>> ^D(Ctrl-D)
   210   >>> ^D(Ctrl-D)
   211   $
   211   $
   212 \end{lstlisting} %$
   212 \end{lstlisting} %$
   213 \alert{Note the change in the prompt}\\
       
   214 \alert{IPython provides many additional features}\\
       
   215 \end{frame}
   213 \end{frame}
   216 
   214 
   217 \section{Starting up Ipython}
   215 \section{Starting up Ipython}
   218 \begin{frame}[fragile]
   216 \begin{frame}[fragile]
   219 \frametitle{Starting up \ldots}
   217 \frametitle{Starting up \ldots}
   229 Exiting
   227 Exiting
   230 \begin{lstlisting}
   228 \begin{lstlisting}
   231   In []: ^D(Ctrl-D)
   229   In []: ^D(Ctrl-D)
   232   Do you really want to exit([y]/n)? y
   230   Do you really want to exit([y]/n)? y
   233 \end{lstlisting}
   231 \end{lstlisting}
   234 \alert{IPython is an improved interpreter}\\
   232 An alternative to IPython is bpython
   235 \alert{Recommended for use in Scientific Computing work}\\
       
   236 \end{frame}
   233 \end{frame}
   237 
   234 
   238 \section{Ipython with magic}
   235 \section{Ipython with magic}
   239 \begin{frame}[fragile]
   236 \begin{frame}[fragile]
   240 \frametitle{Let the magic begin \ldots}
   237 \frametitle{Let the magic begin \ldots}
       
   238 \begin{itemize}
       
   239 \item \alert{IPython is an improved interpreter}\\
       
   240 \item \alert{Recommended for Scientific and Computing work}\\
       
   241 \end{itemize}
   241 \begin{block}{}
   242 \begin{block}{}
   242 \begin{lstlisting}
   243 \begin{lstlisting}
   243   $ ipython -pylab  
   244   $ ipython -pylab  
   244 \end{lstlisting} %$
   245 \end{lstlisting} %$
   245 \end{block}
   246 \end{block}
   395 \begin{lstlisting}
   396 \begin{lstlisting}
   396 In []: savefig('sin.png')
   397 In []: savefig('sin.png')
   397 
   398 
   398 In []: close()
   399 In []: close()
   399 \end{lstlisting}
   400 \end{lstlisting}
       
   401 Supported formats to store images:
       
   402 \begin{itemize}
       
   403 \item png
       
   404 \item eps - Easy to embed in Latex files
       
   405 \item emf
       
   406 \item pdf
       
   407 \item ps
       
   408 \item raw
       
   409 \item rgba
       
   410 \item svg
       
   411 \end{itemize}
   400 \end{frame}
   412 \end{frame}
   401 
   413 
   402 \section{Multiple plots}
   414 \section{Multiple plots}
   403 \begin{frame}[fragile]
   415 \begin{frame}[fragile]
   404 \frametitle{Overlaid Plots}
   416 \frametitle{Overlaid Plots}
   457   \includegraphics[height=2in, interpolate=true]{data/annotate}  
   469   \includegraphics[height=2in, interpolate=true]{data/annotate}  
   458 \end{center}
   470 \end{center}
   459 \end{frame}
   471 \end{frame}
   460 
   472 
   461 \begin{frame}[fragile]
   473 \begin{frame}[fragile]
   462 \frametitle{Axes lengths}
   474 \frametitle{Getting axes lengths}
   463 \emphbar{Get the axes limits}
       
   464   \begin{lstlisting}
   475   \begin{lstlisting}
   465 In []: xmin, xmax = xlim() 
   476 In []: orig_xmin, orig_xmax = xlim() 
   466 In []: ymin, ymax = ylim() 
   477 In []: orig_ymin, orig_ymax = ylim() 
   467   \end{lstlisting}
   478   \end{lstlisting}
   468 \emphbar{Set the axes limits}
   479 \end{frame}
       
   480 
       
   481 \begin{frame}[fragile]
       
   482   \frametitle{Set the axes limits}
   469   \begin{lstlisting}
   483   \begin{lstlisting}
   470 In []: xlim(xmin, 2*pi) 
   484 In []: up_xmin = orig_xmin
   471 In []: ylim(ymin-0.2, ymax+0.2) 
   485 In []: up_xmax = 2*pi
       
   486 In []: up_ymin = ymin-0.2
       
   487 In []: up_ymax = ymax+0.2
       
   488 
       
   489 In []: xlim(up_xmin, up_xmax)
       
   490 In []: ylim(up_ymin, up_ymax)
   472   \end{lstlisting}
   491   \end{lstlisting}
   473 \end{frame}
   492 \end{frame}
   474 
   493 
   475 \begin{frame}[fragile]
   494 \begin{frame}[fragile]
   476 \frametitle{Review Problem}
   495 \frametitle{Review Problem}
   514 In []: ylim(-5*pi, 5*pi)
   533 In []: ylim(-5*pi, 5*pi)
   515 \end{lstlisting}
   534 \end{lstlisting}
   516 \end{frame}
   535 \end{frame}
   517 
   536 
   518 \begin{frame}[fragile]
   537 \begin{frame}[fragile]
   519 \frametitle{Saving Commands}
   538 \frametitle{Command History}
   520 Save commands of review problem into file
   539 Use the \typ{\%hist} \alert{magic} command of IPython 
   521 \begin{itemize}
       
   522 \item Use \typ{\%hist} command of IPython 
       
   523 \item Identify the required line numbers
       
   524 \item Then, use \typ{\%save} command of IPython 
       
   525 \end{itemize}
       
   526 \typ{In []: \%hist}\\
   540 \typ{In []: \%hist}\\
   527 \typ{In []: \%save four_plot.py} \alert{\typ{16 18-27}} 
   541 This displays all the commands typed in so far aka Command History.
   528 \begin{block}{Careful about errors!}
   542 \begin{block}{Careful about errors!}
   529   \kwrd{\%hist} will contain the errors as well,\\
   543   \kwrd{\%hist} will contain the errors as well.\\
   530   so be careful while selecting line numbers.
   544 \end{block}
   531 \end{block}
   545 \begin{block}{Magic Commands?}
       
   546   Magic commands are commands provided by IPython to make our life easier.
       
   547 \end{block}
       
   548 \end{frame}
       
   549 
       
   550 \begin{frame}[fragile]
       
   551   \frametitle{Saving commands into script}
       
   552 Use the \typ{\%save} \alert{magic} command of IPython
       
   553 \begin{block}{}
       
   554 \typ{In []: \%save script_name line_numbers}
       
   555 \end{block}
       
   556 Line numbers can be specified individually separated by commas or as a range separated by a dash.\\
       
   557 \begin{block}{}
       
   558 \typ{In []: \%save four_plot.py} \alert{\typ{16 18-27}} \\  
       
   559 \end{block}
       
   560 This saves from the history the commands entered on line numbers \alert{16, 18, 19, 20, \ldots 27}
   532 \end{frame}
   561 \end{frame}
   533 
   562 
   534 \begin{frame}
   563 \begin{frame}
   535 \frametitle{Python Scripts\ldots}
   564 \frametitle{Python Scripts\ldots}
   536  This is called a Python Script.
   565 Now, four\_plot.py is called a Python Script.
   537  \begin{itemize}
   566  \begin{itemize}
   538  \item run the script in IPython using \typ{\%run -i four_plot.py}\\
   567  \item run the script in IPython using \typ{\%run four_plot.py}\\
   539  \end{itemize}
   568  \end{itemize}
       
   569 \pause
       
   570 \alert{\typ{NameError: name 'linspace' is not defined}}
       
   571 \begin{block}{}
       
   572 To avoid this, run using \alert{\typ{\%run -i four_plot.py}}\\
       
   573 \end{block}
   540 \end{frame}
   574 \end{frame}
   541 
   575 
   542 \begin{frame}[fragile]
   576 \begin{frame}[fragile]
   543   \frametitle{What did we learn?}
   577   \frametitle{What did we learn?}
   544   \begin{itemize}
   578   \begin{itemize}
   545     \item Starting up IPython
   579     \item Starting up IPython
   546     \item \kwrd{\%hist} - History of commands
       
   547     \item \kwrd{\%save} - Saving commands 
       
   548     \item Running a script using \kwrd{\%run -i}
       
   549     \item Creating simple plots.
   580     \item Creating simple plots.
   550     \item Adding labels and legends.
   581     \item Adding labels and legends.
   551     \item Annotating plots.
   582     \item Annotating plots.
   552     \item Changing the looks: size, linewidth
   583     \item Changing the looks: size, linewidth
       
   584     \item \kwrd{\%hist} - History of commands
       
   585     \item \kwrd{\%save} - Saving commands 
       
   586     \item Running a script using \kwrd{\%run -i}
   553   \end{itemize}
   587   \end{itemize}
   554 \end{frame}
   588 \end{frame}
   555 
   589 
   556 \end{document}
   590 \end{document}
   557 
   591