diff options
author | Puneeth Chaganti | 2009-10-23 18:23:32 +0530 |
---|---|---|
committer | Puneeth Chaganti | 2009-10-23 18:23:32 +0530 |
commit | 70062fc1442b81f84df3afbd4330462e735c020a (patch) | |
tree | e4c0d2806e41b9e3eef11089b1772cada34b0dda | |
parent | 2c3db1e7de138b5f0e1db7263c09776d8d7c2a3b (diff) | |
download | workshops-70062fc1442b81f84df3afbd4330462e735c020a.tar.gz workshops-70062fc1442b81f84df3afbd4330462e735c020a.tar.bz2 workshops-70062fc1442b81f84df3afbd4330462e735c020a.zip |
Adding reading files and plotting to day1 session1.
-rw-r--r-- | day1/session2.tex | 116 | ||||
-rw-r--r-- | day1/session3.tex | 21 |
2 files changed, 100 insertions, 37 deletions
diff --git a/day1/session2.tex b/day1/session2.tex index a9a204f..7242f6a 100644 --- a/day1/session2.tex +++ b/day1/session2.tex @@ -224,10 +224,10 @@ Out[]: [<matplotlib.lines.Line2D object at 0xa5b05ac>] \end{lstlisting} \end{frame} -\begin{frame}{So what did we learn here??} +\begin{frame}{New Concepts} \begin{itemize} \item lists - \item \alert{\kwrd{for}} + \item \typ{for} \end{itemize} \end{frame} @@ -283,39 +283,119 @@ In []: for num in lst: \end{lstlisting} \end{frame} -\section{File Handling} \begin{frame}[fragile] - \frametitle{File and \kwrd{for}} +\frametitle{Reading 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$ +\end{itemize} +\end{frame} + +\begin{frame}[fragile] +\frametitle{Reading pendulum.txt} +\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])) +\end{lstlisting} +\begin{itemize} +\item We now have two lists L and T +\item Now, Repeat previous steps for plotting +\end{itemize} +\end{frame} + +\begin{frame}[fragile] +\frametitle{Plotting from pendulum.txt} \begin{lstlisting} -In []: f = open('dummyfile') +In []: TSq = [] + +In []: for t in T: + ....: TSq.append(t*t) -In []: for line in f: - ...: print line - ...: +In []: plot(L, TSq, '.') \end{lstlisting} -\inctime{5} \end{frame} -\section{Strings} -\begin{frame}{Strings} +\begin{frame}{New Concepts} + \begin{itemize} + \item File handling + \item Strings + \item Data-type conversion + \end{itemize} +\end{frame} + +\begin{frame}[fragile] + \frametitle{Reading files \ldots} +\typ{In []: for line in open('pendulum.txt'):} +\begin{itemize} +\item opening file `pendulum.txt' +\item iterating through file using variable \typ{line} +\item \typ{line} is a \kwrd{string} variable +\end{itemize} +\end{frame} + +\begin{frame}[fragile] +\frametitle{Strings} Anything within ``quotes'' is a string! +\begin{lstlisting} +' This is a string ' +" This too! " +""" This one too! """ +''' And one more! ''' +\end{lstlisting} \end{frame} -\begin{frame}[fragile]\frametitle{Strings and \typ{split()}} +\begin{frame}[fragile] +\frametitle{Strings and \typ{split()}} \begin{lstlisting} -In []: a = 'hello world' +In []: line = 'hello world' In []: a.split() Out[]: ['hello', 'world'] \end{lstlisting} -Now try this: +This is what happens with \typ{line} + \begin{lstlisting} +In []: line = '1.2000e-01 7.4252e-01' + +In []: line.split() +Out[]: ['1.2000e-01', '7.4252e-01'] + \end{lstlisting} +\end{frame} + +\begin{frame}[fragile] +\frametitle{Getting floats from strings} + \begin{lstlisting} +In []: type(points[0]) +Out[]: <type 'str'> + \end{lstlisting} +But, we need floating point numbers \begin{lstlisting} -In []: b = 'KD, MCS, PC, SC, SV' +In []: t = float(point[0]) -In []: b.split(',') -Out[]: ['KD', 'MCS', 'PC', 'SC', 'SV'] +In []: type(t) +Out[]: <type 'float'> \end{lstlisting} -\inctime{5} \end{frame} +\begin{frame}[fragile] +\begin{figure} +\includegraphics[width=3.5in]{data/L-Tsq.png} +\end{figure} +\vspace{-0.2in} +Coming up - \alert{Least Square Fit \ldots} +\end{frame} + + + + \end{document} + + + + diff --git a/day1/session3.tex b/day1/session3.tex index bca7e20..eb5c518 100644 --- a/day1/session3.tex +++ b/day1/session3.tex @@ -126,12 +126,11 @@ %% % You might wish to add the option [pausesections] %% \end{frame} + \begin{frame} \frametitle{Least Squares Fit} -In this session - \begin{itemize} -\item We shall plot a least squares fit curve for time-period(T) squared vs. length(L) plot of a Simple Pendulum. -\item Given a file containing L and T values +\item Plot a least squares fit line \end{itemize} \end{frame} @@ -148,22 +147,6 @@ Machinery Required - \end{itemize} \end{frame} -\begin{frame}[fragile] -\frametitle{Reading pendulum.txt} -\begin{itemize} - \item The file has two columns - \item Column1 - L; Column2 - T -\end{itemize} -\begin{lstlisting} -In []: L = [] -In []: T = [] -In []: for line in open('pendulum.txt'): - .... ln, t = line.split() - .... L.append(float(ln)) - .... T.append(float(t)) -\end{lstlisting} -We now have two lists L and T -\end{frame} \begin{frame}[fragile] \frametitle{Calculating $T^2$} |