Changeset e9b4cc4 in sasview
- Timestamp:
- Jan 15, 2009 5:39:19 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:
- 633ba04
- Parents:
- 681f0dc
- Location:
- sansview/perspectives/fitting
- Files:
-
- 1 added
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
sansview/perspectives/fitting/fitpage1D.py
rd23544dc re9b4cc4 483 483 when enter value on panel redraw model according to changed 484 484 """ 485 self.set_model _parameter()485 self.set_model() 486 486 self.compute_chisqr() 487 487 488 489 def set_model_parameter(self): 490 """ 491 this method redraws the model according to parameters values changes 492 and the reset model according to paramaters changes 493 """ 494 print "went here",len(self.parameters) ,self.model 488 def set_model(self): 495 489 if len(self.parameters) !=0 and self.model !=None: 496 490 # Flag to register when a parameter has changed. 497 is_modified = False498 491 for item in self.parameters: 499 492 try: … … 502 495 item[3].Clear() 503 496 item[3].Hide() 504 name=str(item[0].GetLabelText())505 value= float(item[1].GetValue())506 # If the value of the parameter has changed,507 # update the model and set the is_modified flag508 if value != self.model.getParam(name):509 self.model.setParam(name,value)510 is_modified = True511 497 except: 512 498 wx.PostEvent(self.parent.GrandParent, StatusEvent(status=\ 513 499 "Drawing Error:wrong value entered : %s"% sys.exc_value)) 500 self.set_model_parameter() 501 502 def set_model_parameter(self): 503 if len(self.parameters) !=0 and self.model !=None: 504 # Flag to register when a parameter has changed. 505 is_modified = False 506 for item in self.parameters: 507 try: 508 name=str(item[0].GetLabelText()) 509 value= float(item[1].GetValue()) 510 # If the value of the parameter has changed, 511 # update the model and set the is_modified flag 512 if value != self.model.getParam(name): 513 self.model.setParam(name,value) 514 is_modified = True 515 except: 516 wx.PostEvent(self.parent.GrandParent, StatusEvent(status=\ 517 "Model Drawing Error:wrong value entered : %s"% sys.exc_value)) 518 514 519 # Here we should check whether the boundaries have been modified. 515 520 # If qmin and qmax have been modified, update qmin and qmax and -
sansview/perspectives/fitting/fitpage2D.py
rd23544dc re9b4cc4 200 200 for j in range(len(self.data.y_bins)): 201 201 if self.data.y_bins[j]>= ymin and self.data.y_bins[j]<= ymax: 202 print "data error ",self.data.err_data[j][i]203 202 res.append( (self.data.data[j][i]- self.model.runXY(\ 204 203 [self.data.x_bins[i],self.data.y_bins[j]]))\ … … 209 208 if numpy.isfinite(item): 210 209 sum +=item 211 print "chisqr : sum 2D", xmin, xmax, ymin, ymax,sum210 #print "chisqr : sum 2D", xmin, xmax, ymin, ymax,sum 212 211 #print res 213 212 self.tcChi.SetValue(format_number(math.fabs(sum))) -
sansview/perspectives/fitting/fitting.py
rd23544dc re9b4cc4 10 10 from fitproblem import FitProblem 11 11 from fitpanel import FitPanel 12 12 from fit_thread import FitThread 13 13 import models,modelpage 14 14 import fitpage1D,fitpage2D 15 15 import park 16 16 DEFAULT_BEAM = 0.005 17 import time 18 import thread 19 print "main",thread.get_ident() 20 17 21 class Plugin: 18 22 """ … … 28 32 ## List of panels for the simulation perspective (names) 29 33 self.perspective = [] 34 35 self.calc_thread = None 36 self.done = False 30 37 # Start with a good default 31 38 self.elapsed = 0.022 … … 222 229 return model_name,param_name 223 230 224 225 def _single_fit_completed(self,result,pars,cpage,qmin,qmax, ymin=None, ymax=None):231 232 def _single_fit_completed(self,result,pars,cpage,qmin,qmax,elapsed,ymin=None, ymax=None): 226 233 """ 227 234 Display fit result on one page of the notebook. … … 233 240 234 241 """ 242 #self.done = True 243 #wx.PostEvent(self.parent, StatusEvent(status="Fitting Completed: %g" % elapsed)) 235 244 try: 236 245 for page, value in self.page_finder.iteritems(): … … 260 269 261 270 262 def _simul_fit_completed(self,result,qmin,qmax, ymin=None, ymax=None):271 def _simul_fit_completed(self,result,qmin,qmax, elapsed,pars=None,cpage=None, ymin=None, ymax=None): 263 272 """ 264 273 Parameter estimation completed, … … 267 276 @param elapsed: computation time 268 277 """ 278 wx.PostEvent(self.parent, StatusEvent(status="Fitting Completed: %g" % elapsed)) 269 279 try: 270 280 for page, value in self.page_finder.iteritems(): … … 291 301 wx.PostEvent(self.parent, StatusEvent(status="Fitting error: %s" % sys.exc_value)) 292 302 293 303 294 304 def _on_single_fit(self,id=None,qmin=None,qmax=None,ymin=None,ymax=None): 295 305 """ … … 344 354 #of parameter names in the list 345 355 try: 346 result=self.fitter.fit() 347 #self._single_fit_completed(result,pars,current_pg,qmin,qmax) 348 #print "single_fit: result",result.fitness,result.pvec,result.stderr 349 #self._single_fit_completed(result,pars,page,qmin,qmax) 350 self._single_fit_completed(result,pars,page_fitted,qmin,qmax,ymin,ymax) 356 # If a thread is already started, stop it 357 if self.calc_thread != None and self.calc_thread.isrunning(): 358 self.calc_thread.stop() 359 360 self.calc_thread =FitThread(parent =self.parent, 361 fn= self.fitter, 362 pars= pars, 363 cpage= page_fitted, 364 qmin=qmin, 365 qmax=qmax, 366 ymin= ymin, 367 ymax= ymax, 368 completefn=self._single_fit_completed, 369 updatefn=None) 370 self.calc_thread.queue() 371 self.calc_thread.ready(2.5) 372 #while not self.done: 373 #print "when here" 374 # time.sleep(1) 375 376 351 377 except: 352 378 raise … … 412 438 #Do the simultaneous fit 413 439 try: 414 result=self.fitter.fit() 415 self._simul_fit_completed(result,qmin,qmax,ymin,ymax) 440 # If a thread is already started, stop it 441 if self.calc_thread != None and self.calc_thread.isrunning(): 442 self.calc_thread.stop() 443 444 self.calc_thread =FitThread(parent =self.parent, 445 fn= self.fitter, 446 qmin=qmin, 447 qmax=qmax, 448 ymin= ymin, 449 ymax= ymax, 450 completefn= self._simul_fit_completed, 451 updatefn=None) 452 self.calc_thread.queue() 453 self.calc_thread.ready(2.5) 454 416 455 except: 417 456 wx.PostEvent(self.parent, StatusEvent(status="Simultaneous Fitting error: %s" % sys.exc_value)) … … 479 518 self.plot_helper(currpage=page,qmin= qmin,qmax= qmax) 480 519 481 def plot_helper(self,currpage, qmin=None,qmax=None,ymin=None,ymax=None):520 def plot_helper(self,currpage, fitModel=None, qmin=None,qmax=None,ymin=None,ymax=None): 482 521 """ 483 522 Plot a theory given a model and data … … 654 693 except: 655 694 raise 656 def update(self, output,elapsed): 657 print "Got an update", elapsed 658 wx.PostEvent(self.parent, StatusEvent(status="Plot \ 659 updating ... %g sec" % elapsed)) 695 def update(self, output,time): 696 pass 660 697 661 698 def complete(self, output, elapsed, model, qmin, qmax): 662 #printEVT("Calc complete in %g sec" % elapsed)699 663 700 wx.PostEvent(self.parent, StatusEvent(status="Calc \ 664 701 complete in %g sec" % elapsed)) … … 723 760 qmax=qmax, 724 761 completefn=self.complete, 725 updatefn= self.update)762 updatefn=None) 726 763 self.calc_thread.queue() 727 764 self.calc_thread.ready(2.5) -
sansview/perspectives/fitting/model_thread.py
rd15c0202 re9b4cc4 109 109 self.model = model 110 110 self.starttime = 0 111 111 112 112 113 def isquit(self): … … 120 121 raise KeyboardInterrupt 121 122 123 def update(self, output=None, time=None): 124 125 wx.PostEvent(self.parent, StatusEvent(status="Plot \ 126 updating ... %g sec" % time)) 127 122 128 def compute(self): 123 129 import numpy … … 125 131 y = self.y 126 132 output = numpy.zeros((len(x),len(y))) 127 """ 128 if self.qmin *self.qmax >=0: 129 print "same signe plotting" 130 if self.qmax==0: 131 center_x= self.qmin/2 132 center_y= self.qmin /2 133 else: 134 center_x= (self.qmax -self.qmin)/2 135 center_y= (self.qmax -self.qmin)/2 136 else: 137 """ 133 138 134 center_x=0 139 135 center_y=0 140 #print "center_x , center_y",center_x , center_y 141 #print "x ",len(x) 142 #print "y", y 143 #print "int(len(self.x)/2)",int(len(self.x)/2) 136 144 137 self.starttime = time.time() 138 wx.PostEvent(self.parent, StatusEvent(status=\ 139 "Start Drawing model %g " % self.starttime)) 145 140 lx = len(self.x) 146 141 147 142 for i_x in range(len(self.x)): 148 149 # Check whether we need to bail out 150 self.update(output=output) 143 # Check whether we need to bail out 144 self.update(output=output, time=time.time() ) 151 145 self.isquit() 152 146 … … 154 148 try: 155 149 if (self.x[i_x]*self.x[i_x]+self.y[i_y]*self.y[i_y]) \ 156 < self.qmin * self.qmin:157 output[i_x] [i_y]=0158 150 < self.qmin * self.qmin: 151 152 output[i_x] [i_y]=0 159 153 else: 160 value1 = self.model.runXY([self.x[i_x]-center_x, self.y[i_y]-center_y]) 161 162 163 output[i_x] [i_y]=value1 164 165 154 value = self.model.runXY([self.x[i_x]-center_x, self.y[i_y]-center_y]) 155 output[i_x] [i_y]=value 166 156 except: 167 157 wx.PostEvent(self.parent, StatusEvent(status=\ -
sansview/perspectives/fitting/modelpage.py
rd23544dc re9b4cc4 402 402 self.qmax = float(self.xmax.GetValue()) 403 403 is_modified = True 404 if float(self.npts.GetValue()) != self.num_points: 405 self.qmax = float(self.npts.GetValue()) 406 is_modified = True 404 405 if float(self.npts.GetValue()) != self.num_points: 406 self.qmax = float(self.npts.GetValue()) 407 is_modified = True 408 407 409 408 410 if is_modified:
Note: See TracChangeset
for help on using the changeset viewer.