stingray icon indicating copy to clipboard operation
stingray copied to clipboard

lc.shift() does not update tstart Lightcurve attribute

Open andresgur opened this issue 8 months ago • 4 comments

Description of the Bug

lc.shift() does not update tstart Lightcurve attribute.

If we agree tstart should be defined as times[0] - dt/2 (see #910 ) I can fix try to fix this. Either we update tstart on the time setter or we just add another line in shift() similar to:

self.tstart = self._time[0] - 0.5 * self.dt[0]

With the new times

Steps/Code to Replicate the Bug

from stingray import Lightcurve
import numpy as np

times = np.arange(50)

mean_flux = 100.0
std_flux = 2.0 
flux = np.random.normal(loc=mean_flux, scale=std_flux, size=len(times))
flux_err = np.ones_like(flux) * std_flux


lc = Lightcurve(times, flux, err=flux_err, err_dist="None", dt=1.0, skip_checks=True)
shifted_lc = lc.shift(100)
print("Old tstart", lc.tstart)
print("Shift tstart", shifted_lc.tstart)
np.testing.assert_equal(shifted_lc.time[0] - shifted_lc.dt/2, lc.time[0] - lc.dt/2)

Expected Results

tstart for shifted and lc should differ after the time shifting.

Actual Results

Old tstart -0.5 Shift tstart -0.5 Traceback (most recent call last): File "/home/andresgur/scripts/pythonscripts/stingray/bug_shift.py", line 17, in np.testing.assert_equal(shifted_lc.time[0] - shifted_lc.dt/2, lc.time[0] - lc.dt/2) File "/home/andresgur/anaconda3/lib/python3.9/site-packages/numpy/testing/_private/utils.py", line 366, in assert_equal raise AssertionError(msg) AssertionError: Items are not equal: ACTUAL: 99.5 DESIRED: -0.5

andresgur avatar Apr 03 '25 23:04 andresgur

Thanks @andresgur !

matteobachetti avatar Apr 05 '25 15:04 matteobachetti

As discussed in #910, tstart should be defined from gtis, not the time attribute, but for the rest I agree that this should be fixed!

matteobachetti avatar Apr 08 '25 07:04 matteobachetti

Hey @matteobachetti , i have a doubt if a lightcurve was shifted then dt should also be changed.

but we are not changing it. correct me if this is bug.

ankitkhushwaha avatar Apr 12 '25 09:04 ankitkhushwaha

@ankitkhushwaha no, shifting does not affect dt

andresgur avatar May 07 '25 12:05 andresgur