NERC Field Spectroscopy Summer School

J Gómez Dans (NCEO & UCL)

Software requirements

For most of the practicals, we will be using the Python programming language. The reason for this is that Python is free, easy to distribute and relatively straightforward to program even for beginners. Python also plays well with older code written in e.g. Fortran or C, as well as having a fairly complete set of libraries for numerical tasks, including linear algebra, statistics, etc.

We recommend you use the Anaconda Python Distribution, a freely available compendium of both Python and numerical and scientific packages. Anaconda is available for

  • UNIX
  • Windows
  • Mac OSX

You should download and install the Anaconda version that supports Python 2.7 in your laptop.

Installing Anaconda Python on MacOSX and Linux

  1. Download the Miniconda installation package.
  2. In the shell, execute the installer with

     bash Miniconda-latest-MacOSX-x86_64.sh
  3. You can read and accept the license, and make sure you add the Miniconda path to your $PATH variable (e.g. type 'y' a few times!)

  4. You might need to type source ~/.bash_profile to activate the new $PATH
  5. Type

     conda install numpy scipy matplotlib ipython-notebook gdal
  6. Download the zipped up repository with the notes and practicals from here
  7. Unzip it somewhere
  8. Go to the directory you unzipped and launch the IPython notebook as

     ipython notebook
  9. A new tab or browser window should now pop up

Installing Anaconda Python on Windows

  1. Download the installer for either 64bit or 32bit
  2. Click and install it
  3. On a shell, type

     conda install numpy scipy matplotlib ipython-notebook gdal
  4. Download the zipped up repository with the notes and practicals from here
  5. Unzip it somewhere
  6. Go to the directory you unzipped and launch the IPython notebook as

     ipython notebook
  7. A new tab or browser window should now pop up

IPython notebooks

The practicals have associated code and explanations, and are written in IPython notebooks. That means that the code is there for you to modify and explore. IPython notebooks are edited through a web browser. Text and code are entered through cells. Cells can either be standard text (like this one), entered and formatted using markdown syntax. Code is entered in Code cells, perhaps unsurprisingly.

Some example use of the notebook

In Python, the libraries that will get used need to be imported (i.e. you need to make the system aware that you will be using them). Typically, we will want to use numerical arrays (Numpy), Matplotlib for plotting, and Scipy for a wide range of numerical tools. The latter library is quite large, and we will only import it when it's actually needed. The other two are quite likely to be used, so here's how we invoke them:


In [1]:
import numpy as np
import matplotlib.pyplot as plt
# The next line ensures that your plots are displayed in the notebook
# not in a separate window
%matplotlib inline

In [2]:
x = np.arange ( 0, 2*np.pi, 0.01 )
plt.plot ( x, np.sin(3*x)**5, '-')
plt.plot ( x, np.cos(3*x)**5, '-')
plt.plot ( x, np.sin(1.5*x)**3, '-')

plt.xlabel('The $x$ axis [-]')
plt.ylabel('The $y$ axis [-]')


Out[2]:
<matplotlib.text.Text at 0x7fde8e91de10>