summaryrefslogtreecommitdiff
path: root/loading_data_from_files
diff options
context:
space:
mode:
authorPuneeth Chaganti2010-12-01 16:51:35 +0530
committerPuneeth Chaganti2010-12-01 16:51:35 +0530
commitf3a34dfb4e879f3eb7274704f44546aac4add88f (patch)
tree1cb0a8cc5dbd5ee2b374350915ed2addfa0fb447 /loading_data_from_files
parent347866ed0d29db61ee062563b1e1616cfb85588c (diff)
downloadst-scripts-f3a34dfb4e879f3eb7274704f44546aac4add88f.tar.gz
st-scripts-f3a34dfb4e879f3eb7274704f44546aac4add88f.tar.bz2
st-scripts-f3a34dfb4e879f3eb7274704f44546aac4add88f.zip
Renamed all LOs to match with their names in progress.org.
Diffstat (limited to 'loading_data_from_files')
-rw-r--r--loading_data_from_files/pendulum.txt90
-rw-r--r--loading_data_from_files/pendulum_semicolon.txt90
-rw-r--r--loading_data_from_files/primes.txt25
-rw-r--r--loading_data_from_files/quickref.tex12
-rw-r--r--loading_data_from_files/script.rst180
-rw-r--r--loading_data_from_files/slides.org67
-rw-r--r--loading_data_from_files/slides.tex101
7 files changed, 565 insertions, 0 deletions
diff --git a/loading_data_from_files/pendulum.txt b/loading_data_from_files/pendulum.txt
new file mode 100644
index 0000000..7e07566
--- /dev/null
+++ b/loading_data_from_files/pendulum.txt
@@ -0,0 +1,90 @@
+1.0000e-01 6.9004e-01
+1.1000e-01 6.9497e-01
+1.2000e-01 7.4252e-01
+1.3000e-01 7.5360e-01
+1.4000e-01 8.3568e-01
+1.5000e-01 8.6789e-01
+1.6000e-01 8.4182e-01
+1.7000e-01 8.5379e-01
+1.8000e-01 8.5762e-01
+1.9000e-01 8.8390e-01
+2.0000e-01 8.9985e-01
+2.1000e-01 9.8436e-01
+2.2000e-01 1.0244e+00
+2.3000e-01 1.0572e+00
+2.4000e-01 9.9077e-01
+2.5000e-01 1.0058e+00
+2.6000e-01 1.0727e+00
+2.7000e-01 1.0943e+00
+2.8000e-01 1.1432e+00
+2.9000e-01 1.1045e+00
+3.0000e-01 1.1867e+00
+3.1000e-01 1.1385e+00
+3.2000e-01 1.2245e+00
+3.3000e-01 1.2406e+00
+3.4000e-01 1.2071e+00
+3.5000e-01 1.2658e+00
+3.6000e-01 1.2995e+00
+3.7000e-01 1.3142e+00
+3.8000e-01 1.2663e+00
+3.9000e-01 1.2578e+00
+4.0000e-01 1.2991e+00
+4.1000e-01 1.3058e+00
+4.2000e-01 1.3478e+00
+4.3000e-01 1.3506e+00
+4.4000e-01 1.4044e+00
+4.5000e-01 1.3948e+00
+4.6000e-01 1.3800e+00
+4.7000e-01 1.4480e+00
+4.8000e-01 1.4168e+00
+4.9000e-01 1.4719e+00
+5.0000e-01 1.4656e+00
+5.1000e-01 1.4399e+00
+5.2000e-01 1.5174e+00
+5.3000e-01 1.4988e+00
+5.4000e-01 1.4751e+00
+5.5000e-01 1.5326e+00
+5.6000e-01 1.5297e+00
+5.7000e-01 1.5372e+00
+5.8000e-01 1.6094e+00
+5.9000e-01 1.6352e+00
+6.0000e-01 1.5843e+00
+6.1000e-01 1.6643e+00
+6.2000e-01 1.5987e+00
+6.3000e-01 1.6585e+00
+6.4000e-01 1.6317e+00
+6.5000e-01 1.7074e+00
+6.6000e-01 1.6654e+00
+6.7000e-01 1.6551e+00
+6.8000e-01 1.6964e+00
+6.9000e-01 1.7143e+00
+7.0000e-01 1.7706e+00
+7.1000e-01 1.7622e+00
+7.2000e-01 1.7260e+00
+7.3000e-01 1.8089e+00
+7.4000e-01 1.7905e+00
+7.5000e-01 1.7428e+00
+7.6000e-01 1.8381e+00
+7.7000e-01 1.8182e+00
+7.8000e-01 1.7865e+00
+7.9000e-01 1.7995e+00
+8.0000e-01 1.8296e+00
+8.1000e-01 1.8625e+00
+8.2000e-01 1.8623e+00
+8.3000e-01 1.8383e+00
+8.4000e-01 1.8593e+00
+8.5000e-01 1.8944e+00
+8.6000e-01 1.9598e+00
+8.7000e-01 1.9000e+00
+8.8000e-01 1.9244e+00
+8.9000e-01 1.9397e+00
+9.0000e-01 1.9440e+00
+9.1000e-01 1.9718e+00
+9.2000e-01 1.9383e+00
+9.3000e-01 1.9555e+00
+9.4000e-01 2.0006e+00
+9.5000e-01 1.9841e+00
+9.6000e-01 2.0066e+00
+9.7000e-01 2.0493e+00
+9.8000e-01 2.0503e+00
+9.9000e-01 2.0214e+00
diff --git a/loading_data_from_files/pendulum_semicolon.txt b/loading_data_from_files/pendulum_semicolon.txt
new file mode 100644
index 0000000..409867a
--- /dev/null
+++ b/loading_data_from_files/pendulum_semicolon.txt
@@ -0,0 +1,90 @@
+1.0000e-01;6.9004e-01
+1.1000e-01;6.9497e-01
+1.2000e-01;7.4252e-01
+1.3000e-01;7.5360e-01
+1.4000e-01;8.3568e-01
+1.5000e-01;8.6789e-01
+1.6000e-01;8.4182e-01
+1.7000e-01;8.5379e-01
+1.8000e-01;8.5762e-01
+1.9000e-01;8.8390e-01
+2.0000e-01;8.9985e-01
+2.1000e-01;9.8436e-01
+2.2000e-01;1.0244e+00
+2.3000e-01;1.0572e+00
+2.4000e-01;9.9077e-01
+2.5000e-01;1.0058e+00
+2.6000e-01;1.0727e+00
+2.7000e-01;1.0943e+00
+2.8000e-01;1.1432e+00
+2.9000e-01;1.1045e+00
+3.0000e-01;1.1867e+00
+3.1000e-01;1.1385e+00
+3.2000e-01;1.2245e+00
+3.3000e-01;1.2406e+00
+3.4000e-01;1.2071e+00
+3.5000e-01;1.2658e+00
+3.6000e-01;1.2995e+00
+3.7000e-01;1.3142e+00
+3.8000e-01;1.2663e+00
+3.9000e-01;1.2578e+00
+4.0000e-01;1.2991e+00
+4.1000e-01;1.3058e+00
+4.2000e-01;1.3478e+00
+4.3000e-01;1.3506e+00
+4.4000e-01;1.4044e+00
+4.5000e-01;1.3948e+00
+4.6000e-01;1.3800e+00
+4.7000e-01;1.4480e+00
+4.8000e-01;1.4168e+00
+4.9000e-01;1.4719e+00
+5.0000e-01;1.4656e+00
+5.1000e-01;1.4399e+00
+5.2000e-01;1.5174e+00
+5.3000e-01;1.4988e+00
+5.4000e-01;1.4751e+00
+5.5000e-01;1.5326e+00
+5.6000e-01;1.5297e+00
+5.7000e-01;1.5372e+00
+5.8000e-01;1.6094e+00
+5.9000e-01;1.6352e+00
+6.0000e-01;1.5843e+00
+6.1000e-01;1.6643e+00
+6.2000e-01;1.5987e+00
+6.3000e-01;1.6585e+00
+6.4000e-01;1.6317e+00
+6.5000e-01;1.7074e+00
+6.6000e-01;1.6654e+00
+6.7000e-01;1.6551e+00
+6.8000e-01;1.6964e+00
+6.9000e-01;1.7143e+00
+7.0000e-01;1.7706e+00
+7.1000e-01;1.7622e+00
+7.2000e-01;1.7260e+00
+7.3000e-01;1.8089e+00
+7.4000e-01;1.7905e+00
+7.5000e-01;1.7428e+00
+7.6000e-01;1.8381e+00
+7.7000e-01;1.8182e+00
+7.8000e-01;1.7865e+00
+7.9000e-01;1.7995e+00
+8.0000e-01;1.8296e+00
+8.1000e-01;1.8625e+00
+8.2000e-01;1.8623e+00
+8.3000e-01;1.8383e+00
+8.4000e-01;1.8593e+00
+8.5000e-01;1.8944e+00
+8.6000e-01;1.9598e+00
+8.7000e-01;1.9000e+00
+8.8000e-01;1.9244e+00
+8.9000e-01;1.9397e+00
+9.0000e-01;1.9440e+00
+9.1000e-01;1.9718e+00
+9.2000e-01;1.9383e+00
+9.3000e-01;1.9555e+00
+9.4000e-01;2.0006e+00
+9.5000e-01;1.9841e+00
+9.6000e-01;2.0066e+00
+9.7000e-01;2.0493e+00
+9.8000e-01;2.0503e+00
+9.9000e-01;2.0214e+00
diff --git a/loading_data_from_files/primes.txt b/loading_data_from_files/primes.txt
new file mode 100644
index 0000000..384d511
--- /dev/null
+++ b/loading_data_from_files/primes.txt
@@ -0,0 +1,25 @@
+2
+3
+5
+7
+11
+13
+17
+19
+23
+29
+31
+37
+41
+43
+47
+53
+59
+61
+67
+71
+73
+79
+83
+89
+97
diff --git a/loading_data_from_files/quickref.tex b/loading_data_from_files/quickref.tex
new file mode 100644
index 0000000..c3bbe95
--- /dev/null
+++ b/loading_data_from_files/quickref.tex
@@ -0,0 +1,12 @@
+\textbf{Loading data from files}
+
+\lstinline|loadtxt('filename')| returns the columns of file in one
+sequence.
+
+\lstinline|x, y = loadtxt('filename', unpack=True)| to obtain a file
+with 2 columns in separate sequences.
+
+\lstinline|loadtxt('filename', delimiter=';')|, if the file has
+columns separated by ';' instead of spaces/tabs.
+
+
diff --git a/loading_data_from_files/script.rst b/loading_data_from_files/script.rst
new file mode 100644
index 0000000..cc2e008
--- /dev/null
+++ b/loading_data_from_files/script.rst
@@ -0,0 +1,180 @@
+.. Objectives
+.. ----------
+
+.. At the end of this tutorial, you will be able 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.
+
+
+.. Prerequisites
+.. -------------
+
+.. 1. getting started with ``ipython``
+
+.. #[Anand: author and internal reviewer not mentioned]
+.. Author : Puneeth Changanti
+ Internal Reviewer : Nishanth Amuluru
+ External Reviewer :
+ Language Reviewer : Bhanukiran
+ Checklist OK? : <06-11-2010 Anand, OK> [2010-10-05]
+
+Script
+------
+
+{{{ Show the slide containing title }}}
+
+Hello Friends. Welcome to this tutorial on loading data from files.
+
+{{{ Screen shows welcome slide }}}
+
+We often require to plot points obtained from experimental
+observations. In this tutorial we shall learn to read data from files
+and save it into sequences that can later be used to plot.
+
+{{{ Show the outline for this tutorial }}}
+
+We shall use the ``loadtxt`` command to load data from files. We will
+be looking at how to read a file with multiple columns of data and
+load each column of data into a sequence.
+
+{{{ switch back to the terminal }}}
+
+As usual, let us start IPython, using
+::
+
+ ipython -pylab
+
+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.
+The file, in our case, is present in ``/home/fossee/primes.txt``.
+
+{{{ Navigate to the path in the OS, open the file and show it }}}
+
+.. #[punch: do we need a slide for showing the path?]
+
+.. We use the ``cat`` command to see the contents of this file.
+
+.. #[punch: should we show the cat command here? seems like a good place
+ to do it] ::
+
+ cat /home/fossee/primes.txt
+
+.. #[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?
+
+Now let us read this list into the variable ``primes``.
+::
+
+ primes = loadtxt('/home/fossee/primes.txt')
+
+``primes`` is now a sequence of primes, 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.
+
+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.
+
+.. Following is an exercise that you must do.
+
+.. %%1%% Use the ``cat`` command to view the contents of this file.
+
+.. Please, pause the video here. Do the exercise and then continue.
+
+.. This is how we look at the contents of the file, ``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.
+
+Let us, now, read the data into the variable ``pend``. Again, it is
+assumed that the file is in ``/home/fossee/``
+::
+
+ pend = loadtxt('/home/fossee/pendulum.txt')
+
+Let us now print the variable ``pend`` and see what's in it.
+::
+
+ print pend
+
+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.
+::
+
+ 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
+
+Let us now, print the variables L and T, to see what they contain.
+::
+
+ print L
+ print T
+
+.. #[Nishanth]: Stress on ``unpack=True`` ??
+
+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 }}}
+
+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.
+
+%%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.
+
+Please, pause the video here. Do the exercise and then continue.
+
+{{{ switch back to the terminal }}}
+::
+
+ L, T = loadtxt('/home/fossee/pendulum_semicolon.txt', unpack=True, delimiter=';')
+
+ print L
+
+ print T
+
+This brings us to the end of this tutorial.
+
+{{{ show the summary slide }}}
+
+You should now be able to do the following, comfortably.
+
+ + 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.
+
+{{{ Show the "sponsored by FOSSEE" slide }}}
+
+This tutorial was created as a part of FOSSEE project, NME ICT, MHRD India
+
+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
new file mode 100644
index 0000000..91c188a
--- /dev/null
+++ b/loading_data_from_files/slides.org
@@ -0,0 +1,67 @@
+#+LaTeX_CLASS: beamer
+#+LaTeX_CLASS_OPTIONS: [presentation]
+#+BEAMER_FRAME_LEVEL: 1
+
+#+BEAMER_HEADER_EXTRA: \usetheme{Warsaw}\usecolortheme{default}\useoutertheme{infolines}\setbeamercovered{transparent}
+#+COLUMNS: %45ITEM %10BEAMER_env(Env) %10BEAMER_envargs(Env Args) %4BEAMER_col(Col) %8BEAMER_extra(Extra)
+#+PROPERTY: BEAMER_col_ALL 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1.0 :ETC
+
+#+LaTeX_CLASS: beamer
+#+LaTeX_CLASS_OPTIONS: [presentation]
+
+#+LaTeX_HEADER: \usepackage[english]{babel} \usepackage{ae,aecompl}
+#+LaTeX_HEADER: \usepackage{mathpazo,courier,euler} \usepackage[scaled=.95]{helvet}
+
+#+LaTeX_HEADER: \usepackage{listings}
+
+#+LaTeX_HEADER:\lstset{language=Python, basicstyle=\ttfamily\bfseries,
+#+LaTeX_HEADER: commentstyle=\color{red}\itshape, stringstyle=\color{darkgreen},
+#+LaTeX_HEADER: showstringspaces=false, keywordstyle=\color{blue}\bfseries}
+
+#+TITLE: Loading data from files
+#+AUTHOR: FOSSEE
+#+EMAIL:
+#+DATE:
+
+#+DESCRIPTION:
+#+KEYWORDS:
+#+LANGUAGE: en
+#+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
+* 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
+* Summary
+ + 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!
+#+begin_latex
+ \begin{block}{}
+ \begin{center}
+ This spoken tutorial has been produced by the
+ \textcolor{blue}{FOSSEE} team, which is funded by the
+ \end{center}
+ \begin{center}
+ \textcolor{blue}{National Mission on Education through \\
+ Information \& Communication Technology \\
+ MHRD, Govt. of India}.
+ \end{center}
+ \end{block}
+#+end_latex
+
+
diff --git a/loading_data_from_files/slides.tex b/loading_data_from_files/slides.tex
new file mode 100644
index 0000000..858d769
--- /dev/null
+++ b/loading_data_from_files/slides.tex
@@ -0,0 +1,101 @@
+% Created 2010-10-10 Sun 18:12
+\documentclass[presentation]{beamer}
+\usepackage[latin1]{inputenc}
+\usepackage[T1]{fontenc}
+\usepackage{fixltx2e}
+\usepackage{graphicx}
+\usepackage{longtable}
+\usepackage{float}
+\usepackage{wrapfig}
+\usepackage{soul}
+\usepackage{textcomp}
+\usepackage{marvosym}
+\usepackage{wasysym}
+\usepackage{latexsym}
+\usepackage{amssymb}
+\usepackage{hyperref}
+\tolerance=1000
+\usepackage[english]{babel} \usepackage{ae,aecompl}
+\usepackage{mathpazo,courier,euler} \usepackage[scaled=.95]{helvet}
+\usepackage{listings}
+\lstset{language=Python, basicstyle=\ttfamily\bfseries,
+commentstyle=\color{red}\itshape, stringstyle=\color{darkgreen},
+showstringspaces=false, keywordstyle=\color{blue}\bfseries}
+\providecommand{\alert}[1]{\textbf{#1}}
+
+\title{Loading data from files}
+\author{FOSSEE}
+\date{}
+
+\usetheme{Warsaw}\usecolortheme{default}\useoutertheme{infolines}\setbeamercovered{transparent}
+\begin{document}
+
+\maketitle
+
+
+
+
+
+
+
+
+
+\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}
+\end{frame}
+\begin{frame}
+\frametitle{Question 1}
+\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.
+\end{frame}
+\begin{frame}[fragile]
+\frametitle{Solution 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}
+\end{frame}
+\begin{frame}
+\frametitle{Summary}
+\label{sec-4}
+
+\begin{itemize}
+\item Read data from files, containing a single column of data using the
+ \texttt{loadtxt} command.
+\item Read multiple columns of data, separated by spaces or other
+ delimiters.
+\end{itemize}
+\end{frame}
+\begin{frame}
+\frametitle{Thank you!}
+\label{sec-5}
+
+ \begin{block}{}
+ \begin{center}
+ This spoken tutorial has been produced by the
+ \textcolor{blue}{FOSSEE} team, which is funded by the
+ \end{center}
+ \begin{center}
+ \textcolor{blue}{National Mission on Education through \\
+ Information \& Communication Technology \\
+ MHRD, Govt. of India}.
+ \end{center}
+ \end{block}
+\end{frame}
+
+\end{document}