From 443da21e6164287207abaffa5c9643b814afecb0 Mon Sep 17 00:00:00 2001 From: Matteo Bachetti Date: Tue, 3 Dec 2024 14:56:49 +0100 Subject: [PATCH] Test properly --- stingray/tests/test_base.py | 30 ++++++++++++++++++++++++++---- 1 file changed, 26 insertions(+), 4 deletions(-) diff --git a/stingray/tests/test_base.py b/stingray/tests/test_base.py index 3c0073177..1879dffb2 100644 --- a/stingray/tests/test_base.py +++ b/stingray/tests/test_base.py @@ -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): @@ -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):