loading-data-from-files/script.rst
changeset 257 5f2c165b4a3c
parent 250 4d8ef03627b5
child 384 525ae0d74e47
equal deleted inserted replaced
256:a3aa223c1662 257:5f2c165b4a3c
     1 ========
     1 .. Objectives
     2  Script
     2 .. ----------
     3 ========
       
     4 
     3 
     5 Welcome to this tutorial on loading data from files. 
     4 .. At the end of this tutorial, you will be able to
       
     5 
       
     6 .. + Read data from files, containing a single column of data using the
       
     7 ..   ``loadtxt`` command.
       
     8 .. + Read multiple columns of data, separated by spaces or other
       
     9 ..   delimiters.
       
    10 
       
    11 
       
    12 .. Prerequisites
       
    13 .. -------------
       
    14 
       
    15 .. 1. getting started with ``ipython``
       
    16      
       
    17 .. Author              : 
       
    18    Internal Reviewer   : 
       
    19    External Reviewer   :
       
    20    Checklist OK?       : <put date stamp here, if OK> [2010-10-05]
       
    21 
       
    22 Script
       
    23 ------
       
    24 
       
    25 {{{ Show the slide containing title }}}
       
    26 
       
    27 Hello Friends. Welcome to this tutorial on loading data from files.
     6 
    28 
     7 {{{ Screen shows welcome slide }}}
    29 {{{ Screen shows welcome slide }}}
     8 
    30 
     9 We often require to plot points obtained from experimental
    31 We often require to plot points obtained from experimental
    10 observations. In this tutorial we shall learn to read data from files
    32 observations. In this tutorial we shall learn to read data from files
    57 about them, later.
    79 about them, later.
    58 
    80 
    59 Now, let us use the ``loadtxt`` command to read a file that contains
    81 Now, let us use the ``loadtxt`` command to read a file that contains
    60 two columns of data, ``pendulum.txt``. This file contains the length
    82 two columns of data, ``pendulum.txt``. This file contains the length
    61 of the pendulum in the first column and the corresponding time period
    83 of the pendulum in the first column and the corresponding time period
    62 in the second.
    84 in the second. Note that ``loadtxt`` needs both the columns to have
       
    85 equal number of rows. 
    63 
    86 
    64 %%1%% Pause the video here, and use the ``cat`` command to view the
    87 .. Following is an exercise that you must do. 
    65 contents of this file and then resume the video.
       
    66 
    88 
    67 This is how we look at the contents of the file, ``pendulum.txt``
    89 .. %%1%% Use the ``cat`` command to view the contents of this file.
    68 ::
       
    69 
    90 
    70   cat /home/fossee/pendulum.txt
    91 .. Please, pause the video here. Do the exercise and then continue. 
       
    92 
       
    93 .. This is how we look at the contents of the file, ``pendulum.txt``
       
    94 .. ::
       
    95 
       
    96 ..   cat /home/fossee/pendulum.txt
    71 
    97 
    72 .. #[Nishanth]: The first column is L values and second is T values
    98 .. #[Nishanth]: The first column is L values and second is T values
    73                 from a simle pelculum experiment.
    99                 from a simle pelculum experiment.
    74                 Since you are using the variable names later in the
   100                 Since you are using the variable names later in the
    75                 script.
   101                 script.
   112 
   138 
   113 {{{ show the slide with loadtxt --- other features }}}
   139 {{{ show the slide with loadtxt --- other features }}}
   114 
   140 
   115 In this tutorial, we have learnt the basic use of the ``loadtxt``
   141 In this tutorial, we have learnt the basic use of the ``loadtxt``
   116 command, which is capable of doing a lot more than we have used it for
   142 command, which is capable of doing a lot more than we have used it for
   117 until now, for example
   143 until now. Let us look at an example, but before that do this
       
   144 exercise. 
   118 
   145 
   119 %%2%% Pause the video here, and read the file
   146 %%1%% Read the file ``pendulum_semicolon.txt`` which contains the same
   120 ``pendulum_semicolon.txt`` which contains the same data as
   147 data as ``pendulum.txt``, but the columns are separated by semi-colons
   121 ``pendulum.txt``, but the columns are separated by semi-colons instead
   148 instead of spaces. Use the IPython help to see how to do this. 
   122 of spaces. Use the IPython help to see how to do this. Once you have
   149 
   123 finished, resume the video to look at the solution.
   150 Please, pause the video here. Do the exercise and then continue. 
   124 
   151 
   125 {{{ switch back to the terminal }}}
   152 {{{ switch back to the terminal }}}
   126 ::
   153 ::
   127 
   154 
   128   L, T = loadtxt('/home/fossee/pendulum_semicolon.txt', unpack=True, delimiter=';')
   155   L, T = loadtxt('/home/fossee/pendulum_semicolon.txt', unpack=True, delimiter=';')
   140   + Read data from files, containing a single column of data using the
   167   + Read data from files, containing a single column of data using the
   141     ``loadtxt`` command.
   168     ``loadtxt`` command.
   142   + Read multiple columns of data, separated by spaces or other
   169   + Read multiple columns of data, separated by spaces or other
   143     delimiters.
   170     delimiters.
   144 
   171 
   145 Thank you!   
   172 {{{ Show the "sponsored by FOSSEE" slide }}}
   146 
   173 
       
   174 This tutorial was created as a part of FOSSEE project, NME ICT, MHRD India
       
   175 
       
   176 Hope you have enjoyed and found it useful.
       
   177 Thank you!
       
   178