SpectrumSimulation

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

Bases: object

Simulate SpectrumObservation.

For a usage example see spectrum_simulation.html

Parameters:

livetime : Quantity

Livetime

source_model : SpectralModel

Source model

aeff : EffectiveAreaTable

Effective Area

edisp : EnergyDispersion, optional

Energy Dispersion

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() Clear all results.
run(seed) Simulate SpectrumObservationList.
simulate_background_counts(rand) Simulate background PHACountsSpectrum.
simulate_obs(obs_id[, seed]) Simulate one SpectrumObservation.
simulate_source_counts(rand) Simulate source PHACountsSpectrum.

Attributes Documentation

e_reco

Reconstructed energy binning.

npred_background

Predicted background (CountsSpectrum).

Calls gammapy.spectrum.utils.CountsPredictor().

npred_source

Predicted source CountsSpectrum.

Calls gammapy.spectrum.utils.CountsPredictor().

Methods Documentation

reset()[source]

Clear all results.

run(seed)[source]

Simulate SpectrumObservationList.

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

Parameters:

seed : array of ints

Random number generator seeds

simulate_background_counts(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.

Parameters:

rand: `~numpy.random.RandomState`

random state

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

Simulate one SpectrumObservation.

The result is stored as obs attribute

Parameters:

obs_id : int

Observation identifier

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

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

simulate_source_counts(rand)[source]

Simulate source PHACountsSpectrum.

Source counts are added to the on vector.

Parameters:

rand: `~numpy.random.RandomState`

random state