From d9cf21fe923454347945efd79f35153e713c5416 Mon Sep 17 00:00:00 2001 From: Matteo Bachetti Date: Sun, 10 Mar 2024 14:14:47 +0100 Subject: [PATCH 1/5] Fix nphots estimate in accelsearch --- stingray/pulse/accelsearch.py | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/stingray/pulse/accelsearch.py b/stingray/pulse/accelsearch.py index 1b15755ab..ced7bdb36 100644 --- a/stingray/pulse/accelsearch.py +++ b/stingray/pulse/accelsearch.py @@ -353,6 +353,7 @@ def accelsearch( signal = np.asarray(signal) dt = times[1] - times[0] + n_photons = np.sum(signal) if gti is not None: gti = np.asarray(gti) # Fill in the data with a constant outside GTIs @@ -367,7 +368,6 @@ def accelsearch( expo_fraction = 1 gti = np.array([[times[0] - dt / 2, times[-1] + dt / 2]]) - n_photons = np.sum(signal) spectr = fft(signal) * np.sqrt(2 / n_photons) freq = fftfreq(len(spectr), dt) @@ -402,9 +402,7 @@ def accelsearch( start_z = -zmax end_z = zmax range_z = np.arange(start_z, end_z, delta_z) - logger.info( - "min and max possible r_dot: {}--{}".format(delta_z / T**2, np.max(range_z) / T**2) - ) + logger.info("min and max possible r_dot: {}--{}".format(delta_z / T**2, np.max(range_z) / T**2)) freqs_to_search = freq[freq_intv_to_search] candidate_table = Table( From cf1231f5aadef8e2389d54952cd3b2d0ad3e3c5b Mon Sep 17 00:00:00 2001 From: Matteo Bachetti Date: Sun, 10 Mar 2024 14:16:32 +0100 Subject: [PATCH 2/5] Add changelog --- docs/changes/805.bugfix.rst | 1 + 1 file changed, 1 insertion(+) create mode 100644 docs/changes/805.bugfix.rst diff --git a/docs/changes/805.bugfix.rst b/docs/changes/805.bugfix.rst new file mode 100644 index 000000000..8f8786ef6 --- /dev/null +++ b/docs/changes/805.bugfix.rst @@ -0,0 +1 @@ +Fix nphots estimate in accelsearch, that lead to an underestimation of the power of candidates From 5fdd6c6f44653002895736827ca8f190a328420a Mon Sep 17 00:00:00 2001 From: Matteo Bachetti Date: Sun, 10 Mar 2024 14:30:32 +0100 Subject: [PATCH 3/5] Fix formatting --- stingray/pulse/accelsearch.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/stingray/pulse/accelsearch.py b/stingray/pulse/accelsearch.py index ced7bdb36..d7c90cd09 100644 --- a/stingray/pulse/accelsearch.py +++ b/stingray/pulse/accelsearch.py @@ -402,7 +402,7 @@ def accelsearch( start_z = -zmax end_z = zmax range_z = np.arange(start_z, end_z, delta_z) - logger.info("min and max possible r_dot: {}--{}".format(delta_z / T**2, np.max(range_z) / T**2)) + logger.info("min and max r_dot: {}--{}".format(delta_z / T**2, np.max(range_z) / T**2)) freqs_to_search = freq[freq_intv_to_search] candidate_table = Table( From 6c6a67cb9f4163bc63f48ca20a6e758c3dc01ce7 Mon Sep 17 00:00:00 2001 From: Matteo Bachetti Date: Sun, 10 Mar 2024 17:29:31 +0100 Subject: [PATCH 4/5] Rename 805.bugfix.rst to 807.bugfix.rst --- docs/changes/{805.bugfix.rst => 807.bugfix.rst} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename docs/changes/{805.bugfix.rst => 807.bugfix.rst} (100%) diff --git a/docs/changes/805.bugfix.rst b/docs/changes/807.bugfix.rst similarity index 100% rename from docs/changes/805.bugfix.rst rename to docs/changes/807.bugfix.rst From 42ea96435af4aa16d2fb319b842a89fbd887dd85 Mon Sep 17 00:00:00 2001 From: Matteo Bachetti Date: Mon, 11 Mar 2024 11:31:44 +0100 Subject: [PATCH 5/5] 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, + )