diff -r 069d4e86207e -r 846d71a4e915 loading-data-from-files.rst --- a/loading-data-from-files.rst Thu Sep 23 12:46:52 2010 +0530 +++ b/loading-data-from-files.rst Thu Sep 23 12:51:32 2010 +0530 @@ -6,23 +6,15 @@ {{{ Screen shows welcome slide }}} -Until now, all the plots we have made use analytic functions. We have -been using analytic functions to generate a sequence of points and -plotting them, against another sequence of points. But, this is not -what we do most often. We often require to plot points obtained from -experimental observations. - -#[punch: the initial part of the paragraph may be removed, to make -this a more generic LO?] - -In this tutorial we shall learn to read data from files and save it -into sequences that can later be used to plot. +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 get multiple columns of data into multiple -sequences. +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 }}} @@ -33,16 +25,22 @@ 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``. +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?] +.. #[punch: do we need a slide for showing the path?] + +.. We use the ``cat`` command to see the contents of this file. -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] :: -#[punch: should we show the cat command here? seems like a good place -to do it] :: + cat /home/fossee/primes.txt - 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``. :: @@ -71,6 +69,12 @@ cat /home/fossee/pendulum.txt +.. #[Nishanth]: The first column is L values and second is T values + from a simle pelculum 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/`` :: @@ -90,15 +94,21 @@ 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. +sequences. ``unpack=True`` has given us the two columns in to two +separate sequences instead of one complex sequence. {{{ show the slide with loadtxt --- other features }}} @@ -115,7 +125,7 @@ {{{ switch back to the terminal }}} :: - L, T = loadtxt('/home/fossee/pendulum.txt', unpack``True, delimiter``';') + L, T = loadtxt('/home/fossee/pendulum_semicolon.txt', unpack=True, delimiter=';') print L @@ -134,4 +144,3 @@ Thank you! -