sample_times#

gammapy.utils.random.sample_times(size, rate, dead_time=<TimeDelta object: scale='None' format='sec' value=0.0>, return_diff=False, random_state='random-seed')[source]#

Make random times assuming a Poisson process.

This function can be used to test event time series, to have a comparison what completely random data looks like.

Can be used in two ways (in either case the return type is TimeDelta):

  • return_delta=False - Return absolute times, relative to zero (default)

  • return_delta=True - Return time differences between consecutive events.

Parameters:
sizeint

Number of samples.

rateQuantity

Event rate.

dead_timeQuantity or TimeDelta, optional

Dead time after event.

return_diffbool

Return time difference between events. Default False, return absolute times.

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

Defines random number generator initialisation. Passed to get_random_state. Default is “random-seed”.

Returns:
timeTimeDelta

Time differences (second) after time zero.

Examples

Example how to simulate 100 events at a rate of 10 Hz. As expected the last event occurs after about 10 seconds.

>>> from astropy.units import Quantity
>>> from gammapy.utils.random import sample_times
>>> rate = Quantity(10, 'Hz')
>>> times = sample_times(size=100, rate=rate, random_state=0)
>>> times[-1]
<TimeDelta object: scale='None' format='sec' value=9.186484131475074>