Using Python to Read and Plot Data


Before Class

Python is an interactive and extensible programming language. It has extensions to load data from FITS files, process data using compact code without loops, and display plots on the screen. During this project, you will become familiar with the basics of python and some of the particulars about handling data in python.

Python is free software. So, if you want to work on learning python outside of class, you can obtain it via the links and the end of this page. Note that we will use Python 2.7 and not Python 3 (this is because matplotlib only recently added Python 3 support and we don't want to change yet). We will use a number of python packages to read FITS files and display data. You'll be using python heavily during the semester, so it would be good to install it on a computer that you have access to outside of class (like a laptop if you own one).

If you are using a Windows machine or a Mac, we suggest using Anaconda, which eases the installation process and includes most of the needed python packages. To download Anaconda, use this link http://continuum.io/downloads. You'll also need to install pyfits by going to this page http://www.stsci.edu/institute/software_hardware/pyfits/Download

If you use a Linux machine, you can either use Anaconda or do a straight install of python using whatever package manager your system comes with. You will need to install the NumPy, matplotlib, ipython, and pyfits packages separately, which is very easy for distributions like Ubuntu. For those using remote access to orfeo, the required software is already installed.

You will need a text editor to edit the python programs. Matt prefers to edit .py files using gedit. On windows machines, Notepad messes up the formatting, while Wordpad is ok. On Ubuntu (including orfeo), gedit should be installed by default and is pretty nice. Most other text editors work just fine. You should have a text editor on your machine before class and have loaded henley.py (see below) into it to make sure it looks ok.

We will analyze a data file that contains the oxygen line emission measured for different sky fields by Henley and Shelton (2012).
Follow the link to the Henley and Shelton (2012) paper and find the 'Online Data' link. This link brings you to a page of links to online data cited in the paper. Many papers place their large tables online through the Vizier Catalogue Service. Go there to find Tables 1, 2, and 4 of this paper. Make a directory on your machine call hs2012 and download all three tables in fits format. Have a look at the files using fv and check that they look ok.

Instructions

Write a python program to read in the table of oxygen emission lines strengths from Henley and Shelton (2012). Plot the line intensities and their ratio versus Galactic latitude and longitude. Discuss the implications of your results for the geometry of the halo emission. You may wish to address what can be learned from repeated observations of the same field. This should be done individually and handed in individually.

What to hand in

Read the Henley and Shelton (2012) paper. Using the given Python code as a starting point, write your own program that will plot the line intensities and their ratio versus Galactic latitude and longitude. Discuss the implications of your results for the geometry of the halo emission. You may wish to address what can be learned from repeated observations of the same field.


Resources for learning Python

The resources below are a good place to start. If you want to do something specific in python, a good first step is to search on the internet, e.g. try searching for 'python median'.

Python 2.7 Download: http://www.python.org/download/releases/2.7.8/
Interactive, online tutorial: http://www.codecademy.com/tracks/python
PyFITS documentation: http://pythonhosted.org/pyfits/
NumPy tutorial: http://www.scipy.org/Tentative_NumPy_Tutorial
Matplotlib tutorial: http://matplotlib.org/users/pyplot_tutorial.html
Python official web site: http://www.python.org/
PyFits official site: http://www.stsci.edu/institute/software_hardware/pyfits
Question and answer site for programming: http://stackoverflow.com