Changeset ae34d30 in sasview for src


Ignore:
Timestamp:
Apr 17, 2018 11:41:24 AM (6 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:
5a5e371
Parents:
98485fe
Message:

Dmax close events inform P(r) window, data removal removes batch results for that data set, and general code cleanup.

Location:
src/sas/qtgui
Files:
3 edited

Legend:

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

    rf4480f0 rae34d30  
    4242        super(DmaxWindow, self).__init__() 
    4343        self.setupUi(self) 
     44        self.parent = parent 
    4445 
    4546        self.setWindowTitle("Dₐₓ Explorer") 
     
    188189        data._yunit = y_unit 
    189190        self.plot.plot(data=data, marker="-") 
     191 
     192    def closeEvent(self, event): 
     193        """Override close event""" 
     194        self.parent.dmaxWindow = None 
     195        event.accept() 
  • src/sas/qtgui/Perspectives/Inversion/InversionPerspective.py

    r98485fe rae34d30  
    1 import sys 
    21import logging 
    3 import pylab 
    42import numpy as np 
    53 
     
    1614# pr inversion calculation elements 
    1715from sas.sascalc.pr.invertor import Invertor 
    18  
    1916# Batch calculation display 
    2017from sas.qtgui.Utilities.GridPanel import BatchInversionOutputPanel 
     
    6057 
    6158        # The window should not close 
    62         self._allow_close = False 
    63  
    64         # Visible data set items 
     59        self._allowClose = False 
     60 
     61        # Visible data items 
    6562        # current QStandardItem showing on the panel 
    6663        self._data = None 
     
    7269        self._calculator.est_bck = True 
    7370        # plots of self._data 
    74         self.pr_plot = None 
    75         self.data_plot = None 
     71        self.prPlot = None 
     72        self.dataPlot = None 
    7673        # suggested nTerms 
    7774        self.nTermsSuggested = NUMBER_OF_TERMS 
    7875 
    7976        # Calculation threads used by all data items 
    80         self.isBatch = False 
    81         self.calc_thread = None 
    82         self.estimation_thread = None 
    83         self.estimation_thread_nt = None 
     77        self.calcThread = None 
     78        self.estimationThread = None 
     79        self.estimationThreadNT = None 
    8480 
    8581        # Mapping for all data items 
    86         # list mapping data to all parameters 
    87         self._data_list = {} 
     82        # Dictionary mapping data to all parameters 
     83        self._dataList = {} 
    8884        if not isinstance(data, list): 
    8985            data_list = [data] 
     
    9793        self.mapper = QtWidgets.QDataWidgetMapper(self) 
    9894 
    99         # Batch fitting results 
    100         self.grid_window = None 
     95        # Batch fitting parameters 
     96        self.isBatch = False 
     97        self.batchResultsWindow = None 
    10198        self.batchResults = {} 
    10299        self.batchComplete = [] 
     
    127124        """ 
    128125        assert isinstance(value, bool) 
    129         self._allow_close = value 
     126        self._allowClose = value 
    130127 
    131128    def closeEvent(self, event): 
     
    133130        Overwrite QDialog close method to allow for custom widget close 
    134131        """ 
    135         if self._allow_close: 
     132        # Close report widgets before closing/minimizing main widget 
     133        self.closeDMax() 
     134        self.closeBatchResults() 
     135        if self._allowClose: 
    136136            # reset the closability flag 
    137137            self.setClosable(value=False) 
     
    143143            # Maybe we should just minimize 
    144144            self.setWindowState(QtCore.Qt.WindowMinimized) 
     145 
     146    def closeDMax(self): 
     147        if self.dmaxWindow is not None: 
     148            self.dmaxWindow.close() 
     149 
     150    def closeBatchResults(self): 
     151        if self.batchResultsWindow is not None: 
     152            self.batchResultsWindow.close() 
    145153 
    146154    ###################################################################### 
     
    230238        Update boxes with initial values 
    231239        """ 
    232         item = QtGui.QStandardItem(str(BACKGROUND_INPUT)) 
    233         self.model.setItem(WIDGETS.W_BACKGROUND_INPUT, item) 
    234         item = QtGui.QStandardItem("") 
    235         self.model.setItem(WIDGETS.W_QMIN, item) 
    236         item = QtGui.QStandardItem("") 
    237         self.model.setItem(WIDGETS.W_QMAX, item) 
    238         item = QtGui.QStandardItem("") 
    239         self.model.setItem(WIDGETS.W_SLIT_WIDTH, item) 
    240         item = QtGui.QStandardItem("") 
    241         self.model.setItem(WIDGETS.W_SLIT_HEIGHT, item) 
    242         item = QtGui.QStandardItem(str(NUMBER_OF_TERMS)) 
    243         self.model.setItem(WIDGETS.W_NO_TERMS, item) 
    244         item = QtGui.QStandardItem(str(REGULARIZATION)) 
    245         self.model.setItem(WIDGETS.W_REGULARIZATION, item) 
    246         item = QtGui.QStandardItem(str(MAX_DIST)) 
    247         self.model.setItem(WIDGETS.W_MAX_DIST, item) 
    248         item = QtGui.QStandardItem("") 
    249         self.model.setItem(WIDGETS.W_RG, item) 
    250         item = QtGui.QStandardItem("") 
    251         self.model.setItem(WIDGETS.W_I_ZERO, item) 
    252         item = QtGui.QStandardItem("") 
    253         self.model.setItem(WIDGETS.W_BACKGROUND_OUTPUT, item) 
    254         item = QtGui.QStandardItem("") 
    255         self.model.setItem(WIDGETS.W_COMP_TIME, item) 
    256         item = QtGui.QStandardItem("") 
    257         self.model.setItem(WIDGETS.W_CHI_SQUARED, item) 
    258         item = QtGui.QStandardItem("") 
    259         self.model.setItem(WIDGETS.W_OSCILLATION, item) 
    260         item = QtGui.QStandardItem("") 
    261         self.model.setItem(WIDGETS.W_POS_FRACTION, item) 
    262         item = QtGui.QStandardItem("") 
    263         self.model.setItem(WIDGETS.W_SIGMA_POS_FRACTION, item) 
     240        blank_item = QtGui.QStandardItem("") 
     241        no_terms_item = QtGui.QStandardItem(str(NUMBER_OF_TERMS)) 
     242        bgd_item = QtGui.QStandardItem(str(BACKGROUND_INPUT)) 
     243        reg_item = QtGui.QStandardItem(str(REGULARIZATION)) 
     244        max_dist_item = QtGui.QStandardItem(str(MAX_DIST)) 
     245        self.model.setItem(WIDGETS.W_BACKGROUND_INPUT, bgd_item) 
     246        self.model.setItem(WIDGETS.W_QMIN, blank_item) 
     247        self.model.setItem(WIDGETS.W_QMAX, blank_item) 
     248        self.model.setItem(WIDGETS.W_SLIT_WIDTH, blank_item) 
     249        self.model.setItem(WIDGETS.W_SLIT_HEIGHT, blank_item) 
     250        self.model.setItem(WIDGETS.W_NO_TERMS, no_terms_item) 
     251        self.model.setItem(WIDGETS.W_REGULARIZATION, reg_item) 
     252        self.model.setItem(WIDGETS.W_MAX_DIST, max_dist_item) 
     253        self.model.setItem(WIDGETS.W_RG, blank_item) 
     254        self.model.setItem(WIDGETS.W_I_ZERO, blank_item) 
     255        self.model.setItem(WIDGETS.W_BACKGROUND_OUTPUT, bgd_item) 
     256        self.model.setItem(WIDGETS.W_COMP_TIME, blank_item) 
     257        self.model.setItem(WIDGETS.W_CHI_SQUARED, blank_item) 
     258        self.model.setItem(WIDGETS.W_OSCILLATION, blank_item) 
     259        self.model.setItem(WIDGETS.W_POS_FRACTION, blank_item) 
     260        self.model.setItem(WIDGETS.W_SIGMA_POS_FRACTION, blank_item) 
    264261 
    265262    def setupWindow(self): 
     
    285282        Enable buttons when data is present, else disable them 
    286283        """ 
    287         self.calculateAllButton.setEnabled(len(self._data_list) > 1) 
    288         self.calculateThisButton.setEnabled(self.logic.data_is_loaded) 
     284        self.calculateAllButton.setEnabled(len(self._dataList) > 1 
     285                                           and not self.isBatch) 
     286        self.calculateThisButton.setEnabled(self.logic.data_is_loaded 
     287                                            and not self.isBatch) 
    289288        self.removeButton.setEnabled(self.logic.data_is_loaded) 
    290289        self.explorerButton.setEnabled(self.logic.data_is_loaded) 
     
    320319    # GUI Interaction Events 
    321320 
    322     def update_calculator(self): 
     321    def updateCalculator(self): 
    323322        """Update all p(r) params""" 
    324323        self._calculator.set_x(self.logic.data.x) 
     
    338337            self.setClosable(True) 
    339338            self.close() 
    340             InversionWindow.__init__(self.parent(), list(self._data_list.keys())) 
     339            InversionWindow.__init__(self.parent(), list(self._dataList.keys())) 
    341340            exit(0) 
    342341        if self.dmaxWindow is not None: 
     
    384383        :param output_data: Dictionary mapping filename -> P(r) instance 
    385384        """ 
    386         if self.grid_window is None: 
    387             self.grid_window = BatchInversionOutputPanel( 
     385        if self.batchResultsWindow is None: 
     386            self.batchResultsWindow = BatchInversionOutputPanel( 
    388387                parent=self, output_data=self.batchResults) 
    389388        else: 
    390             self.grid_window.setupTable(self.batchResults) 
    391         self.grid_window.show() 
     389            self.batchResultsWindow.setupTable(self.batchResults) 
     390        self.batchResultsWindow.show() 
    392391 
    393392    ###################################################################### 
     
    407406 
    408407        for data in data_item: 
    409             if data in self._data_list.keys(): 
     408            if data in self._dataList.keys(): 
    410409                # Don't add data if it's already in 
    411410                continue 
     
    425424        if dataRef is None: 
    426425            return 
    427         self._data_list[dataRef] = { 
     426        self._dataList[dataRef] = { 
    428427            DICT_KEYS[0]: self._calculator, 
    429             DICT_KEYS[1]: self.pr_plot, 
    430             DICT_KEYS[2]: self.data_plot 
     428            DICT_KEYS[1]: self.prPlot, 
     429            DICT_KEYS[2]: self.dataPlot 
    431430        } 
    432431        # Update batch results window when finished 
    433432        self.batchResults[self.logic.data.filename] = self._calculator 
    434         if self.grid_window is not None: 
     433        if self.batchResultsWindow is not None: 
    435434            self.showBatchOutput() 
    436435 
     
    456455        self._data = data_ref 
    457456        self.logic.data = GuiUtils.dataFromItem(data_ref) 
    458         self._calculator = self._data_list[data_ref].get(DICT_KEYS[0]) 
    459         self.pr_plot = self._data_list[data_ref].get(DICT_KEYS[1]) 
    460         self.data_plot = self._data_list[data_ref].get(DICT_KEYS[2]) 
     457        self._calculator = self._dataList[data_ref].get(DICT_KEYS[0]) 
     458        self.prPlot = self._dataList[data_ref].get(DICT_KEYS[1]) 
     459        self.dataPlot = self._dataList[data_ref].get(DICT_KEYS[2]) 
    461460        self.performEstimate() 
    462461 
     
    477476        self.model.setItem(WIDGETS.W_COMP_TIME, 
    478477                           QtGui.QStandardItem("{:.4g}".format(elapsed))) 
     478        self.model.setItem(WIDGETS.W_MAX_DIST, 
     479                           QtGui.QStandardItem("{:.4g}".format(pr.get_dmax()))) 
    479480        self.regConstantSuggestionButton.setText("{:-3.2g}".format(alpha)) 
    480481        self.noOfTermsSuggestionButton.setText( 
    481482            "{:n}".format(self.nTermsSuggested)) 
    482         self.model.setItem(WIDGETS.W_COMP_TIME, 
    483                            QtGui.QStandardItem("{:.2g}".format(elapsed))) 
    484483 
    485484        if isinstance(pr.chi2, np.ndarray): 
     
    501500                                       "{:.3g}".format( 
    502501                                           pr.get_pos_err(out, cov)))) 
    503         if self.pr_plot is not None: 
    504             title = self.pr_plot.name 
    505             GuiUtils.updateModelItemWithPlot(self._data, self.pr_plot, title) 
    506             self.communicate.plotRequestedSignal.emit([self.pr_plot]) 
    507         if self.data_plot is not None: 
    508             title = self.data_plot.name 
    509             GuiUtils.updateModelItemWithPlot(self._data, self.data_plot, title) 
     502        if self.prPlot is not None: 
     503            title = self.prPlot.name 
     504            GuiUtils.updateModelItemWithPlot(self._data, self.prPlot, title) 
     505            self.communicate.plotRequestedSignal.emit([self.prPlot]) 
     506        if self.dataPlot is not None: 
     507            title = self.dataPlot.name 
     508            GuiUtils.updateModelItemWithPlot(self._data, self.dataPlot, title) 
    510509            self.communicate.plotRequestedSignal.emit( 
    511                 [self.data_plot, self.logic.data]) 
     510                [self.dataPlot, self.logic.data]) 
    512511        self.enableButtons() 
    513512 
    514513    def removeData(self, data_list=None): 
    515514        """Remove the existing data reference from the P(r) Persepective""" 
    516         if self.dmaxWindow is not None: 
    517             self.dmaxWindow.close() 
    518             self.dmaxWindow = None 
    519         if self.grid_window is not None: 
    520             self.grid_window.close() 
    521515        if not data_list: 
    522516            data_list = [self._data] 
     517        self.closeDMax() 
    523518        for data in data_list: 
    524             self._data_list.pop(data) 
     519            self._dataList.pop(data) 
     520            data_file = GuiUtils.dataFromItem(data) 
     521            self.batchResults.pop(data_file.filename) 
    525522        self._data = None 
    526523        for index in range(0, len(self.dataList)): 
     
    528525                self.dataList.removeItem(index) 
    529526        # Last file removed 
    530         if len(self._data_list) == 0: 
    531             self._data = None 
    532             self.pr_plot = None 
    533             self.data_plot = None 
     527        if len(self._dataList) == 0: 
     528            self.prPlot = None 
     529            self.dataPlot = None 
     530            self.logic.data = None 
    534531            self._calculator = Invertor() 
    535             self.logic.data = None 
     532            self.closeBatchResults() 
    536533            self.nTermsSuggested = NUMBER_OF_TERMS 
    537534            self.noOfTermsSuggestionButton.setText("{:n}".format( 
     
    549546 
    550547    def startThreadAll(self): 
     548        self.calculateAllButton.setText("Calculating...") 
    551549        self.batchComplete = [] 
    552550        self.isBatch = True 
     
    556554    def startNextBatchItem(self): 
    557555        self.isBatch = False 
    558         for index in range(len(self._data_list)): 
     556        for index in range(len(self._dataList)): 
    559557            if index not in self.batchComplete: 
    560558                self.dataList.setCurrentIndex(index) 
    561559                self.isBatch = True 
    562560                break 
    563         # If none left, end 
    564561        if self.isBatch: 
    565562            self.performEstimate() 
     563        else: 
     564            # If no data sets left, end batch calculation 
     565            self.calculateAllButton.setText("Calculate All") 
     566            self.enableButtons() 
    566567 
    567568    def startThread(self): 
     
    572573 
    573574        # Set data before running the calculations 
    574         self.update_calculator() 
     575        self.updateCalculator() 
    575576 
    576577        # If a thread is already started, stop it 
    577         if self.calc_thread is not None and self.calc_thread.isrunning(): 
    578             self.calc_thread.stop() 
     578        if self.calcThread is not None and self.calcThread.isrunning(): 
     579            self.calcThread.stop() 
    579580        pr = self._calculator.clone() 
    580581        nfunc = self.getNFunc() 
    581         self.calc_thread = CalcPr(pr, nfunc, 
    582                                   error_func=self._threadError, 
    583                                   completefn=self._calculateCompleted, 
    584                                   updatefn=None) 
    585         self.calc_thread.queue() 
    586         self.calc_thread.ready(2.5) 
     582        self.calcThread = CalcPr(pr, nfunc, 
     583                                 error_func=self._threadError, 
     584                                 completefn=self._calculateCompleted, 
     585                                 updatefn=None) 
     586        self.calcThread.queue() 
     587        self.calcThread.ready(2.5) 
    587588 
    588589    def performEstimateNT(self): 
     
    592593        from .Thread import EstimateNT 
    593594 
    594         self.update_calculator() 
     595        self.updateCalculator() 
    595596 
    596597        # If a thread is already started, stop it 
    597         if (self.estimation_thread_nt is not None and 
    598                 self.estimation_thread_nt.isrunning()): 
    599             self.estimation_thread_nt.stop() 
     598        if (self.estimationThreadNT is not None and 
     599                self.estimationThreadNT.isrunning()): 
     600            self.estimationThreadNT.stop() 
    600601        pr = self._calculator.clone() 
    601602        # Skip the slit settings for the estimation 
     
    605606        nfunc = self.getNFunc() 
    606607 
    607         self.estimation_thread_nt = EstimateNT(pr, nfunc, 
    608                                             error_func=self._threadError, 
    609                                             completefn=self._estimateNTCompleted, 
    610                                             updatefn=None) 
    611         self.estimation_thread_nt.queue() 
    612         self.estimation_thread_nt.ready(2.5) 
     608        self.estimationThreadNT = EstimateNT(pr, nfunc, 
     609                                             error_func=self._threadError, 
     610                                             completefn=self._estimateNTCompleted, 
     611                                             updatefn=None) 
     612        self.estimationThreadNT.queue() 
     613        self.estimationThreadNT.ready(2.5) 
    613614 
    614615    def performEstimate(self): 
     
    619620 
    620621        # If a thread is already started, stop it 
    621         if (self.estimation_thread is not None and 
    622                 self.estimation_thread.isrunning()): 
    623             self.estimation_thread.stop() 
    624         self.estimation_thread = EstimatePr(self._calculator.clone(), 
    625                                             self.getNFunc(), 
    626                                             error_func=self._threadError, 
    627                                             completefn=self._estimateCompleted, 
    628                                             updatefn=None) 
    629         self.estimation_thread.queue() 
    630         self.estimation_thread.ready(2.5) 
     622        if (self.estimationThread is not None and 
     623                self.estimationThread.isrunning()): 
     624            self.estimationThread.stop() 
     625        self.estimationThread = EstimatePr(self._calculator.clone(), 
     626                                           self.getNFunc(), 
     627                                           error_func=self._threadError, 
     628                                           completefn=self._estimateCompleted, 
     629                                           updatefn=None) 
     630        self.estimationThread.queue() 
     631        self.estimationThread.ready(2.5) 
    631632 
    632633    ###################################################################### 
     
    700701 
    701702        # Update P(r) and fit plots 
    702         self.pr_plot = self.logic.newPRPlot(out, self._calculator, cov) 
    703         self.pr_plot.filename = self.logic.data.filename 
    704         self.data_plot = self.logic.new1DPlot(out, self._calculator) 
    705         self.data_plot.filename = self.logic.data.filename 
     703        self.prPlot = self.logic.newPRPlot(out, self._calculator, cov) 
     704        self.prPlot.filename = self.logic.data.filename 
     705        self.dataPlot = self.logic.new1DPlot(out, self._calculator) 
     706        self.dataPlot.filename = self.logic.data.filename 
    706707 
    707708        # Udpate internals and GUI 
  • src/sas/qtgui/Utilities/GridPanel.py

    r98485fe rae34d30  
    352352    def closeEvent(self, event): 
    353353        """Tell the parent window the window closed""" 
    354         self.parent.grid_window = None 
     354        self.parent.batchResultsWindow = None 
    355355        event.accept() 
Note: See TracChangeset for help on using the changeset viewer.