- Timestamp:
- Nov 14, 2018 5:43:28 AM (6 years ago)
- 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
- Location:
- src/sas/qtgui/Perspectives/Fitting
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
src/sas/qtgui/Perspectives/Fitting/Constraint.py
r14ec91c5 rbaeac95 5 5 hence made into a class. 6 6 """ 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): 8 8 self._value = value 9 9 self._param = param 10 self._value_ex = value_ex 10 11 self._func = func 11 12 self.active = True … … 15 16 @property 16 17 def value(self): 18 # value/parameter to fit to (e.g. 1.0 or sld) 17 19 return self._value 18 20 … … 22 24 23 25 @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 24 35 def param(self): 36 # parameter which is being fitted 25 37 return self._param 26 38 … … 31 43 @property 32 44 def func(self): 45 # Function to be used for constraint 46 # e.g. sqrt(M1.sld+1.0) 33 47 return self._func 34 48 … … 39 53 @property 40 54 def min(self): 55 # min param value for single value constraints 41 56 return self._min 42 57 … … 47 62 @property 48 63 def max(self): 64 # max param value for single value constraints 49 65 return self._max 50 66 -
src/sas/qtgui/Perspectives/Fitting/FittingWidget.py
re5ae812 rbaeac95 622 622 to_string = "to its current value" if num_rows == 1 else "to their current values" 623 623 has_constraints = any([self.rowHasConstraint(i) for i in rows]) 624 has_real_constraints = any([self.rowHasActiveConstraint(i) for i in rows]) 624 625 625 626 self.actionSelect = QtWidgets.QAction(self) … … 639 640 self.actionRemoveConstraint.setText(QtCore.QCoreApplication.translate("self", "Remove constraint")) 640 641 642 self.actionEditConstraint = QtWidgets.QAction(self) 643 self.actionEditConstraint.setObjectName("actionEditConstrain") 644 self.actionEditConstraint.setText(QtCore.QCoreApplication.translate("self", "Edit constraint")) 645 641 646 self.actionMultiConstrain = QtWidgets.QAction(self) 642 647 self.actionMultiConstrain.setObjectName("actionMultiConstrain") … … 653 658 if has_constraints: 654 659 menu.addAction(self.actionRemoveConstraint) 660 if num_rows == 1 and has_real_constraints: 661 menu.addAction(self.actionEditConstraint) 655 662 #if num_rows == 1: 656 663 # menu.addAction(self.actionEditConstraint) … … 663 670 self.actionConstrain.triggered.connect(self.addSimpleConstraint) 664 671 self.actionRemoveConstraint.triggered.connect(self.deleteConstraint) 672 self.actionEditConstraint.triggered.connect(self.editConstraint) 665 673 self.actionMutualMultiConstrain.triggered.connect(self.showMultiConstraint) 666 674 self.actionSelect.triggered.connect(self.selectParameters) … … 700 708 new_func = c_text.replace(param_used, updated_param_used) 701 709 constraint.func = new_func 710 constraint.value_ex = updated_param_used 702 711 # Which row is the constrained parameter in? 703 712 row = self.getRowFromName(constraint.param) 713 714 # what is the parameter to constraint to? 715 constraint.value = param_used 704 716 705 717 # Create a new item and add the Constraint object as a child … … 797 809 self.modifyViewOnRow(row, font=font, brush=brush) 798 810 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) 799 851 800 852 def deleteConstraint(self): … … 3603 3655 value = constraint.value 3604 3656 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) 3606 3661 3607 3662 param_list.append([param_name, param_checked, param_value, param_error, param_min, param_max, cons]) … … 3853 3908 # constraints 3854 3909 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: 3856 3911 value = cons[0] 3857 function = cons[1] 3912 param = cons[1] 3913 value_ex = cons[2] 3914 function = cons[3] 3858 3915 constraint = Constraint() 3859 3916 constraint.value = value 3860 3917 constraint.func = function 3918 constraint.param = param 3919 constraint.value_ex = value_ex 3861 3920 self.addConstraintToRow(constraint=constraint, row=row) 3862 3921 -
src/sas/qtgui/Perspectives/Fitting/MultiConstraint.py
r305114c rbaeac95 20 20 Logic class for interacting with MultiConstrainedUI view 21 21 """ 22 def __init__(self, parent=None, params=None ):22 def __init__(self, parent=None, params=None, constraint=None): 23 23 """ 24 24 parent: ConstraintWidget object … … 31 31 self.params = params 32 32 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] 33 44 34 45 self.setupLabels() … … 36 47 37 48 # 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) 40 53 self.cmdOK.clicked.connect(self.accept) 41 54 self.cmdHelp.clicked.connect(self.onHelp) … … 52 65 # Switch parameters 53 66 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]) 54 69 # Try to swap parameter names in the line edit 55 70 current_text = self.txtConstraint.text() … … 64 79 Setup labels based on current parameters 65 80 """ 66 l1 = s elf.params[0]67 l2 = s elf.params[1]81 l1 = str(self.params[0]) 82 l2 = str(self.params[1]) 68 83 self.txtParam1.setText(l1) 69 84 self.txtParam1_2.setText(l1) … … 99 114 return False 100 115 101 param_str = str(self.params[1]) 102 constraint_text = constraint_text.strip() 116 param_str = self.model_name 103 117 104 118 # 1. just the parameter -
src/sas/qtgui/Perspectives/Fitting/UnitTesting/FittingWidgetTest.py
r186d678 rbaeac95 185 185 186 186 # 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) 189 189 190 190 # Set the structure factor … … 219 219 # 220 220 # Now change the model 221 <<<<<<< HEAD222 221 self.widget.cbModel.setCurrentIndex(4) 223 =======224 self.widget.cbModel.setCurrentIndex(2)225 >>>>>>> ESS_GUI226 222 self.assertEqual(self.widget.cbModel.currentText(),'dab') 227 223
Note: See TracChangeset
for help on using the changeset viewer.