Changeset d3c0b95 in sasview for src


Ignore:
Timestamp:
Jan 10, 2018 3:15:53 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:
e147ce2
Parents:
eae226b
git-author:
Piotr Rozyczko <rozyczko@…> (01/10/18 03:05:35)
git-committer:
Piotr Rozyczko <rozyczko@…> (01/10/18 03:15:53)
Message:

Added constraints to the fitter

Location:
src/sas/qtgui/Perspectives/Fitting
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • src/sas/qtgui/Perspectives/Fitting/FittingWidget.py

    reae226b rd3c0b95  
    462462        self.options_widget.plot_signal.connect(self.onOptionsUpdate) 
    463463 
     464    def modelName(self): 
     465        """ 
     466        Returns model name, by default M<tab#>, e.g. M1, M2 
     467        """ 
     468        return "M%i" % self.tab_id 
     469 
     470    def nameForFittedData(self, name): 
     471        """ 
     472        Generate name for the current fit 
     473        """ 
     474        if self.is2D: 
     475            name += "2d" 
     476        name = "%s [%s]" % (self.modelName(), name) 
     477        return name 
     478 
    464479    def showModelContextMenu(self, position): 
    465  
    466         #rows = len([s.row() for s in self.lstParams.selectionModel().selectedRows()]) 
     480        """ 
     481        Show context specific menu in the parameter table. 
     482        When clicked on parameter(s): fitting/constraints options 
     483        When clicked on white space: model description 
     484        """ 
    467485        rows = [s.row() for s in self.lstParams.selectionModel().selectedRows()] 
    468486        menu = self.showModelDescription() if not rows else self.modelContextMenu(rows) 
     
    475493    def modelContextMenu(self, rows): 
    476494        """ 
    477         Create context menu for the given model 
     495        Create context menu for the parameter selection 
    478496        """ 
    479497        menu = QtWidgets.QMenu() 
     
    482500        param_string = "parameter " if num_rows==1 else "parameters " 
    483501        to_string = "to its current value" if num_rows==1 else "to their current values" 
     502        has_constraints = any([self.rowHasConstraint(i) for i in rows]) 
    484503 
    485504        self.actionSelect = QtWidgets.QAction(self) 
     
    511530        menu.addSeparator() 
    512531 
    513         if self.rowHasConstraint(rows[0]): 
     532        if has_constraints: 
    514533            menu.addAction(self.actionRemoveConstraint) 
     534            #if num_rows == 1: 
     535            #    menu.addAction(self.actionEditConstraint) 
    515536        else: 
    516537            menu.addAction(self.actionConstrain) 
    517         if num_rows == 2: 
    518             menu.addAction(self.actionMutualMultiConstrain) 
     538            if num_rows == 2: 
     539                menu.addAction(self.actionMutualMultiConstrain) 
    519540 
    520541        # Define the callbacks 
     
    549570        item = QtGui.QStandardItem() 
    550571        item.setData(constraint) 
     572 
    551573        # Which row is the constrained parameter in? 
    552  
    553574        row = self.rowFromName(constraint.param) 
    554575        self._model_model.item(row, 1).setChild(0, item) 
    555576        #self.constraintAddedSignal.emit([row]) 
     577 
    556578        # Show visual hints for the constraint 
    557579        font = QtGui.QFont() 
     
    560582        self.modifyViewOnRow(row, font=font, brush=brush) 
    561583 
    562         # Pass the constraint to the parser 
     584        # Notify the user 
    563585        self.communicate.statusBarUpdateSignal.emit('Constraints added') 
    564586 
    565587    def rowFromName(self, name): 
    566588        """ 
    567         given parameter name get the row number in self._model_model 
     589        Given parameter name get the row number in self._model_model 
    568590        """ 
    569591        for row in range(self._model_model.rowCount()): 
     
    596618        Adds a constraint on a single parameter. 
    597619        """ 
     620        min_col = self.lstParams.itemDelegate().param_min 
     621        max_col = self.lstParams.itemDelegate().param_max 
    598622        for row in self.selectedParameters(): 
    599623            param = self._model_model.item(row, 0).text() 
    600624            value = self._model_model.item(row, 1).text() 
    601             min = self._model_model.item(row, 2).text() 
    602             max = self._model_model.item(row, 3).text() 
     625            min = self._model_model.item(row, min_col).text() 
     626            max = self._model_model.item(row, max_col).text() 
    603627            # Create a Constraint object 
    604628            constraint = Constraint(param=param, value=value, min=min, max=max) 
     
    608632            self._model_model.item(row, 1).setChild(0, item) 
    609633            # Set min/max to the value constrained 
    610             self._model_model.item(row,2).setText(value) 
    611             self._model_model.item(row,3).setText(value) 
     634            self._model_model.item(row, min_col).setText(value) 
     635            self._model_model.item(row, max_col).setText(value) 
    612636            #self.constraintAddedSignal.emit([row]) 
    613637            # Show visual hints for the constraint 
     
    623647        Delete constraints from selected parameters. 
    624648        """ 
     649        min_col = self.lstParams.itemDelegate().param_min 
     650        max_col = self.lstParams.itemDelegate().param_max 
    625651        for row in self.selectedParameters(): 
    626652            # Get the Constraint object from of the model item 
    627653            item = self._model_model.item(row, 1) 
     654            if not item.hasChildren(): 
     655                continue 
    628656            constraint = item.child(0).data() 
     657            if constraint is None: 
     658                continue 
     659            if not isinstance(constraint, Constraint): 
     660                continue 
    629661            # Retrieve old values and put them on the model 
    630662            if constraint.min is not None: 
    631                 self._model_model.item(row, 2).setText(constraint.min) 
     663                self._model_model.item(row, min_col).setText(constraint.min) 
    632664            if constraint.max is not None: 
    633                 self._model_model.item(row, 3).setText(constraint.max) 
     665                self._model_model.item(row, max_col).setText(constraint.max) 
    634666            # Remove constraint item 
    635667            item.removeRow(0) 
     
    639671        pass 
    640672 
     673    def getConstraintForRow(self, row): 
     674        """ 
     675        For the given row, return its constraint, if any 
     676        """ 
     677        try: 
     678            item = self._model_model.item(row, 1) 
     679            return item.child(0).data() 
     680        except AttributeError: 
     681            # return none when no constraints 
     682            return None 
     683 
    641684    def rowHasConstraint(self, row): 
    642685        """ 
     
    648691    def selectParameters(self): 
    649692        """ 
    650         Selected parameters are chosen for fitting 
     693        Selected parameter is chosen for fitting 
    651694        """ 
    652695        status = QtCore.Qt.Checked 
     
    662705    def selectedParameters(self): 
    663706        """ Returns list of selected (highlighted) parameters """ 
    664         return [s.row() for s in self.lstParams.selectionModel().selectedRows() if self.isCheckable(s.row())] 
     707        return [s.row() for s in self.lstParams.selectionModel().selectedRows() 
     708                if self.isCheckable(s.row())] 
    665709 
    666710    def setParameterSelection(self, status=QtCore.Qt.Unchecked): 
     
    671715        for row in self.selectedParameters(): 
    672716            self._model_model.item(row, 0).setCheckState(status) 
    673         pass 
     717        pass # debugger hook 
     718 
     719    def getConstraintsForModel(self): 
     720        """ 
     721        Return a list of tuples. Each tuple contains constraints mapped as 
     722        ('constrained parameter', 'function to constrain') 
     723        e.g. [('sld','5*sld_solvent')] 
     724        """ 
     725        model_name = self.modelName() 
     726        self.kernel_module.name = model_name 
     727        param_number = self._model_model.rowCount() 
     728        params = [(self._model_model.item(s, 0).text(), 
     729                    model_name+"."+self._model_model.item(s, 1).child(0).data().func) 
     730                    for s in range(param_number) if self.rowHasConstraint(s)] 
     731        return params 
    674732 
    675733    def showModelDescription(self): 
     
    936994        # These should be updating somehow? 
    937995        fit_id = 0 
    938         constraints = [] 
     996        constraints = self.getConstraintsForModel() 
    939997        smearer = None 
    940998        page_id = [210] 
     
    16071665                if isChecked(row_index)] 
    16081666 
    1609     def nameForFittedData(self, name): 
    1610         """ 
    1611         Generate name for the current fit 
    1612         """ 
    1613         if self.is2D: 
    1614             name += "2d" 
    1615         name = "M%i [%s]" % (self.tab_id, name) 
    1616         return name 
    1617  
    16181667    def createNewIndex(self, fitted_data): 
    16191668        """ 
  • src/sas/qtgui/Perspectives/Fitting/MultiConstraint.py

    reae226b rd3c0b95  
    2929 
    3030        self.cmdOK.clicked.connect(self.accept) 
     31        self.cmdHelp.clicked.connect(self.onHelp) 
    3132        self.cmdRevert.clicked.connect(self.revert) 
    3233        self.txtConstraint.editingFinished.connect(self.validateFormula) 
     
    122123        return True 
    123124 
     125    def onHelp(self): 
     126        """ 
     127        Display related help section 
     128        """ 
     129        try: 
     130            location = GuiUtils.HELP_DIRECTORY_LOCATION + \ 
     131            "/user/sasgui/perspectives/fitting/fitting_help.html#simultaneous-fits-with-constraints" 
     132 
     133            self.manager._helpView.load(QtCore.QUrl(location)) 
     134            self.manager._helpView.show() 
     135        except AttributeError: 
     136            # No manager defined - testing and standalone runs 
     137            pass 
    124138 
    125139 
  • src/sas/qtgui/Perspectives/Fitting/UI/MultiConstraintUI.ui

    reae226b rd3c0b95  
    44 <widget class="QDialog" name="MultiConstraintUI"> 
    55  <property name="windowModality"> 
    6    <enum>Qt::WindowModal</enum> 
     6   <enum>Qt::ApplicationModal</enum> 
    77  </property> 
    88  <property name="geometry"> 
     
    150150       <property name="text"> 
    151151        <string>OK</string> 
     152       </property> 
     153      </widget> 
     154     </item> 
     155     <item> 
     156      <widget class="QPushButton" name="cmdCancel"> 
     157       <property name="text"> 
     158        <string>Cancel</string> 
     159       </property> 
     160      </widget> 
     161     </item> 
     162     <item> 
     163      <widget class="QPushButton" name="cmdHelp"> 
     164       <property name="text"> 
     165        <string>Help</string> 
    152166       </property> 
    153167      </widget> 
     
    175189   </hints> 
    176190  </connection> 
     191  <connection> 
     192   <sender>cmdCancel</sender> 
     193   <signal>clicked()</signal> 
     194   <receiver>MultiConstraintUI</receiver> 
     195   <slot>reject()</slot> 
     196   <hints> 
     197    <hint type="sourcelabel"> 
     198     <x>187</x> 
     199     <y>121</y> 
     200    </hint> 
     201    <hint type="destinationlabel"> 
     202     <x>184</x> 
     203     <y>71</y> 
     204    </hint> 
     205   </hints> 
     206  </connection> 
    177207 </connections> 
    178208</ui> 
Note: See TracChangeset for help on using the changeset viewer.