A new set of map and cube classes is being developed in gammapy.maps and long-term will replace the existing gammapy.image.SkyImage and gammapy.cube.SkyCube classes. Please consider trying out gammapy.maps and changing your scripts to use those new classes. See Data Structures for Images and Cubes (gammapy.maps).

Cube Style Analysis (gammapy.cube)


The cube module bundles functionality for combined spatial and spectral analysis (cube style analysis) of gamma-ray sources.

Some information on cube style analysis in gamma-ray astronomy can be found here:

Getting Started

Use SkyCube to read a Fermi-LAT diffuse model cube:

>>> from gammapy.cube import SkyCube
>>> filename = '$GAMMAPY_EXTRA/test_datasets/unbundled/fermi/gll_iem_v02_cutout.fits'
>>> cube =, format='fermi-background')
>>> print(cube)
Sky cube flux with shape=(30, 21, 61) and unit=1 / (cm2 MeV s sr):
 n_lon:       61  type_lon:    GLON-CAR         unit_lon:    deg
 n_lat:       21  type_lat:    GLAT-CAR         unit_lat:    deg
 n_energy:    30  unit_energy: MeV

Use the cube methods to do computations:

import astropy.units as u
emin, emax = [1, 10] * u.GeV
image = cube.sky_image_integral(emin=emin, emax=emax)'ds9')

Using gammapy.cube

Gammapy tutorial notebooks that show examples using gammapy.cube:


gammapy.cube Package

Sky cubes (3-dimensional: energy, lon, lat).


compute_npred_cube(flux_cube, exposure_cube, …) Compute predicted counts cube.
compute_npred_cube_simple(flux_cube, …) Compute predicted counts cube (using a simple method).
make_background_cube(pointing, obstime, bkg, …) Calculate background predicted counts cube.
make_exposure_cube(pointing, livetime, aeff, …) Calculate exposure cube.


CombinedModel3D(spatial_model, spectral_model) Combine spatial and spectral model into a 3D model.
SingleObsCubeMaker(obs, empty_cube_images, …) Compute SkyCube images for one observation.
SkyCube([name, data, wcs, energy_axis, meta]) Sky cube with dimensions lon, lat and energy.
SkyCubeImages([name, images, wcs, energy, meta]) Class to represent connection between SkyImage and SkyCube.
StackedObsCubeMaker(empty_cube_images[, …]) Compute stacked cubes for many observations.