From 19c618e18f46bcd26ae75a54c17dbfa0498dad32 Mon Sep 17 00:00:00 2001 From: Daniela Huppenkothen Date: Wed, 29 May 2019 16:39:56 -0700 Subject: [PATCH] Fixed bug in simulating light curves from PSDs given as arrays --- stingray/simulator/simulator.py | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/stingray/simulator/simulator.py b/stingray/simulator/simulator.py index 1730dbcca..c65f54c7b 100644 --- a/stingray/simulator/simulator.py +++ b/stingray/simulator/simulator.py @@ -67,6 +67,9 @@ def simulate(self, *args): * x = simulate(s): For generating a light curve from user-provided spectrum. + **Note**: In this case, the `red_noise` parameter is provided. + You can generate a longer light curve by providing a higher + frequency resolution on the input power spectrum. Parameters: * s : array-like @@ -370,7 +373,10 @@ def _simulate_power_spectrum(self, s): a1 = self.random_state.normal(size=len(s)) a2 = self.random_state.normal(size=len(s)) - lc = self._find_inverse(a1*s, a2*s) + real = a1 * np.sqrt(s) + imaginary = a2 * np.sqrt(s) + + lc = self._find_inverse(real, imaginary) lc = Lightcurve(self.time, self._extract_and_scale(lc), err_dist='gauss', dt=self.dt) @@ -401,7 +407,7 @@ def _simulate_model(self, model): # Compute PSD from model simpsd = model(simfreq) - fac = np.sqrt(simpsd/2.) + fac = np.sqrt(simpsd) pos_real = self.random_state.normal(size=nbins//2)*fac pos_imag = self.random_state.normal(size=nbins//2)*fac @@ -443,7 +449,7 @@ def _simulate_model_string(self, model_str, params): else: raise ValueError('Params should be list or dictionary!') - fac = np.sqrt(simpsd/2.) + fac = np.sqrt(simpsd) pos_real = self.random_state.normal(size=nbins//2)*fac pos_imag = self.random_state.normal(size=nbins//2)*fac