def updateGraph(self, ddict): self.__lastDict = ddict edgeEnergy = ddict['edge_energy'] preRegions = ddict['pre_edge']['regions'] postRegions = ddict['post_edge']['regions'] event = ddict.get('event', None) if event == "AutoEdgeEnergyClicked": try: # recalculate edge energy following region limits xmin = edgeEnergy + preRegions[0][0] xmax = edgeEnergy + postRegions[0][1] idx = numpy.nonzero((self.energy >= xmin) &\ (self.energy <= xmax))[0] x = numpy.take(self.energy, idx) y = numpy.take(self.spectrum, idx) edgeEnergy = XASNormalization.estimateXANESEdge(y, energy=x, full=False) self.parametersWidget.setEdgeEnergy(edgeEnergy, emin=self.energy.min(), emax=self.energy.max()) self.__lastDict['edge_energy'] = edgeEnergy except: pass parameters = {} parameters['pre_edge_order'] = ddict['pre_edge']['polynomial'] parameters['post_edge_order'] = ddict['post_edge']['polynomial'] algorithm = 'polynomial' self.updateMarkers(edgeEnergy, preRegions, postRegions, edge_auto=ddict['auto_edge']) try: normalizationResult = XASNormalization.XASNormalization( self.spectrum, self.energy, edge=edgeEnergy, pre_edge_regions=preRegions, post_edge_regions=postRegions, algorithm=algorithm, algorithm_parameters=parameters) except: msg = qt.QMessageBox(self) msg.setIcon(qt.QMessageBox.Critical) msg.setWindowTitle("Normalization Error") msg.setText("An error has occured while normalizing the data") msg.setInformativeText(str(sys.exc_info()[1])) msg.setDetailedText(traceback.format_exc()) msg.exec_() return nEnergy, nSpectrum, usedEdge, jump = normalizationResult[0:4] preEdgeFunction, preEdgeParameters = normalizationResult[4:6] postEdgeFunction, postEdgeParameters = normalizationResult[6:8] idx = self.energy > (usedEdge + preRegions[0][0]) x = self.energy[idx] yPre = preEdgeFunction(preEdgeParameters, x) yPost = postEdgeFunction(postEdgeParameters, x) self.graph.addCurve(x, yPre, legend="Pre-edge Polynomial") self.graph.addCurve(x, yPost + yPre, legend="Post-edge Polynomial")
def __init__(self, parent, spectrum, energy=None): qt.QWidget.__init__(self, parent) self.setWindowTitle("XAS Normalization Configuration Window") self.mainLayout = qt.QVBoxLayout(self) self.mainLayout.setContentsMargins(0, 0, 0, 0) self.mainLayout.setSpacing(2) if energy is None: self.energy = range(len(spectrum)) else: self.energy = energy self.spectrum = spectrum self.parametersWidget = XASNormalizationParametersWidget(self) self.graph = PlotWindow.PlotWindow(self, backend=backend, plugins=False, newplot=False) self.__lastDict = {} self.graph.sigPlotSignal.connect(self._handleGraphSignal) self.graph.addCurve(self.energy, spectrum, legend="Spectrum", replace=True) self.mainLayout.addWidget(self.parametersWidget) self.mainLayout.addWidget(self.graph) # initialize variables edgeEnergy, sortedX, sortedY, xPrime, yPrime =\ XASNormalization.estimateXANESEdge(spectrum, energy=self.energy, full=True) self._xPrime = xPrime self._yPrime = yPrime self.parametersWidget.setEdgeEnergy(edgeEnergy, emin=self.energy.min(), emax=self.energy.max()) self.getParameters = self.parametersWidget.getParameters self.setParameters = self.parametersWidget.setParameters self.parametersWidget.sigXASNormalizationParametersSignal.connect( \ self.updateGraph) self.updateGraph(self.getParameters())
def __init__(self, parent, spectrum, energy=None): qt.QWidget.__init__(self, parent) self.setWindowTitle("XAS Normalization Configuration Window") self.mainLayout = qt.QVBoxLayout(self) self.mainLayout.setContentsMargins(0, 0, 0, 0) self.mainLayout.setSpacing(2) if energy is None: self.energy = numpy.arange(len(spectrum)).astype(numpy.float64) else: self.energy = energy self.spectrum = numpy.array(spectrum, dtype=numpy.float64, copy=False) self.parametersWidget = XASNormalizationParametersWidget(self) self.graph = PlotWindow.PlotWindow(self, backend=backend, plugins=False, newplot=False) self.__lastDict = {} self.graph.sigPlotSignal.connect(self._handleGraphSignal) self.graph.addCurve(self.energy, spectrum, legend="Spectrum", replace=True) self.mainLayout.addWidget(self.parametersWidget) self.mainLayout.addWidget(self.graph) # initialize variables edgeEnergy, sortedX, sortedY, xPrime, yPrime =\ XASNormalization.estimateXANESEdge(spectrum, energy=self.energy, full=True) self._xPrime = xPrime self._yPrime = yPrime self.parametersWidget.setEdgeEnergy(edgeEnergy, emin=self.energy.min(), emax=self.energy.max()) self.getParameters = self.parametersWidget.getParameters self.setParameters = self.parametersWidget.setParameters self.parametersWidget.sigXASNormalizationParametersSignal.connect( \ self.updateGraph) self.updateGraph(self.getParameters())
def setData(self, spectrum, energy=None): self.spectrum = spectrum if energy is None: self.energy = range(len(spectrum)) else: self.energy = energy self.graph.clearMarkers() self.graph.clearCurves() self.graph.addCurve(self.energy, self.spectrum, legend="Spectrum") edgeEnergy = XASNormalization.estimateXANESEdge(self.spectrum, energy=self.energy, full=False) self.parametersWidget.setEdgeEnergy(edgeEnergy, emin=self.energy.min(), emax=self.energy.max()) self.updateGraph(self.getParameters())
def __init__(self, parent, spectrum, energy=None): qt.QWidget.__init__(self, parent) self.setWindowTitle("XAS Normalization Configuration Window") self.mainLayout = qt.QVBoxLayout(self) self.mainLayout.setContentsMargins(0, 0, 0, 0) self.mainLayout.setSpacing(2) if energy is None: self.energy = range(len(spectrum)) else: self.energy = energy self.spectrum = spectrum self.parametersWidget = XASNormalizationParametersWidget(self) self.graph = PlotWindow(self, position=False, aspectRatio=False, colormap=False, yInverted=False, roi=False, mask=False, fit=False) # next two lines deprecated with silx 0.8.0 # self.graph.zoomModeAction.setVisible(False) # self.graph.panModeAction.setVisible(False) toolbar = self.graph.getInteractiveModeToolBar() toolbar.getZoomModeAction().setVisible(False) toolbar.getPanModeAction().setVisible(False) self.__lastDict = {} self.graph.sigPlotSignal.connect(self._handleGraphSignal) self.graph.addCurve(self.energy, spectrum, legend="Spectrum") self.graph.setActiveCurve("Spectrum") self.mainLayout.addWidget(self.parametersWidget) self.mainLayout.addWidget(self.graph) # initialize variables edgeEnergy, sortedX, sortedY, xPrime, yPrime =\ XASNormalization.estimateXANESEdge(spectrum, energy=self.energy, full=True) self._xPrime = xPrime self._yPrime = yPrime self.parametersWidget.setEdgeEnergy(edgeEnergy, emin=self.energy.min(), emax=self.energy.max()) self.getParameters = self.parametersWidget.getParameters self.setParameters = self.parametersWidget.setParameters self.parametersWidget.sigXASNormalizationParametersSignal.connect( \ self.updateGraph) self.updateGraph(self.getParameters())
def setData(self, spectrum, energy=None): self.spectrum = spectrum if energy is None: self.energy = range(len(spectrum)) else: self.energy = energy self.graph.clearMarkers() self.graph.addCurve(self.energy, self.spectrum, legend="Spectrum", replot=True, replace=True) edgeEnergy = XASNormalization.estimateXANESEdge(self.spectrum, energy=self.energy, full=False) self.parametersWidget.setEdgeEnergy(edgeEnergy, emin=self.energy.min(), emax=self.energy.max()) self.updateGraph(self.getParameters())
def updateGraph(self, ddict): self.__lastDict = ddict edgeEnergy = ddict['edge_energy'] preRegions = ddict['pre_edge']['regions'] postRegions = ddict['post_edge']['regions'] event = ddict.get('event', None) if event == "AutoEdgeEnergyClicked": try: # recalculate edge energy following region limits xmin = edgeEnergy + preRegions[0][0] xmax = edgeEnergy + postRegions[0][1] idx = numpy.nonzero((self.energy >= xmin) &\ (self.energy <= xmax))[0] x = numpy.take(self.energy, idx) y = numpy.take(self.spectrum, idx) edgeEnergy = XASNormalization.estimateXANESEdge(y, energy=x, full=False) self.parametersWidget.setEdgeEnergy(edgeEnergy, emin=self.energy.min(), emax=self.energy.max()) self.__lastDict['edge_energy'] = edgeEnergy except: pass parameters = {} parameters['pre_edge_order'] = ddict['pre_edge']['polynomial'] parameters['post_edge_order'] = ddict['post_edge']['polynomial'] algorithm = 'polynomial' self.updateMarkers(edgeEnergy, preRegions, postRegions, edge_auto=ddict['auto_edge']) try: normalizationResult = XASNormalization.XASNormalization(self.spectrum, self.energy, edge=edgeEnergy, pre_edge_regions=preRegions, post_edge_regions=postRegions, algorithm=algorithm, algorithm_parameters=parameters) except: msg = qt.QMessageBox(self) msg.setIcon(qt.QMessageBox.Critical) msg.setWindowTitle("Normalization Error") msg.setText("An error has occured while normalizing the data") msg.setInformativeText(str(sys.exc_info()[1])) msg.setDetailedText(traceback.format_exc()) msg.exec_() return nEnergy, nSpectrum, usedEdge, jump = normalizationResult[0:4] preEdgeFunction, preEdgeParameters = normalizationResult[4:6] postEdgeFunction, postEdgeParameters = normalizationResult[6:8] idx = self.energy > (usedEdge + preRegions[0][0]) x = self.energy[idx] yPre = preEdgeFunction(preEdgeParameters, x) yPost = postEdgeFunction(postEdgeParameters, x) self.graph.addCurve(x, yPre, legend="Pre-edge Polynomial", replace=False) self.graph.addCurve(x, yPost+yPre, legend="Post-edge Polynomial", replace=False, replot=True)