edit · print · PDF

Please note that all the SIEpedia's articles address specific issues or questions raised by IAC users, so they do not attempt to be rigorous or exhaustive, and may or may not be useful or applicable in different or more general contexts.

Python for astronomers

Python is becoming one the most used interpreted languages for data analysis, competing directly with well-stablish comercial solutions as Matlab or IDL. Apart from its simple syntax and very smooth learning curve, the main adventage of Python is that you can use it virtually for everything, having modules for database interaction, web development, parallel computing and a long etcetera. Of course, there mature scientific and mathematical libraries.

Beeing Python so extensive, its easy to get lost with all the posible modules and its documentation, because there're many options to do the same. Differing from monilitic-packages as IDL or Matlab, where you have one plotting library, one GUI library, a standard IDE (integrated Development Eviroment) and so on, all with a common documentation, in Python, as with any general use programming language, you have to choose the modules you need and install them, refering to the documentation of each module separatley.

In this guide you will find which are the most common packages and documentation for astronomy and where to obtain them.

The basics

Obiusly first you need Python itsef. If you are using GNU/Linux or a Mac, its already installed by default on this systems. If you have Windows you can install the official package or the Python(x,y) project (recomended) which apart from Python includes the most common scientific packages and tools.

Scientific packages

The main scientific package is Scipy, which includes ODE solvers, linear algebra libraries, interpolation, optimization, etc. Scipy requires Numpy, a powerfull arrays library.

  • Scipy - The main scientific library
  • Numpy - Arrays manipulation library
  • Matplotlib - 2D (and basic 3D) plotting library
  • IPython - An advanced interactive console

From GNU/Linux, you can try to obtain this packages using the package installer of your distribution (apt-get in Ubuntu/Debian, yum in Fedora or YAST in SUSE). The Python(x,y) package (Windows only) includes all this.

Astronomy packages

It depends on what you want to do, but the most used package for astronomy are:

  • Astropython - A knowledge base for research in astronomy using Python
  • Pyfits - FITS images and tables manipulation
  • Astrolib modules - Some packages for astronomy, incuding coords (for celestial coordinates manipulation), asciidata (ascii data tables) and pyWCS a WCSLib wrapper (in alpha state, so far)
  • PyRAF - A command language for IRAF writted in Python. It also enable to call IRAF tasks from Python. Requires IRAF.
  • APLpy - Astronomical Plotting Library with matplotlib
  • ATpy - Astronomical tables library. It supports several formats including Fits, VOtable, IPAC, SQL, etc.
  • Asciitable - ASCII table reader
  • Kapteyn Package - A very complete and well documented collection of libraries from the Kapteyn Astronomical Institute. It includes coordinate and WCS manipulation, tables and plotting utilities.
  • astLib - An astronomical library with modules for coordinates, plotting, statistics and more.
  • pywcsgrid2 - Astronomical plotting with matplotlib.
  • SAMPy - A SAMP implementation for Python.
  • pyregion - A ds9 region files parser.
  • CosmoPy - A cosmology package.
  • idlsave - An IDL's "save" file format reader (to numpy types). Do not requires IDL.
  • python-sao - A Python interface to ds9.
  • Astropysics - Astrophysics utilities for python
  • astrogui - FITS data reduction package (still in alpha phase)
  • cosmics.py - L.A.Cosmic algorithm implementation in Python (for cosmic ray detection)
  • Alipy - Tool for align a set of dithered FITS images (using pyraf and sextractor)
  • Chantipy - A Python interface to the CHIANTI atomic database for astrophysical spectroscopy
  • python-montage - A Python wrapper for montage
  • NTV - FITS image viewer, similar to atv for idl
  • pyTMP - python interface to the TPM (Telescope Pointing Machine) library

Other usefull packages

  • Sympy - Impresive symbolic calculus module
  • Mayavi - A powerfull 3D data visualizer (Matplotlib cannot do only make simple 3D plots)
  • f2py - Fortran to Python interface creator

Documentation

If you don't know anything about Python, just begin with official tutorial, its breaf and clear. Then, the main reference for astronomers is the Perry Greenfield and Robert Jedrzejewski's Using Python for interactive data analysis in astronomy tutorial, which covers the Python's basics and all the important astronomical packages with many examples (many thanks Perry and Robert!). Remenber that the reference website for scientific packages and documentation is Scipy.org.

Here are documentation of the main scientific packages:

Video tutorials and demostrations

edit · print · PDF
Page last modified on September 03, 2010, at 03:54 PM