Пример #1
0
def test():
    import numpy
    #import DefaultFitFunctions as SpecfitFunctions
    from PyMca5.PyMca import SpecfitFunctions
    a=SpecfitFunctions.SpecfitFunctions()
    x = numpy.arange(1000).astype(numpy.float64)
    p1 = numpy.array([1500,100.,50.0])
    p2 = numpy.array([1500,700.,50.0])
    y = a.gauss(p1, x)
    y = y + a.gauss(p2,x) + x * 5.
    if 0:
        fit = SimpleFitModule.SimpleFit()
        fit.importFunctions(SpecfitFunctions)
        fit.setFitFunction('Gaussians')
        #fit.setBackgroundFunction('Gaussians')
        #fit.setBackgroundFunction('Constant')
        fit.setData(x, y)
        w = SimpleFitGui(fit=fit)
        w.show()
    else:
        fit=None
        w = SimpleFitGui(fit=fit)
        w.setData(x, y, xmin=x[0], xmax=x[-1])
        w.show()
        from PyMca5.PyMca import SimpleFitUserEstimatedFunctions
        fname = SimpleFitUserEstimatedFunctions.__file__
        w.importFunctions(fname)
        w.setFitFunction('User Estimated Gaussians')
    return w
Пример #2
0
    def __init__(self, parent=None, fit=None, graph=None, actions=True):
        if fit is None:
            fit = SimpleFitModule.SimpleFit()
            # inject config widget by patching the module
            w = SpecfitConfigGui.SpecfitConfigGui
            SpecfitFunctions.WIDGET = [w for _t in SpecfitFunctions.THEORY]
            fit.importFunctions(SpecfitFunctions)
        SimpleFitGui.__init__(self, parent, fit, graph, actions)

        self.fitAllInstance = SimpleFitAll.SimpleFitAll(fit=self.fitModule)

        self.fitActions.dismissButton.hide()
        self.outputParameters = OutputParameters(self)
        self.startFitAllButton = qt.QPushButton(self)
        self.startFitAllButton.setText("Fit all")
        self.startFitAllButton.clicked.connect(self.startFitAll)
        self.progressBar = qt.QProgressBar(self)
        self.mainLayout.addWidget(self.outputParameters)
        self.mainLayout.addWidget(self.startFitAllButton)
        self.mainLayout.addWidget(self.progressBar)

        # progress handling
        self._total = 100
        self._index = 0
        self.fitAllInstance.setProgressCallback(self.progressUpdate)

        self.curves_x = None
        self.curves_y = None
        self.legends = None
        self.xlabels = None
        self.ylabels = None

        # store active curve
        self._activeData = None
Пример #3
0
    def __init__(self, parent=None, fit=None, graph=None, actions=True):
        qt.QWidget.__init__(self, parent)
        self.setWindowTitle("SimpleFitGui")
        if fit is None:
            self.fitModule = SimpleFitModule.SimpleFit()
            self.fitModule.importFunctions(SimpleFitUserEstimatedFunctions)
            self.fitModule.loadUserFunctions()
        else:
            self.fitModule = fit
        if graph is None:
            self.__useTab = True
            self.graph = PlotWindow.PlotWindow(newplot=False,
                                               plugins=False,
                                               fit=False,
                                               control=True,
                                               position=True)
        else:
            self.__useTab = False
            self.graph = graph
        self._configurationDialog = None
        self.mainLayout = qt.QVBoxLayout(self)
        self.mainLayout.setContentsMargins(2, 2, 2, 2)
        self.mainLayout.setSpacing(2)
        self.topWidget  = TopWidget(self)
        config = self.fitModule.getConfiguration()
        self.topWidget.setFunctions(config['fit']['functions'])
        config = None

        if self.__useTab:
            self.mainTab = qt.QTabWidget(self)
            self.mainLayout.addWidget(self.mainTab)
            self.parametersTable = Parameters.Parameters()
            self.mainTab.addTab(self.graph, 'GRAPH')
            self.mainTab.addTab(self.parametersTable, 'FIT')
        else:
            self.parametersTable = Parameters.Parameters(self)

        self.statusWidget  = StatusWidget(self)

        self.mainLayout.addWidget(self.topWidget)
        if self.__useTab:
            self.mainLayout.addWidget(self.mainTab)
        else:
            self.mainLayout.addWidget(self.parametersTable)
        self.mainLayout.addWidget(self.statusWidget)

        if actions:
            #build the actions widget
            self.fitActions = qt.QWidget(self)
            self.fitActions.mainLayout = qt.QHBoxLayout(self.fitActions)
            self.fitActions.mainLayout.setContentsMargins(2, 2, 2, 2)
            self.fitActions.mainLayout.setSpacing(2)
            self.fitActions.estimateButton = qt.QPushButton(self.fitActions)
            self.fitActions.estimateButton.setText("Estimate")
            self.fitActions.startFitButton = qt.QPushButton(self.fitActions)
            self.fitActions.startFitButton.setText("Start Fit")
            self.fitActions.dismissButton = qt.QPushButton(self.fitActions)
            self.fitActions.dismissButton.setText("Dismiss")
            self.fitActions.mainLayout.addWidget(self.fitActions.estimateButton)
            self.fitActions.mainLayout.addWidget(self.fitActions.startFitButton)
            self.fitActions.mainLayout.addWidget(self.fitActions.dismissButton)
            self.mainLayout.addWidget(self.fitActions)

        #connect top widget
        self.topWidget.addFunctionButton.clicked.connect(\
                    self.importFunctionsSlot)

        self.topWidget.fitFunctionCombo.currentIndexChanged[int].connect(\
                     self.fitFunctionComboSlot)

        self.topWidget.backgroundCombo.currentIndexChanged[int].connect(\
                     self.backgroundComboSlot)

        self.topWidget.configureButton.clicked.connect(\
                    self.configureButtonSlot)

        if actions:
            #connect actions
            self.fitActions.estimateButton.clicked.connect(self.estimate)
            self.fitActions.startFitButton.clicked.connect(self.startFit)
            self.fitActions.dismissButton.clicked.connect(self.dismiss)
