Skip to content

Commit 989e62f

Browse files
Merge pull request #971 from swapsha96/fix/911
Update 'tstart' in 'shift' method if present and unit test
2 parents 80f5b0e + 54441df commit 989e62f

4 files changed

Lines changed: 9 additions & 3 deletions

File tree

docs/changes/971.bugfix.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
The ``shift()`` method on ``Lightcurve`` and other ``StingrayTimeseries`` objects updates the ``tstart`` attribute correctly.

docs/contributing.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -418,5 +418,5 @@ Attribution
418418
~~~~~~~~~~~
419419

420420
This Code of Conduct is adapted from the `Contributor
421-
Covenant <http://contributor-covenant.org>`__, version 1.4, available at
422-
`http://contributor-covenant.org/version/1/4 <http://contributor-covenant.org/version/1/4/>`__
421+
Covenant <https://contributor-covenant.org>`__, version 1.4, available at
422+
`https://contributor-covenant.org/version/1/4 <https://contributor-covenant.org/version/1/4/>`__

stingray/base.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1554,7 +1554,7 @@ def change_mjdref(self, new_mjdref: float, inplace=False) -> StingrayTimeseries:
15541554
return ts
15551555

15561556
def shift(self, time_shift: float, inplace=False) -> StingrayTimeseries:
1557-
"""Shift the time and the GTIs by the same amount
1557+
"""Shift the time, GTIs and tstart by the same amount
15581558
15591559
Parameters
15601560
----------
@@ -1583,6 +1583,9 @@ def shift(self, time_shift: float, inplace=False) -> StingrayTimeseries:
15831583
if ts._gti is not None:
15841584
ts._gti = np.asanyarray(ts._gti) + time_shift # type: ignore
15851585

1586+
if hasattr(ts, "tstart") and ts.tstart is not None:
1587+
ts.tstart += time_shift
1588+
15861589
return ts
15871590

15881591
def _operation_with_other_obj(

stingray/tests/test_lightcurve.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1379,8 +1379,10 @@ def test_shift(self):
13791379
lc = Lightcurve(times, counts, input_counts=True)
13801380
lc2 = lc.shift(1)
13811381
assert np.allclose(lc2.time - 1, times)
1382+
assert lc2.tstart == lc.tstart + 1
13821383
lc2 = lc.shift(-1)
13831384
assert np.allclose(lc2.time + 1, times)
1385+
assert lc2.tstart == lc.tstart - 1
13841386
assert np.allclose(lc2.counts, lc.counts)
13851387
assert np.allclose(lc2.countrate, lc.countrate)
13861388
lc = Lightcurve(times, counts, input_counts=False)

0 commit comments

Comments
 (0)