Skip to content
Merged
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
21 changes: 17 additions & 4 deletions src/PyMca5/PyMcaGui/physics/xrf/McaAdvancedFit.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
#
# The PyMca X-Ray Fluorescence Toolkit
#
# Copyright (c) 2004-2023 European Synchrotron Radiation Facility
# Copyright (c) 2004-2025 European Synchrotron Radiation Facility
#
# This file is part of the PyMca X-ray Fluorescence Toolkit developed at
# the ESRF.
Expand Down Expand Up @@ -291,7 +291,7 @@ def __init__(self, parent=None, name="PyMca - McaAdvancedFit",fl=0,
self.matrixXRFMCSpectrumButton.setToolTip('Calculate Matrix Spectrum Using Monte Carlo')
self.peaksSpectrumButton.setToolTip('Toggle Individual Peaks Spectrum Calculation On/Off')

self.mcafit = ClassMcaTheory.McaTheory()
self.mcafit = ClassMcaTheory.McaTheory()

self.fitButton.clicked.connect(self.fit)
self.printButton.clicked.connect(self.printActiveTab)
Expand Down Expand Up @@ -1640,9 +1640,9 @@ def setData(self,*var,**kw):
sigmay
uncertainties to be applied if different than sqrt(y)
xmin
minimum channel of the fit
minimum channel/x value of the fit. It will be ignored if use_limits is True
xmax
maximum channel of the fit
maximum channel/x value of the fit. It will be ignored if use_limits is True
calibration
list of the form [a, b, c] containing the mca calibration
time
Expand All @@ -1662,6 +1662,15 @@ def setData(self,*var,**kw):
self.info[key] = kw[key]
else:
self.info[key] = 'X'

# PyMca McaWindow is systematically sending the zoomed region xmin and xmax
# To make sure the limits configuration settings respect the selected GUI behavior
# xmin and xmax they need to be set or overwritten here if required
for key in ['xmin', 'xmax']:
if self.mcafit.config['fit']['use_limit']:
kw[key] = self.mcafit.config['fit'][key]
_logger.info("%s limit overwritten by fit configuration" % key)

key = 'xmin'
if key in kw:
self.info[key] = "%.3f" % kw[key]
Expand All @@ -1682,8 +1691,12 @@ def setData(self,*var,**kw):
self.info[key] = kw[key]
else:
self.info[key] = None

# TODO: These two variables do not seem to be used anywhere.
# Is there a reason to keep a reference?
self.__var = var
self.__kw = kw

try:
self.mcafit.setData(*var,**kw)
except ValueError:
Expand Down
35 changes: 16 additions & 19 deletions src/PyMca5/PyMcaPhysics/xrf/ClassMcaTheory.py
Original file line number Diff line number Diff line change
Expand Up @@ -1114,26 +1114,23 @@ def setData(self,*var,**kw):
elif self.config["concentrations"].get("useautotime", False):
self.config["concentrations"]["time"] = timeFactor

xmin = self.config['fit']['xmin']
if not self.config['fit']['use_limit']:
if 'xmin' in kw:
xmin=kw['xmin']
if xmin is not None:
self.config['fit']['xmin'] = xmin
else:
xmin=min(self.xdata)
elif len(self.xdata):
xmin=min(self.xdata)
xmax = self.config['fit']['xmax']
xmin = kw.get("xmin")
if xmin is None and self.config['fit']['use_limit']:
xmin = self.config['fit']['xmin']
if xmin is None and len(self.xdata):
xmin = min(self.xdata)

xmax = kw.get("xmax")
if xmax is None and self.config['fit']['use_limit']:
xmax = self.config['fit']['xmax']
if xmax is None and len(self.xdata):
xmax = max(self.xdata)

if not self.config['fit']['use_limit']:
if 'xmax' in kw:
xmax=kw['xmax']
if xmax is not None:
self.config['fit']['xmax'] = xmax
else:
xmax=max(self.xdata)
elif len(self.xdata):
xmax=max(self.xdata)
self.config['fit']['xmin'] = xmin
self.config['fit']['xmax'] = xmax

_logger.info("X-axis fit limits: xmin=%s, xmax=%s", xmin, xmax)

self.lastxmin = xmin
self.lastxmax = xmax
Expand Down
4 changes: 3 additions & 1 deletion src/PyMca5/PyMcaPhysics/xrf/FastXRFLinearFit.py
Original file line number Diff line number Diff line change
Expand Up @@ -129,11 +129,13 @@ def fitMultipleSpectra(self, x=None, y=None, xmin=None, xmax=None,
else:
yref = ysum

# Get the basis of the linear models (i.e. derivative to peak areas)
# Make sure the fit limits are taken from the configuration
if xmin is None:
xmin = config['fit']['xmin']
if xmax is None:
xmax = config['fit']['xmax']

# Get the basis of the linear models (i.e. derivative to peak areas)
dtypeCalculcation = self._fitDtypeCalculation(data)
self._mcaTheory.setData(x=x, y=yref, xmin=xmin, xmax=xmax)
derivatives, freeNames, nFree, nFreeBkg = self._fitCreateModel(dtype=dtypeCalculcation)
Expand Down
3 changes: 3 additions & 0 deletions src/PyMca5/PyMcaPhysics/xrf/LegacyFastXRFLinearFit.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,10 +114,13 @@ def fitMultipleSpectra(self, x=None, y=None, xmin=None, xmax=None,
# read the current configuration
# it is a copy, we can modify it at will
config = self._mcaTheory.getConfiguration()

# Make sure the fit limits are taken from the configuration
if xmin is None:
xmin = config['fit']['xmin']
if xmax is None:
xmax = config['fit']['xmax']

toReconfigure = False

# if concentrations and use times, it needs to be reconfigured
Expand Down
2 changes: 1 addition & 1 deletion src/PyMca5/PyMcaPhysics/xrf/LegacyMcaAdvancedFitBatch.py
Original file line number Diff line number Diff line change
Expand Up @@ -561,7 +561,7 @@ def __processOneMca(self,x,y,filename,key,info=None):
else:
useExistingResult = 0
try:
#I make sure I take the fit limits configuration
# Make sure the fit limits are taken from the configuration
self.mcafit.config['fit']['use_limit'] = 1
self.mcafit.setData(x,y, time=info.get("McaLiveTime", None))
except Exception:
Expand Down
4 changes: 2 additions & 2 deletions src/PyMca5/PyMcaPhysics/xrf/McaAdvancedFitBatch.py
Original file line number Diff line number Diff line change
Expand Up @@ -753,8 +753,8 @@ def __fitOneMca(self,x,y,filename,key,info=None):

def _attemptMcaLoad(self, x, y, filename, info=None):
try:
#I make sure I take the fit limits configuration
self.mcafit.config['fit']['use_limit'] = 1 # TODO: why???
# Make sure the fit limits are taken from the configuration
self.mcafit.config['fit']['use_limit'] = 1
self.mcafit.setData(x, y, time=info.get("McaLiveTime", None))
except Exception:
self._restoreFitConfig(filename, 'entering data')
Expand Down