Skip to content

Commit 7a8a752

Browse files
fix tstart in lightcurve.shift
1 parent 03942ab commit 7a8a752

File tree

1 file changed

+41
-1
lines changed

1 file changed

+41
-1
lines changed

stingray/lightcurve.py

Lines changed: 41 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
import os
99
import logging
1010
import warnings
11+
import copy
1112
from collections.abc import Iterable
1213

1314
import numpy as np
@@ -87,7 +88,7 @@ class Lightcurve(StingrayTimeseries):
8788
Statistical distribution used to calculate the
8889
uncertainties and other statistical values appropriately.
8990
Default makes no assumptions and keep errors equal to zero.
90-
91+
9192
At the moment Stingray only uses ``poisson`` err_dist.
9293
All analysis in the light curve will assume Poisson errors.
9394
@@ -1163,6 +1164,45 @@ def truncate(self, start=0, stop=None, method="index"):
11631164

11641165
return super().truncate(start=start, stop=stop, method=method)
11651166

1167+
def shift(self, time_shift: float, inplace=False):
1168+
"""Shift the time and the GTIs by the same amount
1169+
1170+
Parameters
1171+
----------
1172+
time_shift: float
1173+
The time interval by which the time series will be shifted (in
1174+
the same units as the time array in :class:`StingrayTimeseries`
1175+
1176+
Other parameters
1177+
----------------
1178+
inplace : bool
1179+
If True, overwrite the current time series. Otherwise, return a new one.
1180+
1181+
Returns
1182+
-------
1183+
ts : ``StingrayTimeseries`` object
1184+
The new time series shifted by ``time_shift``
1185+
1186+
"""
1187+
if inplace:
1188+
ts = self
1189+
else:
1190+
ts = copy.deepcopy(self)
1191+
ts.time = ts._time = np.asanyarray(ts.time) + time_shift # type: ignore
1192+
1193+
if isinstance(self.dt, Iterable):
1194+
ts.tstart = ts._time[0] - 0.5 * self.dt[0]
1195+
ts.tseg = ts._time[-1] - ts._time[0] + self.dt[-1] / 2 + self.dt[0] / 2
1196+
else:
1197+
ts.tstart = ts._time[0] - 0.5 * self.dt
1198+
ts.tseg = ts._time[-1] - ts._time[0] + self.dt
1199+
# Pay attention here: if the GTIs are created dynamically while we
1200+
# access the property,
1201+
if ts._gti is not None:
1202+
ts._gti = np.asanyarray(ts._gti) + time_shift # type: ignore
1203+
1204+
return ts
1205+
11661206
def split(self, min_gap, min_points=1):
11671207
"""
11681208
For data with gaps, it can sometimes be useful to be able to split

0 commit comments

Comments
 (0)