Merged with mainline.
authorPuneeth Chaganti <punchagan@fossee.in>
Thu, 05 Nov 2009 14:07:26 +0530
changeset 278 5d680ab63dde
parent 277 ef9337f7048c (current diff)
parent 276 4555c3814dd4 (diff)
child 279 e7ce6f9d7e15
Merged with mainline.
day1/session4.tex
--- a/day1/session2.tex	Thu Nov 05 13:44:46 2009 +0530
+++ b/day1/session2.tex	Thu Nov 05 14:07:26 2009 +0530
@@ -1,4 +1,4 @@
-%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
 %Tutorial slides on Python.
 %
 % Author: FOSSEE
@@ -124,12 +124,9 @@
 \end{frame}
 
 \begin{frame}
-\frametitle{Why we didn't close the IPython??}
-\begin{itemize}
-  \item IPython provides a convenient feature
-  \item To go back, edit, and re-run commands
-  \item But when you close, this is lost
-\end{itemize}
+\frametitle{Why we didn't close IPython?}
+  IPython provides a convenient feature to go back, edit, and re-run commands.\\
+  \alert{But when you close, all this is lost.}
 \end{frame}
 
 \begin{frame}
@@ -148,7 +145,7 @@
 \begin{frame}[fragile]
 \frametitle{Python Scripts}
 \begin{itemize}
-\item Put all commands used in review problem into a file. 
+\item Put commands used in review problem into file. 
 \item use hist command of IPython.
 \end{itemize}
 \begin{lstlisting}
@@ -161,17 +158,18 @@
 \frametitle{Python Scripts\ldots}
   \begin{itemize}
     \item Open a new file in an \alert{editor}
-    \item Copy and paste required lines from the output of \typ{\%hist -n}
+    \item Copy and paste from the output of \typ{\%hist -n}
     \item Save the file as \typ{sine_plot.py}
   \end{itemize}
   \begin{itemize}
-  \item run the file in IPython using \typ{\%run sine_plot.py}\\
+  \item run the file in IPython using \typ{\%run -i sine_plot.py}\\
   \end{itemize}
 \end{frame}
 
 \begin{frame}[fragile]
 \frametitle{Why would I plot f(x)?}
 How often do we plot analytical functions?\\We plot experimental data more.
+\begin{small}
 \begin{lstlisting}
 In []: x = [0, 1, 2, 3]
 
@@ -179,14 +177,21 @@
 
 In []: plot(x, y)
 Out[]: [<matplotlib.lines.Line2D object at 0xa73aa8c>]
+
+In []: xlabel('X')
+Out[]: <matplotlib.text.Text object at 0x986e9ac>
+
+In []: ylabel('Y')
+Out[]: <matplotlib.text.Text object at 0x98746ec>
 \end{lstlisting}
+\end{small}
 \end{frame}
 
 \begin{frame}[fragile]
 \begin{figure}
 \includegraphics[width=3.5in]{data/straightline.png}
 \end{figure}
-\alert{Is this what you have??}
+\alert{Is this what you have?}
 \end{frame}
 
 \begin{frame}[fragile]
@@ -197,11 +202,11 @@
 \begin{lstlisting}
   In []: clf()
 
-  In []: plot(L, TSq, 'o')
+  In []: plot(x, y, 'o')
   Out[]: [<matplotlib.lines.Line2D object at 0xac17e0c>]
 
   In []: clf()
-  In []: plot(L, TSq, '.')
+  In []: plot(x, y, '.')
   Out[]: [<matplotlib.lines.Line2D object at 0xac17e0c>]
 \end{lstlisting}
 \end{frame}
@@ -216,8 +221,8 @@
 \begin{frame}[fragile]
 \frametitle{Additional Plotting Attributes}
 \begin{itemize}
-  \item \kwrd{'o'} - Dots
-  \item \kwrd{'.'} - Smaller Dots
+  \item \kwrd{'o'} - Filled circles
+  \item \kwrd{'.'} - Small Dots
   \item \kwrd{'-'} - Lines
   \item \kwrd{'- -'} - Dashed lines
 \end{itemize}
@@ -226,14 +231,14 @@
 \section{Lists}
 \begin{frame}[fragile]
   \frametitle{How to create the data?}
-What were \typ{x} and \typ{y}??\\
+What were \typ{x} and \typ{y}?\\
 \begin{center}
 \alert{\typ{lists!!}}
 \end{center}
 \begin{lstlisting}
 In []: mtlist = [] #Empty List
 
-In []: lst = [1,2,3,4,5] 
+In []: lst = [ 1, 2, 3, 4, 5] 
 \end{lstlisting}
 \end{frame}
 
@@ -248,31 +253,31 @@
 \begin{frame}[fragile]
   \frametitle{List: Slicing}
   \begin{block}{Remember\ldots}
-	\kwrd{In []: lst = [1,2,3,4,5]}
+	\kwrd{In []: lst = [ 1, 2, 3, 4, 5]}
   \end{block}
-\alert{\typ{list[initial:final:step]}}
 \begin{lstlisting}
 In []: lst[1:3]  # A slice.
 Out[]: [2, 3]
 
 In []: lst[1:-1]
-Out[]: [2, 3]
+Out[]: [2, 3, 4]
 \end{lstlisting}
+\alert{\typ{list[initial:final]}}
 \end{frame}
 
 %% more on list slicing
 \begin{frame}[fragile]
 \frametitle{List operations}
 \begin{lstlisting}
-In []: anthrlst = [6,7,8,9]
-In []: lnglst = lst + anthrlst
+In []: a = [ 6, 7, 8, 9]
+In []: b = lst + a
 
-In []: lnglst
+In []: b
 Out[]: [1, 2, 3, 4, 5, 6, 7, 8, 9]
 
 In []: lst.append(6)
 In []: lst
-Out[]: [1, 2, 3, 4, 5, 6]
+Out[]: [ 1, 2, 3, 4, 5, 6]
 \end{lstlisting}
 %\inctime{10}
 \end{frame}
@@ -333,7 +338,7 @@
 In []: plot(L, TSq)
 Out[]: [<matplotlib.lines.Line2D object at 0xa5b05ac>]
 \end{lstlisting}
-This gives the list \kwrd{TSq} which is the list of squares of T values.
+This gives \kwrd{TSq} which is the list of squares of T values.
 \end{frame}
 
 \begin{frame}[fragile]
@@ -343,31 +348,11 @@
 \end{frame}
 
 \begin{frame}[fragile]
-\frametitle{More of \texttt{for}}
-\begin{itemize}
-\item Used to iterate over lists
-\item Let us look at another example.
-\end{itemize}
+\frametitle{What about larger data sets?}
+\alert{Data is usually present in a file!} \\
+Lets look at the \typ{pendulum.txt} file.
 \begin{lstlisting}
-In []: lst = [1,2,3,4,5,6]
-In []: for num in lst:
- ....:     print num, num*num
- ....:    
-1 1
-2 4
-3 9
-4 16
-5 25
-6 36
-\end{lstlisting}
-\end{frame}
-
-\begin{frame}[fragile]
-\frametitle{What about larger data sets??}
-\alert{Data is usually present in a file!} \\
-Lets look at the pendulum.txt file.
-\begin{lstlisting}
-$cat data/pendulum.txt 
+$ cat pendulum.txt 
 1.0000e-01 6.9004e-01
 1.1000e-01 6.9497e-01
 1.2000e-01 7.4252e-01
@@ -379,18 +364,16 @@
 \end{frame}
 
 \begin{frame}[fragile]
-\frametitle{Reading pendulum.txt}
+\frametitle{Reading \typ{pendulum.txt}}
 \begin{itemize}
-  \item We now wish to repeat the plot using the values from a file
-  \item Given a file containing L vs. T values 
-  \item Column1 - L; Column2 - T  
-  \item Read the file
-  \item Plot points for L vs. $T^2$ 
+  \item Let us generate a plot from the data file
+  \item File contains L vs. T values 
+  \item L - Column1; T - Column2
 \end{itemize}
 \end{frame}
 
 \begin{frame}[fragile]
-\frametitle{Reading pendulum.txt}
+\frametitle{Reading \typ{pendulum.txt}}
 \begin{lstlisting}
 In []: L = []
 In []: T = []
@@ -401,12 +384,12 @@
 \end{lstlisting}
 \begin{itemize}
 \item We now have two lists L and T
-\item Now, Repeat previous steps for plotting
+\item Now, repeat previous steps for plotting
 \end{itemize}
 \end{frame}
 
 \begin{frame}[fragile]
-\frametitle{Plotting from pendulum.txt}
+\frametitle{Plotting from \typ{pendulum.txt}}
 \begin{lstlisting}
 In []: TSq = []
 
@@ -427,9 +410,9 @@
   \frametitle{Reading files \ldots}
 \typ{In []: for line in open('pendulum.txt'):}
 \begin{itemize}
-\item opening file `pendulum.txt'
-\item iterating through the file by reading each line into variable \typ{line}
-\item \typ{line} is a \kwrd{string} variable
+\item opening file `\typ{pendulum.txt}'
+\item reading the file line by line
+\item \typ{line} is a \kwrd{string}
 \end{itemize}
 \end{frame}
 
@@ -448,9 +431,9 @@
 \begin{frame}[fragile]
 \frametitle{Strings and \typ{split()}}
   \begin{lstlisting}
-In []: line = 'hello world'
+In []: greet = 'hello world'
 
-In []: line.split()
+In []: greet.split()
 Out[]: ['hello', 'world']
   \end{lstlisting}
 This is what happens with \typ{line}
@@ -470,20 +453,49 @@
   \end{lstlisting}
 But, we need floating point numbers
   \begin{lstlisting}
-In []: t = float(point[0])
+In []: t = float(points[0])
 
 In []: type(t)
 Out[]: <type 'float'>
   \end{lstlisting}
 \end{frame}
 
+\begin{frame}[fragile]
+\frametitle{Let's review the code}
+\begin{small}
+\begin{lstlisting}
+In []: L = []
+In []: T = []
+In []: for line in open('pendulum.txt'):
+  ....     points = line.split()
+  ....     L.append(float(points[0]))
+  ....     T.append(float(points[1]))
+
+In []: TSq = []
+
+In []: for t in T:
+ ....:     TSq.append(t*t)
+
+In []: plot(L, TSq, '.')
+\end{lstlisting}
+\end{small}
+\end{frame}
+
+\begin{frame}[fragile]
+\begin{figure}
+\includegraphics[width=3.5in]{data/L-Tsq.png}
+\end{figure}
+\end{frame}
+
 \section {Summary}
-\begin{frame}
-\frametitle{Summary}
-So what did we learn in this session??
+\begin{frame}[fragile]
+\frametitle{What did we learn?}
 \begin{itemize}
-  \item Creating and running Python scripts
-  \item Plotting points and Plotting attributes
+  \item \kwrd{\%hist -n}
+  \item Python scripts
+  \item \kwrd{\%run -i}
+  \item Plotting points
+  \item Plot attributes
   \item Lists
   \item \kwrd{for}
   \item Reading files