Ignore:
Timestamp:
Jan 15, 2009 5:39:19 PM (16 years ago)
Author:
Gervaise Alina <gervyh@…>
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
Message:

add thread for fitting

File:
1 edited

Legend:

Unmodified
Added
Removed
  • sansview/perspectives/fitting/fitting.py

    rd23544dc re9b4cc4  
    1010from fitproblem import FitProblem 
    1111from fitpanel import FitPanel 
    12  
     12from fit_thread import FitThread 
    1313import models,modelpage 
    1414import fitpage1D,fitpage2D 
    1515import park 
    1616DEFAULT_BEAM = 0.005 
     17import time 
     18import thread 
     19print "main",thread.get_ident() 
     20 
    1721class Plugin: 
    1822    """ 
     
    2832        ## List of panels for the simulation perspective (names) 
    2933        self.perspective = [] 
     34         
     35        self.calc_thread = None 
     36        self.done = False 
    3037        # Start with a good default 
    3138        self.elapsed = 0.022 
     
    222229            return model_name,param_name 
    223230         
    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): 
    226233        """ 
    227234            Display fit result on one page of the notebook. 
     
    233240           
    234241        """ 
     242        #self.done = True 
     243        #wx.PostEvent(self.parent, StatusEvent(status="Fitting Completed: %g" % elapsed)) 
    235244        try: 
    236245            for page, value in self.page_finder.iteritems(): 
     
    260269             
    261270        
    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): 
    263272        """ 
    264273            Parameter estimation completed,  
     
    267276            @param elapsed: computation time 
    268277        """ 
     278        wx.PostEvent(self.parent, StatusEvent(status="Fitting Completed: %g" % elapsed)) 
    269279        try: 
    270280            for page, value in self.page_finder.iteritems(): 
     
    291301             wx.PostEvent(self.parent, StatusEvent(status="Fitting error: %s" % sys.exc_value)) 
    292302             
    293      
     303   
    294304    def _on_single_fit(self,id=None,qmin=None,qmax=None,ymin=None,ymax=None): 
    295305        """  
     
    344354                #of parameter names in the list       
    345355        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            
    351377        except: 
    352378            raise 
     
    412438        #Do the simultaneous fit 
    413439        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             
    416455        except: 
    417456            wx.PostEvent(self.parent, StatusEvent(status="Simultaneous Fitting error: %s" % sys.exc_value)) 
     
    479518        self.plot_helper(currpage=page,qmin= qmin,qmax= qmax) 
    480519         
    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): 
    482521        """ 
    483522            Plot a theory given a model and data 
     
    654693                except: 
    655694                    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 
    660697     
    661698    def complete(self, output, elapsed, model, qmin, qmax): 
    662         #printEVT("Calc complete in %g sec" % elapsed)  
     699        
    663700        wx.PostEvent(self.parent, StatusEvent(status="Calc \ 
    664701        complete in %g sec" % elapsed)) 
     
    723760                                       qmax=qmax, 
    724761                            completefn=self.complete, 
    725                             updatefn=self.update) 
     762                            updatefn=None) 
    726763            self.calc_thread.queue() 
    727764            self.calc_thread.ready(2.5) 
Note: See TracChangeset for help on using the changeset viewer.