From 42ea96435af4aa16d2fb319b842a89fbd887dd85 Mon Sep 17 00:00:00 2001 From: Matteo Bachetti Date: Mon, 11 Mar 2024 11:31:44 +0100 Subject: [PATCH] Test with missing data --- stingray/pulse/accelsearch.py | 6 +++++- stingray/pulse/tests/test_accelsearch.py | 24 ++++++++++++++++++++++++ 2 files changed, 29 insertions(+), 1 deletion(-) diff --git a/stingray/pulse/accelsearch.py b/stingray/pulse/accelsearch.py index d7c90cd09..8183e7c94 100644 --- a/stingray/pulse/accelsearch.py +++ b/stingray/pulse/accelsearch.py @@ -354,7 +354,11 @@ def accelsearch( dt = times[1] - times[0] n_photons = np.sum(signal) - if gti is not None: + if gti is not None and isinstance(gti, Iterable) and len(gti) > 1: + warnings.warn( + "Data contain multiple GTIs. Bad time intervals will be " + "filled with the mean of the signal." + ) gti = np.asarray(gti) # Fill in the data with a constant outside GTIs gti_mask = create_gti_mask(times, gti) diff --git a/stingray/pulse/tests/test_accelsearch.py b/stingray/pulse/tests/test_accelsearch.py index fe8ec6c88..8fd3d54ca 100644 --- a/stingray/pulse/tests/test_accelsearch.py +++ b/stingray/pulse/tests/test_accelsearch.py @@ -107,3 +107,27 @@ def test_noisy_neg_fdot(self): -self.fdot * self.rescale_fdot, atol=2 * self.dfdot * self.rescale_fdot, ) + + def test_signal_with_gaps(self): + with pytest.warns(UserWarning, match="Data contain multiple GTIs."): + candidate_table = accelsearch( + self.times, + self.signal, + zmax=10, + candidate_file="bubu.csv", + delta_z=0.5, + gti=[[self.tstart, self.tstart + 10], [self.tstart + 20, self.tstop]], + debug=True, + interbin=True, + nproc=1, + ) + best = np.argmax(candidate_table["power"]) + assert np.isclose(candidate_table["frequency"][best], self.freq, atol=5 * self.df) + + print(candidate_table["fdot"][best] * self.rescale_fdot, self.fdot * self.rescale_fdot) + + assert np.isclose( + candidate_table["fdot"][best] * self.rescale_fdot, + self.fdot * self.rescale_fdot, + atol=2 * self.dfdot * self.rescale_fdot, + )