SpectrumEvaluator

class gammapy.spectrum.SpectrumEvaluator(model, aeff=None, edisp=None, livetime=None, e_true=None)[source]

Bases: object

Calculate number of predicted counts (npred).

The true and reconstructed energy binning are inferred from the provided IRFs.

Parameters:
model : SpectralModel

Spectral model

aeff : EffectiveAreaTable

EffectiveArea

edisp : EnergyDispersion, optional

EnergyDispersion

livetime : Quantity

Observation duration (may be contained in aeff)

e_true : Quantity, optional

Desired energy axis of the prediced counts vector if no IRFs are given

Examples

Calculate predicted counts in a desired reconstruced energy binning

from gammapy.irf import EnergyDispersion, EffectiveAreaTable
from gammapy.spectrum import models, SpectrumEvaluator
import numpy as np
import astropy.units as u
import matplotlib.pyplot as plt

e_true = np.logspace(-2, 2.5, 109) * u.TeV
e_reco = np.logspace(-2, 2, 73) * u.TeV

aeff = EffectiveAreaTable.from_parametrization(energy=e_true)
edisp = EnergyDispersion.from_gauss(e_true=e_true, e_reco=e_reco,
                                    sigma=0.3, bias=0)

model = models.PowerLaw(index=2.3,
                        amplitude="2.5e-12 cm-2 s-1 TeV-1",
                        reference="1 TeV")

livetime = 1 * u.h

predictor = SpectrumEvaluator(model=model,
                              aeff=aeff,
                              edisp=edisp,
                              livetime=livetime)
predictor.compute_npred().plot_hist()
plt.show()

(png, hires.png, pdf)

../_images/gammapy-spectrum-SpectrumEvaluator-1.png

Methods Summary

apply_aeff(self, integral_flux)
apply_edisp(self, true_counts)
compute_npred(self)
integrate_model(self) Integrate model in true energy space

Methods Documentation

apply_aeff(self, integral_flux)[source]
apply_edisp(self, true_counts)[source]
compute_npred(self)[source]
integrate_model(self)[source]

Integrate model in true energy space