From 9161cdcad811dbc493ab0a0bfc8bcb41b988c748 Mon Sep 17 00:00:00 2001 From: Jerome Kieffer Date: Wed, 29 Apr 2026 10:08:03 +0200 Subject: [PATCH 1/7] make uncertainty trigger the use of weighted fit related to #4590 --- src/silx/math/fit/fitmanager.py | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/src/silx/math/fit/fitmanager.py b/src/silx/math/fit/fitmanager.py index 233010c09f..88d9f9bc15 100644 --- a/src/silx/math/fit/fitmanager.py +++ b/src/silx/math/fit/fitmanager.py @@ -777,10 +777,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 + 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): @@ -789,7 +787,10 @@ 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( From 44444bbc925fb07d7ae20bdfa8e4ad9af4724d3f Mon Sep 17 00:00:00 2001 From: Jerome Kieffer Date: Wed, 29 Apr 2026 10:19:05 +0200 Subject: [PATCH 2/7] I HATE `black` --- src/silx/math/fit/fitmanager.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/silx/math/fit/fitmanager.py b/src/silx/math/fit/fitmanager.py index 88d9f9bc15..5cbfe8af56 100644 --- a/src/silx/math/fit/fitmanager.py +++ b/src/silx/math/fit/fitmanager.py @@ -788,7 +788,11 @@ def setdata(self, x, y, sigmay=None, xmin=None, xmax=None): self.xdata = self.xdata[bool_array] self.ydata = self.ydata[bool_array] if sigmay is None: - self.sigmay = self.sigmay[bool_array] if self.fitconfig["WeightFlag"] else None + self.sigmay = ( + self.sigmay[bool_array] + if self.fitconfig["WeightFlag"] + else None + ) else: self.sigmay0 = self.sigmay = self.sigmay[bool_array] From 79c0be5a29488eaca0336576fc54b1db63faf24a Mon Sep 17 00:00:00 2001 From: Jerome Kieffer Date: Wed, 29 Apr 2026 16:04:17 +0200 Subject: [PATCH 3/7] fix split pseudo Voight 2 functions --- src/silx/math/fit/fittheories.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/silx/math/fit/fittheories.py b/src/silx/math/fit/fittheories.py index 5bbe221028..57fbdfc23c 100644 --- a/src/silx/math/fit/fittheories.py +++ b/src/silx/math/fit/fittheories.py @@ -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"]: From c5ee38475d44c6ad8d6cb604b51623bd2a094f16 Mon Sep 17 00:00:00 2001 From: Jerome Kieffer Date: Wed, 29 Apr 2026 17:09:14 +0200 Subject: [PATCH 4/7] fix docstring --- src/silx/math/fit/fitmanager.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/silx/math/fit/fitmanager.py b/src/silx/math/fit/fitmanager.py index 5cbfe8af56..2ca2e3c45e 100644 --- a/src/silx/math/fit/fitmanager.py +++ b/src/silx/math/fit/fitmanager.py @@ -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", From f1d5f89565583a431a5ec52dc320b19358b59972 Mon Sep 17 00:00:00 2001 From: Jerome Kieffer Date: Wed, 29 Apr 2026 21:47:44 +0200 Subject: [PATCH 5/7] Update docstring --- src/silx/math/fit/fitmanager.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/silx/math/fit/fitmanager.py b/src/silx/math/fit/fitmanager.py index 2ca2e3c45e..e7f7969a14 100644 --- a/src/silx/math/fit/fitmanager.py +++ b/src/silx/math/fit/fitmanager.py @@ -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 @@ -53,7 +53,7 @@ __authors__ = ["V.A. Sole", "P. Knobel"] __license__ = "MIT" -__date__ = "16/01/2017" +__date__ = "29/04/2026" _logger = logging.getLogger(__name__) @@ -749,7 +749,8 @@ 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, unless (i.e. ``None``), + the 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 From 57621c17f21c75721db44a3ab4dd8843e962107e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=B4me=20Kieffer?= Date: Thu, 30 Apr 2026 09:04:11 +0200 Subject: [PATCH 6/7] increment version to development version --- src/silx/_version.py | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/src/silx/_version.py b/src/silx/_version.py index 1d705dcff6..95401465ce 100755 --- a/src/silx/_version.py +++ b/src/silx/_version.py @@ -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 @@ -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__ = [ @@ -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) strictversion = version = debianversion = "%d.%d.%d" % version_info[:3] if version_info.releaselevel != "final": From 5baa3bb9db04e21217e9b30d78524f69e5360cd3 Mon Sep 17 00:00:00 2001 From: Jerome Kieffer Date: Thu, 30 Apr 2026 16:09:07 +0200 Subject: [PATCH 7/7] Update src/silx/math/fit/fitmanager.py Co-authored-by: Thomas VINCENT --- src/silx/math/fit/fitmanager.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/silx/math/fit/fitmanager.py b/src/silx/math/fit/fitmanager.py index e7f7969a14..f562105815 100644 --- a/src/silx/math/fit/fitmanager.py +++ b/src/silx/math/fit/fitmanager.py @@ -749,8 +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 provided, enables weighted fit, unless (i.e. ``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