Changeset 948add7 in sasview for sansview/perspectives/fitting
- Timestamp:
- Sep 30, 2008 2:38:58 PM (16 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:
- 8e81af0
- Parents:
- 8bbab51
- Location:
- sansview/perspectives/fitting
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
sansview/perspectives/fitting/fitpage.py
r00561739 r948add7 221 221 flag=self.checkFitRange() 222 222 if flag== True: 223 qmin = float(self.xmin.GetValue()) 224 qmax = float(self.xmax.GetValue()) 225 x,y,dy = [numpy.asarray(v) for v in (self.data.x,self.data.y,self.data.dy)] 226 if qmin==None and qmax==None: 227 fx =numpy.asarray([self.model.run(v) for v in x]) 228 res=(y - fx)/dy 229 else: 230 idx = (x>= qmin) & (x <=qmax) 231 fx = numpy.asarray([self.model.run(item)for item in x[idx ]]) 232 res= (y[idx] - fx)/dy[idx] 233 234 sum=0 235 for item in res: 236 if numpy.isfinite(item): 237 sum +=item 238 self.tcChi.SetValue(format_number(math.fabs(sum))) 223 try: 224 qmin = float(self.xmin.GetValue()) 225 qmax = float(self.xmax.GetValue()) 226 x,y,dy = [numpy.asarray(v) for v in (self.data.x,self.data.y,self.data.dy)] 227 if qmin==None and qmax==None: 228 fx =numpy.asarray([self.model.run(v) for v in x]) 229 res=(y - fx)/dy 230 else: 231 idx = (x>= qmin) & (x <=qmax) 232 fx = numpy.asarray([self.model.run(item)for item in x[idx ]]) 233 res= (y[idx] - fx)/dy[idx] 234 sum=0 235 for item in res: 236 if numpy.isfinite(item): 237 sum +=item 238 self.tcChi.SetValue(format_number(math.fabs(sum))) 239 except: 240 wx.PostEvent(self.parent.GrandParent, StatusEvent(status=\ 241 "Chisqr cannot be compute: %s"% sys.exc_value)) 239 242 240 243 … … 248 251 qmax =float( self.xmax.GetValue()) 249 252 if len(self.param_toFit) >0 and flag==True: 253 self.manager.schedule_for_fit( value=1,fitproblem =None) 250 254 self.manager._on_single_fit(qmin=qmin,qmax=qmax) 251 255 else: … … 546 550 name=str(item[0].GetLabelText()) 547 551 value= float(item[1].GetValue()) 548 549 552 self.model.setParam(name,value) 550 553 self.manager.redraw_model(float(self.xmin.GetValue())\ -
sansview/perspectives/fitting/fitproblem.py
r00561739 r948add7 19 19 self.theory_name=None 20 20 self.model_list=[] 21 self.schedule= 'False'21 self.schedule=0 22 22 self.param_name= None 23 23 self.param_value=None … … 41 41 def get_model(self): 42 42 """ @return: saved model """ 43 print "fitproblem",self.model_list43 #print "fitproblem",self.model_list 44 44 return self.model_list 45 45 … … 68 68 @param value: value of that parameter 69 69 """ 70 print "fitproblem",name,value70 #print "fitproblem",name,value 71 71 #self.model_list[0].setParam(name,value) 72 72 self.param_name = name … … 78 78 @param value: value of that parameter 79 79 """ 80 print self.param_name, self.param_value80 #print self.param_name, self.param_value 81 81 #self.model_list[0].setParam(name,value) 82 82 return self.param_name, self.param_value … … 87 87 @param value: new model 88 88 """ 89 print "fitproblem : reset model"89 #print "fitproblem : reset model" 90 90 self.model_list[0]=model 91 91 92 def schedule_tofit(self, schedule= 'False'):92 def schedule_tofit(self, schedule=0): 93 93 """ 94 94 set schedule to true to decide if this fit must be performed -
sansview/perspectives/fitting/fitting.py
r00561739 r948add7 158 158 wx.PostEvent(self.parent, StatusEvent(status="Fitting error: \ 159 159 data already Selected ")) 160 160 def schedule_for_fit(self,value=0,fitproblem =None): 161 """ 162 163 """ 164 if fitproblem !=None: 165 fitproblem.schedule_tofit(value) 166 else: 167 current_pg=self.fit_panel.get_current_page() 168 for page, val in self.page_finder.iteritems(): 169 if page ==current_pg : 170 val.schedule_tofit(value) 171 break 172 161 173 162 174 def get_page_finder(self): … … 199 211 200 212 201 def _single_fit_completed(self,result,pars,c urrent_pg,qmin,qmax):213 def _single_fit_completed(self,result,pars,cpage,qmin,qmax): 202 214 """ 203 215 Display fit result on one page of the notebook. … … 211 223 try: 212 224 for page, value in self.page_finder.iteritems(): 213 if page== current_pg:225 if page==cpage : 214 226 data = value.get_data() 215 227 list = value.get_model() … … 229 241 # print "fitting result : stderr",result.stderr 230 242 231 c urrent_pg.onsetValues(result.fitness, result.pvec,result.stderr)232 self.plot_helper(currpage=c urrent_pg,qmin=qmin,qmax=qmax)243 cpage.onsetValues(result.fitness, result.pvec,result.stderr) 244 self.plot_helper(currpage=cpage,qmin=qmin,qmax=qmax) 233 245 except: 234 246 raise … … 245 257 try: 246 258 for page, value in self.page_finder.iteritems(): 247 if value.get_scheduled()== 'True':259 if value.get_scheduled()==1: 248 260 data = value.get_data() 249 261 list = value.get_model() … … 276 288 277 289 """ 290 #print "in single fitting" 278 291 #set an engine to perform fit 279 292 from sans.fit.Fitting import Fit … … 283 296 id=0 284 297 self.id = id 298 page_fitted=None 299 fit_problem=None 285 300 #Get information (model , data) related to the page on 286 301 #with the fit will be perform 287 302 current_pg=self.fit_panel.get_current_page() 303 simul_pg=self.fit_panel.get_page(0) 304 288 305 for page, value in self.page_finder.iteritems(): 289 if page ==current_pg:306 if value.get_scheduled() ==1 : 290 307 data = value.get_data() 291 308 list=value.get_model() 292 309 model=list[0] 293 294 310 #Create list of parameters for fitting used 295 311 pars=[] 296 312 templist=[] 297 313 try: 298 templist=current_pg.get_param_list() 314 #templist=current_pg.get_param_list() 315 templist=page.get_param_list() 316 for element in templist: 317 pars.append(str(element[0].GetLabelText())) 318 pars.sort() 319 #Do the single fit 320 self.fitter.set_model(Model(model), self.id, pars) 321 self.fitter.set_data(Data(sans_data=data),self.id,qmin,qmax) 322 self.fitter.select_problem_for_fit(Uid=self.id,value=value.get_scheduled()) 323 page_fitted=page 324 self.id+=1 325 self.schedule_for_fit( 0,value) 299 326 except: 300 327 wx.PostEvent(self.parent, StatusEvent(status="Fitting error: %s" % sys.exc_value)) 301 328 return 302 303 for element in templist:304 try:305 pars.append(str(element[0].GetLabelText()))306 except:307 wx.PostEvent(self.parent, StatusEvent(status="Fitting error: %s" % sys.exc_value))308 return309 329 # make sure to keep an alphabetic order 310 #of parameter names in the list 311 pars.sort() 312 #Do the single fit 313 try: 314 self.fitter.set_model(Model(model), self.id, pars) 315 #print "fitting: data .x",data.x 316 #print "fitting: data .y",data.y 317 #print "fitting: data .dy",data.dy 318 self.fitter.set_data(Data(sans_data=data),self.id,qmin,qmax) 319 320 result=self.fitter.fit() 321 self._single_fit_completed(result,pars,current_pg,qmin,qmax) 322 323 except: 324 raise 325 wx.PostEvent(self.parent, StatusEvent(status="Single Fit error: %s" % sys.exc_value)) 326 return 330 #of parameter names in the list 331 try: 332 result=self.fitter.fit() 333 #self._single_fit_completed(result,pars,current_pg,qmin,qmax) 334 print "single_fit: result",result.fitness,result.pvec,result.stderr 335 #self._single_fit_completed(result,pars,page,qmin,qmax) 336 self._single_fit_completed(result,pars,page_fitted,qmin,qmax) 337 except: 338 wx.PostEvent(self.parent, StatusEvent(status="Single Fit error: %s" % sys.exc_value)) 339 return 327 340 328 341 def _on_simul_fit(self, id=None,qmin=None,qmax=None): … … 346 359 for page, value in self.page_finder.iteritems(): 347 360 try: 348 if value.get_scheduled()== 'True':361 if value.get_scheduled()==1: 349 362 data = value.get_data() 350 363 list = value.get_model() … … 363 376 new_model=Model(model) 364 377 param_name,param_value=value.get_model_param() 365 print "fitting ",param_name 366 new_model.set( param_name =str(param_value)) 367 #self.fitter.set_model(new_model, self.id, pars) 378 print "fitting ",param_name,value.get_model_param() 379 if param_value !=None: 380 new_model.set( param_name =str(param_value)) 381 self.fitter.set_model(new_model, self.id, pars) 368 382 self.fitter.set_data(Data(sans_data=data),self.id,qmin,qmax) 369 383 self.fitter.select_problem_for_fit(Uid=self.id,value=value.get_scheduled()) 370 384 self.id += 1 371 385 except: -
sansview/perspectives/fitting/simfitpage.py
r00561739 r948add7 44 44 45 45 self.ctl2 = wx.TextCtrl(self, -1, style=wx.TE_MULTILINE) 46 #self.ctl2.Bind(wx.EVT_KILL_FOCUS, self._onTextEnter) 47 #self.ctl2.Bind(wx.EVT_TEXT_ENTER, self._onTextEnter) 46 48 47 self.sizer2.Add(self.ctl2, 0, wx.LEFT|wx.RIGHT|wx.ADJUST_MINSIZE, 10) 49 48 … … 65 64 def onFit(self,event): 66 65 """ signal for fitting""" 67 self._onTextEnter() 68 if len(self.model_toFit) >0 : 66 67 if len(self.model_toFit) ==1 : 68 self.manager._on_single_fit() 69 print "simfitpage: when here" 70 elif len(self.model_toFit) > 1 : 69 71 if len(self.params)>0: 72 self._onTextEnter() 70 73 self.set_model() 71 74 else: … … 94 97 for item in self.model_list: 95 98 item[0].SetValue(True) 96 item[1].schedule_tofit('True') 99 #item[1].schedule_tofit(1) 100 self.manager.schedule_for_fit( value=1,fitproblem =item[1]) 97 101 self.model_toFit.append(item) 98 102 else: 103 print"simfit: deselected all" 104 self.manager.schedule_for_fit( value=0,fitproblem =item[1]) 99 105 for item in self.model_list: 100 106 item[0].SetValue(False) 101 item[1].schedule_tofit('False') 107 #item[1].schedule_tofit(0) 108 102 109 self.model_toFit=[] 103 110 … … 113 120 self.sizer1.Clear(True) 114 121 self.page_finder=page_finder 122 self.cb1.SetValue(False) 115 123 ix = 0 116 124 iy = 1 … … 139 147 def remove_model(self,delpage): 140 148 """ 141 Remove a checkbox and the name re alted to a model selected on page delpage149 Remove a checkbox and the name related to a model selected on page delpage 142 150 @param delpage: the page removed 143 151 """ … … 147 155 for item in self.model_list: 148 156 try: 157 # redraw the panel without the name of the model associated 158 # with the page to delete 149 159 if not delpage in item: 150 160 #print "simfitpage: redraw modelname",item[3] … … 156 166 wx.EVT_CHECKBOX(self, cb.GetId(), self.select_model_name) 157 167 else: 168 # if the page to delete in item remove it from the model list 158 169 self.model_list.remove(item) 159 170 except: 160 raise 171 wx.PostEvent(self.parent.GrandParent, StatusEvent(status="Page deletion Error: %s" % sys.exc_value)) 172 161 173 self.sizer1.Layout() 162 174 self.vbox.Layout() … … 172 184 item[1].schedule_tofit('True') 173 185 self.model_toFit.append(item) 174 else: 186 self.manager.schedule_for_fit( value=1,fitproblem =item[1]) 187 else: 188 print"simfit: deselected one" 189 self.manager.schedule_for_fit( value=0,fitproblem =item[1]) 175 190 if item in self.model_toFit: 176 191 self.model_toFit.remove(item) 177 item[1].schedule_tofit('False') 192 193 178 194 self.cb1.SetValue(False) 179 195 if len(self.model_list)==len(self.model_toFit): … … 181 197 else: 182 198 self.cb1.SetValue(False) 183 199 200 184 201 185 202 def set_model(self): … … 235 252 except: 236 253 wx.PostEvent(self.parent.GrandParent, StatusEvent(status="Constraint Error: %s" % sys.exc_value)) 254 return 237 255 except: 238 256 raise
Note: See TracChangeset
for help on using the changeset viewer.