-
Notifications
You must be signed in to change notification settings - Fork 80
FitManager: make uncertainty trigger the use of weighted fit #4591
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
9161cdc
44444bb
79c0be5
4bedb1d
c5ee384
f1d5f89
57621c1
5baa3bb
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| 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 | ||
|
|
@@ -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 | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Then maybe good to add to the Did you check how this works from the fit widgets?
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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.
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
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): | ||
|
|
@@ -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( | ||
|
|
||
There was a problem hiding this comment.
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: