class gammapy.spectrum.SpectrumSimulation(livetime, source_model, aeff=None, edisp=None, e_true=None, background_model=None, alpha=None)[source]

Bases: object

Simulate SpectrumObservation.

For a usage example see spectrum_simulation.html

livetime : Quantity


source_model : SpectralModel

Source model

aeff : EffectiveAreaTable, optional

Effective Area

edisp : EnergyDispersion, optional

Energy Dispersion

e_true : Quantity, optional

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

background_model : SpectralModel, optional

Background model

alpha : float, optional

Exposure ratio between source and background

Attributes Summary

e_reco Reconstructed energy binning.
npred_background Predicted background (CountsSpectrum).
npred_source Predicted source CountsSpectrum.

Methods Summary

reset(self) Clear all results.
run(self, seed) Simulate list of SpectrumDatasetOnOff.
simulate_background_counts(self, rand) Simulate background PHACountsSpectrum.
simulate_obs(self, obs_id[, seed]) Simulate one SpectrumObservation.
simulate_source_counts(self, rand) Simulate source PHACountsSpectrum.

Attributes Documentation


Reconstructed energy binning.


Predicted background (CountsSpectrum).

Calls gammapy.spectrum.utils.SpectrumEvaluator().


Predicted source CountsSpectrum.

Calls gammapy.spectrum.utils.SpectrumEvaluator().

Methods Documentation


Clear all results.

run(self, seed)[source]

Simulate list of SpectrumDatasetOnOff.

The seeds will be set as observation ID. Previously produced results will be overwritten.

seed : array of ints

Random number generator seeds

simulate_background_counts(self, rand)[source]

Simulate background PHACountsSpectrum.

Background counts are added to the on vector. Furthermore background counts divided by alpha are added to the off vector.

TODO: At the moment the source IRFs are used. Make it possible to pass dedicated background IRFs.

rand : RandomState

random state

simulate_obs(self, obs_id, seed='random-seed')[source]

Simulate one SpectrumObservation.

The result is stored as obs attribute

obs_id : int

Observation identifier

seed : {int, ‘random-seed’, ‘global-rng’, RandomState}

see :func:~`gammapy.utils.random.get_random_state`

simulate_source_counts(self, rand)[source]

Simulate source PHACountsSpectrum.

Source counts are added to the on vector.

rand : RandomState

random state