Using agnpy radiative processes to fit a MWL SED

agnpy includes sherpa and gammapy wrappers that allow the user to fit the broad-band emission of jetted AGN. The wrappers consider the combination of several radiative processes and return a model object that can be used by the fitting routine of the two packages. In this documentation page, we gather several examples showing how to obtain the best-fit parameters for these models via a \(\chi^2\) minimisation. The data to be fitted are flux points, representing the flux measurement of an instrument in one or more energy bins.

Prerequisites

Note that the agnpy.fit module, containing the wrappers, needs gammapy and sherpa to be installed. These packages are not among the basic dependencies of agnpy and will not be installed automatically if agnpy is installed via conda or pip. Check the documentation of the relative packages for their installation instructions. The following warning message will be printed by agnpy if the packages have not been installed:

WARNING:root:sherpa and gammapy are not installed, the agnpy.fit module cannot be used

In this case, all agnpy modules except agnpy.fit, can be used normally.

Fit using the sherpa wrapper

Fit using the Gammapy wrapper

For Gammapy we show, beside the simple \(\chi^2\) minimisation, how to use a Monte Carlo Markov Chain (MCMC) to perform the fit.

Loading MWL SED data with Gammapy and sherpa

We provide, in agnpy.fit, functions that can directly load flux points in sherpa and Gammapy data objects. The SED format that these functions can read follows the one proposed by the Data Formats for Gamma-ray Astronomy. More specifically, the flux point format that can be currently read by the load_sherpa_flux_points and load_gammapy_flux_points functions has the following mandatory columns:

  • e_ref, representing the energy of the center of the flux points (eV);

  • e2dnde, representing the energy flux (erg / (cm2 s));

  • e2dnde_errn, representing the lower error on the energy flux (erg / (cm2 s));

  • e2dnde_errp, representing the higher error on the energy flux (erg / (cm2 s));

  • instrument, representing the instrument that performed the measurement.