Kapteyn Institute Kapteyn Package


The Kapteyn Package is a collection of Python modules and applications developed by the computer group of the Kapteyn Astronomical Institute, University of Groningen, The Netherlands. The purpose of the package is to provide tools for the development of astronomical applications with Python.

The package is suitable for both inexperienced and experienced users and developers and documentation is provided for both groups. The documentation also provides in-depth chapters about celestial transformations and spectral translations.

Some of the package’s features:

  • The handling of spatial and spectral coordinates, WCS projections and transformations between different sky systems. Spectral translations (e.g., between frequencies and velocities) are supported and also mixed coordinates. (Modules wcs and celestial)
  • Versatile tools for writing small and dedicated applications for the inspection of FITS headers, the extraction and display of (FITS) data, interactive inspection of this data (color editing) and for the creation of plots with world coordinate information. (Module maputils) As one example, a gallery of all-sky plots is provided.
  • A class for the efficient reading, writing and manipulating simple table-like structures in text files. (Module tabarray)
  • Utilities for use with matplotlib such as obtaining coordinate information from plots, interactively modifiable colormaps and timer events (module mplutil); tools for parsing and interpreting coordinate information entered by the user (module positions).


The following modules are included:

  • wcs, a binary module which handles spatial and spectral coordinates and provides WCS projections and transformations between different sky systems. Spectral translations (e.g., between frequencies and velocities) are supported and also mixed coordinates.
  • celestial, containing NumPy-based functions for creating matrices for transformation between different celestial systems. Also a number of other utility functions are included.
  • wcsgrat, for calculating parameters for WCS graticules. It does not require a plot package.
  • maputils. Provides methods for reading FITS files. It can extract 2-dim image data from data sets with three or more axes. A class is added which prepares FITS data to plot itself as an image with Matplotlib.
  • positions, enabling a user/programmer to specify positions in either pixel- or world coordinates.
  • rulers, defining a class for drawing rulers.
  • shapes, defining a class for interactively drawing shapes that define an area in an image. For each area a number of properties of the data is calculated. This module can duplicate a shape in different images using transformations to world coordinates. This enables one for instance to compare flux in two images with different WCS systems.
  • mplutil, utilities for use with matplotlib. Classes AxesCallback, providing a more powerful mechanism for handling events from LocationEvent and derived classes than matplotlib provides itself; TimeCallback for handling timer events and VariableColormap which implements a matplotlib Colormap subclass with special methods that allow the colormap to be modified.
  • kmpfit, providing a class and a function for non-linear least-squares fitting, using the Levenberg-Marquardt technique. It is based on the implementation in C of Craig Markwardt’s MPFIT.
  • tabarray, providing a class for the efficient reading, writing and manipulating simple table-like structures in text files.


To install the Kapteyn Package, at least Python [1] 2.4 and NumPy [2] (both with header files) are required. For using it, the availability of PyFITS [3] or Astropy [4] and matplotlib [5] is recommended. Windows users may also need to install Readline [6] or an equivalent package.

Mark Calabretta’s WCSLIB [7] does not need to be installed separately anymore. Its code is now included in the Kapteyn Package under the GNU Lesser General Public License.


The Kapteyn Package and the example scripts can be downloaded via links on the package’s homepage: http://www.astro.rug.nl/software/kapteyn/


First unpack the downloaded .tar.gz or .zip file and go to the resulting directory. Then one of the following options can be chosen:

  1. Install into your Python system (you usually need root permission for this):

    python setup.py install
  2. If you prefer not to modify your Python installation, you can create a directory under which to install the module e.g., mydir. Then install as follows:

    python setup.py install --install-lib mydir

    To use the package you then need to include mydir in your PYTHONPATH.

  3. If you want to use this package only for GIPSY, you can install it as follows:

    python setup.py install --install-lib $gip_exe

    The GIPSY installation procedure normally does this automatically, so usually this will not be necessary.

Windows installer

An experimental installer for Microsoft Windows (together with other packages that the Kapteyn Package depends on) is also available. Currently only for Python 2.6 on 32-bit systems. http://www.astro.rug.nl/software/kapteyn_windows/

Scisoft problem

If you have Scisoft installed on your computer, it may interfere with the installation of the Kapteyn Package. To install it properly, disable the setup of Scisoft in your startup file (e.g. ~/.cshrc, .profile) by commenting it out.

Mac OS X Compiler problem

There is a known problem with Apple’s llvm-gcc-4.2 compiler. This compiler is known to crash with an internal compiler error (Segmentation fault: 11) when WCSLIB routine wcserr.c is compiled. For this reason, setup.py tries to detect this compiler and use the clang compiler instead. If compilation still fails, one could try to prefix a shell variable definition to the install command like this:

export CC=CLANG; python setup.py install ...

Table Of Contents

Please cite the Kapteyn Package if you use it in the preparation of a publication. These citations help us to justify the resources spent on this software.