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
You should download and install the Anaconda version that supports Python 2.7 in your laptop.
In the shell, execute the installer with
bash Miniconda-latest-MacOSX-x86_64.sh
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!)
source ~/.bash_profile to activate the new $PATHType
conda install numpy scipy matplotlib ipython-notebook gdal
Go to the directory you unzipped and launch the IPython notebook as
ipython notebook
On a shell, type
conda install numpy scipy matplotlib ipython-notebook gdal
Go to the directory you unzipped and launch the IPython notebook as
ipython notebook
A new tab or browser window should now pop up
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.
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]: