---
title: 'Gammapy: Open-Source Gamma-Ray Analysis'
url: https://www.emergentmind.com/topics/gammapy
type: topic
---

# Gammapy: Open-Source Gamma-Ray Analysis

Gammapy is an open-source Python package for high-level analysis and simulation of gamma-ray astronomy data. It is designed to provide a common, high-level analysis framework for very-high-energy and high-energy gamma-ray data, taking preprocessed high-level data products—especially event lists and instrument response functions (IRFs)—and turning them into scientifically interpretable results such as images, spectra, light curves, source catalogs, and population simulations. In its v1.0 long-term-support release, it is presented as a community-developed project and as the core science-analysis library selected for the Cherenkov Telescope Array Observatory (CTAO), while remaining useful for current instruments such as H.E.S.S., MAGIC, VERITAS, Fermi-LAT, and HAWC [1509.07408] [2308.13584] [2308.13389].

## 1. Origins, motivation, and scientific setting

Gammapy began as a place to share Python scripts for morphological fitting in the context of the H.E.S.S. Galactic plane survey. It then grew into an Astropy-affiliated package with a broader goal: to become a community-developed, reusable analysis framework for gamma-ray astronomers. From the outset, two objectives were emphasized: support for standard analysis tasks that are common in gamma-ray astronomy, and support for prototyping of new methods through a flexible Python-based workflow [1509.07408].

The scientific motivation came from the rapid growth of gamma-ray astronomy over the past decade, in which H.E.S.S., MAGIC, VERITAS, and Fermi-LAT provided detailed images and spectra of the gamma-ray universe for the first time. CTA was especially important in this context because it was being prepared as an open observatory, increasing the need for accessible, community-driven analysis software. In 2017, Gammapy was explicitly proposed as a prototype for the CTA science tools, with the argument that CTA required software that is open, maintainable over decades, extensible to new methods, and usable by a broad community [1709.01751].

By 2023, the software was described as having come a long way since its start in 2014, with Gammapy v1.0 presented as the first long-term stable release. The same roadmap states that it was selected as the official CTAO Science Analysis tool and was also an approved analysis software within the H.E.S.S. and MAGIC collaborations. This places Gammapy at the intersection of instrument-specific collaboration workflows and a broader move toward open, interoperable high-level data analysis in gamma-ray astronomy [2308.13389].

## 2. Data model, architecture, and workflow

Gammapy sits in the high-level analysis part of gamma-ray astronomy. It is not primarily a low-level reconstruction package; instead, it consumes reduced event data and IRFs and performs scientific modeling, statistical inference, and production of higher-level results. The package architecture mirrors that role through sub-packages for data access, IRFs, maps, makers, datasets, modeling, statistics, estimators, catalog handling, and a higher-level analysis interface [2308.13584].

A central abstraction is the progression from DL3 to DL4. DL3 data are lists of reconstructed gamma-like events together with IRFs. Gammapy reduces these data by binning them in energy and sky coordinates, producing binned counts cubes, exposure maps, and related analysis containers. The package supports WCS maps for regular projected sky images, HEALPix maps for all-sky data, and region maps for aperture-style or one-dimensional spectral analyses. This allows the same framework to be used for pointed observations, wide-field analyses, and region-based spectroscopy [2308.13584].

The response model is factorized as
$$
R(p, E \mid p_{\rm true}, E_{\rm true}) = A_{\rm eff}(p_{\rm true}, E_{\rm true})\, PSF(p \mid p_{\rm true}, E_{\rm true})\, E_{\rm disp}(E \mid p_{\rm true}, E_{\rm true}) .
$$
Here \(A_{\rm eff}\) is the effective area, \(PSF\) the point spread function, and \(E_{\rm disp}\) the energy dispersion. This factorization is the basis for forward-folding likelihood analysis and also underlies the common-data-format philosophy that permits instrument-independent workflows once observations have been reduced to event lists and IRFs [2308.13584].

At the source-model level, Gammapy uses a factorized representation
$$
\phi(\ell, b, E, t) = F(E)\cdot G(\ell, b, E)\cdot H(t, E),
$$
combining spectral, spatial, and temporal components. A plausible implication is that the package was designed from the beginning to support not only classical spectral fitting but also genuinely joint spatial-spectral-temporal inference whenever the relevant dataset and IRFs are available [2308.13584].

## 3. Statistical framework and high-level analysis capabilities

