Changeset 116dd4c1 in sasview for src/sas/qtgui/Perspectives/Fitting/FittingWidget.py
- Timestamp:
- Jan 24, 2018 10:07:08 AM (6 years ago)
- 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:
- c6343a5
- Parents:
- eb1a386
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
src/sas/qtgui/Perspectives/Fitting/FittingWidget.py
rba01ad1 r116dd4c1 212 212 self.orig_poly_index = 3 213 213 214 # Page id for fitting 215 # To keep with previous SasView values, use 200 as the start offset 216 self.page_id = 200 + self.tab_id 217 214 218 # Data for chosen model 215 219 self.model_data = None … … 732 736 return True 733 737 return False 734 #return True if (item.hasChildren() and isinstance(item.child(0).data(), Constraint)) else False 738 739 def rowHasActiveConstraint(self, row): 740 """ 741 Finds out if row of the main model has an active constraint child 742 """ 743 item = self._model_model.item(row,1) 744 if item.hasChildren(): 745 c = item.child(0).data() 746 if isinstance(c, Constraint) and c.func and c.active: 747 return True 748 return False 735 749 736 750 def selectParameters(self): … … 780 794 #preamble(s) +self._model_model.item(s, 1).child(0).data().func) 781 795 self._model_model.item(s, 1).child(0).data().func) 782 for s in range(param_number) if self.rowHas Constraint(s)]796 for s in range(param_number) if self.rowHasActiveConstraint(s)] 783 797 return params 784 798 … … 1056 1070 Perform fitting on the current data 1057 1071 """ 1058 1059 # Data going in 1060 data = self.logic.data 1061 model = self.kernel_module 1062 qmin = self.q_range_min 1063 qmax = self.q_range_max 1064 params_to_fit = self.parameters_to_fit 1065 1066 # Potential weights added directly to data 1067 self.addWeightingToData(data) 1068 1069 # Potential smearing added 1070 # Remember that smearing_min/max can be None -> 1071 # deal with it until Python gets discriminated unions 1072 smearing, accuracy, smearing_min, smearing_max = self.smearing_widget.state() 1073 1074 # These should be updating somehow? 1072 # initialize fitter constants 1075 1073 fit_id = 0 1076 constraints = self.getConstraintsForModel()1077 smearer = None1078 page_id = [210]1079 1074 handler = None 1080 1075 batch_inputs = {} 1081 1076 batch_outputs = {} 1082 list_page_id = [page_id]1083 1077 #--------------------------------- 1084 1078 if USING_TWISTED: … … 1091 1085 updater = handler.update_fit 1092 1086 1093 # Parameterize the fitter 1094 fitters = [] 1095 for fit_index in self.all_data: 1096 fitter = Fit() 1097 data = GuiUtils.dataFromItem(fit_index) 1098 try: 1099 fitter.set_model(model, fit_id, params_to_fit, data=data, 1100 constraints=constraints) 1101 except ValueError as ex: 1102 logging.error("Setting model parameters failed with: %s" % ex) 1103 return 1104 1105 qmin, qmax, _ = self.logic.computeRangeFromData(data) 1106 fitter.set_data(data=data, id=fit_id, smearer=smearer, qmin=qmin, 1107 qmax=qmax) 1108 fitter.select_problem_for_fit(id=fit_id, value=1) 1109 fitter.fitter_id = page_id 1110 fit_id += 1 1111 fitters.append(fitter) 1087 # Prepare the fitter object 1088 fitters, _ = self.prepareFitters() 1112 1089 1113 1090 # Create the fitting thread, based on the fitter … … 1115 1092 1116 1093 calc_fit = FitThread(handler=handler, 1117 1118 1119 1120 page_id=list_page_id,1121 1122 1094 fn=fitters, 1095 batch_inputs=batch_inputs, 1096 batch_outputs=batch_outputs, 1097 page_id=[[self.page_id]], 1098 updatefn=updater, 1099 completefn=completefn) 1123 1100 1124 1101 if USING_TWISTED: … … 1209 1186 chi2_repr = GuiUtils.formatNumber(self.chi2, high=True) 1210 1187 self.lblChi2Value.setText(chi2_repr) 1188 1189 def prepareFitters(self, fitter=None, fit_id=0): 1190 """ 1191 Prepare the Fitter object for use in fitting 1192 """ 1193 # fitter = None -> single/batch fitting 1194 # fitter = Fit() -> simultaneous fitting 1195 1196 # Data going in 1197 data = self.logic.data 1198 model = self.kernel_module 1199 qmin = self.q_range_min 1200 qmax = self.q_range_max 1201 params_to_fit = self.parameters_to_fit 1202 1203 # Potential weights added directly to data 1204 self.addWeightingToData(data) 1205 1206 # Potential smearing added 1207 # Remember that smearing_min/max can be None -> 1208 # deal with it until Python gets discriminated unions 1209 smearing, accuracy, smearing_min, smearing_max = self.smearing_widget.state() 1210 1211 constraints = self.getConstraintsForModel() 1212 smearer = None 1213 handler = None 1214 batch_inputs = {} 1215 batch_outputs = {} 1216 1217 fitters = [] 1218 for fit_index in self.all_data: 1219 fitter_single = Fit() if fitter is None else fitter 1220 data = GuiUtils.dataFromItem(fit_index) 1221 try: 1222 fitter_single.set_model(model, fit_id, params_to_fit, data=data, 1223 constraints=constraints) 1224 except ValueError as ex: 1225 logging.error("Setting model parameters failed with: %s" % ex) 1226 return 1227 1228 qmin, qmax, _ = self.logic.computeRangeFromData(data) 1229 fitter_single.set_data(data=data, id=fit_id, smearer=smearer, qmin=qmin, 1230 qmax=qmax) 1231 fitter_single.select_problem_for_fit(id=fit_id, value=1) 1232 if fitter is None: 1233 # Assign id to the new fitter only 1234 fitter_single.fitter_id = [self.page_id] 1235 fit_id += 1 1236 fitters.append(fitter_single) 1237 1238 return fitters, fit_id 1211 1239 1212 1240 def iterateOverModel(self, func):
Note: See TracChangeset
for help on using the changeset viewer.