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
- rate
Quantity
Event rate (dimension: 1 / TIME)
- dead_time
Quantity
orTimeDelta
, 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
- time
TimeDelta
Time differences (second) after time zero.
- time
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>