Skip to content

Commit

Permalink
Test properly
Browse files Browse the repository at this point in the history
  • Loading branch information
matteobachetti committed Dec 3, 2024
1 parent 6d197a2 commit 443da21
Showing 1 changed file with 26 additions and 4 deletions.
30 changes: 26 additions & 4 deletions stingray/tests/test_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -1086,15 +1086,30 @@ def test_change_mjdref(self):
assert np.allclose(new_so.time - 43200, self.sting_obj.time)
assert np.allclose(new_so.gti - 43200, self.sting_obj.gti)

def test_read_timeseries_by_time_intv(self):
@pytest.mark.parametrize("check_gtis", [True, False])
def test_read_timeseries_by_time_intv(self, check_gtis):
reader = FITSTimeseriesReader(self.fname, output_class=DummyStingrayTs)[:]

# Full slice
evs = list(reader.filter_at_time_intervals([80000100, 80001100]))
evs = list(reader.filter_at_time_intervals([80000100, 80001000], check_gtis=check_gtis))
assert len(evs) == 1
ev0 = evs[0]
assert np.all((ev0.time > 80000100) & (ev0.time < 80001100))
assert np.all((ev0.gti >= 80000100) & (ev0.gti < 80001100))
assert np.all((ev0.time > 80000100) & (ev0.time < 80001000))
assert np.all((ev0.gti >= 80000100) & (ev0.gti <= 80001000))
assert np.isclose(ev0.gti[0, 0], 80000100)
assert np.isclose(ev0.gti[-1, 1], 80001000)

def test_read_timeseries_by_time_intv_check_bad_gtis(self):
reader = FITSTimeseriesReader(self.fname, output_class=DummyStingrayTs)[:]

# Full slice
evs = list(reader.filter_at_time_intervals([80000100, 80001100], check_gtis=False))
assert len(evs) == 1
ev0 = evs[0]
assert np.all((ev0.time > 80000100) & (ev0.time < 80001025))
assert np.isclose(ev0.gti[0, 0], 80000100)
# This second gti will be ugly, larger than the original gti boundary
assert np.isclose(ev0.gti[-1, 1], 80001100)

@pytest.mark.parametrize("gti_kind", ["same", "one", "multiple"])
def test_read_apply_gti_lists(self, gti_kind):
Expand All @@ -1115,6 +1130,13 @@ def test_read_apply_gti_lists(self, gti_kind):
# Check that the gtis of the output event lists are the same we input
assert np.allclose(ev.gti, gti_list[i])

def test_read_apply_gti_lists_ignore_empty(self):
reader = FITSTimeseriesReader(self.fname, output_class=DummyStingrayTs)
gti_list = [[], [[80000000, 80000512]], [[80000513, 80001024]]]
evs = list(reader.apply_gti_lists(gti_list))
assert np.allclose(evs[0].gti, gti_list[1])
assert np.allclose(evs[1].gti, gti_list[2])


class TestJoinEvents:
def test_join_without_times_simulated(self):
Expand Down

0 comments on commit 443da21

Please sign in to comment.