TimmerKonig_lightcurve_simulator#

gammapy.stats.TimmerKonig_lightcurve_simulator(power_spectrum, npoints, spacing, nchunks=10, random_state='random-seed', power_spectrum_params=None, mean=0.0, std=1.0, poisson=False)[source]#

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

Parameters:
power_spectrumfunction

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

npointsint

Number of points in the output time series.

spacingQuantity

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

nchunksint, optional

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

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

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.

meanfloat, Quantity, optional

Desired mean of the final series. Default is 0.

stdfloat, Quantity, optional

Desired standard deviation of the final series. Default is 1.

poissonbool, optional

Whether to apply poissonian noise to the final time series. Default is False.

Returns:
time_seriesndarray

Simulated time series.

time_axisQuantity

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

References

[Timmer1995]

“On generating power law noise”, J. Timmer and M, Konig, section 3 https://ui.adsabs.harvard.edu/abs/1995A%26A…300..707T/abstract

Examples

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})