Changeset f1ec901 in sasview for src


Ignore:
Timestamp:
Nov 21, 2017 3:21:57 AM (6 years ago)
Author:
Piotr Rozyczko <rozyczko@…>
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:
0580c77
Parents:
0261bc1
Message:

Minor updates to inversion

Location:
src/sas
Files:
4 edited

Legend:

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

    r6a3e1fe rf1ec901  
    3838 
    3939    name = "Inversion" 
     40    estimateSignal = QtCore.pyqtSignal(tuple) 
     41    estimateNTSignal = QtCore.pyqtSignal(tuple) 
     42    calculateSignal = QtCore.pyqtSignal(tuple) 
    4043 
    4144    def __init__(self, parent=None, data=None): 
     
    7679            for datum in data_list: 
    7780                self._data_list[datum] = self._calculator.clone() 
     81 
     82        # dict of models for quick update after calculation 
     83        # {item:model} 
     84        self._models = {} 
    7885 
    7986        # plots for current data 
     
    132139        """Connect the use controls to their appropriate methods""" 
    133140        self.dataList.currentIndexChanged.connect(self.displayChange) 
    134         #self.calculateAllButton.clicked.connect(self.startThreadAll) 
    135         #self.calculateThisButton.clicked.connect(self.startThread) 
     141        self.calculateAllButton.clicked.connect(self.startThreadAll) 
     142        self.calculateThisButton.clicked.connect(self.startThread) 
    136143        self.removeButton.clicked.connect(self.removeData) 
    137144        self.helpButton.clicked.connect(self.help) 
     
    141148        self.noOfTermsSuggestionButton.clicked.connect(self.acceptNoTerms) 
    142149        self.explorerButton.clicked.connect(self.openExplorerWindow) 
    143         self.backgroundInput.textChanged.connect( 
     150 
     151        self.backgroundInput.editingFinished.connect( 
    144152            lambda: self._calculator.set_est_bck(int(is_float( 
    145                 str(self.backgroundInput.text()))))) 
    146         self.minQInput.textChanged.connect( 
     153                self.backgroundInput.text())))) 
     154        self.minQInput.editingFinished.connect( 
    147155            lambda: self._calculator.set_qmin(is_float( 
    148                 str(self.minQInput.text())))) 
    149         self.regularizationConstantInput.textChanged.connect( 
     156                self.minQInput.text()))) 
     157        self.regularizationConstantInput.editingFinished.connect( 
    150158            lambda: self._calculator.set_alpha(is_float( 
    151                 str(self.regularizationConstantInput.text())))) 
    152         self.maxDistanceInput.textChanged.connect( 
     159                self.regularizationConstantInput.text()))) 
     160        self.maxDistanceInput.editingFinished.connect( 
    153161            lambda: self._calculator.set_dmax(is_float( 
    154                 str(self.maxDistanceInput.text())))) 
    155         self.maxQInput.textChanged.connect( 
     162                self.maxDistanceInput.text()))) 
     163        self.maxQInput.editingFinished.connect( 
    156164            lambda: self._calculator.set_qmax(is_float( 
    157                 str(self.maxQInput.text())))) 
    158         self.slitHeightInput.textChanged.connect( 
     165                self.maxQInput.text()))) 
     166        self.slitHeightInput.editingFinished.connect( 
    159167            lambda: self._calculator.set_slit_height(is_float( 
    160                 str(self.slitHeightInput.text())))) 
    161         self.slitWidthInput.textChanged.connect( 
     168                self.slitHeightInput.text()))) 
     169        self.slitWidthInput.editingFinished.connect( 
    162170            lambda: self._calculator.set_slit_width(is_float( 
    163                 str(self.slitHeightInput.text())))) 
     171                self.slitHeightInput.text()))) 
     172 
    164173        self.model.itemChanged.connect(self.model_changed) 
     174        self.estimateNTSignal.connect(self._estimateNTUpdate) 
     175        self.estimateSignal.connect(self._estimateUpdate) 
     176        self.calculateSignal.connect(self._calculateUpdate) 
    165177 
    166178    def setupMapper(self): 
     
    208220        # Main Buttons 
    209221        self.mapper.addMapping(self.removeButton, WIDGETS.W_REMOVE) 
    210         #self.mapper.addMapping(self.calculateAllButton, WIDGETS.W_CALCULATE_ALL) 
    211         #self.mapper.addMapping(self.calculateThisButton, 
    212         #                       WIDGETS.W_CALCULATE_VISIBLE) 
     222        self.mapper.addMapping(self.calculateAllButton, WIDGETS.W_CALCULATE_ALL) 
     223        self.mapper.addMapping(self.calculateThisButton, 
     224                               WIDGETS.W_CALCULATE_VISIBLE) 
    213225        self.mapper.addMapping(self.helpButton, WIDGETS.W_HELP) 
    214226 
     
    269281        self.removeButton.setEnabled(self.logic.data_is_loaded) 
    270282        self.explorerButton.setEnabled(self.logic.data_is_loaded) 
    271         #self.calculateAllButton.setEnabled(self.logic.data_is_loaded) 
    272         #self.calculateThisButton.setEnabled(self.logic.data_is_loaded) 
    273283 
    274284    def populateDataComboBox(self, filename, data_ref): 
     
    291301 
    292302    def displayChange(self): 
    293         variant_ref = self.dataList.itemData(self.dataList.currentIndex()) 
    294         self.setCurrentData(variant_ref) 
     303        ref_item = self.dataList.itemData(self.dataList.currentIndex()) 
     304        self._model_item = ref_item 
     305        self.setCurrentData(ref_item) 
     306        self.setCurrentModel(ref_item) 
    295307 
    296308    def removeData(self): 
     
    304316    ###################################################################### 
    305317    # GUI Interaction Events 
     318 
     319    def setCurrentModel(self, ref_item): 
     320        '''update the current model with stored values''' 
     321        if ref_item in self._models: 
     322            self.model = self._models[ref_item] 
    306323 
    307324    def update_calculator(self): 
     
    394411            self.model.setItem(WIDGETS.W_QMIN, QtGui.QStandardItem("{:.4g}".format(qmin))) 
    395412            self.model.setItem(WIDGETS.W_QMAX, QtGui.QStandardItem("{:.4g}".format(qmax))) 
     413            self._models[data] = self.model 
     414            self.model_item = data 
    396415 
    397416        self.enableButtons() 
     
    417436        self.pr_plot = self.pr_plot_list[data_ref] 
    418437        self.data_plot = self.data_plot_list[data_ref] 
    419         # Rerun the calculations for the current set 
    420         self.startThread() 
    421         self.model_changed() 
    422438 
    423439    ###################################################################### 
     
    448464        self.calc_thread = CalcPr(pr, nfunc, 
    449465                                  error_func=self._threadError, 
    450                                   completefn=self._completed, updatefn=None) 
     466                                  completefn=self._calculateCompleted, 
     467                                  updatefn=None) 
    451468        self.calc_thread.queue() 
    452469        self.calc_thread.ready(2.5) 
     
    454471    def performEstimateNT(self): 
    455472        """ 
    456             Perform parameter estimation 
     473        Perform parameter estimation 
    457474        """ 
    458475        from .Thread import EstimateNT 
     
    468485        pr.slit_width = 0.0 
    469486        nfunc = self.getNFunc() 
     487 
    470488        self.estimation_thread = EstimateNT(pr, nfunc, 
    471489                                            error_func=self._threadError, 
     
    500518 
    501519    def _estimateCompleted(self, alpha, message, elapsed): 
     520        ''' Send a signal to the main thread for model update''' 
     521        self.estimateSignal.emit((alpha, message, elapsed)) 
     522 
     523    def _estimateUpdate(self, output_tuple): 
    502524        """ 
    503525        Parameter estimation completed, 
     
    507529        :param elapsed: computation time 
    508530        """ 
     531        alpha, message, elapsed = output_tuple 
    509532        # Save useful info 
    510533        self.model.setItem(WIDGETS.W_COMP_TIME, QtGui.QStandardItem(str(elapsed))) 
     
    516539 
    517540    def _estimateNTCompleted(self, nterms, alpha, message, elapsed): 
     541        ''' Send a signal to the main thread for model update''' 
     542        self.estimateNTSignal.emit((nterms, alpha, message, elapsed)) 
     543 
     544    def _estimateNTUpdate(self, output_tuple): 
    518545        """ 
    519546        Parameter estimation completed, 
     
    523550        :param nterms: estimated number of terms 
    524551        :param elapsed: computation time 
    525  
    526         """ 
     552        """ 
     553        nterms, alpha, message, elapsed = output_tuple 
    527554        # Save useful info 
    528555        self.noOfTermsSuggestionButton.setText("{:n}".format(nterms)) 
     
    531558        self.regConstantSuggestionButton.setEnabled(True) 
    532559        self.model.setItem(WIDGETS.W_COMP_TIME, QtGui.QStandardItem(str(elapsed))) 
    533         #self.PrTabWidget.setCurrentIndex(0) 
    534560        if message: 
    535561            logging.info(message) 
    536562 
    537     def _completed(self, out, cov, pr, elapsed): 
     563    def _calculateCompleted(self, out, cov, pr, elapsed): 
     564        ''' Send a signal to the main thread for model update''' 
     565        self.calculateSignal.emit((out, cov, pr, elapsed)) 
     566 
     567    def _calculateUpdate(self, output_tuple): 
    538568        """ 
    539569        Method called with the results when the inversion is done 
     
    543573        :param pr: Invertor instance 
    544574        :param elapsed: time spent computing 
    545  
    546         """ 
     575        """ 
     576        out, cov, pr, elapsed = output_tuple 
    547577        # Save useful info 
    548578        cov = np.ascontiguousarray(cov) 
     
    572602        # Append data to data list 
    573603        self._data_list[self._data] = self._calculator.clone() 
     604 
     605        # Update model dict 
     606        self._models[self.model_item] = self.model 
    574607 
    575608        # Create new P(r) and fit plots 
  • src/sas/qtgui/Perspectives/Inversion/UI/TabbedInversionUI.ui

    r6a3e1fe rf1ec901  
    88    <y>0</y> 
    99    <width>458</width> 
    10     <height>679</height> 
     10    <height>695</height> 
    1111   </rect> 
    1212  </property> 
     
    565565   </item> 
    566566   <item row="2" column="0"> 
    567     <layout class="QHBoxLayout" name="horizontalLayout_8"> 
    568      <property name="sizeConstraint"> 
    569       <enum>QLayout::SetDefaultConstraint</enum> 
    570      </property> 
     567    <layout class="QHBoxLayout" name="horizontalLayout_5"> 
     568     <item> 
     569      <widget class="QPushButton" name="calculateThisButton"> 
     570       <property name="text"> 
     571        <string>Calculate</string> 
     572       </property> 
     573      </widget> 
     574     </item> 
     575     <item> 
     576      <widget class="QPushButton" name="calculateAllButton"> 
     577       <property name="text"> 
     578        <string>Calculate All</string> 
     579       </property> 
     580      </widget> 
     581     </item> 
    571582     <item> 
    572583      <spacer name="horizontalSpacer"> 
     
    579590       <property name="sizeHint" stdset="0"> 
    580591        <size> 
    581          <width>40</width> 
     592         <width>158</width> 
    582593         <height>20</height> 
    583594        </size> 
  • src/sas/sascalc/pr/invertor.py

    r6a3e1fe rf1ec901  
    481481            float(chi2) 
    482482        except: 
    483             chi2 = -1.0 
     483            chi2 = [-1.0] 
    484484        self.chi2 = chi2 
    485485 
  • src/sas/sasgui/perspectives/pr/pr_thread.py

    • Property mode changed from 100755 to 100644
    rfa81e94 rf1ec901  
    4141            # Thread was interrupted, just proceed 
    4242            pass 
    43         except: 
     43        except Exception as ex: 
    4444            if self.error_func is not None: 
    45                 self.error_func("CalcPr.compute: %s" % sys.exc_info()[1]) 
     45                self.error_func("CalcPr.compute: %s" % ex) 
    4646 
    4747class EstimatePr(CalcThread): 
     
    6969            # Thread was interrupted, just proceed 
    7070            pass 
    71         except: 
     71        except Exception as ex: 
    7272            if self.error_func is not None: 
    73                 self.error_func("EstimatePr.compute: %s" % sys.exc_info()[1]) 
     73                self.error_func("EstimatePr.compute: %s" % ex) 
    7474 
    7575class EstimateNT(CalcThread): 
     
    109109            # Thread was interrupted, just proceed 
    110110            pass 
    111         except: 
     111        except Exception as ex: 
    112112            if self.error_func is not None: 
    113                 self.error_func("EstimatePr2.compute: %s" % sys.exc_info()[1]) 
     113                self.error_func("EstimatePr2.compute: %s" % ex) 
Note: See TracChangeset for help on using the changeset viewer.