A Tutorial for Astropy

Introduction

A brief history of the Astropy Project

  • Started about 4 years ago
    • Goal to standardize on core set of astronomical libraries
      • And to foster use of standard libraries in Python application and library packages
  • STScI has migrated its standard libraries to astropy and is transitioning to use it for all its released software
  • Very active community
  • Much effort going into consistency and testing
  • Some of the most active members are teaching this tutorial
    • Does not include me...

Not part of Tutorial

  • Intro to Python
    • though this still may be useful if you know no Python
      • i.e., you can see what is possible
  • comprehensive coverage of all of Astropy
    • Just too much in astropy to cover
  • covering other major astronomical tools in Python

Outline of Tutorial

  • Introduction (15 minutes talking / 15 minutes exercise): Perry Greenfield
  • Units/Quantities (15/15): Erik Bray
  • Tables (25/25): Tom Aldcroft

15 minute break

  • Data Access
    • FITS files (20/20): Erik Bray
    • ascii tables (20/20): Tom Aldcroft
  • Coordinates (sky/time) (15/15): Tom Robitaille
  • Astropy work in progress (5): Tom Robitaille

Software Prerequisites

  • astropy 0.4 (0.3.2 will suffice, but coordinates examples will be different in some cases; we wish to teach the new version even if not all have it installed)
  • numpy 1.8.1
  • matplotlib 1.3.1
  • ipython 2.0.0

Easist ways to obtain are:

Anaconda (2.0) http://continuum.io/downloads

The above includes astropy 0.3.2

To update that version to 0.4rc1 (at the OS shell level):

conda install astropy=0.4rc1

IPython Notebook is the basis for tutorial material

  • show of hands: who has never used the IPython notebook?
  • Tutorial notebooks are available from xxx
  • Tutorial-related web pages are at xxx
  • For exercises, note that '-Return' is needed to execute code cell
    • also note that only last item repr is shown (use print for multiple outputs)

To obtain the notebooks used for this tutorial, and the associated data, download:

http://bit.ly/astropy-scipy2014 (~30 MB zip file)

The notebook files themselves can be found under the notebooks/ subdirectory of that zip file. The associated data files are under notebooks/data. Many of the examples references data files with relative filenames like data/<filename>, launch ipython from within the notebooks/ directory for best results in resolving filenames.

Practical Exercises

In general, we will supply enough exercises to fill everyone's time. Depending on background and experience, some will only get the first part or two done; some will get further. The exercises generally increase in sophistication and difficulty. Few will finish all.

For the introduction, the exercises are mainly to see that everything is working and installed on your computer

Level 1

Open the second tutorial session (Unit_Conversion.ipynb). Execute a few code cells

In [1]:
# example code cell
x = 2**10
print x
1024

Level 2

Create a new cell and try the following imports

import numpy as np
import astropy.units as u
import astropy.io.fits as iof
import astropy.wcs as wcs
import astropy.io.ascii as ioa
import astropy.coordinates as coord
import astropy.time as time
import matplotlib.pyplot as plt

IF any of these don't work, ask for help with checking your installation.

Level 3

Try executing the following commands within an ipython notebook cell (requires downloading data files and unpacking. Run these commands from the directory that the files are in):

# assumes above imports have been done
hdus = iof.open('data/msx.fits')
plt.imshow(hdus[0].data, vmax=0.0003, origin='lower')

Level 4

Write a python function to compute the first 10**100 primes in 5 minutes. Select the most interesting one.