summaryrefslogtreecommitdiff
path: root/loading_data_from_files
diff options
context:
space:
mode:
authorJovina2011-05-06 17:37:20 +0530
committerJovina2011-05-06 17:37:20 +0530
commit96ef551c38234ab234e47b78936f184b9e4e42e3 (patch)
tree45ddcb5677663110835fff126d0c6373d359f9ba /loading_data_from_files
parent8f769af90d747f7e12e4ef64ec2ee9dabf19b727 (diff)
downloadst-scripts-96ef551c38234ab234e47b78936f184b9e4e42e3.tar.gz
st-scripts-96ef551c38234ab234e47b78936f184b9e4e42e3.tar.bz2
st-scripts-96ef551c38234ab234e47b78936f184b9e4e42e3.zip
Modified embellishing a plot,loading data from files,plotting data.
Diffstat (limited to 'loading_data_from_files')
-rw-r--r--loading_data_from_files/script.rst194
-rw-r--r--loading_data_from_files/slides.org74
-rw-r--r--loading_data_from_files/slides.tex97
3 files changed, 248 insertions, 117 deletions
diff --git a/loading_data_from_files/script.rst b/loading_data_from_files/script.rst
index 029983d..0ff85c0 100644
--- a/loading_data_from_files/script.rst
+++ b/loading_data_from_files/script.rst
@@ -14,7 +14,6 @@
.. 1. getting started with ``ipython``
-.. #[Anand: author and internal reviewer not mentioned]
.. Author : Puneeth Changanti
Internal Reviewer : Nishanth Amuluru
External Reviewer :
@@ -24,131 +23,165 @@
Script
------
+.. L1
+
{{{ Show the first slide containing title, name of the production
team along with the logo of MHRD }}}
+.. R1
+
Hello Friends. Welcome to this tutorial on "loading data from files".
+.. L2
+
{{{ Show slide with objectives }}}
-We often require to plot points obtained from experimental
-observations.
+.. R2
At the end of this tutorial, you will be able to,
- 1. Read data from files, containing a single column of data using the ``loadtxt`` command.
+ 1. Read data from files, containing a single column of data
#. Read multiple columns of data, separated by spaces or other delimiters.
-{{{ switch to the terminal }}}
+.. L3
-As usual, let us start IPython, using
+{{{ switch to the terminal }}}
::
- ipython -pylab
+ ipython -pylab
+
+.. R3
+
+As usual, let us switch to the terminal and start IPython, using ipython -pylab
+
+.. R4
Now, Let us begin with reading the file primes.txt, which contains
-just a list of primes listed in a column, using the loadtxt command.
+a list of prime numbers listed in a column, using the loadtxt command.
+Please make sure that you provide the correct path of the file 'primes.txt'.
The file, in our case, is present in ``/home/fossee/primes.txt``.
+.. L4
+
{{{ Navigate to the path in the OS, open the file and show it }}}
-.. #[punch: do we need a slide for showing the path?]
+.. L5
+::
-.. We use the ``cat`` command to see the contents of this file.
+ cat /home/fossee/primes.txt
-.. #[punch: should we show the cat command here? seems like a good place
- to do it] ::
+.. R5
- cat /home/fossee/primes.txt
+Otherwise we can use the ``cat`` command to locate the file and read the contents of it.
-.. #[Nishanth]: A problem for windows users.
- Should we simply open the file and show them the data
- so that we can be fine with GNU/Linux ;) and windows?
+.. R6
Now let us read this list into the variable ``primes``.
+
+.. L6
::
- primes = loadtxt('/home/fossee/primes.txt')
+ primes = loadtxt('/home/fossee/primes.txt')
+
+.. R7
-``primes`` is now a sequence of primes, that was listed in the file,
+``primes`` is now a sequence of prime numbers, that was listed in the file,
``primes.txt``.
We now type, ``print primes`` to see the sequence printed.
-We observe that all of the numbers end with a period. This is so,
-because these numbers are actually read as ``floats``. We shall learn
-about them, later.
+.. L7
+::
-Now, let us use the ``loadtxt`` command to read a file that contains
-two columns of data, ``pendulum.txt``. This file contains the length
-of the pendulum in the first column and the corresponding time period
-in the second. Note that ``loadtxt`` needs both the columns to have
-equal number of rows.
+ print primes
+
+.. R8
+
+We observe that all the numbers end with a period. This is so,
+because these numbers are actually read as ``floats``.
+
+.. L8
+
+{{{Highlight the output on the terminal}}}
-.. Following is an exercise that you must do.
+.. R9
-.. %%1%% Use the ``cat`` command to view the contents of this file.
+Now, let us use the ``loadtxt`` command to read a file ``pendulum.txt`` that contains
+two columns of data. This file contains the length
+of the pendulum in the first column and the corresponding time period
+in the second. Note that here ``loadtxt`` needs both the columns to have
+equal number of rows.
-.. Please, pause the video here. Do the exercise and then continue.
+We use the ``cat`` command to view the contents of this file.
-.. This is how we look at the contents of the file, ``pendulum.txt``
-.. ::
+.. L9
+::
-.. cat /home/fossee/pendulum.txt
+ cat /home/fossee/pendulum.txt
-.. #[Nishanth]: The first column is L values and second is T values
- from a simple pendulum experiment.
- Since you are using the variable names later in the
- script.
- Not necessary but can be included also.
+.. R10
Let us, now, read the data into the variable ``pend``. Again, it is
assumed that the file is in ``/home/fossee/``
+
+.. L10
::
- pend = loadtxt('/home/fossee/pendulum.txt')
+ pend = loadtxt('/home/fossee/pendulum.txt')
+
+.. R11
Let us now print the variable ``pend`` and see what's in it.
+
+.. L11
::
- print pend
+ print pend
+
+.. R12
Notice that ``pend`` is not a simple sequence like ``primes``. It has
two sequences, containing both the columns of the data file. Let us
use an additional argument of the ``loadtxt`` command, to read it into
two separate, simple sequences.
+
+.. L12
::
- L, T = loadtxt('/home/fossee/pendulum.txt', unpack=True)
+ L, T = loadtxt('/home/fossee/pendulum.txt', unpack=True)
-.. #[Nishanth]: It has a sequence of items in which each item contains
- two values. first is l and second is t
+.. R13
Let us now, print the variables L and T, to see what they contain.
+
+.. L13
+
::
- print L
- print T
+ print L
+ print T
-.. #[Nishanth]: Stress on ``unpack=True`` ??
+.. R14
Notice, that L and T now contain the first and second columns of data
from the data file, ``pendulum.txt``, and they are both simple
sequences. ``unpack=True`` has given us the two columns into two
separate sequences instead of one complex sequence.
-{{{ show the slide with loadtxt --- other features }}}
+.. L14
+
+.. R15
+
+Till now, we have learnt the basic use of the ``loadtxt``
+command.Let us try an example.
-In this tutorial, we have learnt the basic use of the ``loadtxt``
-command, which is capable of doing a lot more than we have used it for
-until now. Let us look at an example, but before that do this
-exercise.
+Pause the video here, try out the following exercise and resume the video.
-%%1%% Read the file ``pendulum_semicolon.txt`` which contains the same
+Read the file ``pendulum_semicolon.txt`` which contains the same
data as ``pendulum.txt``, but the columns are separated by semi-colons
instead of spaces. Use the IPython help to see how to do this.
-Please, pause the video here. Do the exercise and then continue.
+.. L15
{{{ switch back to the terminal }}}
::
@@ -159,20 +192,63 @@ Please, pause the video here. Do the exercise and then continue.
print T
-This brings us to the end of this tutorial.
+.. L16
{{{ show the summary slide }}}
-You should now be able to do the following, comfortably.
+.. R16
+
+This brings us to the end of this tutorial.
+let's revise quickly what we have learnt today.In this tutorial we learnt,
- + Read data from files, containing a single column of data using the
+ 1. To Read data from files, containing a single column of data using the
``loadtxt`` command.
- + Read multiple columns of data, separated by spaces or other
- delimiters.
+ #. To Read multiple columns of data, separated by spaces or other delimiters.
+
+.. L17
+
+{{Show self assessment questions slide}}
+
+.. R17
+
+1. ``loadtxt`` can read data only from a file with one column
+ only. True or False?
+
+2. Given a file ``data.txt`` with three columns of data separated by
+ spaces, read it into 3 separate simple sequences.
+
+3. Given a file ``data.txt`` with three columns of data separated by
+ ":", read it into 3 separate simple sequences.
+
+
+.. L18
+
+{{{solution of self assessment questions on slide}}}
+
+.. R18
+
+And the answers,
+
+1. False. ``loadtxt`` command can read data from files having both single columns as well as
+ multiple columns.
+
+2. A file with three columns of data seperated by spaces to be read into 3 seperate sequences,
+ we use the loadtxt command as,
+::
+
+ x = loadtxt("data.txt", unpack=True)
+
+3. If a file with three columns of data seperated by delimiters,we read it into three seperate sequences
+ by using an additional argument of delimiter in the loadtxt command
+::
+
+ x = loadtxt("data.txt", unpack=True, delimiter=":")
+
+.. L19
-{{{ Show the "sponsored by FOSSEE" slide }}}
+{{{ Show the Thankyou slide }}}
-This tutorial was created as a part of FOSSEE project, NME ICT, MHRD India
+.. R19
Hope you have enjoyed and found it useful.
Thank you!
diff --git a/loading_data_from_files/slides.org b/loading_data_from_files/slides.org
index 91c188a..4691c98 100644
--- a/loading_data_from_files/slides.org
+++ b/loading_data_from_files/slides.org
@@ -18,7 +18,7 @@
#+LaTeX_HEADER: commentstyle=\color{red}\itshape, stringstyle=\color{darkgreen},
#+LaTeX_HEADER: showstringspaces=false, keywordstyle=\color{blue}\bfseries}
-#+TITLE: Loading data from files
+#+TITLE:
#+AUTHOR: FOSSEE
#+EMAIL:
#+DATE:
@@ -29,37 +29,61 @@
#+OPTIONS: H:3 num:nil toc:nil \n:nil @:t ::t |:t ^:t -:t f:t *:t <:t
#+OPTIONS: TeX:t LaTeX:nil skip:nil d:nil todo:nil pri:nil tags:not-in-toc
-* Outline
- + Read data from files with a single column of data
- + Read data from files with multiple columns
+*
+ #+begin_latex
+\begin{center}
+\textcolor{blue}{Loading Data from Files}
+\end{center}
+\begin{center}
+\includegraphics[scale=0.25]{../images/iitb-logo.png}\\
+Developed by FOSSEE Team, IIT-Bombay. \\
+Funded by National Mission on Education through ICT
+
+MHRD, Govt. of India
+\end{center}
+#+end_latex
+* Objectives
+ At the end of this tutorial, you will be able to,
+ - Read data from files with a single column of data.
+ - Read data from files with multiple columns seperated by
+ spaces and other delimiters.
* Question 1
- Read the file ~pendulum_semicolon.txt~ which contains the same data
- as ~pendulum.txt~, but the columns are separated by semi-colons
- instead of spaces. Use the IPython help to see how to do this.
-* Solution 1
- #+begin_src python
- In []: L, T = loadtxt('/home/fossee/pendulum_semicolon.txt', unpack=True, delimiter=';')
-
- In []: print L
-
- In []: print T
- #+end_src
+ Read the file ~pendulum\_semicolon.txt~ which contains the same data
+ as ~pendulum.txt~ , but the columns are seperated by semi-colons instead
+ of spaces.Use the IPython help to see how to do this.
* Summary
- + Read data from files, containing a single column of data using the
+ In this tutorial,we have learnt to-
+ - Read data from files, containing a single column of data using the
~loadtxt~ command.
- + Read multiple columns of data, separated by spaces or other
- delimiters.
-* Thank you!
+ - Read multiple columns of data, separated by spaces or other
+ delimiters by adding additional arguments to the ~loadtxt~ command.
+* Evaluation
+ 1. ``loadtxt`` can read data only from a file with one column only.
+ True or False?
+
+ 2. Given a file ``data.txt`` with three columns of data separated by
+ spaces, read it into 3 separate simple sequences.
+
+ 3. Given a file ``data.txt`` with three columns of data separated by
+ ":", read it into 3 separate simple sequences.
+
+* Solutions
+ 1. False
+
+ 2. x = loadtxt("data.txt", unpack=True)
+
+ 3. x = loadtxt("data.txt", unpack=True, delimiter=":")
+* Acknowledgement
#+begin_latex
- \begin{block}{}
+ \begin{block}{}
\begin{center}
- This spoken tutorial has been produced by the
- \textcolor{blue}{FOSSEE} team, which is funded by the
+ \textcolor{blue}{\Large THANK YOU!}
\end{center}
+ \end{block}
+\begin{block}{}
\begin{center}
- \textcolor{blue}{National Mission on Education through \\
- Information \& Communication Technology \\
- MHRD, Govt. of India}.
+ For more Information, visit our website\\
+ \url{http://fossee.in/}
\end{center}
\end{block}
#+end_latex
diff --git a/loading_data_from_files/slides.tex b/loading_data_from_files/slides.tex
index 858d769..1a8cc3a 100644
--- a/loading_data_from_files/slides.tex
+++ b/loading_data_from_files/slides.tex
@@ -1,4 +1,4 @@
-% Created 2010-10-10 Sun 18:12
+% Created 2011-05-06 Fri 12:18
\documentclass[presentation]{beamer}
\usepackage[latin1]{inputenc}
\usepackage[T1]{fontenc}
@@ -23,14 +23,14 @@ commentstyle=\color{red}\itshape, stringstyle=\color{darkgreen},
showstringspaces=false, keywordstyle=\color{blue}\bfseries}
\providecommand{\alert}[1]{\textbf{#1}}
-\title{Loading data from files}
+\title{}
\author{FOSSEE}
\date{}
\usetheme{Warsaw}\usecolortheme{default}\useoutertheme{infolines}\setbeamercovered{transparent}
\begin{document}
-\maketitle
+
@@ -41,61 +41,92 @@ showstringspaces=false, keywordstyle=\color{blue}\bfseries}
\begin{frame}
-\frametitle{Outline}
-\label{sec-1}
-\begin{itemize}
-\item Read data from files with a single column of data
-\item Read data from files with multiple columns
-\end{itemize}
+\begin{center}
+\textcolor{blue}{Loading Data from Files}
+\end{center}
+\begin{center}
+\includegraphics[scale=0.25]{../images/iitb-logo.png}\\
+Developed by FOSSEE Team, IIT-Bombay. \\
+Funded by National Mission on Education through ICT
+
+MHRD, Govt. of India
+\end{center}
\end{frame}
\begin{frame}
-\frametitle{Question 1}
+\frametitle{Objectives}
\label{sec-2}
- Read the file \texttt{pendulum\_semicolon.txt} which contains the same data
- as \texttt{pendulum.txt}, but the columns are separated by semi-colons
- instead of spaces. Use the IPython help to see how to do this.
+ At the end of this tutorial, you will be able to,
+
+\begin{itemize}
+\item Read data from files with a single column of data.
+\item Read data from files with multiple columns seperated by
+ spaces and other delimiters.
+\end{itemize}
\end{frame}
-\begin{frame}[fragile]
-\frametitle{Solution 1}
+\begin{frame}
+\frametitle{Question 1}
\label{sec-3}
-\lstset{language=Python}
-\begin{lstlisting}
-In []: L, T = loadtxt('/home/fossee/pendulum_semicolon.txt', unpack=True, delimiter=';')
-
-In []: print L
-
-In []: print T
-\end{lstlisting}
+ Read the file \verb~pendulum\_semicolon.txt~ which contains the same data
+ as \verb~pendulum.txt~ , but the columns are seperated by semi-colons instead
+ of spaces.Use the IPython help to see how to do this.
\end{frame}
\begin{frame}
\frametitle{Summary}
\label{sec-4}
+ In this tutorial,we have learnt to-
+
\begin{itemize}
\item Read data from files, containing a single column of data using the
- \texttt{loadtxt} command.
+ \verb~loadtxt~ command.
\item Read multiple columns of data, separated by spaces or other
- delimiters.
+ delimiters by adding additional arguments to the \verb~loadtxt~ command.
\end{itemize}
\end{frame}
\begin{frame}
-\frametitle{Thank you!}
+\frametitle{Evaluation}
\label{sec-5}
- \begin{block}{}
+
+\begin{enumerate}
+\item ``loadtxt`` can read data only from a file with one column only.
+ True or False?
+\item Given a file ``data.txt`` with three columns of data separated by
+ spaces, read it into 3 separate simple sequences.
+\item Given a file ``data.txt`` with three columns of data separated by
+ ``:'', read it into 3 separate simple sequences.
+\end{enumerate}
+
+\end{frame}
+\begin{frame}
+\frametitle{Solutions}
+\label{sec-6}
+
+
+\begin{enumerate}
+\item False
+\item x = loadtxt(``data.txt'', unpack=True)
+\item x = loadtxt(``data.txt'', unpack=True, delimiter='':'')
+\end{enumerate}
+\end{frame}
+\begin{frame}
+\frametitle{Acknowledgement}
+\label{sec-7}
+
+ \begin{block}{}
\begin{center}
- This spoken tutorial has been produced by the
- \textcolor{blue}{FOSSEE} team, which is funded by the
+ \textcolor{blue}{\Large THANK YOU!}
\end{center}
+ \end{block}
+\begin{block}{}
\begin{center}
- \textcolor{blue}{National Mission on Education through \\
- Information \& Communication Technology \\
- MHRD, Govt. of India}.
+ For more Information, visit our website\\
+ \url{http://fossee.in/}
\end{center}
\end{block}
\end{frame}
-\end{document}
+\end{document} \ No newline at end of file