random_times

gammapy.time.random_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 (dimension: 1 / TIME)

dead_timeQuantity or TimeDelta, optional

Dead time after event (dimension: TIME)

return_diffbool

Return time difference between events? (default: no, return absolute times)

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

Defines random number generator initialisation. Passed to get_random_state.

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.time import random_times
>>> rate = Quantity(10, 'Hz')
>>> times = random_times(size=100, rate=rate, random_state=0)
>>> times[-1]
<TimeDelta object: scale='None' format='sec' value=9.186484131475076>