Changeset f72333f in sasview for sansview/perspectives/fitting/fitting.py
- Timestamp:
- May 10, 2010 6:50:05 PM (14 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:
- 4fbc93e
- Parents:
- 2d409fa
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
sansview/perspectives/fitting/fitting.py
r784e2fa rf72333f 44 44 (PageInfoEvent, EVT_PAGE_INFO) = wx.lib.newevent.NewEvent() 45 45 46 46 from fitpage import Chi2UpdateEvent 47 47 class PlotInfo: 48 48 """ … … 104 104 #dictionary containing data name and error on dy of that data 105 105 self.err_dy = {} 106 106 self.theory_data = None 107 107 108 108 … … 146 146 self.fit_panel.set_model_list(self.menu_mng.get_model_list()) 147 147 owner.Bind(fitpage.EVT_MODEL_BOX,self._on_model_panel) 148 148 149 149 #create menubar items 150 150 return [(id, self.menu1, "Fitting")] … … 370 370 wx.PostEvent(self.parent, StatusEvent(status="Fitting \ 371 371 is cancelled" , type="stop")) 372 373 def set_smearer_nodraw(self,smearer, qmin=None, qmax=None): 374 """ 375 Get a smear object and store it to a fit problem 376 @param smearer: smear object to allow smearing data 377 """ 378 self.current_pg=self.fit_panel.get_current_page() 379 self.page_finder[self.current_pg].set_smearer(smearer) 380 ## draw model 1D with smeared data 381 data = self.page_finder[self.current_pg].get_fit_data() 382 model = self.page_finder[self.current_pg].get_model() 383 ## if user has already selected a model to plot 384 ## redraw the model with data smeared 385 386 smear =self.page_finder[self.current_pg].get_smearer() 372 387 373 388 def set_smearer(self,smearer, qmin=None, qmax=None): … … 383 398 ## if user has already selected a model to plot 384 399 ## redraw the model with data smeared 385 400 386 401 smear =self.page_finder[self.current_pg].get_smearer() 387 402 if model!= None: … … 405 420 406 421 """ 407 ## draw model 1D with no loaded data 408 self._draw_model1D( model= model, data= data,enable1D=enable1D, smearer= smearer, 409 qmin= qmin, qmax= qmax, qstep= qstep ) 410 ## draw model 2D with no initial data 411 self._draw_model2D(model=model, 412 data = data, 413 enable2D= enable2D, 414 qmin=qmin, 415 qmax=qmax, 416 qstep=qstep) 422 423 if data.__class__.__name__ !="Data2D": 424 ## draw model 1D with no loaded data 425 self._draw_model1D( model= model, data= data, 426 enable1D=enable1D, 427 smearer= smearer, 428 qmin= qmin, qmax= qmax, qstep= qstep ) 429 else: 430 ## draw model 2D with no initial data 431 self._draw_model2D(model=model, 432 data = data, 433 enable2D= enable2D, 434 smearer= smearer, 435 qmin=qmin, 436 qmax=qmax, 437 qstep=qstep) 417 438 418 439 def onFit(self): … … 600 621 wx.PostEvent(self.parent, StatusEvent(status=msg, info="error")) 601 622 return 602 623 624 603 625 def _onEVT_SLICER_PANEL(self, event): 604 626 """ … … 1087 1109 1088 1110 1089 def _complete1D(self, x,y, elapsed, model,data=None):1111 def _complete1D(self, x,y, elapsed,index,model,data=None): 1090 1112 """ 1091 1113 Complete plotting 1D data … … 1106 1128 1107 1129 title= new_plot.name 1130 # x, y are only in range of index 1131 self.theory_data = new_plot 1108 1132 #new_plot.perspective = self.get_perspective() 1109 1133 # Pass the reset flag to let the plotting event handler … … 1116 1140 else: 1117 1141 wx.PostEvent(self.parent, NewPlotEvent(plot=new_plot,title= str(title))) 1142 # Chisqr in fitpage 1143 current_pg=self.fit_panel.get_current_page() 1144 wx.PostEvent(current_pg,Chi2UpdateEvent(output=self._cal_chisqr(data=data,index=index))) 1118 1145 msg = "Plot 1D complete !" 1119 1146 wx.PostEvent( self.parent, StatusEvent(status=msg , type="stop" )) … … 1134 1161 1135 1162 1136 def _complete2D(self, image,data, model, elapsed, qmin, qmax,qstep=DEFAULT_NPTS):1163 def _complete2D(self, image,data, model, elapsed,index,qmin, qmax,qstep=DEFAULT_NPTS): 1137 1164 """ 1138 1165 Complete get the result of modelthread and create model 2D … … 1165 1192 theory.xmin= data.xmin 1166 1193 theory.xmax= data.xmax 1167 1168 1194 1195 self.theory_data = theory 1169 1196 ## plot 1170 1197 wx.PostEvent(self.parent, NewPlotEvent(plot=theory, 1171 1198 title="Analytical model 2D ", reset=True )) 1199 # Chisqr in fitpage 1200 current_pg=self.fit_panel.get_current_page() 1201 wx.PostEvent(current_pg,Chi2UpdateEvent(output=self._cal_chisqr(data=data,index=index))) 1172 1202 msg = "Plot 2D complete !" 1173 1203 wx.PostEvent( self.parent, StatusEvent( status= msg , type="stop" )) 1174 1204 1175 1205 def _on_data_error(self, event): 1176 1206 """ … … 1179 1209 """ 1180 1210 self.err_dy = event.err_dy 1181 #print "receiving error dy",self.err_dy1182 1211 1183 def _draw_model2D(self,model,data=None, description=None, enable2D=False,1212 def _draw_model2D(self,model,data=None, smearer= None,description=None, enable2D=False, 1184 1213 qmin=DEFAULT_QMIN, qmax=DEFAULT_QMAX, qstep=DEFAULT_NPTS): 1185 1214 """ … … 1208 1237 x= data.x_bins 1209 1238 y= data.y_bins 1210 1239 1211 1240 if not enable2D: 1212 return 1241 return None,None 1213 1242 try: 1214 1243 from model_thread import Calc2D … … 1216 1245 if self.calc_2D != None and self.calc_2D.isrunning(): 1217 1246 self.calc_2D.stop() 1247 1218 1248 self.calc_2D = Calc2D( x= x, 1219 1249 y= y, 1220 1250 model= model, 1221 1251 data = data, 1252 smearer = smearer, 1222 1253 qmin= qmin, 1223 1254 qmax= qmax, … … 1226 1257 updatefn= self._update2D ) 1227 1258 self.calc_2D.queue() 1228 1259 1229 1260 except: 1230 1261 msg= " Error occurred when drawing %s Model 2D: "%model.name 1231 1262 msg+= " %s"%sys.exc_value 1232 1263 wx.PostEvent( self.parent, StatusEvent(status= msg )) 1233 return 1264 1234 1265 1235 1266 def _draw_model1D(self, model, data=None, smearer= None, … … 1257 1288 1258 1289 if not enable1D: 1259 return 1290 return 1260 1291 1261 1292 try: … … 1273 1304 updatefn = self._update1D ) 1274 1305 self.calc_1D.queue() 1275 1306 1276 1307 except: 1277 1308 msg= " Error occurred when drawing %s Model 1D: "%model.name 1278 1309 msg+= " %s"%sys.exc_value 1279 1310 wx.PostEvent( self.parent, StatusEvent(status= msg )) 1280 return 1281 1282 1311 1312 def _cal_chisqr(self, data=None, index=None): 1313 """ 1314 Get handy Chisqr using the output from draw1D and 2D, 1315 instead of calling expansive CalcChisqr in guithread 1316 """ 1317 # default chisqr 1318 chisqr = None 1319 # return None if data == None 1320 if data == None: return chisqr 1321 1322 # Get data: data I, theory I, and data dI in order 1323 if data.__class__.__name__ =="Data2D": 1324 if index == None: index = numpy.ones(len(data.data),ntype=bool) 1325 fn = data.data[index] 1326 gn = self.theory_data.data[index] 1327 en = data.err_data[index] 1328 else: 1329 # 1 d theory from model_thread is only in the range of index 1330 if index == None: index = numpy.ones(len(data.y),ntype=bool) 1331 1332 fn = data.y[index] 1333 gn = self.theory_data.y 1334 en = data.dy[index] 1335 1336 # residual 1337 res = (fn - gn)/en 1338 # get chisqr only w/finite 1339 chisqr = numpy.average(res[numpy.isfinite(res)]*res[numpy.isfinite(res)]) 1340 1341 return chisqr 1342 1343 1283 1344 def profile(fn, *args, **kw): 1284 1345 import cProfile, pstats, os
Note: See TracChangeset
for help on using the changeset viewer.