Abstract : A collection of python resources for astronomy
Category : Recommended Active
Astropython.org contributor Prasanth has put together a resource list by topic that presents a current view of what is available for astronomers using Python in scientific data analysis. This posting echoes the original blog post content referenced above.
Table of contents
- Basic requirements
- A selection of libraries
- Other interesting python libraries for astronomy
- Libraries for interacting with other applications
- Performing specific tasks
- Read, manipulate and write tabular data in various formats
- Plots and annotated images
- Performing astrometry calculations
- Mathematical and scientific calculations
- Calling C, Fortran and IDL code
- Creating graphical and command line user interfaces
- Command line interfaces
- Graphical interfaces
- Accessing VO resources
- Creating documentation
- Miscellaneous modules
- Information sources on using python in scientific data analysis
- Learning python
When installing non-python packages, make sure that in addition to the package itself, development libraries and header files, if available, are also installed.
There are a few python "distributions" that come with almost all these packages, and their dependencies, and only some of the astronomy specific packages need to be installed separately. Another advantage of of using these distributions is that the python installation that comes with the operating system can be left as it is. But on the other hand they may not be available for all operating systems.
Some python distributions i.e., python + libraries, are:
Free for academic usage.
Available only for windows. This is the easiest way for windows users to setup a good python environment for scientific computing.
Contains a set of python libraries, in addition to a very large collection of non-python astronomy software. The ESO version is available only for Fedora 11. A version for Mac OS X is available at http://web.mac.com/npirzkal/Scisoft/Scisoft.html
The STScI python library is a collection of several astronomy libraries. It includes some of the astronomy related packages mentioned below. Astrolib is another project aimed at developing python modules for astronomy.
In the following, the words libraries, modules and packages are all used to indicate a collection of related python code.
Any version of python >= 2.5 should be compatible with most of the astronomy packages. But python 3.x series does not have wide support at this time. It is not compatible with python 2.x and it will take a while for most packages to become available for python 3.x. But note that numpy 1.5.0 and asciitable 0.3.1 work with python 3.x.
- C and Fortran compilers
Get the latest version of gcc.
- C and Fortran libraries
Readline is a must for efficient interaction at the terminal.
Python tkinter module provides interface to Tcl/Tk that allows building graphical user interfaces.
- PIL : Python Imaging Library
PIL is a python library for performing image manipulations. It can be used to read and write images in various formats, apply various transformations to the image data and other such operations.
A library for creating GUIs. This is a python binding for the wxWidgets library. This is used by matplotlib as one of its backends.
The main feature provided by numpy is the ability to work with multidimensional arrays in an efficient manner. This forms the basis for carrying out mathematical calculations, such as those related to histograms, correlations, linear algebra etc., . Scipy, for example, builds upon these facilities provided by numpy to create higher level scientific and mathematical routines.
This is an excellent substitute for the default python shell. Perhaps the most attractive part of this shell is the ability to list the contents of a module or object. For example, after importing the math module, we can type math. and press the tab key, to get a list of members of the module. The command math.sin? will print the docstring for the function sin in the math module. The %cpaste magic command, allows code to be pasted into the shell, which would otherwise result in indentation errors.
- setuptools and/or pip
These two tools allow easy installation of python packages.
Many packages can be installed using the commands:
pip install <package-name>
These commands will download the required files and install the packages.
A selection of libraries
This library provides facilities for reading, manipulating and writing FITS files.
This library can be used for managing astronomical coordinate systems. Ultimately, this library aims to provide facilities needed by astronomers for planning and preparing for observing runs.
It currently provides facilities for coordinate conversions and is under development.
- astroasciidata, vo.table, asciitable and ATpy
Together with pyfits, these libraries provide comprehensive facilities for dealing with the variety of tables used in storing astronomical data. For example, asciitable can read data from tables in the CDS format provided by VizieR and ApJ. ATpy can read daophot data files.
- pyraf, urwid and pmw
This library provides an interface to the DS9 image display program. Numdisplay can also interact with the ximtool image display program.
There is another package, pyds9, from the developers of DS9, that provides the similar functionality.
Matplotlib is a 2D plotting library, with some 3D plotting functionality.
APLpy builds on matplotlib, and allows creation of production-quality plots of astronomical imaging data in FITS format. Some of the features provided are overlaying coordinate grids, 3-color RGB image display, contours and markers etc., .
A collection of modules for handling World Coordinate System transformations, coordinate conversions, handling FITS files, plotting and others. It also has a module for parsing and interpreting coordinate information entered as strings.
- PyEphem, pyslalib and pytpm
PyEphem can be used to get quick answers to questions such as, Which constellation is Jupiter in tonight?, What is the rising/setting time for Moon, at a particular location?, What is the current Julian Date?. It also has methods for coordinate conversion, finding sidereal time and others. PyEphem has built-in ephemerides for major planets and can read ephemerides in various formats.
PyEphem uses C routines from the XEphem package and a copy of the C library is included with the source code.
Pyslalib is a python interface to the SLALIB fortran library. This can be used to perform lower level astrometry calculations such as, direction between points on a sphere, conversion between Cartesian and spherical coordinates and also higher level computations such as calculation of Julian Dates. It also has functions to process sexagesimal string into angles, converting radians into degrees, arcminutes and arcseconds and other.
This module comes with a version of the SLALIB fortran library.
Pytpm is an interface to Jeff Percival‘s Telescope Pointing Machine C library. This library is similar to SLALIB in that it provides functions for performing astrometry calculations, but differs from SLALIB in adopting a "state machine" approach to performing these calculations. An end user can perform coordinate conversion calculations without having to deal with the details of the procedure, such as the order of applying individual routines. One call to a function, specifying the starting "state" and end "state" is all that is required for performing the appropriate conversion.
Pytpm includes a copy of the TPM C library that is part of the coords package.
Together with Kapteyn, these three modules provide most of the facilities for performing astrometry calculations.
- Scipy and ScientificPython
Modules implementing various algorithms for scientific computing.
Sphinx generates formatted documentation from text documents written in the reStructuredText format. This module can read "docstrings" from python code and include them in the final document. It incorporates several features such as running "doctests" in python code, producing plots by running python code, links to source files and others. Most of these functionalities are provided using "sphinx extensions". Source code for matplotlib, matplotlib sampledoc tutorial and the sphinxcontrib collection include many such extensions, in addition to those that come with sphinx.
This is a framework for writing tests for python code. It can find unit tests in python source files and execute them. It provides various other features for performing test on python code.
Libraries pyfits, pywcs, pyraf, pysynphot, and numdisplay are, along with many other libraries, bundled with the stsci_python collection. Sphinx and nose are not astronomy specific packages. Sphinx is used for creating documentation and nose is a framework for carrying out unittests. Both of these, documentation and testing, are integral to any software project and hence they are included here.
Other interesting python libraries for astronomy
Astronomical Interferometry in PYthon is a collection of tools for radio astronomical interferometry.
- astLib and pyWCSTools
Another collection of python code for astronomy, including coordinate conversions, WCS manipulations and so on.
Software for pulsar search and analysis.
RO is a collection of scripts, written by Russel Owen of University of Washington in Seattle, providing Tkinter GUI extensions, Tkinter-compatible networking, astronomical calculations such as coordinate conversion, time related functions and so on. It includes a module for interacting with DS9.
This is a library for accessing the CHIANTI database and calculating various quantities of interest.
Sherpa is a modelling and fitting package that is part of Chandra Interactive Analysis of Observations software suite. It uses IPython as its user interface and is also importable as a module from within python.
Libraries for interacting with other applications
- rpy and rpy2 provide interfaces to the R software environment.
- python-montage is an interface to the IPAC montage software.
- pymidas is an interface to ESO-MIDAS.
- pyraf can be used to call NOAO IRAF tasks from python.
- pygrace is an interface to the Grace plotting tool.
- pIDLy, and pyIDL allow interaction with IDL. IDLSave can read
IDL "save" files.
- ppgplot can be used to call pgplot library functions from python.
- pygipsy allows the usage of python as the scripting language for GIPSY.
- GDL has an interface to python and can also be installed as a python module.
- CASA is integrated with python.
- ParselTongue is a python interface to AIPS.
- pygildas is aimed at "interleaving Python and GILDAS".
Performing specific tasks
Some libraries for performing tasks such as reading tabular data, creating plot, calling C libraries and so on.
Read, manipulate and write tabular data in various formats
- ASCII tables
- SExtractor tables
Use astroasciidata. The meta-data stored in SExtractor tables are also read in by this module and can be accessed from within python, using the various facilities provided by AstroAsciiData.
- FITS tables
- VO tables
- Tables from SQLite, MySQL and PostgreSQL.
- HDF5 tables
- CDS format tables, and Vizier and ApJ machine readable tables
The asciitable module can read ascii files in these formats.
Plots and annotated images
A library for creating, mainly, 2D plots.
- APLpy and Kapteyn
Two libraries for creating plots and annotated images.
A library for 3D data visualization.
This module can be used for calling Gnuplot from python.
- rpy and rpy2
These provide access to the R software environment, including plotting facilities.
This module allows calling functions in the pgplot library from python.
Pygrace provides an interface to the GRACE plotting library.
A plotting application toolkit that is part of the Enthought Tool Suite.
A scientific plotting and graphing package, with a graphical user interface.
Performing astrometry calculations
There are several libraries that provide functions for performing astrometry calculations. These are Kapteyn, pytpm, pyslalib , coords, RO, astLib, astropysics and PyEphem. Only PyEphem provides facilites for handling ephemerides of solar system objects and calculating quantities such as rise and set times of these objects.
Calling C, Fortran and IDL code
Use pyraf interface to IRAF and pyIDL and pIDLy interfaces to IDL. pysynphot can be used for synthetic photometry and spectrum manipulation. The library tfit is a photometry package, but is currently not maintained.
Creating graphical and command line user interfaces
This module provides cog integration, using which code included in documentation source can be executed and the result included in the final document. For more such functionality see the programoutput sphinx extension at http://bitbucket.org/birkenfeld/sphinx-contrib/. Sphinx has an extension that can insert matplotlib plots generated from running code in an external file or embedded in the documentation source. Interesting experiments in "literate programming" with python are pyreport and Pweave.
Information sources on using python in scientific data analysis
- AstroPy mailing list
- A good introduction to numpy is available at http://mentat.za.net/numpy/intro/intro.html.
- Interactive Data Analysis in Astronomy
This is an extensive tutorial, by Perry Greenfield and Robert Jedrzejewski, on the usage of python for interactive data analysis in astronomy. It also serves as a resource for learning python.
- Python Scripting for Computational Science
This is a book on the usage of python for data analysis and scripting. This book is not directly targeted at astronomical data analysis but is aimed at general scientific data analysis.
This book is written by Hans Petter Langtangen
- Software Carpentry
Not specific to astronomy, but a great resource for learning about methodologies in scientific computing, with focus on python.
Information on setting up a python enviroment for scienctific calculations, written by Fernando Pérez of UC Berkeley. This document also includes links to books, web pages, videos and other resources for learning python.
FOSSEE stands for Free and Open source Software for Science and Engineering Education. It is a project based at the Indian Institute of Technology, Bombay (IITB) and is funded by the Ministry of Human Resource Department, of the Government of India. The project focus at IITB is on the use of "Scilab and python in the area of numerical computing".
- Some courses concentrating on python for astronomy data analysis