An introduction to scientific computing with Python
Postgraduate Course — Summer, 2009
Outline
Part 1: Introduction
- Why (and why not) to use a modern, high-level, scripting language
- Why Python is awesome
- Introduction to the language
- startup, syntax, constructs, functions, classes, getting help
- Good programming practice versus ‘thinking aloud’
- Python 2.x versus 3.x
Part 2: Scientific programming in Python
- Arrays – Numerical Python
- Using arrays wisely
- Plotting
- Scientific Python
- optimisation, interpolation, statistics, filtering, integration, …
- Other tools
- GNU Scientific Library, R, …
Part 3: Python for observers
- Handling FITS files
- PyRAF – scripting IRAF with Python
Lectures
- Tue 7 July 1pm CAPT A113
- Tue 14 July 1pm CAPT A113
- Tue 21 July 1pm CAPT A113
The slides accompanying the lectures are available as a PDF below. Please let me know if you find any mistakes.
Installing software
New fangled all-in-one stuff
Having poked my head out and looked around in preparing for this course, I now appear to be a bit old school using Emacs + Bash + Python + Scipy + Numpy + Matplotlib + etc. all installed separately. There are some all-in-one packages that look good:
- EPD: http://www.enthought.com/products/epd.php
- python(x,y): http://www.pythonxy.com
- Ipython: http://ipython.scipy.org/
- any more you might find…
These don’t currently don’t seem to include stsci_python, so this will need to be installed separately. However, if someone wants to suggest it, they may consider including it. Another issue is that they don’t appear to have general Linux support, but rather they are specific to one or two distributions.
If anyone has success with these packages, I’d really like to hear about it!
Your Linux distribution package manager
Python will certainly be available to install from your Linux pakage manager (e.g. Yast in Suse), hopefully a reasonably recent version. You may find Numpy, Scipy and Matplotlib in there too. However, you will probably need to install stsci_python manually (if you need to interface with IRAF, use FITS files or display in DS9).
Python
If you are using a Linux or Mac OSX system, you probably already have Python installed. However, sometimes it can be quite an old version that the operating system uses. Typing ‘python’ at the command prompt will start the interpreter and tell you the version. At time of writing the recommended version for scientific computing is 2.5.4. Versions older than 2.5 may work with the scientific tools, but their may be problems. The same is currently true for versions 2.6+ (although the very latest version of Scipy 0.7.1 claims to work with Python 2.6, so give it a try if you are feeling brave). Python 3.x has undergone some major changes and will not be compatible with many scientific tools for some time.
Get the recommended version of Python here: http://www.python.org/download/releases/2.5.4/
Installation should be quite straightforward. When it is installed, typing ‘python’ at the command prompt should indicate the correct version. If it does not, then you need to either make sure the new python executable is in your path ahead of the old one, or create an alias.
Numpy and Scipy
Get the latest versions (currently Numpy 1.3.0 and Scipy 0.7.1) from here: http://scipy.org/Download
Again, installation should be straightforward, either by installation package on OSX or Windows, or by one or two commands on Linux (see the README).
Matplotlib
I claimed that this was included in Scipy. I think it was once, but doesn’t seem to be now. Anyway, it should be easy to install if you’ve managed Scipy.
Get it here: http://matplotlib.sourceforge.net/
stsci_python
This provides PyFITS, PyRAF and Numdisplay.
Get it from: http://www.stsci.edu/resources/software_hardware/pyraf/stsci_python
Finding help
Python documentation
- Homepage
- Latest documentation (but not for recommended version)
- Documentation for current recommended version (2.5.4): http://www.python.org/doc/2.5.4/
- Library reference (useful): http://www.python.org/doc/2.5.4/lib/
- Library reference index (very useful): http://www.python.org/doc/2.5.4/lib/genindex.html
