Skip to content

Commit

Permalink
Test with missing data
Browse files Browse the repository at this point in the history
  • Loading branch information
matteobachetti committed Mar 11, 2024
1 parent 5fdd6c6 commit 42ea964
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 1 deletion.
6 changes: 5 additions & 1 deletion stingray/pulse/accelsearch.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
24 changes: 24 additions & 0 deletions stingray/pulse/tests/test_accelsearch.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
)

0 comments on commit 42ea964

Please sign in to comment.