Matt Craig, Professor of Physics and Astronomy at Minnesota State University Moorhead, has created this list of Astropy affiliated packages to help improve your experience exploring astronomy using Python. This post was inspired by Ole Moeller-Nilsson’s recent blog post on how to get started doing astronomy with open data and Python.

One of the things I both love and hate about Python is that there is almost always more than one way to get a job done. When I first switched to Python I found that really frustrating. Of the three (or four or five or six) astronomy packages, which one was “the” package to use? Or was I supposed to use the more fundamental tools, like Numpy or SciPy? Now that I’ve been using Python for a few years, I’ve come to appreciate the diversity of tools.

I was reminded of this by a recent NumFOCUS blog post about doing astronomy with Python and open data which outlined how to use several fundamental packages to do image reduction and photometry. Here I’ll give an overview of several high-level packages for doing astronomy that are Astropy affiliated packages; these are packages that follow the same coding, documentation and testing conventions as the core astropy package. The full list of affiliated packages is on the Astropy project’s website.

I’ll give a quick overview of the packages and then wrap up with some installation instructions. I’ve only mentioned each package once in the description below, even though several really cross categories.

Some good news/bad news before we start: there are almost thirty affiliated packages, and there are many very good astronomy-related packages that are not affiliated packages. The menu of interesting Python packages only seems to increase.

Optical/IR image processing


Reduced, reprojected, stacked image with overlay of sources detected by photutils (gray circles) and two catalogs from Vizier. Courtesy of ccdproc, astropscrappy, reproject, photutils, and astroquery.


More specialized, but in the same genre, is python-cpl, a python interface to recipes of the ESO data reduction pipeline.

Once you’ve calibrated your images, photutils can be used to do source detection and aperture and PSF photometry. If you need to stack those images first, try reproject which can align them for you if the images have WCS headers.

You probably want to look at all of those nice images you are working with, so up next is…

Image viewers and plotting helpers

ginga provides by a “reference” viewer and the libraries for making your own image viewer or for customizing the reference viewer. If you use IRAF you should check out imexam, which duplicates the functionality of the IRAF tool of the same name.

Coming soon to a notebook near you: ginga-based image viewer widget…


APLpy (pronounced “apple pie”) makes it easy to prepare publication-quality plots of images with lots of options for annotating them or overlaying additional information. Finally, montage-wrapper provides a python interface to the Montage image mosaic system (Montage itself is developed and maintained by IPAC and is not an affiliated package).

There are two packages for interacting with regions on the sky: pyregion, which handles ds9 and ciao region files and helps you overlay them on matplotlib images, and the more general regions, which is still in the very early stages of development. Rounding out this category is spherical-goemetry for representing spherical polygons on the sky.


Though it can display images, glueviz is really a much more general tool. It allows you create links between plots so that you can, say, select stars on part of a color-magnitude diagram and see those points highlighted on an image of the region containing those stars.

Optical spectroscopy

The specutils package provides tools for working with 1-D spectra; it is undergoing rapid development, described in detail in a proposal for the future of spectroscopy in astropy, but currently provides tools for reading and writing spectra in a variety of formats, and for performing common operations. A couple of packages in the early stages of developments (they are not affiliated packages yet) are specreduce, for reducing spectra, and specviz for viewing those spectra.

omnifit performs spectroscopic fitting of interstellar ices.

Finally, gwcs is being developed both to handle celestial for the James Webb Space Telescope and to provide a framework for spectral coordinates. It provides a framework for carrying out a sequence of transforms from one set of coordinates to another.


As a former theorist myself, it is exciting to see so many theory and simulation packages. If you want to do galactic dynamics in python, galpy is for you; it includes a wide variety of potentials and sampling of distribution functions.

asro-gala, which also does gravitational dynamics, contains several general-purpose integrators and tools for carrying out several coordinate and velocity transforms in our galaxy.

cluster-lensing computes galaxy cluster halo properties and weak lensing profiles.

If a single cluster isn’t enough for you, use halotools to construct your own mock universe. Given a set of dark matter halos from a simulation, it can populate those halos with galaxies and make measurements on them.

Crossover appeal

A few packages don’t fit neatly into a single category.

One is astroML which contains a variety of astronomy-related machine learning tools, and even has an