Skip to content

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

Open
@andresgur

Description

@andresgur

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugIt's a bug! Unexpected or unwanted behavior.help wantedWe need additional help with these issues!

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions