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": diff --git a/src/silx/math/fit/fitmanager.py b/src/silx/math/fit/fitmanager.py index 233010c09f..f562105815 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__) @@ -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", @@ -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 @@ -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 + 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 +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( 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"]: