Changeset a3c94b54 in sasview for src


Ignore:
Timestamp:
Jan 10, 2018 5:05:35 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:
fca1f50
Parents:
2109350
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

    r2109350 ra3c94b54  
    466466        self.options_widget.plot_signal.connect(self.onOptionsUpdate) 
    467467 
     468    def modelName(self): 
     469        """ 
     470        Returns model name, by default M<tab#>, e.g. M1, M2 
     471        """ 
     472        return "M%i" % self.tab_id 
     473 
     474    def nameForFittedData(self, name): 
     475        """ 
     476        Generate name for the current fit 
     477        """ 
     478        if self.is2D: 
     479            name += "2d" 
     480        name = "%s [%s]" % (self.modelName(), name) 
     481        return name 
     482 
    468483    def showModelContextMenu(self, position): 
    469  
    470         #rows = len([s.row() for s in self.lstParams.selectionModel().selectedRows()]) 
     484        """ 
     485        Show context specific menu in the parameter table. 
     486        When clicked on parameter(s): fitting/constraints options 
     487        When clicked on white space: model description 
     488        """ 
    471489        rows = [s.row() for s in self.lstParams.selectionModel().selectedRows()] 
    472490        menu = self.showModelDescription() if not rows else self.modelContextMenu(rows) 
     
    479497    def modelContextMenu(self, rows): 
    480498        """ 
    481         Create context menu for the given model 
     499        Create context menu for the parameter selection 
    482500        """ 
    483501        menu = QtWidgets.QMenu() 
     
    486504        param_string = "parameter " if num_rows==1 else "parameters " 
    487505        to_string = "to its current value" if num_rows==1 else "to their current values" 
     506        has_constraints = any([self.rowHasConstraint(i) for i in rows]) 
    488507 
    489508        self.actionSelect = QtWidgets.QAction(self) 
     
    515534        menu.addSeparator() 
    516535 
    517         if self.rowHasConstraint(rows[0]): 
     536        if has_constraints: 
    518537            menu.addAction(self.actionRemoveConstraint) 
     538            #if num_rows == 1: 
     539            #    menu.addAction(self.actionEditConstraint) 
    519540        else: 
    520541            menu.addAction(self.actionConstrain) 
    521         if num_rows == 2: 
    522             menu.addAction(self.actionMutualMultiConstrain) 
     542            if num_rows == 2: 
     543                menu.addAction(self.actionMutualMultiConstrain) 
    523544 
    524545        # Define the callbacks 
     
    553574        item = QtGui.QStandardItem() 
    554575        item.setData(constraint) 
     576 
    555577        # Which row is the constrained parameter in? 
    556  
    557578        row = self.rowFromName(constraint.param) 
    558579        self._model_model.item(row, 1).setChild(0, item) 
    559580        #self.constraintAddedSignal.emit([row]) 
     581 
    560582        # Show visual hints for the constraint 
    561583        font = QtGui.QFont() 
     
    564586        self.modifyViewOnRow(row, font=font, brush=brush) 
    565587 
    566         # Pass the constraint to the parser 
     588        # Notify the user 
    567589        self.communicate.statusBarUpdateSignal.emit('Constraints added') 
    568590 
    569591    def rowFromName(self, name): 
    570592        """ 
    571         given parameter name get the row number in self._model_model 
     593        Given parameter name get the row number in self._model_model 
    572594        """ 
    573595        for row in range(self._model_model.rowCount()): 
     
    600622        Adds a constraint on a single parameter. 
    601623        """ 
     624        min_col = self.lstParams.itemDelegate().param_min 
     625        max_col = self.lstParams.itemDelegate().param_max 
    602626        for row in self.selectedParameters(): 
    603627            param = self._model_model.item(row, 0).text() 
    604628            value = self._model_model.item(row, 1).text() 
    605             min = self._model_model.item(row, 2).text() 
    606             max = self._model_model.item(row, 3).text() 
     629            min = self._model_model.item(row, min_col).text() 
     630            max = self._model_model.item(row, max_col).text() 
    607631            # Create a Constraint object 
    608632            constraint = Constraint(param=param, value=value, min=min, max=max) 
     
    612636            self._model_model.item(row, 1).setChild(0, item) 
    613637            # Set min/max to the value constrained 
    614             self._model_model.item(row,2).setText(value) 
    615             self._model_model.item(row,3).setText(value) 
     638            self._model_model.item(row, min_col).setText(value) 
     639            self._model_model.item(row, max_col).setText(value) 
    616640            #self.constraintAddedSignal.emit([row]) 
    617641            # Show visual hints for the constraint 
     
    627651        Delete constraints from selected parameters. 
    628652        """ 
     653        min_col = self.lstParams.itemDelegate().param_min 
     654        max_col = self.lstParams.itemDelegate().param_max 
    629655        for row in self.selectedParameters(): 
    630656            # Get the Constraint object from of the model item 
    631657            item = self._model_model.item(row, 1) 
     658            if not item.hasChildren(): 
     659                continue 
    632660            constraint = item.child(0).data() 
     661            if constraint is None: 
     662                continue 
     663            if not isinstance(constraint, Constraint): 
     664                continue 
    633665            # Retrieve old values and put them on the model 
    634666            if constraint.min is not None: 
    635                 self._model_model.item(row, 2).setText(constraint.min) 
     667                self._model_model.item(row, min_col).setText(constraint.min) 
    636668            if constraint.max is not None: 
    637                 self._model_model.item(row, 3).setText(constraint.max) 
     669                self._model_model.item(row, max_col).setText(constraint.max) 
    638670            # Remove constraint item 
    639671            item.removeRow(0) 
     
    643675        pass 
    644676 
     677    def getConstraintForRow(self, row): 
     678        """ 
     679        For the given row, return its constraint, if any 
     680        """ 
     681        try: 
     682            item = self._model_model.item(row, 1) 
     683            return item.child(0).data() 
     684        except AttributeError: 
     685            # return none when no constraints 
     686            return None 
     687 
    645688    def rowHasConstraint(self, row): 
    646689        """ 
     
    652695    def selectParameters(self): 
    653696        """ 
    654         Selected parameters are chosen for fitting 
     697        Selected parameter is chosen for fitting 
    655698        """ 
    656699        status = QtCore.Qt.Checked 
     
    666709    def selectedParameters(self): 
    667710        """ Returns list of selected (highlighted) parameters """ 
    668         return [s.row() for s in self.lstParams.selectionModel().selectedRows() if self.isCheckable(s.row())] 
     711        return [s.row() for s in self.lstParams.selectionModel().selectedRows() 
     712                if self.isCheckable(s.row())] 
    669713 
    670714    def setParameterSelection(self, status=QtCore.Qt.Unchecked): 
     
    675719        for row in self.selectedParameters(): 
    676720            self._model_model.item(row, 0).setCheckState(status) 
    677         pass 
     721        pass # debugger hook 
     722 
     723    def getConstraintsForModel(self): 
     724        """ 
     725        Return a list of tuples. Each tuple contains constraints mapped as 
     726        ('constrained parameter', 'function to constrain') 
     727        e.g. [('sld','5*sld_solvent')] 
     728        """ 
     729        model_name = self.modelName() 
     730        self.kernel_module.name = model_name 
     731        param_number = self._model_model.rowCount() 
     732        params = [(self._model_model.item(s, 0).text(), 
     733                    model_name+"."+self._model_model.item(s, 1).child(0).data().func) 
     734                    for s in range(param_number) if self.rowHasConstraint(s)] 
     735        return params 
    678736 
    679737    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

    r2109350 ra3c94b54  
    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

    r2109350 ra3c94b54  
    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.