# modeling - Models and fitting¶

## Introduction¶

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.

## Using gammapy.modeling¶

Gammapy tutorial notebooks that show examples using gammapy.modeling:

## Reference/API¶

### gammapy.modeling Package¶

Models and fitting.

#### Classes¶

 Covariance(parameters[, data]) Parameter covariance class Fit([backend, optimize_opts, …]) Fit class. Parameter(name, value[, unit, scale, min, …]) A model parameter. Parameters([parameters]) Parameters container.

### gammapy.modeling.models Package¶

Built-in models in Gammapy.

#### Functions¶

 create_crab_spectral_model([reference]) Create a Crab nebula reference spectral model. create_cosmic_ray_spectral_model([particle]) Cosmic a cosmic ray spectral model at Earth.

#### Classes¶

 Models([models]) Sky model collection. SkyModel(spectral_model[, spatial_model, …]) Sky model component. FoVBackgroundModel([spectral_model, …]) Field of view background model TemplateNPredModel(map[, spectral_model, …]) Background model. SpatialModel(**kwargs) Spatial model base class. SpectralModel(**kwargs) Spectral model base class. TemporalModel(**kwargs) Temporal model base class. ConstantSpatialModel(**kwargs) Spatially constant (isotropic) spatial model. TemplateSpatialModel(map[, meta, normalize, …]) Spatial sky map template model. DiskSpatialModel(**kwargs) Constant disk model. GaussianSpatialModel(**kwargs) Two-dimensional Gaussian model. Two-dimensional Generealized Gaussian model. PointSpatialModel(**kwargs) Point Source. ShellSpatialModel(**kwargs) Shell model. Shell2SpatialModel(**kwargs) Shell model with outer radius and relative width parametrization ConstantSpectralModel(**kwargs) Constant model. CompoundSpectralModel(model1, model2, operator) Arithmetic combination of two spectral models. PowerLawSpectralModel(**kwargs) Spectral power-law model. PowerLaw2SpectralModel(**kwargs) Spectral power-law model with integral as amplitude parameter. BrokenPowerLawSpectralModel(**kwargs) Spectral broken power-law model. Spectral smooth broken power-law model. PiecewiseNormSpectralModel(energy[, norms, …]) Piecewise spectral correction ExpCutoffPowerLawSpectralModel(**kwargs) Spectral exponential cutoff power-law model. Spectral exponential cutoff power-law model used for 3FGL. Spectral super exponential cutoff power-law model used for 3FGL. Spectral super exponential cutoff power-law model used for 4FGL. LogParabolaSpectralModel(**kwargs) Spectral log parabola model. TemplateSpectralModel(energy, values[, …]) A model generated from a table of energy and value arrays. GaussianSpectralModel(**kwargs) Gaussian spectral model. EBLAbsorptionNormSpectralModel(energy, …) Gamma-ray absorption models. NaimaSpectralModel(radiative_model[, …]) A wrapper for Naima models. ScaleSpectralModel(model[, norm]) Wrapper to scale another spectral model by a norm factor. PowerLawNormSpectralModel(**kwargs) Spectral power-law model with normalized amplitude parameter. LogParabolaNormSpectralModel(**kwargs) Norm spectral log parabola model. Norm spectral exponential cutoff power-law model. ConstantTemporalModel(**kwargs) Constant temporal model. LinearTemporalModel(**kwargs) Temporal model with a linear variation. LightCurveTemplateTemporalModel(table[, …]) Temporal light curve model. ExpDecayTemporalModel(**kwargs) Temporal model with an exponential decay. GaussianTemporalModel(**kwargs) A Gaussian temporal profile PowerLawTemporalModel(**kwargs) Temporal model with a Power Law decay. SineTemporalModel(**kwargs) Temporal model with a sinusoidal modulation.

#### Variables¶

 MODEL_REGISTRY Registry of model classes SPATIAL_MODEL_REGISTRY Registry of spatial model classes. TEMPORAL_MODEL_REGISTRY Registry of temporal models classes. SPECTRAL_MODEL_REGISTRY Registry of spectral model classes.