Skip to content

FitManager with uncertainties should not be "pre-declared" #4590

@kif

Description

@kif

While trying to follow this tutorial:
https://www.silx.org/doc/silx/latest/Tutorials/fit.html#fitting-gaussians

I stumbled upon a bug, or at least a very unexpected behaviour:

from silx.math.fit.functions import sum_gauss
from silx.math.fit import fittheories
from silx.math.fit.fitmanager import FitManager
result = results["CdTe:Si"]
print(len(result.radial), len(result.intensity), len(result.sigma))
>>> 4000 4000 4000
fit = FitManager()
# fit.fitconfig["WeightFlag"] = True
fit.setdata(result.radial, result.intensity, sigmay=result.sigma, xmin=8)
---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
Cell In[56], line 1
----> 1 fit.setdata(result.radial, result.intensity, sigmay=result.sigma, xmin=8)

File ~/.venv/py313/lib/python3.13/site-packages/silx/math/fit/fitmanager.py:792, in FitManager.setdata(self, x, y, sigmay, xmin, xmax)
    790         self.xdata = self.xdata[bool_array]
    791         self.ydata = self.ydata[bool_array]
--> 792         self.sigmay = self.sigmay[bool_array] if sigmay is not None else None
    794 self._finite_mask = numpy.logical_and(
    795     numpy.all(
    796         numpy.isfinite(self.xdata), axis=tuple(range(1, self.xdata.ndim))
    797     ),
    798     numpy.isfinite(self.ydata),
    799 )

TypeError: 'NoneType' object is not subscriptable

To me, setdata with some uncertainties should automatically set the flag "WeightFlag"

Metadata

Metadata

Assignees

No one assigned

    Type

    No fields configured for Bug.

    Projects

    Status
    Todo

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions