ObservationEventSampler#

class gammapy.datasets.ObservationEventSampler(random_state='random-seed', oversample_energy_factor=10, t_delta=<Quantity 0.5 s>, keep_mc_id=True, n_event_bunch=10000, dataset_kwargs=None)[source]#

Bases: MapDatasetEventSampler

Sample event lists for a given observation and signal models.

Signal events are sampled from the predicted counts distribution given by the product of the sky models and the expected exposure. They are then folded with the instrument response functions. To improve performance, IRFs are evaluated on a pre-defined binning, not at each individual event energy / coordinate.

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

Defines random number generator initialisation via the get_random_state function.

oversample_energy_factorint, optional

Defines an oversampling factor for the energies; it is used only when sampling an energy-dependent time-varying source. Default is 10.

t_deltaQuantity, optional

Time interval used to sample the time-dependent source. Default is 0.5 s.

keep_mc_idbool, optional

Flag to tag sampled events from a given model with a Montecarlo identifier. Default is True. If set to False, no identifier will be assigned.

n_event_bunchint

Size of events bunches to sample. If None, sample all events in memory. Default is 10000.

dataset_kwargsdict, optional

Arguments passed to create_map_dataset_from_observation()

Methods Summary

event_det_coords(observation, events)

Add columns of detector coordinates (DETX-DETY) to the event list.

event_list_meta(dataset, observation[, ...])

Event list meta info.

run(observation[, models, dataset_name])

Sample events for given observation and signal models.

sample_background(dataset)

Sample background.

sample_edisp(edisp_map, events)

Sample energy dispersion map.

sample_psf(psf_map, events)

Sample PSF map.

sample_sources(dataset)

Sample source model components.

Methods Documentation

static event_det_coords(observation, events)#

Add columns of detector coordinates (DETX-DETY) to the event list.

Parameters:
observationObservation

In memory observation.

eventsEventList

Event list.

Returns:
eventsEventList

Event list with columns of event detector coordinates.

static event_list_meta(dataset, observation, keep_mc_id=True)#

Event list meta info. Please, note that this function will be updated in the future.

Parameters:
datasetMapDataset

Map dataset.

observationObservation

In memory observation.

keep_mc_idbool

Flag to tag sampled events from a given model with a Montecarlo identifier. Default is True. If set to False, no identifier will be assigned.

Returns:
metadict

Meta dictionary.

run(observation, models=None, dataset_name=None)[source]#

Sample events for given observation and signal models.

The signal distribution is sampled from the given models in true coordinates and energy. The true quantities are then folded with the IRFs to obtain the observable quantities.

Parameters:
observationObservation

Observation to be simulated.

modelsModels, optional

Models to simulate. Can be None to only sample background events. Default is None.

dataset_namestr, optional

If models contains one or multiple FoVBackgroundModel it should match the dataset_name of the background model to use. Default is None.

Returns
——-
observationObservation

A copy of the input observation with event list filled.

sample_background(dataset)#

Sample background.

Parameters:
datasetMapDataset

Map dataset.

Returns:
eventsgammapy.data.EventList

Background events.

sample_edisp(edisp_map, events)#

Sample energy dispersion map.

Parameters:
edisp_mapEDispMap

Energy dispersion map.

eventsEventList

Event list with the true energies.

Returns:
eventsEventList

Event list with reconstructed energy column.

sample_psf(psf_map, events)#

Sample PSF map.

Parameters:
psf_mapPSFMap

PSF map.

eventsEventList

Event list.

Returns:
eventsEventList

Event list with reconstructed position columns.

sample_sources(dataset)#

Sample source model components.

Parameters:
datasetMapDataset

Map dataset.

Returns:
eventsEventList

Event list.