Example #1
0
    def test_read():
        model = SkyDiffuseCube.read(
            "$GAMMAPY_DATA/tests/unbundled/fermi/gll_iem_v02_cutout.fits")
        assert model.map.unit == "cm-2 s-1 MeV-1 sr-1"

        # Check pixel inside map
        val = model.evaluate(0 * u.deg, 0 * u.deg, 100 * u.GeV)
        assert val.unit == "cm-2 s-1 MeV-1 sr-1"
        assert val.shape == (1, )
        assert_allclose(val.value, 1.396424e-12, rtol=1e-5)
Example #2
0
def diffuse_model():
    axis = MapAxis.from_nodes([0.1, 100],
                              name="energy",
                              unit="TeV",
                              interp="log")
    m = Map.create(npix=(4, 3),
                   binsz=2,
                   axes=[axis],
                   unit="cm-2 s-1 MeV-1 sr-1",
                   coordsys="GAL")
    m.data += 42
    return SkyDiffuseCube(m)
Example #3
0

# In[ ]:


psf_kernel.psf_kernel_map.sum_over_axes().plot(stretch="log", add_cbar=True);


# ## Background
# 
# Let's compute a background cube, with predicted number of background events per pixel from the diffuse Galactic and isotropic model components. For this, we use the use the [gammapy.cube.MapEvaluator](http://docs.gammapy.org/dev/api/gammapy.cube.MapEvaluator.html) to multiply with the exposure and apply the PSF. The Fermi-LAT energy dispersion at high energies is small, we neglect it here.

# In[ ]:


model = SkyDiffuseCube(diffuse_galactic)

evaluator = MapEvaluator(model=model, exposure=exposure, psf=psf_kernel)

background_gal = counts.copy(data=evaluator.compute_npred())
background_gal.sum_over_axes().plot()
print("Background counts from Galactic diffuse: ", background_gal.data.sum())


# In[ ]:


model = SkyModel(SkyDiffuseConstant(), diffuse_iso)

evaluator = MapEvaluator(model=model, exposure=exposure, psf=psf_kernel)
Example #4
0
covariance = result.parameters.covariance
spec.parameters.covariance = covariance[2:5, 2:5]

energy_range = [0.3, 10] * u.TeV
spec.plot(energy_range=energy_range, energy_power=2)
ax = spec.plot_error(energy_range=energy_range, energy_power=2)

# Apparently our model should be improved by adding a component for diffuse Galactic emission and at least one second point source.

# ### Add Galactic diffuse emission to model

# We use both models at the same time, our diffuse model (the same from the Fermi file used before) and our model for the central source. This time, in order to make it more realistic, we will consider an exponential cut off power law spectral model for the source. We will fit again the normalisation and tilt of the background.

# In[ ]:

diffuse_model = SkyDiffuseCube.read(
    "$GAMMAPY_DATA/fermi-3fhl-gc/gll_iem_v06_gc.fits.gz")

background_diffuse = BackgroundModel.from_skymodel(diffuse_model,
                                                   exposure=maps["exposure"],
                                                   psf=psf_kernel)

# In[ ]:

background_irf = BackgroundModel(maps["background"], norm=1.0, tilt=0.0)
background_total = background_irf + background_diffuse

# In[ ]:

spatial_model = SkyPointSource(lon_0="-0.05 deg", lat_0="-0.05 deg")
spectral_model = ExponentialCutoffPowerLaw(
    index=2 * u.Unit(""),