{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# Flux point fitting in Gammapy\n", "\n", "\n", "## Introduction\n", "\n", "In this tutorial we're going to learn how to fit spectral models to combined Fermi-LAT and IACT flux points.\n", "\n", "The central class we're going to use for this example analysis is: \n", "\n", "- [gammapy.spectrum.FluxPointFitter](http://docs.gammapy.org/0.7/api/gammapy.spectrum.FluxPointFitter.html)\n", "\n", "In addition we will work with the following data classes:\n", "\n", "- [gammapy.spectrum.FluxPoints](http://docs.gammapy.org/0.7/api/gammapy.spectrum.FluxPoints.html)\n", "- [gammapy.catalog.SourceCatalogGammaCat](http://docs.gammapy.org/0.7/api/gammapy.catalog.SourceCatalogGammaCat.html)\n", "- [gammapy.catalog.SourceCatalog3FHL](http://docs.gammapy.org/0.7/api/gammapy.catalog.SourceCatalog3FHL.html)\n", "- [gammapy.catalog.SourceCatalog3FGL](http://docs.gammapy.org/0.7/api/gammapy.catalog.SourceCatalog3FGL.html)\n", "\n", "And the following spectral model classes:\n", "\n", "- [PowerLaw](http://docs.gammapy.org/0.7/api/gammapy.spectrum.models.PowerLaw.html)\n", "- [ExponentialCutoffPowerLaw](http://docs.gammapy.org/0.7/api/gammapy.spectrum.models.ExponentialCutoffPowerLaw.html)\n", "- [LogParabola](http://docs.gammapy.org/0.7/api/gammapy.spectrum.models.LogParabola.html)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Setup\n", "\n", "Let us start with the usual IPython notebook and Python imports:" ] }, { "cell_type": "code", "execution_count": 1, "metadata": {}, "outputs": [], "source": [ "%matplotlib inline\n", "import numpy as np\n", "import matplotlib.pyplot as plt" ] }, { "cell_type": "code", "execution_count": 2, "metadata": {}, "outputs": [], "source": [ "from astropy import units as u\n", "from astropy.table import vstack\n", "from gammapy.spectrum.models import PowerLaw, ExponentialCutoffPowerLaw, LogParabola\n", "from gammapy.spectrum import FluxPointFitter, FluxPoints\n", "from gammapy.catalog import SourceCatalog3FGL, SourceCatalogGammaCat, SourceCatalog3FHL" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Load spectral points\n", "\n", "For this analysis we choose to work with the source 'HESS J1507-622' and the associated Fermi-LAT sources '3FGL J1506.6-6219' and '3FHL J1507.9-6228e'. We load the source catalogs, and then access source of interest by name:" ] }, { "cell_type": "code", "execution_count": 3, "metadata": {}, "outputs": [], "source": [ "fermi_3fgl = SourceCatalog3FGL()\n", "fermi_3fhl = SourceCatalog3FHL()\n", "gammacat = SourceCatalogGammaCat()" ] }, { "cell_type": "code", "execution_count": 4, "metadata": {}, "outputs": [], "source": [ "source_gammacat = gammacat['HESS J1507-622']\n", "source_fermi_3fgl = fermi_3fgl['3FGL J1506.6-6219']\n", "source_fermi_3fhl = fermi_3fhl['3FHL J1507.9-6228e']" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "The corresponding flux points data can be accessed with `.flux_points` attribute:" ] }, { "cell_type": "code", "execution_count": 5, "metadata": {}, "outputs": [ { "data": { "text/html": [ "Table length=6\n", "
e_ref | dnde | dnde_errn | dnde_errp |
---|---|---|---|
TeV | 1 / (cm2 s TeV) | 1 / (cm2 s TeV) | 1 / (cm2 s TeV) |
float32 | float32 | float32 | float32 |
0.8609 | 2.29119e-12 | 8.70543e-13 | 8.95502e-13 |
1.56151 | 6.98172e-13 | 2.20354e-13 | 2.30407e-13 |
2.76375 | 1.69062e-13 | 6.7587e-14 | 7.18838e-14 |
4.8916 | 7.72925e-14 | 2.40132e-14 | 2.60749e-14 |
9.98858 | 1.03253e-14 | 5.06315e-15 | 5.64195e-15 |
27.0403 | 7.44987e-16 | 5.72089e-16 | 7.25999e-16 |