stingray icon indicating copy to clipboard operation
stingray copied to clipboard

err_dist None does not work, and default err_dist contradicts docs

Open andresgur opened this issue 8 months ago • 0 comments

Description of the Bug

Valid statistics for err_dist are:

from stingray.lightcurve import valid_statistics
print(valid_statistics)

['poisson', 'gauss', None]

But None does not work as methods expect a string (see below)

The docs also say:

err_dist: str, optional, default ``None``
    Statistical distribution used to calculate the
    uncertainties and other statistical values appropriately.
    Default makes no assumptions and keep errors equal to zero.

But the default is "poiss"

I propose to default to "none" instead of None, and make "none" one of the valid_statistics intended for None

Steps/Code to Replicate the Bug

You can reproduce the error as:

times = np.arange(1000)

mean_flux = 100.0 # mean flux
std_flux = 2.0 # standard deviation on the flux
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)

You can also use "None" and it won't work either, because is not a keyword in valid_statistics (see below)

Expected Results

No error upon using None

Actual Results

lc = Lightcurve(times, flux, err=flux_err, err_dist=None, dt=1.0, skip_checks=True) File "/home/andresgur/scripts/pythonscripts/stingray/stingray/lightcurve.py", line 278, in init if err_dist.lower() not in valid_statistics: AttributeError: 'NoneType' object has no attribute 'lower'

lc = Lightcurve(times, flux, err=flux_err, err_dist="None", dt=1.0, skip_checks=True)

File "/home/andresgur/scripts/pythonscripts/stingray/stingray/lightcurve.py", line 280, in init raise StingrayError( stingray.exceptions.StingrayError: ('Statistic not recognized.Please select one of these: ', "['poisson', 'gauss', None]")

andresgur avatar Mar 30 '25 11:03 andresgur