Changeset baeac95 in sasview


Ignore:
Timestamp:
Nov 14, 2018 5:43:28 AM (6 years ago)
Author:
Piotr Rozyczko <piotr.rozyczko@…>
Branches:
ESS_GUI, ESS_GUI_batch_fitting, ESS_GUI_bumps_abstraction, ESS_GUI_iss1116, ESS_GUI_opencl, ESS_GUI_ordering, ESS_GUI_sync_sascalc
Children:
ecc5d043
Parents:
e5ae812
Message:

Added Edit to single page constraint SASVIEW-1043

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

Legend:

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

    r14ec91c5 rbaeac95  
    55    hence made into a class. 
    66    """ 
    7     def __init__(self, parent=None, param=None, value=0.0, min=None, max=None, func=None): 
     7    def __init__(self, parent=None, param=None, value=0.0, min=None, max=None, func=None, value_ex=None): 
    88        self._value = value 
    99        self._param = param 
     10        self._value_ex = value_ex 
    1011        self._func = func 
    1112        self.active = True 
     
    1516    @property 
    1617    def value(self): 
     18        # value/parameter to fit to (e.g. 1.0 or sld) 
    1719        return self._value 
    1820 
     
    2224 
    2325    @property 
     26    def value_ex(self): 
     27        # full parameter name to fit to (e.g. M1.sld) 
     28        return self._value_ex 
     29 
     30    @value_ex.setter 
     31    def value_ex(self, val): 
     32        self._value_ex = val 
     33 
     34    @property 
    2435    def param(self): 
     36        # parameter which is being fitted 
    2537        return self._param 
    2638 
     
    3143    @property 
    3244    def func(self): 
     45        # Function to be used for constraint 
     46        # e.g. sqrt(M1.sld+1.0) 
    3347        return self._func 
    3448 
     
    3953    @property 
    4054    def min(self): 
     55        # min param value for single value constraints 
    4156        return self._min 
    4257 
     
    4762    @property 
    4863    def max(self): 
     64        # max param value for single value constraints 
    4965        return self._max 
    5066 
  • src/sas/qtgui/Perspectives/Fitting/FittingWidget.py

    re5ae812 rbaeac95  
    622622        to_string = "to its current value" if num_rows == 1 else "to their current values" 
    623623        has_constraints = any([self.rowHasConstraint(i) for i in rows]) 
     624        has_real_constraints = any([self.rowHasActiveConstraint(i) for i in rows]) 
    624625 
    625626        self.actionSelect = QtWidgets.QAction(self) 
     
    639640        self.actionRemoveConstraint.setText(QtCore.QCoreApplication.translate("self", "Remove constraint")) 
    640641 
     642        self.actionEditConstraint = QtWidgets.QAction(self) 
     643        self.actionEditConstraint.setObjectName("actionEditConstrain") 
     644        self.actionEditConstraint.setText(QtCore.QCoreApplication.translate("self", "Edit constraint")) 
     645 
    641646        self.actionMultiConstrain = QtWidgets.QAction(self) 
    642647        self.actionMultiConstrain.setObjectName("actionMultiConstrain") 
     
    653658        if has_constraints: 
    654659            menu.addAction(self.actionRemoveConstraint) 
     660            if num_rows == 1 and has_real_constraints: 
     661                menu.addAction(self.actionEditConstraint) 
    655662            #if num_rows == 1: 
    656663            #    menu.addAction(self.actionEditConstraint) 
     
    663670        self.actionConstrain.triggered.connect(self.addSimpleConstraint) 
    664671        self.actionRemoveConstraint.triggered.connect(self.deleteConstraint) 
     672        self.actionEditConstraint.triggered.connect(self.editConstraint) 
    665673        self.actionMutualMultiConstrain.triggered.connect(self.showMultiConstraint) 
    666674        self.actionSelect.triggered.connect(self.selectParameters) 
     
    700708        new_func = c_text.replace(param_used, updated_param_used) 
    701709        constraint.func = new_func 
     710        constraint.value_ex = updated_param_used 
    702711        # Which row is the constrained parameter in? 
    703712        row = self.getRowFromName(constraint.param) 
     713 
     714        # what is the parameter to constraint to? 
     715        constraint.value = param_used 
    704716 
    705717        # Create a new item and add the Constraint object as a child 
     
    797809            self.modifyViewOnRow(row, font=font, brush=brush) 
    798810        self.communicate.statusBarUpdateSignal.emit('Constraint added') 
     811 
     812    def editConstraint(self): 
     813        """ 
     814        Delete constraints from selected parameters. 
     815        """ 
     816        params_list = [s.data() for s in self.lstParams.selectionModel().selectedRows() 
     817                   if self.isCheckable(s.row())] 
     818        assert len(params_list) == 1 
     819        row = self.lstParams.selectionModel().selectedRows()[0].row() 
     820        constraint = self.getConstraintForRow(row) 
     821        # Create and display the widget for param1 and param2 
     822        mc_widget = MultiConstraint(self, params=params_list, constraint=constraint) 
     823        # Check if any of the parameters are polydisperse 
     824        if not np.any([FittingUtilities.isParamPolydisperse(p, self.model_parameters, is2D=self.is2D) for p in params_list]): 
     825            # no parameters are pd - reset the text to not show the warning 
     826            mc_widget.lblWarning.setText("") 
     827        if mc_widget.exec_() != QtWidgets.QDialog.Accepted: 
     828            return 
     829 
     830        constraint = Constraint() 
     831        c_text = mc_widget.txtConstraint.text() 
     832 
     833        # widget.params[0] is the parameter we're constraining 
     834        constraint.param = mc_widget.params[0] 
     835        # parameter should have the model name preamble 
     836        model_name = self.kernel_module.name 
     837        # param_used is the parameter we're using in constraining function 
     838        param_used = mc_widget.params[1] 
     839        # Replace param_used with model_name.param_used 
     840        updated_param_used = model_name + "." + param_used 
     841        # Update constraint with new values 
     842        constraint.func = c_text 
     843        constraint.value_ex = updated_param_used 
     844        constraint.value = param_used 
     845 
     846        # Which row is the constrained parameter in? 
     847        row = self.getRowFromName(constraint.param) 
     848 
     849        # Create a new item and add the Constraint object as a child 
     850        self.addConstraintToRow(constraint=constraint, row=row) 
    799851 
    800852    def deleteConstraint(self): 
     
    36033655                value = constraint.value 
    36043656                func = constraint.func 
    3605                 cons = (value, func) 
     3657                value_ex = constraint.value_ex 
     3658                param = constraint.param 
     3659 
     3660                cons = (value, param, value_ex, func) 
    36063661 
    36073662            param_list.append([param_name, param_checked, param_value, param_error, param_min, param_max, cons]) 
     
    38533908            # constraints 
    38543909            cons = param_dict[param_name][4+ioffset] 
    3855             if cons is not None and cons: 
     3910            if cons is not None and len(cons)==4: 
    38563911                value = cons[0] 
    3857                 function = cons[1] 
     3912                param = cons[1] 
     3913                value_ex = cons[2] 
     3914                function = cons[3] 
    38583915                constraint = Constraint() 
    38593916                constraint.value = value 
    38603917                constraint.func = function 
     3918                constraint.param = param 
     3919                constraint.value_ex = value_ex 
    38613920                self.addConstraintToRow(constraint=constraint, row=row) 
    38623921 
  • src/sas/qtgui/Perspectives/Fitting/MultiConstraint.py

    r305114c rbaeac95  
    2020    Logic class for interacting with MultiConstrainedUI view 
    2121    """ 
    22     def __init__(self, parent=None, params=None): 
     22    def __init__(self, parent=None, params=None, constraint=None): 
    2323        """ 
    2424        parent: ConstraintWidget object 
     
    3131        self.params = params 
    3232        self.parent = parent 
     33        self.function = None 
     34 
     35        self.input_constraint = constraint 
     36        if self.input_constraint is not None: 
     37            variable = constraint.value 
     38            #variable = func[func.index('.')+1:] 
     39            self.function = constraint.func 
     40            self.params.append(variable) 
     41            self.model_name = constraint.value_ex 
     42        else: 
     43            self.model_name = self.params[1] 
    3344 
    3445        self.setupLabels() 
     
    3647 
    3748        # Set param text control to the second parameter passed 
    38         self.txtConstraint.setText(self.params[1]) 
    39  
     49        if self.input_constraint is None: 
     50            self.txtConstraint.setText(self.params[1]) 
     51        else: 
     52            self.txtConstraint.setText(self.function) 
    4053        self.cmdOK.clicked.connect(self.accept) 
    4154        self.cmdHelp.clicked.connect(self.onHelp) 
     
    5265        # Switch parameters 
    5366        self.params[1], self.params[0] = self.params[0], self.params[1] 
     67        # change fully qualified param name (e.g. M1.sld -> M1.sld_solvent) 
     68        self.model_name = self.model_name.replace(self.params[0], self.params[1]) 
    5469        # Try to swap parameter names in the line edit 
    5570        current_text = self.txtConstraint.text() 
     
    6479        Setup labels based on current parameters 
    6580        """ 
    66         l1 = self.params[0] 
    67         l2 = self.params[1] 
     81        l1 = str(self.params[0]) 
     82        l2 = str(self.params[1]) 
    6883        self.txtParam1.setText(l1) 
    6984        self.txtParam1_2.setText(l1) 
     
    99114            return False 
    100115 
    101         param_str = str(self.params[1]) 
    102         constraint_text = constraint_text.strip() 
     116        param_str = self.model_name 
    103117 
    104118        # 1. just the parameter 
  • src/sas/qtgui/Perspectives/Fitting/UnitTesting/FittingWidgetTest.py

    r186d678 rbaeac95  
    185185 
    186186        # Observe no such luck 
    187         self.assertEqual(self.widget.cbCategory.currentIndex(), 6) 
    188         self.assertEqual(self.widget.cbModel.count(), 29) 
     187        self.assertEqual(self.widget.cbCategory.currentIndex(), 7) 
     188        self.assertEqual(self.widget.cbModel.count(), 30) 
    189189 
    190190        # Set the structure factor 
     
    219219        #  
    220220        # Now change the model 
    221 <<<<<<< HEAD 
    222221        self.widget.cbModel.setCurrentIndex(4) 
    223 ======= 
    224         self.widget.cbModel.setCurrentIndex(2) 
    225 >>>>>>> ESS_GUI 
    226222        self.assertEqual(self.widget.cbModel.currentText(),'dab') 
    227223 
Note: See TracChangeset for help on using the changeset viewer.