Ignore:
Timestamp:
Oct 28, 2017 10:02:15 AM (7 years ago)
Author:
krzywon
Branches:
ESS_GUI, ESS_GUI_Docs, ESS_GUI_batch_fitting, ESS_GUI_bumps_abstraction, ESS_GUI_iss1116, ESS_GUI_iss879, ESS_GUI_iss959, ESS_GUI_opencl, ESS_GUI_ordering, ESS_GUI_sync_sascalc
Children:
d132f33
Parents:
e7651ff
Message:

Plots generated and linked to data set.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/sas/qtgui/Perspectives/Inversion/InversionPerspective.py

    re7651ff r57ad773  
    1212# pr inversion GUI elements 
    1313from InversionUtils import WIDGETS 
    14 import UI.TabbedPrInversionUI 
    15 from UI.TabbedPrInversionUI import Ui_PrInversion 
     14import UI.TabbedInversionUI 
     15from UI.TabbedInversionUI import Ui_PrInversion 
    1616from InversionLogic import InversionLogic 
    1717 
     
    118118        """Connect the use controls to their appropriate methods""" 
    119119        self.enableButtons() 
    120         self.checkBgdClicked(False) 
    121120        # TODO: enable the drop down box once batch is working 
    122121        self.dataList.setEnabled(False) 
     
    130129        self.noOfTermsSuggestionButton.clicked.connect(self.acceptNoTerms) 
    131130        self.explorerButton.clicked.connect(self.openExplorerWindow) 
     131        self.backgroundInput.textChanged.connect( 
     132            lambda: self._calculator.set_est_bck(int(is_float( 
     133                str(self.backgroundInput.text()))))) 
     134        self.minQInput.textChanged.connect( 
     135            lambda: self._calculator.set_qmin(is_float( 
     136                str(self.minQInput.text())))) 
     137        self.regularizationConstantInput.textChanged.connect( 
     138            lambda: self._calculator.set_alpha(is_float( 
     139                str(self.regularizationConstantInput.text())))) 
     140        self.maxDistanceInput.textChanged.connect( 
     141            lambda: self._calculator.set_dmax(is_float( 
     142                str(self.maxDistanceInput.text())))) 
     143        self.maxQInput.textChanged.connect( 
     144            lambda: self._calculator.set_qmax(is_float( 
     145                str(self.maxQInput.text())))) 
     146        self.slitHeightInput.textChanged.connect( 
     147            lambda: self._calculator.set_slit_height(is_float( 
     148                str(self.slitHeightInput.text())))) 
     149        self.slitWidthInput.textChanged.connect( 
     150            lambda: self._calculator.set_slit_width(is_float( 
     151                str(self.slitHeightInput.text())))) 
    132152        self.model.itemChanged.connect(self.model_changed) 
     153        self.estimateBgd.setChecked(True) 
    133154 
    134155    def setupMapper(self): 
     
    255276 
    256277    def update_calculator(self): 
    257         """Update all p(r) params. Take all GUI values as an override""" 
     278        """Update all p(r) params""" 
    258279        self._calculator.set_x(self._data_set.x) 
    259280        self._calculator.set_y(self._data_set.y) 
    260281        self._calculator.set_err(self._data_set.dy) 
    261         self._calculator.set_qmin(is_float(UI.TabbedPrInversionUI._fromUtf8( 
    262             self.minQInput.text()))) 
    263         self._calculator.set_qmax(is_float(UI.TabbedPrInversionUI._fromUtf8( 
    264             self.maxQInput.text()))) 
    265         self._calculator.set_alpha(is_float(UI.TabbedPrInversionUI._fromUtf8( 
    266             self.regularizationConstantInput.text()))) 
    267         self._calculator.set_dmax(is_float(UI.TabbedPrInversionUI._fromUtf8( 
    268             self.maxDistanceInput.text()))) 
    269         self._calculator.set_est_bck(int(is_float( 
    270             UI.TabbedPrInversionUI._fromUtf8(self.backgroundInput.text())))) 
    271         self._calculator.set_slit_height(is_float( 
    272             UI.TabbedPrInversionUI._fromUtf8(self.slitHeightInput.text()))) 
    273         self._calculator.set_slit_width(is_float( 
    274             UI.TabbedPrInversionUI._fromUtf8(self.slitWidthInput.text()))) 
    275282 
    276283    def _calculation(self): 
     
    278285        Calculate the P(r) for every data set in the data list 
    279286        """ 
    280         # Pull in any GUI changes before running the calculations 
     287        # Set data before running the calculations 
    281288        self.update_calculator() 
    282289        # Run 
     
    287294        if not self.mapper: 
    288295            return 
    289         # TODO: Update plots 
     296        if self.pr_plot is not None: 
     297            title = self.pr_plot.name 
     298            GuiUtils.updateModelItemWithPlot( 
     299                self._data, QtCore.QVariant(self.pr_plot), title) 
     300        if self.data_plot is not None: 
     301            title = self.data_plot.name 
     302            GuiUtils.updateModelItemWithPlot( 
     303                self._data, QtCore.QVariant(self.data_plot), title) 
    290304        self.mapper.toFirst() 
    291305 
     
    303317        self._helpView.show() 
    304318 
    305     def checkBgdClicked(self, boolean=None): 
    306         if boolean or self.manualBgd.isChecked(): 
    307             self.manualBgd.setChecked(True) 
    308             self.toggleBgd(self.manualBgd) 
    309         else: 
    310             self.estimateBgd.setChecked(True) 
    311             self.toggleBgd(self.estimateBgd) 
    312  
    313     def toggleBgd(self, item=None): 
     319    def toggleBgd(self): 
    314320        """ 
    315321        Toggle the background between manual and estimated 
    316322        :param item: gui item that was triggered 
    317323        """ 
    318         if not item: 
    319             self.checkBgdClicked() 
    320         elif isinstance(item, QtGui.QRadioButton): 
    321             if item is self.estimateBgd: 
    322                 self.backgroundInput.setEnabled(False) 
    323             else: 
    324                 self.backgroundInput.setEnabled(True) 
     324        sender = self.sender() 
     325        if sender is self.estimateBgd: 
     326            self.backgroundInput.setEnabled(False) 
     327        else: 
     328            self.backgroundInput.setEnabled(True) 
    325329 
    326330    def openExplorerWindow(self): 
     
    353357            self._data = data 
    354358            self._data_set = GuiUtils.dataFromItem(data) 
    355             self.enableButtons() 
    356359            self.populateDataComboBox(self._data_set.filename) 
    357360 
    358361            # Estimate initial values from data 
    359362            self.performEstimate() 
    360             self.logic.data(self._calculator) 
    361  
    362             self._manager.createGuiData(None) 
    363  
    364             # TODO: Finish plotting 
    365             if self.pr_plot is None: 
    366                 self.pr_plot = None 
    367                 #self.pr_plot = self.logic.new1DPlot(self._calculator) 
    368             if self.data_plot is None: 
    369                 self.data_plot = None 
    370  
    371             qmin, qmax, _ = self.logic.computeDataRange() 
    372             title = self._data.filename 
     363            self.logic = InversionLogic(self._data_set) 
     364 
     365            qmin, qmax = self.logic.computeDataRange() 
    373366 
    374367            self.model.setItem(WIDGETS.W_QMIN, QtGui.QStandardItem( 
     
    376369            self.model.setItem(WIDGETS.W_QMAX, QtGui.QStandardItem( 
    377370                "{:.4g}".format(qmax))) 
    378             #reactor.callFromThread(GuiUtils.updateModelItemWithPlot, 
    379             #                       self._model_item, self._communicator, title) 
     371 
     372            self.enableButtons() 
    380373 
    381374            # TODO: Only load 1st data until batch mode working. Thus, break 
     
    395388            self.calc_thread.stop() 
    396389        pr = self._calculator.clone() 
    397         nfunc = int(UI.TabbedPrInversionUI._fromUtf8( 
     390        nfunc = int(UI.TabbedInversionUI._fromUtf8( 
    398391            self.noOfTermsInput.text())) 
    399392        self.calc_thread = CalcPr(pr, nfunc, 
     
    418411        pr.slit_height = 0.0 
    419412        pr.slit_width = 0.0 
    420         nfunc = int(UI.TabbedPrInversionUI._fromUtf8( 
     413        nfunc = int(UI.TabbedInversionUI._fromUtf8( 
    421414            self.noOfTermsInput.text())) 
    422415        self.estimation_thread = EstimateNT(pr, nfunc, 
     
    440433            self.estimation_thread.stop() 
    441434        pr = self._calculator.clone() 
    442         nfunc = int(UI.TabbedPrInversionUI._fromUtf8( 
     435        nfunc = int(UI.TabbedInversionUI._fromUtf8( 
    443436            self.noOfTermsInput.text())) 
    444437        self.estimation_thread = EstimatePr(pr, nfunc, 
     
    503496        """ 
    504497        # Save useful info 
    505         # Keep a copy of the last result 
    506         self._last_calculator = pr.clone() 
    507  
    508         # Save Pr invertor 
    509         self._calculator = pr 
    510498        cov = np.ascontiguousarray(cov) 
     499        pr.cov = cov 
     500        pr.out = out 
     501        pr.elapsed = elapsed 
    511502 
    512503        # Show result on control panel 
     
    533524        # Display results tab 
    534525        self.PrTabWidget.setCurrentIndex(1) 
     526        # Save Pr invertor 
     527        self._calculator = pr 
     528        # Append data to data list 
    535529        self._data_list.append({self._data: pr}) 
    536530 
    537         # TODO: Show plots - Really, this should be linked to the inputs, etc, 
    538         # TODO: so it should happen automagically 
    539         # Show I(q) fit 
    540         # self.show_iq(out, self._calculator) 
    541         # Show P(r) fit 
    542         # self.show_pr(out, self._calculator, cov) 
     531        if self.pr_plot is None: 
     532            self.pr_plot = self.logic.newPRPlot(out, self._calculator, cov) 
     533        if self.data_plot is None: 
     534            self.data_plot = self.logic.new1DPlot(out, self._calculator) 
    543535 
    544536    def _threadError(self, error): 
Note: See TracChangeset for help on using the changeset viewer.