Python Classes for Loading and Viewing Radio Astronomy Data Cubes
Switch branches/tags
Nothing to show
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Type Name Latest commit message Commit time
Failed to load latest commit information.


Python Classes for Loading and Viewing Radio Astronomy Data Cubes

By Braden MacDonald

Copyright (c) 2011 Braden MacDonald. Released under a BSD License.


This package provides a simple interface for loading radio astronomy data cubes from a FITS file.

Developed for use with Python 2.7


  • Uses PyFITS to load cube data from FITS files in a standardized way.
  • Uses PyWCS to determine the sky coordinates of any data element in the cube in a very easy-to-use way
  • Includes a simple algorithm for determining the standard deviation of noise in the cube as a function of position.
  • Has a CubeViewDialog class that can be used from ipython or other applications to display a data cube, browse through its contents,
    select points from within the cube (uses matplotlib and pygtk), and highlight regions of the cube with different colors
  • Installs a script called, which provides a simple ipython-like interface for quickly viewing a data cube and executing arbitrary commands using the data in the cube (uses matplotlib and pygtk)
  • Also capable of loading artificial data cubes that do not have coordinate information (only "OBJECT", "LINENAME", and "NAXIS" headers are required in the FITS file as of version 0.2).


To install, simply run the following command:

pip install git+git:// 

(Requires that you have pip and distribute installed.)

To install it locally (not system-wide), add a --user argument after "install". To install an editable version, add a -e argument.


Using IPython and pylab to view the spatial noise deviation in a cube:

# Enter these commands into ipython with pylab enabled:
import astrocube
cube = astrocube.DataCube("L1448.13co.fits") # Substitute with your own file
imshow(cube.noise_dev_xy) # n.b. by default the matplotlib y axis is upside-down

Visualizing and interacting with a cube using a simple GUI:

import astrocube
import astrocube.cubeview
import numpy as np
cube = astrocube.DataCube("L1448.13co.fits")  # Substitute with your own file
dialog = astrocube.cubeview.CubeViewDialog(cube)
print("Select a point in the data cube, then close the dialog.")
v = dialog.view # Shorten this for convenience
print("You selected the point ({x},{y},{z})".format(x=v.x,y=v.y,z=v.z))
print("The sky coordinates of that point are: {0}".format(", ".join(cube.point_coords_str(v.x,v.y,v.z))))
print("Now let's look at the most intense value in the data cube.")
(v.x, v.y, v.z) = np.unravel_index(np.nanargmax(,


Cube data is accessed through the .data attribute of the DataCube class. However, the numpy ndarray indices accessible through the DataCube class are standardized to follow Python conventions, not FITS/FORTRAN conventions. This means that the first index is the x axis (right ascension), the second index is the y axis (declination), and the third index is the z axis (spectral dimension). (Exception: when loading data from cubes that do not have coordinate information in the FITS header, the indices are kept in the same order found in the file.)