Gammapy is fundamentally a likelihood-based analysis framework. After data reduction, one or more source models are associated with one or more datasets, and the model parameters are estimated by Poisson maximum-likelihood fitting on the reduced data. The expected counts are obtained by forward folding the source model through the effective area, PSF, and energy dispersion, together with the background term. In the v1.0 paper, the Cash statistic is written as
$$
\mathcal{C} = 2 \sum_i \left( N_{\mathrm{Pred},i} - N_{\mathrm{Obs},i}\log N_{\mathrm{Pred},i} \right),
$$
and the package is described as supporting both `cash` and `wstat` statistics, with `wstat` used when background is derived from ON/OFF measurements [2308.13584] [2308.13389].

The analysis capabilities span image analysis, spectral analysis, light-curve analysis, source catalog access and processing, source detection, background estimation and modeling, IRF handling, morphological modeling and fitting, and time-series handling. In early versions, Gammapy also integrated with Sherpa to enable interactive and scripted fitting, including spectral, light-curve, and morphology models, confidence intervals, likelihood profiles, and goodness-of-fit measures. A command-line example from the original overview is `gammapy-sherpa-like`, which performs Poisson maximum-likelihood morphology fitting from FITS inputs [1509.07408].

The v1.0 release formalized these capabilities around dataset classes such as `MapDataset`, `SpectrumDataset`, `MapDatasetOnOff`, `SpectrumDatasetOnOff`, and `FluxPointsDataset`. Higher-level estimators derive flux points, flux maps, significance maps, likelihood or TS maps, flux profiles, and light curves. In the early code base, the `gammapy.detect` module included `compute_ts_map`, a high-performance function for computing test statistic maps for survey data; in later versions, TS maps, likelihood profiles, and light curves were presented as standard products of the framework [1509.07408] [2308.13584].

The package also supports astrophysical modeling beyond purely phenomenological source fitting. The `gammapy.astro` subpackage can simulate Galactic TeV source populations from assumed spatial distributions and population models, and later papers describe interfaces to Naima, dark-matter spatial and spectral models, and user-defined models or likelihoods. This supports both routine analysis and method development within the same software environment [1509.07408] [2308.13389].

## 4. Standardization, interoperability, and validation across instruments

A core idea of Gammapy is that gamma-ray data from different instruments can be treated in a similar way once they are reduced to common high-level data products. This principle is inseparable from the gamma-astro-data-format (GADF), which packages event lists and IRFs in standardized FITS-based form and makes multi-instrument analysis operational in a common analysis layer [1509.07408] [1903.06621].

The 2019 multi-instrument Crab analysis is a canonical demonstration. In that work, Gammapy was used to read, homogenize, and analyze high-level gamma-ray data from Fermi-LAT, MAGIC, VERITAS, FACT, and H.E.S.S., and to perform a joint maximum likelihood spectral fit of the Crab Nebula. The paper’s main result was methodological rather than source-specific: a common data format, open-source tools, and public analysis assets made multi-instrument gamma-ray analyses straightforward and reproducible, and the joint fit had smaller confidence contours than the single-instrument fits [1903.06621].

The same logic was extended to wide-field ground-particle-array data. The HAWC standardization papers show that HAWC event lists and IRFs can be represented in GADF-compliant products and then analyzed with Gammapy. Published HAWC results for the Crab Nebula, eHWC J1907+063, and Mrk 421 were reproduced with excellent agreement, and a joint Crab fit including six different gamma-ray experiments was presented as evidence that a particle detector array could participate in the same open, reproducible joint-likelihood machinery as IACT and satellite data [2109.04097] [2203.05937].

MAGIC standardization provides a further validation layer. MAGIC DL3 products were analyzed with Gammapy and compared against the proprietary MAGIC chain MARS. Counts histograms, effective area, energy dispersion, spectra, and light curves showed good agreement, and the 2025 MAGIC standardization paper frames the chain explicitly as **MARS → magic_dl3 → DL3 FITS → Gammapy analysis**. One technical caveat was identified: the last effective-area point differed because of different interpolation methods in Gammapy and MARS. This is significant because the discrepancy was traced to a specific technical source rather than to a general incompatibility [2302.13615] [2511.23244].

In parallel, the community has been moving from GADF toward the Very-high-energy Open Data Format (VODF). That initiative presents VODF as the shared data language for high-level science-ready, binned, advanced-science, and catalog products, while Gammapy is one of the principal analysis engines designed to exploit that language. This suggests that the software’s long-term role is tied not only to individual observatories but also to the evolving metadata, provenance, and interoperability standards of very-high-energy astrophysics [2308.13385].

## 5. Multiwavelength extension and physical modeling

