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')

TODO: also show how to work with counts and exposure cube using the example at test_datasets/unbundled/fermi (or make a better one).


gammapy.cube Package

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


compute_npred_cube(flux_cube, exposure_cube, ...) Compute predicted counts cube in energy bins.
make_exposure_cube(pointing, livetime, aeff, ...) Calculate exposure cube.


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.