Пример #4
0
    def __init__(self, parent=None, fit=None, graph=None, actions=True):
        qt.QWidget.__init__(self, parent)
        self.setWindowTitle("SimpleFitGui")
        if fit is None:
            self.fitModule = SimpleFitModule.SimpleFit()
            self.fitModule.importFunctions(SimpleFitUserEstimatedFunctions)
            self.fitModule.loadUserFunctions()
        else:
            self.fitModule = fit
        if graph is None:
            self.__useTab = True
            self.graph = PlotWindow(self,
                                    aspectRatio=False,
                                    colormap=False,
                                    yInverted=False,
                                    roi=False,
                                    mask=False,
                                    fit=False,
                                    control=True,
                                    position=True)
            self.graph.getInteractiveModeToolBar().setVisible(False)
            # No context menu by default, execute zoomBack on right click
            plotArea = self.graph.getWidgetHandle()
            plotArea.setContextMenuPolicy(qt.Qt.CustomContextMenu)
            plotArea.customContextMenuRequested.connect(self._zoomBack)
        else:
            self.__useTab = False
            self.graph = graph
        self._configurationDialog = None
        self.mainLayout = qt.QVBoxLayout(self)
        self.mainLayout.setContentsMargins(2, 2, 2, 2)
        self.mainLayout.setSpacing(2)
        self.topWidget = TopWidget(self)
        config = self.fitModule.getConfiguration()
        self.topWidget.setFunctions(config['fit']['functions'])
        config = None

        if self.__useTab:
            self.mainTab = qt.QTabWidget(self)
            self.mainLayout.addWidget(self.mainTab)
            self.parametersTable = Parameters.Parameters()
            self.mainTab.addTab(self.graph, 'GRAPH')
            self.mainTab.addTab(self.parametersTable, 'FIT')
        else:
            self.parametersTable = Parameters.Parameters(self)

        self.statusWidget = StatusWidget(self)

        self.mainLayout.addWidget(self.topWidget)
        if self.__useTab:
            self.mainLayout.addWidget(self.mainTab)
        else:
            self.mainLayout.addWidget(self.parametersTable)
        self.mainLayout.addWidget(self.statusWidget)

        if actions:
            #build the actions widget
            self.fitActions = qt.QWidget(self)
            self.fitActions.mainLayout = qt.QHBoxLayout(self.fitActions)
            self.fitActions.mainLayout.setContentsMargins(2, 2, 2, 2)
            self.fitActions.mainLayout.setSpacing(2)
            self.fitActions.estimateButton = qt.QPushButton(self.fitActions)
            self.fitActions.estimateButton.setText("Estimate")
            self.fitActions.startFitButton = qt.QPushButton(self.fitActions)
            self.fitActions.startFitButton.setText("Start Fit")
            self.fitActions.dismissButton = qt.QPushButton(self.fitActions)
            self.fitActions.dismissButton.setText("Dismiss")
            self.fitActions.mainLayout.addWidget(
                self.fitActions.estimateButton)
            self.fitActions.mainLayout.addWidget(
                self.fitActions.startFitButton)
            self.fitActions.mainLayout.addWidget(self.fitActions.dismissButton)
            self.mainLayout.addWidget(self.fitActions)

        #connect top widget
        self.topWidget.addFunctionButton.clicked.connect(\
                    self.importFunctions)

        self.topWidget.fitFunctionCombo.currentIndexChanged[int].connect(\
                     self.fitFunctionComboSlot)

        self.topWidget.backgroundCombo.currentIndexChanged[int].connect(\
                     self.backgroundComboSlot)

        self.topWidget.configureButton.clicked.connect(\
                    self.configureButtonSlot)

        if actions:
            #connect actions
            self.fitActions.estimateButton.clicked.connect(self.estimate)
            self.fitActions.startFitButton.clicked.connect(self.startFit)
            self.fitActions.dismissButton.clicked.connect(self.dismiss)