Although Gammapy was developed for gamma-ray astronomy, later work shows that its likelihood-and-IRF framework can be extended well beyond a gamma-ray-only use case. A strong example is the joint eROSITA and H.E.S.S. analysis of the pulsar wind nebula MSH 15-52. That paper describes custom converters for eROSITA event files and RMFs, construction of effective-area and PSF products, an OnOff background treatment, and a Sherpa wrapper for X-ray spectral models. The authors present the first 3D fit to eROSITA data by using Gammapy and then combine those X-ray data with public H.E.S.S. observations and Fermi catalog flux points in a single Gammapy `Datasets` object for a joint physical fit of the underlying particle population [2510.04857].

The same paper writes the forward-folding count prediction as
$$
N (p,E)\,\mathrm{d}p\,\mathrm{d}E = E_\text{disp}\cdot\big[ PSF \cdot ( A_\text{eff} \cdot t_\text{obs} \cdot \phi ) \big] + Bkg(p,E)\cdot t_\text{obs},
$$
and uses Naima models imported into Gammapy to construct a leptonic synchrotron-plus-inverse-Compton scenario. This is a direct example of Gammapy functioning as a common inference layer for heterogeneous event-level datasets rather than only as a gamma-ray package [2510.04857].

A broader multiwavelength demonstration is the OP 313 study, which uses Gammapy as the common analysis engine for Liverpool Telescope IO:O, Swift-UVOT, Swift-XRT, NuSTAR, and Fermi-LAT. The workflow converts heterogeneous instrument products into Gammapy-compatible high-level datasets: one-dimensional spectra for optical, UV, and X-ray instruments, and a three-dimensional `MapDataset` for Fermi-LAT. The paper argues that this unified forward-folding approach preserves detector responses, background models, and Poisson statistics that would be lost in flux-point-first workflows [2409.20487].

These developments suggest an expansion of Gammapy from a gamma-ray analysis package into a more general high-energy and multiwavelength forward-folding environment, provided that instrument data can be reformulated into compatible high-level products with the necessary response information. That implication is explicit in the multiwavelength papers but remains dependent on instrument-specific conversion layers and validation procedures [2510.04857] [2409.20487].

## 6. Development model, roadmap, and emerging directions

Gammapy has been developed as a community open-source project from the beginning. The 2015 overview describes version v0.3 as alpha-quality software, publicly hosted on GitHub under the BSD license, with GitHub used for code hosting, issues, feature requests, and pull requests, Travis CI for continuous integration and testing, Sphinx for documentation, and Read the Docs for hosted documentation. The authors explicitly invited contributions and described the project as a collaboration hub for scientists doing gamma-ray astronomy with Python [1509.07408].

By the v1.0 and roadmap papers, the software is presented as a mature, lightweight analysis framework with serialized data products that are interoperable with other software. The roadmap highlights an improved API, better Astropy compliance, expanded HAWC tutorials and interoperability, and plans for support of event types, unbinned likelihood analysis, spectral unfolding, transient source detections, distributed computing for scalable analysis, and enhanced support for all-sky instruments like Fermi-LAT and HAWC [2308.13389] [2308.13584].

One historical point is noteworthy. In the 2015 paper, unbinned analyses are not planned. In the 2023 roadmap, support for unbinned likelihood analysis is foreseen. This suggests an evolution in scope from an explicitly binned-analysis framework toward a broader statistical toolkit as user requirements and instrument ecosystems changed [1509.07408] [2308.13389].

Recent work also shows the emergence of Gammapy-specific automation around large language models. The AstroAgent prototype is described as an open-access code-generation service built around Gammapy workflows, using retrieval from Gammapy code, API parts, tutorials, and documentation, and validating generated code on synthetic data or on the H.E.S.S. DL3 public test data release 1. GammapyGPT extends that idea into a generation → execution → validation → repair loop for runnable, validated analysis scripts in a controlled environment [2503.00821] [2509.26110].

At the method level, Gammapy continues to acquire new inference tools. A 2025 paper introduces `EnergyDependentMorphologyEstimator` in Gammapy v1.2, defining a likelihood-ratio test between a global morphology shared across energy bins and independent morphologies fit in each energy bin. Applied to HESS J1825-137 and to a CTAO-simulated compact source, the estimator yielded significances of \(9.8\sigma\) and \(9.7\sigma\), respectively, for energy-dependent morphology. This indicates that the software’s development is not limited to workflow consolidation, but also includes new statistical estimators for source characterization in three-dimensional likelihood analyses [2507.17622].

Source: https://www.emergentmind.com/topics/gammapy