Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 13 additions & 9 deletions src/silx/_version.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/usr/bin/env python3
# /*##########################################################################
#
# Copyright (c) 2015-2025 European Synchrotron Radiation Facility
# Copyright (c) 2015-2026 European Synchrotron Radiation Facility
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
Expand Down Expand Up @@ -48,12 +48,12 @@

"""

from collections import namedtuple
from typing import NamedTuple

__authors__ = ["Jérôme Kieffer"]
__license__ = "MIT"
__copyright__ = "European Synchrotron Radiation Facility, Grenoble, France"
__date__ = "12/12/2023"
__date__ = "30/04/2026"
__status__ = "production"
__docformat__ = "restructuredtext"
__all__ = [
Expand All @@ -71,18 +71,22 @@

MAJOR = 3
MINOR = 0
MICRO = 0
RELEV = "final" # <16
MICRO = 1
RELEV = "dev" # <16
SERIAL = 0 # <16

date = __date__


_version_info = namedtuple(
"version_info", ["major", "minor", "micro", "releaselevel", "serial"]
)
class VersionInfo(NamedTuple):
major: int
minor: int
micro: int
releaselevel: str
serial: int

version_info = _version_info(MAJOR, MINOR, MICRO, RELEV, SERIAL)

version_info = VersionInfo(MAJOR, MINOR, MICRO, RELEV, SERIAL)
Comment on lines +81 to +89
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's keep it private:

Suggested change
class VersionInfo(NamedTuple):
major: int
minor: int
micro: int
releaselevel: str
serial: int
version_info = _version_info(MAJOR, MINOR, MICRO, RELEV, SERIAL)
version_info = VersionInfo(MAJOR, MINOR, MICRO, RELEV, SERIAL)
class _VersionInfo(NamedTuple):
major: int
minor: int
micro: int
releaselevel: str
serial: int
version_info = _VersionInfo(MAJOR, MINOR, MICRO, RELEV, SERIAL)


strictversion = version = debianversion = "%d.%d.%d" % version_info[:3]
if version_info.releaselevel != "final":
Expand Down
29 changes: 19 additions & 10 deletions src/silx/math/fit/fitmanager.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# /*#########################################################################
#
# Copyright (c) 2004-2023 European Synchrotron Radiation Facility
# Copyright (c) 2004-2026 European Synchrotron Radiation Facility
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
Expand Down Expand Up @@ -53,7 +53,7 @@

__authors__ = ["V.A. Sole", "P. Knobel"]
__license__ = "MIT"
__date__ = "16/01/2017"
__date__ = "29/04/2026"

_logger = logging.getLogger(__name__)

Expand All @@ -78,12 +78,14 @@ class FitManager:
:param weight_flag: If this parameter is ``True`` and ``sigmay``
uncertainties are not specified, the square root of ``y`` is used
as weights in the least-squares problem. If ``False``, the
uncertainties are set to 1.
uncertainties are set to 1. By default, it is set to ``True`` if
``sigmay`` is provided and ``False`` otherwise.
:type weight_flag: boolean
"""

def __init__(self, x=None, y=None, sigmay=None, weight_flag=False):
def __init__(self, x=None, y=None, sigmay=None, weight_flag=None):
""" """
weight_flag = (sigmay is not None) if weight_flag is None else weight_flag
self.fitconfig = {
"WeightFlag": weight_flag,
"fitbkg": "No Background",
Expand Down Expand Up @@ -747,7 +749,9 @@ def setdata(self, x, y, sigmay=None, xmin=None, xmax=None):
:type y: Sequence or numpy array or None
:param sigmay: The uncertainties in the ``ydata`` array. These are
used as weights in the least-squares problem.
If ``None``, the uncertainties are assumed to be 1.
If provided, enables weighted fit.
If not provided (i.e. ``None``): use the square root of ``y`` if ``weight_flag`` is ``True``
else uncertainties are assumed to be 1.
:type sigmay: Sequence or numpy array or None
:param xmin: Lower value of x values to use for fitting
:param xmax: Upper value of x values to use for fitting
Expand Down Expand Up @@ -777,10 +781,8 @@ def setdata(self, x, y, sigmay=None, xmin=None, xmax=None):
numpy.sqrt(self.ydata) if self.fitconfig["WeightFlag"] else None
)
else:
self.sigmay0 = numpy.array(sigmay)
self.sigmay = (
numpy.array(sigmay) if self.fitconfig["WeightFlag"] else None
)
self.fitconfig["WeightFlag"] = True
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Then maybe good to add to the setdata docstring that setting sigmay enables WeightFlag. I agree it is expected but since there looks to be a few ways to set this best to make it explicit.

Did you check how this works from the fit widgets?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, I did not check it ... BTW, I doubt this code is used anywhere since the "split Pseudo-Voigt 2" mode could not work at all, since array are not initialized at the proper size.

The code-style is very PyMca-like, fit results would deserve to be dataclass or namedtuple instances, but this is not the use-case for this PR.

Copy link
Copy Markdown
Member

@vasole vasole May 5, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The code-style is very PyMca-like, fit results would deserve to be dataclass or namedtuple instances, but this is not the use-case for this PR.

I would prefer the expression "pre python2.6" (released in October 2008). PyMca could not use something that was not existing when it was written.

self.sigmay0 = self.sigmay = numpy.array(sigmay)

# take the data between limits, using boolean array indexing
if (xmin is not None or xmax is not None) and len(self.xdata):
Expand All @@ -789,7 +791,14 @@ def setdata(self, x, y, sigmay=None, xmin=None, xmax=None):
bool_array = (self.xdata >= xmin) & (self.xdata <= xmax)
self.xdata = self.xdata[bool_array]
self.ydata = self.ydata[bool_array]
self.sigmay = self.sigmay[bool_array] if sigmay is not None else None
if sigmay is None:
self.sigmay = (
self.sigmay[bool_array]
if self.fitconfig["WeightFlag"]
else None
)
else:
self.sigmay0 = self.sigmay = self.sigmay[bool_array]

self._finite_mask = numpy.logical_and(
numpy.all(
Expand Down
2 changes: 1 addition & 1 deletion src/silx/math/fit/fittheories.py
Original file line number Diff line number Diff line change
Expand Up @@ -726,7 +726,7 @@ def estimate_splitpvoigt2(self, x, y):
fittedpar, cons = self.estimate_height_position_fwhm(x, y)
npeaks = len(fittedpar) // 3
newpar = []
newcons = numpy.zeros((5 * npeaks, 3), numpy.float64)
newcons = numpy.zeros((6 * npeaks, 3), numpy.float64)
# find out related parameters proper index
if not self.config["NoConstraintsFlag"]:
if self.config["SameFwhmFlag"]:
Expand Down
Loading