Changeset 6dbff18 in sasview
- Timestamp:
- Sep 3, 2018 10:14:52 AM (6 years ago)
- Branches:
- ESS_GUI, ESS_GUI_batch_fitting, ESS_GUI_bumps_abstraction, ESS_GUI_iss1116, ESS_GUI_iss879, ESS_GUI_opencl, ESS_GUI_ordering, ESS_GUI_sync_sascalc
- Children:
- 79bd268
- Parents:
- 8274471e
- git-author:
- Piotr Rozyczko <rozyczko@…> (09/03/18 10:13:50)
- git-committer:
- Piotr Rozyczko <rozyczko@…> (09/03/18 10:14:52)
- Location:
- src/sas/qtgui/Perspectives/Fitting
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
src/sas/qtgui/Perspectives/Fitting/FittingWidget.py
reef298d4 r6dbff18 226 226 self.models = {} 227 227 # Parameters to fit 228 self.parameters_to_fit = None 228 self.main_params_to_fit = [] 229 self.poly_params_to_fit = [] 230 self.magnet_params_to_fit = [] 231 229 232 # Fit options 230 233 self.q_range_min = 0.005 … … 956 959 957 960 # Reset parameters to fit 958 self. parameters_to_fit = None961 self.resetParametersToFit() 959 962 self.has_error_column = False 960 963 self.has_poly_error_column = False … … 980 983 981 984 # Reset parameters to fit 982 self. parameters_to_fit = None985 self.resetParametersToFit() 983 986 self.has_error_column = False 984 987 self.has_poly_error_column = False 985 988 986 989 self.respondToModelStructure(model=model, structure_factor=structure) 990 991 def resetParametersToFit(self): 992 """ 993 Clears the list of parameters to be fitted 994 """ 995 self.main_params_to_fit = [] 996 self.poly_params_to_fit = [] 997 self.magnet_params_to_fit = [] 987 998 988 999 def onCustomModelChange(self): … … 1132 1143 parameter_name = parameter_name + '.width' 1133 1144 if value == QtCore.Qt.Checked: 1134 self.p arameters_to_fit.append(parameter_name)1145 self.poly_params_to_fit.append(parameter_name) 1135 1146 else: 1136 if parameter_name in self.p arameters_to_fit:1137 self.p arameters_to_fit.remove(parameter_name)1138 self.cmdFit.setEnabled(self. parameters_to_fit != [] and self.logic.data_is_loaded)1147 if parameter_name in self.poly_params_to_fit: 1148 self.poly_params_to_fit.remove(parameter_name) 1149 self.cmdFit.setEnabled(self.haveParamsToFit()) 1139 1150 1140 1151 elif model_column in [delegate.poly_min, delegate.poly_max]: … … 1188 1199 value = item.checkState() 1189 1200 if value == QtCore.Qt.Checked: 1190 self. parameters_to_fit.append(parameter_name)1201 self.magnet_params_to_fit.append(parameter_name) 1191 1202 else: 1192 if parameter_name in self. parameters_to_fit:1193 self. parameters_to_fit.remove(parameter_name)1194 self.cmdFit.setEnabled(self. parameters_to_fit != [] and self.logic.data_is_loaded)1203 if parameter_name in self.magnet_params_to_fit: 1204 self.magnet_params_to_fit.remove(parameter_name) 1205 self.cmdFit.setEnabled(self.haveParamsToFit()) 1195 1206 # Update state stack 1196 1207 self.updateUndo() … … 1477 1488 qmin = self.q_range_min 1478 1489 qmax = self.q_range_max 1479 params_to_fit = self.parameters_to_fit 1490 1491 params_to_fit = self.main_params_to_fit 1492 if self.chkPolydispersity.isChecked(): 1493 params_to_fit += self.poly_params_to_fit 1494 if self.chkMagnetism.isChecked(): 1495 params_to_fit += self.magnet_params_to_fit 1480 1496 if not params_to_fit: 1481 1497 raise ValueError('Fitting requires at least one parameter to optimize.') … … 2046 2062 self._last_model_row = self._model_model.rowCount() 2047 2063 2064 def haveParamsToFit(self): 2065 """ 2066 Finds out if there are any parameters ready to be fitted 2067 """ 2068 return (self.main_params_to_fit!=[] 2069 or self.poly_params_to_fit!=[] 2070 or self.magnet_params_to_fit != []) and \ 2071 self.logic.data_is_loaded 2072 2048 2073 def onMainParamsChange(self, item): 2049 2074 """ … … 2054 2079 if model_column == 0: 2055 2080 self.checkboxSelected(item) 2056 self.cmdFit.setEnabled(self. parameters_to_fit != [] and self.logic.data_is_loaded)2081 self.cmdFit.setEnabled(self.haveParamsToFit()) 2057 2082 # Update state stack 2058 2083 self.updateUndo() … … 2113 2138 # Convert to proper indices and set requested enablement 2114 2139 self.setParameterSelection(status) 2115 #[self._model_model.item(row, 0).setCheckState(status) for row in self.selectedParameters()]2116 2140 self._model_model.blockSignals(False) 2117 2141 2118 2142 # update the list of parameters to fit 2119 main_params = self.checkedListFromModel(self._model_model) 2120 poly_params = self.checkedListFromModel(self._poly_model) 2121 magnet_params = self.checkedListFromModel(self._magnet_model) 2122 2123 # Retrieve poly params names 2124 poly_params = [param.rsplit()[-1] + '.width' for param in poly_params] 2125 2126 self.parameters_to_fit = main_params + poly_params + magnet_params 2143 self.main_params_to_fit = self.checkedListFromModel(self._model_model) 2127 2144 2128 2145 def checkedListFromModel(self, model): … … 2752 2769 2753 2770 fp.chi2 = self.chi2 2754 fp.parameters_to_fit = self.parameters_to_fit 2771 fp.main_params_to_fit = self.main_params_to_fit 2772 fp.poly_params_to_fit = self.poly_params_to_fit 2773 fp.magnet_params_to_fit = self.magnet_params_to_fit 2755 2774 fp.kernel_module = self.kernel_module 2756 2775 -
src/sas/qtgui/Perspectives/Fitting/UnitTesting/FittingWidgetTest.py
r3f5b901 r6dbff18 420 420 #QtWidgets.QApplication(sys.argv).exec_() 421 421 422 423 422 # Set the checbox 424 423 self.widget._poly_model.item(0,0).setCheckState(2) 425 424 # Assure the parameter is added 426 self.assertEqual(self.widget.p arameters_to_fit, ['radius_bell.width'])425 self.assertEqual(self.widget.poly_params_to_fit, ['radius_bell.width']) 427 426 428 427 # Add another parameter 429 428 self.widget._poly_model.item(2,0).setCheckState(2) 430 429 # Assure the parameters are added 431 self.assertEqual(self.widget.p arameters_to_fit, ['radius_bell.width', 'length.width'])430 self.assertEqual(self.widget.poly_params_to_fit, ['radius_bell.width', 'length.width']) 432 431 433 432 # Change the min/max values … … 683 682 684 683 # Test no fitting params 685 self.widget. parameters_to_fit = []684 self.widget.main_params_to_fit = [] 686 685 687 686 logging.error = MagicMock() … … 709 708 710 709 # Test no fitting params 711 self.widget. parameters_to_fit = []710 self.widget.main_params_to_fit = [] 712 711 713 712 logging.error = MagicMock() … … 735 734 736 735 # Assing fitting params 737 self.widget. parameters_to_fit = ['scale']736 self.widget.main_params_to_fit = ['scale'] 738 737 739 738 # Spying on status update signal … … 748 747 749 748 # the fit button changed caption and got disabled 750 self.assertEqual(self.widget.cmdFit.text(), 'Stop fit') 751 self.assertFalse(self.widget.cmdFit.isEnabled()) 749 # could fail if machine fast enough to finish 750 #self.assertEqual(self.widget.cmdFit.text(), 'Stop fit') 751 #self.assertFalse(self.widget.cmdFit.isEnabled()) 752 752 753 753 # Signal pushed up … … 779 779 780 780 # Assing fitting params 781 self.widget. parameters_to_fit = ['scale']781 self.widget.main_params_to_fit = ['scale'] 782 782 783 783 # Spying on status update signal … … 792 792 793 793 # the fit button changed caption and got disabled 794 self.assertEqual(self.widget.cmdFit.text(), 'Stop fit')795 self.assertFalse(self.widget.cmdFit.isEnabled())794 #self.assertEqual(self.widget.cmdFit.text(), 'Stop fit') 795 #self.assertFalse(self.widget.cmdFit.isEnabled()) 796 796 797 797 # Signal pushed up … … 857 857 category_index = self.widget.cbCategory.findText('Sphere') 858 858 self.widget.cbCategory.setCurrentIndex(category_index) 859 self.widget. parameters_to_fit = ['scale']859 self.widget.main_params_to_fit = ['scale'] 860 860 # Invoke the tested method 861 861 fp = self.widget.currentState() … … 905 905 906 906 # Test no fitting params 907 self.widget. parameters_to_fit = ['scale']907 self.widget.main_params_to_fit = ['scale'] 908 908 909 909 # Invoke the tested method … … 943 943 category_index = self.widget.cbCategory.findText("Sphere") 944 944 self.widget.cbCategory.setCurrentIndex(category_index) 945 self.widget. parameters_to_fit = ['scale']945 self.widget.main_params_to_fit = ['scale'] 946 946 947 947 # Invoke the tested method … … 954 954 self.assertEqual(fp.current_category, "Sphere") 955 955 self.assertEqual(fp.current_model, "adsorbed_layer") 956 self.assertListEqual(fp. parameters_to_fit, ['scale'])956 self.assertListEqual(fp.main_params_to_fit, ['scale']) 957 957 958 958 def testPushFitPage(self): … … 974 974 self.widget.undo_supported = True 975 975 self.widget.cbCategory.setCurrentIndex(category_index) 976 self.widget. parameters_to_fit = ['scale']976 self.widget.main_params_to_fit = ['scale'] 977 977 978 978 # Check that the stack is updated
Note: See TracChangeset
for help on using the changeset viewer.