diff --git a/stingray/fourier.py b/stingray/fourier.py index f3aae7a2f..011818c75 100644 --- a/stingray/fourier.py +++ b/stingray/fourier.py @@ -2058,17 +2058,17 @@ def lsft_slow( ft_res : numpy.ndarray An array of Fourier transformed data. """ - y_ = copy.deepcopy(y) - np.mean(y) - freqs = freqs[freqs >= 0] + y_ = y - np.mean(y) + freqs = np.asarray(freqs[np.asarray(freqs) >= 0]) ft_real = np.zeros_like(freqs) ft_imag = np.zeros_like(freqs) ft_res = np.zeros_like(freqs, dtype=np.complex128) - num_y = len(y_) - num_freqs = len(freqs) + num_y = y_.shape[0] + num_freqs = freqs.shape[0] sum_y = np.sum(y_) - const1 = np.sqrt(0.5) * np.sqrt(num_y) + const1 = np.sqrt(0.5 * num_y) const2 = const1 * np.sign(sign) ft_real = ft_imag = np.zeros(num_freqs) ft_res = np.zeros(num_freqs, dtype=np.complex128) diff --git a/stingray/lombscargle.py b/stingray/lombscargle.py index 7096611ef..4756815a2 100644 --- a/stingray/lombscargle.py +++ b/stingray/lombscargle.py @@ -476,17 +476,9 @@ def _initialize_empty(self): self.variance2 = None return - def phase_lag(self): - """Not applicable for unevenly sampled data""" - raise AttributeError( - "Object has no attribute named 'phase_lag' ! Not applicable for unevenly sampled data" - ) - def time_lag(self): - """Not applicable for unevenly sampled data""" - raise AttributeError( - "Object has no attribute named 'time_lag' ! Not applicable for unevenly sampled data" - ) + super().__doc__ + return self.phase_lag() / (2 * np.pi * self.freq) def classical_significances(self): """Not applicable for unevenly sampled data""" diff --git a/stingray/tests/test_fourier.py b/stingray/tests/test_fourier.py index 7cb787b59..582837619 100644 --- a/stingray/tests/test_fourier.py +++ b/stingray/tests/test_fourier.py @@ -545,9 +545,11 @@ def test_unnormalize_poisson_noise(self, norm, power_type): @pytest.mark.parametrize("phlag", [0.05, 0.1, 0.2, 0.4]) def test_lag(phlag): - freq=1.1123232252 + freq = 1.1123232252 + def func(time, phase=0): return 2 + np.sin(2 * np.pi * (time * freq - phase)) + time = np.sort(np.random.uniform(0, 100, 3000)) ft0 = lsft_slow(func(time, 0), time, np.array([freq])) ft1 = lsft_slow(func(time, phlag), time, np.array([freq])) @@ -556,9 +558,9 @@ def func(time, phase=0): measured_lag -= 0.5 while measured_lag <= -0.5: measured_lag += 0.5 - + print(measured_lag) - assert np.isclose((np.angle(ft1) - np.angle(ft0)) / 2 / np.pi, phlag, atol=0.01) + assert np.isclose((np.angle(ft1) - np.angle(ft0)) / 2 / np.pi, phlag, atol=0.02, rtol=0.02) def test_lsft_slow_fast(): diff --git a/stingray/tests/test_lombscargle.py b/stingray/tests/test_lombscargle.py index 5c48c2dbe..4672befd7 100644 --- a/stingray/tests/test_lombscargle.py +++ b/stingray/tests/test_lombscargle.py @@ -158,8 +158,6 @@ def test_valid_method(self, method): @pytest.mark.parametrize( "func_name", [ - "phase_lag", - "time_lag", "classical_significances", "from_time_array", "from_events",