|
8 | 8 | import os |
9 | 9 | import logging |
10 | 10 | import warnings |
| 11 | +import copy |
11 | 12 | from collections.abc import Iterable |
12 | 13 |
|
13 | 14 | import numpy as np |
@@ -87,7 +88,7 @@ class Lightcurve(StingrayTimeseries): |
87 | 88 | Statistical distribution used to calculate the |
88 | 89 | uncertainties and other statistical values appropriately. |
89 | 90 | Default makes no assumptions and keep errors equal to zero. |
90 | | - |
| 91 | +
|
91 | 92 | At the moment Stingray only uses ``poisson`` err_dist. |
92 | 93 | All analysis in the light curve will assume Poisson errors. |
93 | 94 |
|
@@ -1163,6 +1164,45 @@ def truncate(self, start=0, stop=None, method="index"): |
1163 | 1164 |
|
1164 | 1165 | return super().truncate(start=start, stop=stop, method=method) |
1165 | 1166 |
|
| 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 | + |
1166 | 1206 | def split(self, min_gap, min_points=1): |
1167 | 1207 | """ |
1168 | 1208 | For data with gaps, it can sometimes be useful to be able to split |
|
0 commit comments