def init(config): global advanced_fit, mass_fraction_tool from PyMca5.PyMcaPhysics.xrf.ClassMcaTheory import McaTheory config['fit']['use_limit'] = 1 advanced_fit = McaTheory(config=config) advanced_fit.enableOptimizedLinearFit() if 'concentrations' in config: mass_fraction_tool = ConcentrationsTool(config['concentrations']) mass_fraction_tool.config['time'] = 1 else: mass_fraction_tool = None
def __init__(self, concentrationsWidget=None, parent=None): QtGui.QWidget.__init__(self, parent) uic.loadUi(resources['mcaspectrum.ui'], self) self.concentrationsWidget = concentrationsWidget self.mcafit = McaTheory() # self.mcafit.enableOptimizedLinearFit() self.fitData = None self.figure = McaSpectrumFigure(self) self.toolbar = MplToolbar(self.figure, self) self.gridlayout1.addWidget(self.toolbar, 0, 0, 1, 1) self.gridlayout1.addWidget(self.figure, 1, 0, 1, 1) self.mcaLogscaleButton.clicked.connect(self.enableLogscale)
def __init__(self, parent=None): super(SpectrumAnalysisThread, self).__init__(parent) self.mcafit = McaTheory() self.timer = QtCore.QTimer(self) self.timer.timeout.connect(self.update) self.timer.start(20)
class McaSpectrum(QtGui.QWidget): """ """ def __init__(self, concentrationsWidget=None, parent=None): QtGui.QWidget.__init__(self, parent) uic.loadUi(resources['mcaspectrum.ui'], self) self.concentrationsWidget = concentrationsWidget self.mcafit = McaTheory() # self.mcafit.enableOptimizedLinearFit() self.fitData = None self.figure = McaSpectrumFigure(self) self.toolbar = MplToolbar(self.figure, self) self.gridlayout1.addWidget(self.toolbar, 0, 0, 1, 1) self.gridlayout1.addWidget(self.figure, 1, 0, 1, 1) self.mcaLogscaleButton.clicked.connect(self.enableLogscale) def __getattr__(self, attr): return getattr(self.figure, attr) def configure(self, configDict): newDict = self.mcafit.configure(configDict) try: self.concentrationsWidget.setParameters(newDict['concentrations'], signal=False) except KeyError: pass return newDict def enableInteraction(self): self.mcaAutoscaleButton.setEnabled(True) self.mcaLogscaleButton.setEnabled(True) def enableLogscale(self, val): self.figure.useLogScale = val self.updateFigure() def fit(self): if self.mcafit.config['peaks'] == {}: msg = QtGui.QMessageBox(self) msg.setIcon(QtGui.QMessageBox.Information) msg.setText("No peaks defined.\nPlease configure peaks") msg.exec_() return self.mcafit.estimate() fitresult, fitData = self.mcafit.startfit(digest=1) self.fitData = copy.deepcopy(fitData) self.peaksSpectrum() self.updateFigure() config = self.mcafit.config if 'concentrations' in self.mcafit.config: fitresult = {'fitresult': fitresult, 'result': self.fitData} tool = self.concentrationsWidget toolconfig = tool.getParameters() concDict = config['concentrations'] tool.setParameters(concDict, signal=False) try: dict = tool.processFitResult(config=concDict, fitresult=fitresult, elementsfrommatrix=False, fluorates=self.mcafit._fluoRates) except: msg = qt.QMessageBox(self) msg.setIcon(qt.QMessageBox.Critical) msg.setText("Error processing fit result: %s" % (sys.exc_info()[1])) msg.exec_() return copy.deepcopy(fitresult) def peaksSpectrum(self): fitresult = self.fitData config = self.mcafit.configure() groupsList = fitresult['groups'] if not isinstance(groupsList, list): groupsList = [groupsList] nglobal = len(fitresult['parameters']) - len(groupsList) dict = self.fitData newparameters = fitresult['fittedpar'] * 1 for i in range(nglobal, len(fitresult['parameters'])): newparameters[i] = 0.0 for i in range(nglobal, len(fitresult['parameters'])): group = fitresult['parameters'][i] group = fitresult['parameters'][i] parameters = newparameters * 1 parameters[i] = fitresult['fittedpar'][i] xmatrix = fitresult['xdata'] ymatrix = self.mcafit.mcatheory(parameters, xmatrix) ymatrix.shape = [len(ymatrix), 1] label = 'y' + group if self.mcafit.STRIP: dict[label] = ymatrix + self.mcafit.zz else: dict[label] = ymatrix dict[label].shape = (len(dict[label]), ) self.fitData[label] = dict[label] * 1.0 def setData(self, *args, **kwargs): self.mcafit.setData(*args, **kwargs) def updateFigure(self): self.figure.updateFigure(self.fitData)
class McaSpectrum(QtGui.QWidget): """ """ def __init__(self, concentrationsWidget=None, parent=None): QtGui.QWidget.__init__(self, parent) uic.loadUi(resources['mcaspectrum.ui'], self) self.concentrationsWidget = concentrationsWidget self.mcafit = McaTheory() # self.mcafit.enableOptimizedLinearFit() self.fitData = None self.figure = McaSpectrumFigure(self) self.toolbar = MplToolbar(self.figure, self) self.gridlayout1.addWidget(self.toolbar, 0, 0, 1, 1) self.gridlayout1.addWidget(self.figure, 1, 0, 1, 1) self.mcaLogscaleButton.clicked.connect(self.enableLogscale) def __getattr__(self, attr): return getattr(self.figure, attr) def configure(self, configDict): newDict = self.mcafit.configure(configDict) try: self.concentrationsWidget.setParameters(newDict['concentrations'], signal=False) except KeyError: pass return newDict def enableInteraction(self): self.mcaAutoscaleButton.setEnabled(True) self.mcaLogscaleButton.setEnabled(True) def enableLogscale(self, val): self.figure.useLogScale = val self.updateFigure() def fit(self): if self.mcafit.config['peaks'] == {}: msg = QtGui.QMessageBox(self) msg.setIcon(QtGui.QMessageBox.Information) msg.setText("No peaks defined.\nPlease configure peaks") msg.exec_() return self.mcafit.estimate() fitresult, fitData = self.mcafit.startfit(digest=1) self.fitData = copy.deepcopy(fitData) self.peaksSpectrum() self.updateFigure() config = self.mcafit.config if 'concentrations' in self.mcafit.config: fitresult = {'fitresult': fitresult, 'result': self.fitData} tool = self.concentrationsWidget toolconfig = tool.getParameters() concDict = config['concentrations'] tool.setParameters(concDict, signal=False) try: dict = tool.processFitResult(config=concDict, fitresult=fitresult, elementsfrommatrix=False, fluorates=self.mcafit._fluoRates) except: msg = qt.QMessageBox(self) msg.setIcon(qt.QMessageBox.Critical) msg.setText("Error processing fit result: %s" % (sys.exc_info()[1])) msg.exec_() return copy.deepcopy(fitresult) def peaksSpectrum(self): fitresult = self.fitData config = self.mcafit.configure() groupsList = fitresult['groups'] if not isinstance(groupsList, list): groupsList = [groupsList] nglobal = len(fitresult['parameters']) - len(groupsList) dict = self.fitData newparameters = fitresult['fittedpar'] * 1 for i in range(nglobal, len(fitresult['parameters'])): newparameters[i] = 0.0 for i in range(nglobal, len(fitresult['parameters'])): group = fitresult['parameters'][i] group = fitresult['parameters'][i] parameters = newparameters * 1 parameters[i] = fitresult['fittedpar'][i] xmatrix = fitresult['xdata'] ymatrix = self.mcafit.mcatheory(parameters, xmatrix) ymatrix.shape = [len(ymatrix), 1] label = 'y'+group if self.mcafit.STRIP: dict[label] = ymatrix + self.mcafit.zz else: dict[label] = ymatrix dict[label].shape = (len(dict[label]),) self.fitData[label] = dict[label] * 1.0 def setData(self, *args, **kwargs): self.mcafit.setData(*args, **kwargs) def updateFigure(self): self.figure.updateFigure(self.fitData)