Changeset 6a4002d in sasview
- Timestamp:
- Oct 11, 2011 5:55:23 PM (13 years ago)
- Branches:
- master, 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, costrafo411, magnetic_scatt, release-4.1.1, release-4.1.2, release-4.2.2, release_4.0.1, ticket-1009, ticket-1094-headless, ticket-1242-2d-resolution, ticket-1243, ticket-1249, ticket885, unittest-saveload
- Children:
- d7345b71
- Parents:
- 444c900e
- Location:
- fittingview/src/sans/perspectives/fitting
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
fittingview/src/sans/perspectives/fitting/fit_thread.py
r8d57bdb r6a4002d 93 93 # self.handler.error(msg=msg) 94 94 except: 95 raise 95 96 if self.handler is not None: 96 97 self.handler.error(msg=str(sys.exc_value)) -
fittingview/src/sans/perspectives/fitting/fitpage.py
re3f6ef5 r6a4002d 26 26 from basepage import PageInfoEvent 27 27 from sans.models.qsmearing import smear_selection 28 29 28 30 29 class FitPage(BasicPage): … … 2082 2081 dispersity = None 2083 2082 pass 2084 #set the panel when fit result are float not list 2085 if out.__class__== numpy.float64: 2086 self.param_toFit[0][2].SetValue(format_number(out, True)) 2083 2087 2084 2088 if self.param_toFit[0][4].IsShown and not self.is_mac: 2089 self.param_toFit[0][4].Hide() 2090 if cov !=None : 2091 self.text2_3.Show(True) 2092 try: 2093 if self.enable_disp.GetValue(): 2094 if hasattr(self,"text_disp_1" ): 2095 if self.text_disp_1 !=None: 2096 self.text_disp_1.Show(True) 2097 except: 2098 pass 2099 2100 if cov[0]==None or not numpy.isfinite(cov[0]): 2101 if self.param_toFit[0][3].IsShown and not self.is_mac: 2102 self.param_toFit[0][3].Hide() 2103 else: 2104 self.param_toFit[0][3].Show(True) 2105 self.param_toFit[0][4].Show(True) 2106 self.param_toFit[0][4].SetValue(format_number(cov[0], True)) 2107 has_error = True 2108 else: 2109 2110 i = 0 2111 #Set the panel when fit result are list 2112 for item in self.param_toFit: 2113 if len(item)>5 and item != None: 2114 ## reset error value to initial state 2115 if not self.is_mac: 2116 item[3].Hide() 2117 item[4].Hide() 2118 2119 for ind in range(len(out)): 2120 2121 if item[1] == p_name[ind]: 2122 break 2123 if len(out)<=len(self.param_toFit) and out[ind] !=None: 2124 val_out = format_number(out[ind], True) 2125 item[2].SetValue(val_out) 2126 2127 2128 if(cov !=None): 2129 2130 try: 2131 if dispersity !=None: 2132 if self.enable_disp.GetValue(): 2133 if hasattr(self,"text_disp_1" ): 2134 if self.text_disp_1!=None: 2135 if not self.text_disp_1.IsShown()\ 2136 and not self.is_mac: 2137 self.text_disp_1.Show(True) 2138 except: 2139 pass 2140 2141 if cov[ind]!=None : 2142 if numpy.isfinite(float(cov[ind])): 2143 val_err = format_number(cov[ind], True) 2144 if not self.is_mac: 2145 item[3].Show(True) 2146 item[4].Show(True) 2147 item[4].SetValue(val_err) 2148 2149 has_error = True 2150 i += 1 2085 i = 0 2086 #Set the panel when fit result are list 2087 for item in self.param_toFit: 2088 if len(item)>5 and item != None: 2089 ## reset error value to initial state 2090 if not self.is_mac: 2091 item[3].Hide() 2092 item[4].Hide() 2093 for ind in range(len(out)): 2094 if item[1] == p_name[ind]: 2095 break 2096 if len(out)<=len(self.param_toFit) and out[ind] !=None: 2097 val_out = format_number(out[ind], True) 2098 item[2].SetValue(val_out) 2099 2100 if(cov !=None): 2101 try: 2102 if dispersity !=None: 2103 if self.enable_disp.GetValue(): 2104 if hasattr(self,"text_disp_1" ): 2105 if self.text_disp_1!=None: 2106 if not self.text_disp_1.IsShown()\ 2107 and not self.is_mac: 2108 self.text_disp_1.Show(True) 2109 except: 2110 pass 2111 2112 if cov[ind]!=None : 2113 if numpy.isfinite(float(cov[ind])): 2114 val_err = format_number(cov[ind], True) 2115 if not self.is_mac: 2116 item[3].Show(True) 2117 item[4].Show(True) 2118 item[4].SetValue(val_err) 2119 has_error = True 2120 i += 1 2151 2121 #Show error title when any errors displayed 2152 2122 if has_error: -
fittingview/src/sans/perspectives/fitting/fitting.py
re3f6ef5 r6a4002d 828 828 batch_outputs=batch_outputs, 829 829 page_id=list_page_id, 830 completefn=self._ simul_fit_completed,830 completefn=self._fit_completed, 831 831 ftol=self.ftol) 832 832 else: … … 837 837 batch_outputs=batch_outputs, 838 838 page_id=list_page_id, 839 completefn=self._ single_fit_completed,839 completefn=self._fit_completed, 840 840 ftol=self.ftol) 841 841 … … 850 850 page_id=list_page_id, 851 851 updatefn=handler.update_fit, 852 completefn=self._ simul_fit_completed,852 completefn=self._fit_completed, 853 853 ftol=self.ftol) 854 854 self.fit_thread_list[current_page_id] = calc_fit … … 1067 1067 1068 1068 1069 1070 1069 def _batch_single_fit_complete_helper(self, result, pars, page_id, 1071 1070 batch_outputs, batch_inputs, elapsed=None): … … 1092 1091 batch_outputs[pars[index]] = [] 1093 1092 batch_inputs["error on %s" % pars[index]] = [] 1093 msg = "" 1094 1094 for res in result: 1095 #Separate result in to data corresponding to each page1096 temp_pars = []1097 temp_res_param = []1098 # Park sorts the params by itself so that we must check1099 # param name and resort it back as it was. No effects on Scipy.1100 if res.parameters != None:1101 model = cpage.model1102 for fid in self.page_finder[pid]:1103 if fid != None:1104 # Below works only for batch using one model1105 model = self.page_finder[pid][fid].get_model()1106 break1107 for p in res.parameters:1108 model_name, param_name = self.split_string(p.name)1109 if model.name == model_name:1110 p_name= model.name+"."+param_name1111 if p.name == p_name:1112 temp_res_param.append(p)1113 temp_pars.append(param_name)1114 res.parameters = temp_res_param1115 pars = temp_pars1116 1117 1095 model, data = res.inputs[0] 1118 temp_model = model#.clone() 1119 if res is None: 1120 null_value = numpy.nan 1121 cell = BatchCell() 1122 cell.label = null_value 1123 cell.value = null_value 1124 cell.object = [None] 1125 batch_outputs["Chi2"].append(cell) 1126 for param in temp_model.getParamList(): 1127 if temp_model.is_fittable(param): 1128 for index in range(len(pars)): 1129 #replug only fitted values 1130 if param != pars[index]: 1131 batch_outputs[pars[index]].append(null_value) 1132 item = null_value 1133 batch_inputs["error on %s" % pars[index]].append(item) 1134 if pars[index] in model.getParamList(): 1135 temp_model.setParam(pars[index], res.pvec[index]) 1136 else: 1137 batch_outputs[str(param)].append(temp_model.getParam(param)) 1096 if res.fitness is None or \ 1097 not numpy.isfinite(res.fitness) or \ 1098 numpy.any(res.pvec == None) or not \ 1099 numpy.all(numpy.isfinite(res.pvec)): 1100 data_name = str(None) 1101 if data is not None: 1102 data_name = str(data.name) 1103 model_name = str(None) 1104 if model is not None: 1105 model_name = str(model.name) 1106 msg += "Data %s and Model %s did not fit.\n" % (data_name, 1107 model_name) 1108 print msg 1109 wx.PostEvent(self.parent, StatusEvent(status=msg, 1110 error="error", 1111 type="stop")) 1138 1112 else: 1139 from sans.guiframe.data_processor import BatchCell 1113 #Separate result in to data corresponding to each page 1114 temp_pars = [] 1115 temp_res_param = [] 1116 # Park sorts the params by itself so that we must check 1117 # param name and resort it back as it was. No effects on Scipy. 1118 if res.parameters != None: 1119 model = cpage.model 1120 for fid in self.page_finder[pid]: 1121 if fid != None: 1122 # Below works only for batch using one model 1123 model = self.page_finder[pid][fid].get_model() 1124 break 1125 for p in res.parameters: 1126 model_name, param_name = self.split_string(p.name) 1127 if model.name == model_name: 1128 p_name= model.name+"."+param_name 1129 if p.name == p_name: 1130 temp_res_param.append(p) 1131 temp_pars.append(param_name) 1132 res.parameters = temp_res_param 1133 pars = temp_pars 1140 1134 cell = BatchCell() 1141 1135 cell.label = res.fitness 1142 1136 cell.value = res.fitness 1143 1137 batch_outputs["Chi2"].append(cell) 1144 for param in temp_model.getParamList():1145 if temp_model.is_fittable(param):1138 for param in model.getParamList(): 1139 if model.is_fittable(param): 1146 1140 for index in range(len(pars)): 1147 1141 #replug only fitted values … … 1150 1144 item = res.stderr[index] 1151 1145 batch_inputs["error on %s" % pars[index]].append(item) 1152 if pars[index] in temp_model.getParamList():1153 temp_model.setParam(pars[index], res.pvec[index])1146 if pars[index] in model.getParamList(): 1147 model.setParam(pars[index], res.pvec[index]) 1154 1148 else: 1155 batch_outputs[str(param)].append( temp_model.getParam(param))1149 batch_outputs[str(param)].append(model.getParam(param)) 1156 1150 1157 self.page_finder[pid].set_batch_result(batch_inputs=batch_inputs,1158 batch_outputs=batch_outputs)1151 self.page_finder[pid].set_batch_result(batch_inputs=batch_inputs, 1152 batch_outputs=batch_outputs) 1159 1153 cpage = self.fit_panel.get_page_by_id(pid) 1160 1154 cpage._on_fit_complete() … … 1162 1156 fitproblem = self.page_finder[pid][data.id] 1163 1157 1164 1165 1158 from sans.models.qsmearing import smear_selection 1166 #smearer = fitproblem.get_smearer() 1167 smearer = smear_selection(data, temp_model) 1159 smearer = smear_selection(data, model) 1168 1160 qmin, qmax = fitproblem.get_range() 1169 1161 weight = fitproblem.get_weight() 1170 1162 flag = issubclass(data.__class__, Data2D) 1171 self.draw_model(model=temp_model, 1163 """ 1164 self.draw_model(model=model, 1172 1165 page_id=pid, 1173 1166 data=data, … … 1182 1175 weight=weight, 1183 1176 source='fit') 1177 """ 1184 1178 1185 1179 def on_set_batch_result(self, page_id, fid, batch_outputs, batch_inputs): … … 1220 1214 batch_outputs["Chi2"][index].object = [residuals] 1221 1215 1222 def _single_fit_completed(self, result, pars, page_id, batch_outputs,1216 def old_single_fit_completed(self, result, pars, page_id, batch_outputs, 1223 1217 batch_inputs=None, elapsed=None): 1224 1218 """ … … 1251 1245 type="stop")) 1252 1246 return 1253 if not numpy.isfinite(result.fitness) or \ 1247 if result.fitness is not None or \ 1248 not numpy.isfinite(result.fitness) or \ 1254 1249 numpy.any(result.pvec == None) or \ 1255 1250 not numpy.all(numpy.isfinite(result.pvec)): … … 1290 1285 raise 1291 1286 1292 def _ simul_fit_completed(self, result, page_id, batch_outputs,1287 def _fit_completed(self, result, page_id, batch_outputs, 1293 1288 batch_inputs=None, 1294 1289 pars=None, … … 1308 1303 self._mac_sleep(0.2) 1309 1304 try: 1310 msg = "" 1311 if result == None: 1305 index = 0 1306 for uid in page_id: 1307 res = result[index] 1308 if res.fitness is not None or \ 1309 not numpy.isfinite(res.fitness) or \ 1310 numpy.any(res.pvec == None) or \ 1311 not numpy.all(numpy.isfinite(res.pvec)): 1312 msg = "Fitting did not converge!!!" 1313 wx.PostEvent(self.parent, 1314 StatusEvent(status=msg, 1315 info="warning", 1316 type="stop")) 1317 self._update_fit_button(page_id) 1318 cpage = self.fit_panel.get_page_by_id(uid) 1319 # Make sure we got all results 1320 #(CallAfter is important to MAC) 1321 wx.CallAfter(cpage.onsetValues, res.fitness, res.param_list, 1322 res.pvec, res.stderr) 1323 index += 1 1324 cpage._on_fit_complete() 1325 if res.stderr == None: 1326 msg = "Fit Abort: " 1327 else: 1328 msg = "Fitting: " 1329 msg += "Completed!!!" 1330 wx.PostEvent(self.parent, StatusEvent(status=msg)) 1331 except ValueError: 1332 raise 1312 1333 self._update_fit_button(page_id) 1313 msg = "ComplexFitting did not converge!!!"1314 wx.PostEvent(self.parent, StatusEvent(status=msg, 1334 msg = "Single Fitting did not converge!!!" 1335 wx.PostEvent(self.parent, StatusEvent(status=msg, info="error", 1315 1336 type="stop")) 1316 return 1317 if not numpy.isfinite(result.fitness) or \ 1318 numpy.any(result.pvec == None) or not \ 1319 numpy.all(numpy.isfinite(result.pvec)): 1320 self._update_fit_button(page_id) 1321 msg= "Simultaneous Fitting did not converge!!!" 1322 wx.PostEvent(self.parent, StatusEvent(status=msg,type="stop")) 1323 return 1324 1325 for uid in page_id: 1326 fpdict = self.page_finder[uid] 1327 for value in fpdict.itervalues(): 1328 model = value.get_model() 1329 data = value.get_fit_data() 1330 small_param_name = [] 1331 small_out = [] 1332 small_cov = [] 1333 #Separate result in to data corresponding to each page 1334 for p in result.parameters: 1335 #print "simul ----", p , p.__class__, p.model.name, p.data.name 1336 model_name, param_name = self.split_string(p.name) 1337 if model.name == model_name: 1338 p_name= model.name+"."+param_name 1339 if p.name == p_name: 1340 if p.value != None and numpy.isfinite(p.value): 1341 small_out.append(p.value) 1342 small_param_name.append(param_name) 1343 small_cov.append(p.stderr) 1344 # Display result on each page 1345 cpage = self.fit_panel.get_page_by_id(uid) 1346 wx.CallAfter(cpage.onsetValues, 1347 result.fitness, 1348 small_param_name, 1349 small_out,small_cov) 1350 cpage._on_fit_complete() 1351 msg = "Fit completed!" 1352 wx.PostEvent(self.parent, StatusEvent(status=msg)) 1353 except Exception: 1337 except: 1354 1338 raise 1355 1339 self._update_fit_button(page_id) 1356 msg = "Complex Fitting did not converge!!!" 1340 msg = "Single Fit completed but Following" 1341 msg += " error occurred:%s" % sys.exc_value 1357 1342 wx.PostEvent(self.parent, StatusEvent(status=msg, info="error", 1358 1343 type="stop")) 1359 return 1360 except: 1361 self._update_fit_button(page_id) 1362 msg = "Simultaneous Fit completed" 1363 msg += " but Following error occurred:%s" % sys.exc_value 1364 wx.PostEvent(self.parent, StatusEvent(status=msg, type="stop")) 1365 1344 1366 1345 def _update_fit_button(self, page_id): 1367 1346 """
Note: See TracChangeset
for help on using the changeset viewer.