Modeling and Fitting (DL4 to DL5)#

gammapy.modeling contains all the functionality related to modeling and fitting data. This includes spectral, spatial and temporal model classes, as well as the fit and parameter API.

Assuming you have prepared your gamma-ray data as a set of Dataset objects, and stored one or more datasets in a Datasets container, you are all set for modeling and fitting. Either via a YAML config file, or via Python code, define the Models to use, which is a list of SkyModel objects representing additive emission components, usually sources or diffuse emission, although a single source can also be modeled by multiple components if you want. The SkyModel is a factorised model with a SpectralModel component and a SpatialModel component. Most commonly used models in gamma-ray astronomy are built-in, see the Model gallery. It is easy to create user-defined models and datasets, Gammapy is very flexible.

The Fit class provides methods to fit, i.e. optimise parameters and estimate parameter errors and correlations. It interfaces with a Datasets object, which in turn is connected to a Models object, which has a Parameters object, which contains the model parameters. Currently iminuit is used as modeling and fitting backend, in the future we plan to support other optimiser and error estimation methods, e.g. from scipy. Models can be unique for a given dataset, or contribute to multiple datasets and thus provide links, allowing e.g. to do a joint fit to multiple IACT datasets, or to a joint IACT and Fermi-LAT dataset. Many examples are given in the tutorials.

Built-in models#

Gammapy provides a large choice of spatial, spectral and temporal models. You may check out the whole list of built-in models in the Model gallery.

Custom models#

Gammapy provides an easy interface to Implementing a custom model.

Using gammapy.modeling#

Examples using gammapy.modeling.Fit#

Low level API

Low level API

Low level API
Fermi-LAT with Gammapy

Fermi-LAT with Gammapy

Fermi-LAT with Gammapy
Spectral analysis of extended sources

Spectral analysis of extended sources

Spectral analysis of extended sources
Flux point fitting

Flux point fitting

Flux point fitting
Spectral analysis

Spectral analysis

Spectral analysis
Spectral analysis with energy-dependent directional cuts

Spectral analysis with energy-dependent directional cuts

Spectral analysis with energy-dependent directional cuts
1D spectrum simulation

1D spectrum simulation

1D spectrum simulation
3D detailed analysis

3D detailed analysis

3D detailed analysis
Multi instrument joint 3D and 1D analysis

Multi instrument joint 3D and 1D analysis

Multi instrument joint 3D and 1D analysis
Basic image exploration and fitting

Basic image exploration and fitting

Basic image exploration and fitting
Event sampling

Event sampling

Event sampling
3D map simulation

3D map simulation

3D map simulation
Simulating and fitting a time varying source

Simulating and fitting a time varying source

Simulating and fitting a time varying source
Pulsar analysis

Pulsar analysis

Pulsar analysis
Fitting

Fitting

Fitting