Skip to content

Commit

Permalink
Make better test for binned data
Browse files Browse the repository at this point in the history
  • Loading branch information
matteobachetti committed Feb 19, 2024
1 parent 720b50f commit 19d0c15
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
11 changes: 10 additions & 1 deletion stingray/crossspectrum.py
Original file line number Diff line number Diff line change
Expand Up @@ -1573,10 +1573,19 @@ def _initialize_from_any_input(
data1 = data1.apply_gtis(inplace=False)
data2 = data2.apply_gtis(inplace=False)

if hasattr(data1, "counts"):
data1_is_binned = (
"counts" in data1.array_attrs() or "_counts" in data1.internal_array_attrs()
)
data2_is_binned = (
"counts" in data2.array_attrs() or "_counts" in data2.internal_array_attrs()
)

if data1_is_binned and data2_is_binned:
assert data2.time.size == data1.time.size and np.allclose(
data2.time - data1.time, 0
), "Time arrays are not the same"
elif data1_is_binned or data2_is_binned:
raise ValueError("Please use input data of the same kind")

if isinstance(data1, EventList):
spec = crossspectrum_from_events(
Expand Down
9 changes: 9 additions & 0 deletions stingray/tests/test_crossspectrum.py
Original file line number Diff line number Diff line change
Expand Up @@ -724,6 +724,15 @@ def test_make_crossspectrum_diff_lc_counts_shape(self):
with pytest.raises(AssertionError, match="Time arrays are not the same"):
Crossspectrum(self.lc1, lc_)

def test_make_crossspectrum_lc_and_evts(self):
counts = np.array([1] * 10001)
dt = 0.0001
time = np.arange(0.0, 1.0001, dt)
lc_ = Lightcurve(time, counts, gti=[[time[0] - dt / 2, time[-1] + dt / 2]])
ev_ = EventList(time)
with pytest.raises(ValueError, match="Please use input data of the same kind"):
Crossspectrum(ev_, lc_, skip_checks=True)

def test_make_crossspectrum_diff_lc_stat(self):
lc_ = copy.deepcopy(self.lc1)
lc_.err_dist = "gauss"
Expand Down

0 comments on commit 19d0c15

Please sign in to comment.