gammapy.stats.TimmerKonig_lightcurve_simulator(power_spectrum, npoints, spacing, leakage_protection=1.0, random_state='random-seed', power_spectrum_params=None)[source]#

Implementation of the Timmer-Koenig algorithm to simulate a time series from a power spectrum.


Power spectrum used to generate the time series. It is expected to be a function mapping the input frequencies to the periodogram.


Number of points in the output time series.


Sample spacing, inverse of the sampling rate. The units are inherited by the resulting time axis.

leakage_protectionfloat, optional

Factor by which to multiply the length of the time series to avoid red noise leakage. Default is 1.0.

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

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

power_spectrum_paramsdict, optional

Dictionary of parameters to be provided to the power spectrum function.


Simulated time series.


Time axis of the series in the same units as ‘spacing’. It will be defined with length ‘npoints’, from 0 to ‘npoints’*’spacing’.



“On generating power law noise”, J. Timmer and M, Konig, section 3



To pass the function to be used in the simlation one can use either the ‘lambda’ keyword or an extended definition. Parameters of the function can be passed using the ‘power_spectrum_params’ keyword. For example, these are three ways to pass a power law (red noise) with index 2:

>>> from gammapy.stats import TimmerKonig_lightcurve_simulator
>>> import astropy.units as u
>>> def powerlaw(x):
...     return x**(-2)
>>> def powerlaw_with_parameters(x, i):
...     return x**(-i)
>>> ts, ta = TimmerKonig_lightcurve_simulator(lambda x: x**(-2), 20, 1*u.h)
>>> ts2, ta2 = TimmerKonig_lightcurve_simulator(powerlaw, 20, 1*u.h)
>>> ts3, ta3 = TimmerKonig_lightcurve_simulator(powerlaw_with_parameters,
...                                            20, 1*u.h, power_spectrum_params={"i":2})