Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update tstart and tseg when using Lightcurve.truncate() #753

Merged
merged 3 commits into from
Sep 6, 2023
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions docs/changes/753.bugfix.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Update tstart and tseg when using Lightcurve.truncate()
7 changes: 5 additions & 2 deletions stingray/lightcurve.py
Original file line number Diff line number Diff line change
Expand Up @@ -1243,9 +1243,12 @@ def truncate(self, start=0, stop=None, method="index"):
raise ValueError("Unknown method type " + method + ".")

if method.lower() == "index":
return self._truncate_by_index(start, stop)
new_lc = self._truncate_by_index(start, stop)
else:
return self._truncate_by_time(start, stop)
new_lc = self._truncate_by_time(start, stop)
new_lc.tstart = new_lc.gti[0, 0]
new_lc.tseg = new_lc.gti[-1, 1] - new_lc.gti[0, 0]
return new_lc

def _truncate_by_index(self, start, stop):
"""Private method for truncation using index values."""
Expand Down
9 changes: 9 additions & 0 deletions stingray/tests/test_lightcurve.py
Original file line number Diff line number Diff line change
Expand Up @@ -814,6 +814,8 @@ def test_truncate_by_index(self):
assert np.allclose(lc1.frac_exp, np.array([1, 1, 1]))
np.testing.assert_almost_equal(lc1.gti[0][0], 1.5)
assert lc1.mjdref == lc.mjdref
assert lc1.tstart == 1.5
assert lc1.tseg == 3

lc2 = lc.truncate(stop=2)
assert np.allclose(lc2.time, np.array([1, 2]))
Expand All @@ -824,6 +826,9 @@ def test_truncate_by_index(self):
np.testing.assert_almost_equal(lc2.gti[-1][-1], 2.5)
assert lc2.mjdref == lc.mjdref

assert lc2.tstart == lc.tstart
assert lc2.tseg == 2

def test_truncate_by_time_stop_less_than_start(self):
lc = Lightcurve(self.times, self.counts)

Expand All @@ -843,12 +848,16 @@ def test_truncate_by_time(self):
assert np.allclose(lc1.counts, np.array([2, 2, 2, 2]))
np.testing.assert_almost_equal(lc1.gti[0][0], 0.5)
assert lc1.mjdref == lc.mjdref
assert lc1.tstart == 0.5
assert lc1.tseg == 4.0

lc2 = lc.truncate(stop=3, method="time")
assert np.allclose(lc2.time, np.array([1, 2]))
assert np.allclose(lc2.counts, np.array([2, 2]))
np.testing.assert_almost_equal(lc2.gti[-1][-1], 2.5)
assert lc2.mjdref == lc.mjdref
assert lc2.tstart == 0.5
assert lc2.tseg == 2

def test_split_with_two_segments(self):
test_time = np.array([1, 2, 3, 6, 7, 8])
Expand Down