Changeset 0aeabc6 in sasview


Ignore:
Timestamp:
May 18, 2009 10:17:11 AM (15 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:
b0eee0f0
Parents:
138c139
Message:

refactor draw model .working on save option

Location:
sansview/perspectives/fitting
Files:
5 edited

Legend:

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

    r71f0373 r0aeabc6  
    7171        self.qmin_x= 0.0001 
    7272        self.qmax_x= 0.13 
    73         self.num_points= 100 
     73        self.num_points= 50 
    7474        ## Create memento to save the current state 
    7575         
     
    321321                    #TODO: total hack - fix this 
    322322                    self.state.model= self.model.clone() 
    323                     if not hasattr(self.model, "_persistency_dict"): 
    324                         self.model._persistency_dict = {} 
     323                    #if not hasattr(self.model, "_persistency_dict"): 
     324                    self.model._persistency_dict = {} 
    325325                    self.model._persistency_dict[p] = [self.values, self.weights] 
    326326                    self.state.model._persistency_dict[p] = [self.values, self.weights] 
     
    330330               
    331331                ## Redraw the model 
    332                 print "select angle => draw" 
     332                
    333333                self._draw_model() 
    334334                ## post state to fit panel 
     
    368368         
    369369        self.state.model = self.model.clone() 
    370         if not hasattr(self.model, "_persistency_dict"): 
    371                             self.model._persistency_dict = {} 
     370        #if not hasattr(self.model, "_persistency_dict"): 
     371        self.model._persistency_dict = {} 
    372372        self.state.model._persistency_dict= copy.deepcopy(self.model._persistency_dict) 
    373373                         
     
    471471            Store current state 
    472472        """ 
     473        ## save model option 
    473474        if self.model!= None: 
    474475            self.disp_list= self.model.getDispParamList() 
    475476            self.state.disp_list= copy.deepcopy(self.disp_list) 
    476477            self.state.model = self.model.clone() 
    477         self.state.save_data(self.data) 
    478         self.state.disp_list = self.disp_list 
     478             
    479479        self.state.enable2D = copy.deepcopy(self.enable2D) 
    480480        self.state.values= copy.deepcopy(self.values) 
    481481        self.state.weights = copy.deepcopy( self.weights) 
     482        ## save data     
     483        self.state.save_data(self.data) 
     484        
    482485        try: 
    483486            n = self.disp_box.GetCurrentSelection() 
     
    516519            self.state.values = copy.deepcopy(self.values) 
    517520            self.state.weights = copy.deepcopy(self.weights) 
     521        ## save plotting range 
    518522        self._save_plotting_range() 
    519523         
     
    545549            state of the graphic interface 
    546550        """ 
    547         ## set the value of the current state to the state given as parameter 
    548         self.state = state.clone()  
    549          
    550         self.model= self.state.model 
    551         self.data = self.state.data 
    552         self.smearer= self.state.smearer 
     551        self.model= state.model 
     552        self.data = state.data 
     553        self.smearer= state.smearer 
    553554        self.enable2D= state.enable2D 
    554555         
     
    573574             
    574575        ## display dispersion info layer 
    575         self.enable_disp.SetValue(self.state.enable_disp) 
    576         self.disable_disp.SetValue(self.state.disable_disp) 
     576        self.enable_disp.SetValue(state.enable_disp) 
     577        self.disable_disp.SetValue(state.disable_disp) 
    577578         
    578579        if hasattr(self, "disp_box"): 
    579             self.disp_box.SetSelection(self.state.disp_box)   
     580            self.disp_box.SetSelection(state.disp_box)   
    580581            n = self.disp_box.GetCurrentSelection() 
    581582            dispersity= self.disp_box.GetClientData(n) 
     
    586587                self.disp_cb_dict = {} 
    587588                self.disp_cb_dict = copy.deepcopy(state.disp_cb_dict)  
    588                 self.state.disp_cb_dict = copy.deepcopy(state.disp_cb_dict)  
    589589                
    590590                self._disp_obj_dict={} 
    591                 for k , v in self.state._disp_obj_dict.iteritems(): 
     591                for k , v in state._disp_obj_dict.iteritems(): 
    592592                    self._disp_obj_dict[k]=v 
    593593           
     
    599599                for k,v in state.disp_cb_dict.iteritems(): 
    600600                    self.disp_cb_dict[k].SetValue(v)  
    601                     self.state.disp_cb_dict[k]=v  
     601                     
    602602                    if self.disp_cb_dict[k].GetValue(): 
    603603                        # Create the dispersion objects 
     
    610610                        #TODO: refactor model to clean this up? 
    611611                        self._disp_obj_dict[k] = disp_model 
    612                         self.state._disp_obj_dict [k]= disp_model 
    613                         self.state.values=[] 
    614                         self.state.weights=[] 
    615                         self.state.values = self.values 
    616                         self.state.weights = self.weights 
     612                       
    617613                        self.values=[] 
    618614                        self.weights = [] 
     
    621617                     
    622618                        # Set the new model as the dispersion object for the selected parameter 
    623                         if not hasattr(self.model, "_persistency_dict"): 
    624                             self.model._persistency_dict = {} 
     619                        #if not hasattr(self.model, "_persistency_dict"): 
     620                        self.model._persistency_dict = {} 
    625621                        self.model._persistency_dict[k] = [state.values, state.weights] 
    626622                        self.model.set_dispersion(k, disp_model) 
    627623                         
    628624        ##plotting range restore     
    629         self._reset_plotting_range() 
     625        self._reset_plotting_range(state) 
    630626        ## smearing info  restore 
    631627        if hasattr(self,"enable_smearer"): 
    632628            ## set smearing value whether or not the data contain the smearing info 
    633             self.enable_smearer.SetValue(self.state.enable_smearer) 
    634             self.disable_smearer.SetValue(self.state.disable_smearer) 
    635             self.compute_chisqr(smearer= self.smearer)   
     629            self.enable_smearer.SetValue(state.enable_smearer) 
     630            self.disable_smearer.SetValue(state.disable_smearer) 
     631            self.tcChi.SetLabel(str( state.tcChi)) 
     632            self.sizer5.Layout() 
     633            self.Layout() 
     634            self.Refresh() 
     635            #self.compute_chisqr(smearer= self.smearer)   
    636636             
    637637        ## reset state of checkbox,textcrtl  and dispersity parameters value 
     
    642642        ## draw the model with previous parameters value 
    643643        self._onparamEnter_helper() 
    644        
     644        
    645645        ## reset context menu items 
    646646        self._reset_context_menu() 
    647          
    648  
     647        ## set the value of the current state to the state given as parameter 
     648        self.state = state.clone()  
     649        ## post state to fit panel 
     650        event = PageInfoEvent(page = self) 
     651        wx.PostEvent(self.parent, event) 
    649652         
    650653    def _selectDlg(self): 
     
    674677     
    675678     
    676     def _reset_plotting_range(self): 
     679    def _reset_plotting_range(self, state): 
    677680        """ 
    678681            Reset the plotting range to a given state 
    679682        """ 
    680         
    681         self.qmin.SetValue(str(self.state.qmin)) 
    682         self.qmax.SetValue(str(self.state.qmax))  
     683        self.qmin.SetValue(str(state.qmin)) 
     684        self.qmax.SetValue(str(state.qmax))  
    683685        if self.state.npts!=None: 
    684             self.npts.SetValue(format_number(self.state.npts))  
    685             self.num_points = float(self.state.npts) 
    686              
    687         self.qmin_x = float(self.qmin.GetValue()) 
    688         self.qmax_x = float(self.qmax.GetValue()) 
    689          
     686            self.npts.SetValue(str(state.npts))  
     687             
    690688         
    691689    def _save_plotting_range(self ): 
     
    743741            ## if any value is modify draw model with new value 
    744742            if is_modified: 
    745                 print "is_modified--->",is_modified 
     743                
    746744                self._draw_model()  
    747745                self.save_current_state() 
     
    960958                if self.enable_smearer.GetValue(): 
    961959                    temp_smear= self.smearer 
    962             print "self.model.dispersion",self.model.dispersion 
     960            
    963961            self.manager.draw_model(self.model, data=self.data, 
    964962                                    smearer= temp_smear, 
     
    11431141            from sans.models.MultiplicationModel import MultiplicationModel 
    11441142            self.model= MultiplicationModel(form_factor(),struct_factor()) 
     1143             
    11451144        else: 
    11461145            if form_factor != None: 
     
    13391338            self.model.set_dispersion(p, disp_model) 
    13401339            # Redraw the model 
    1341             print "reset dispersity=> draw" 
     1340            
    13421341            self._draw_model() 
    13431342             
  • sansview/perspectives/fitting/fitpage.py

    r71f0373 r0aeabc6  
    557557                tcrtl.SetBackgroundColour("pink") 
    558558                tcrtl.Refresh() 
     559                return 
    559560        else: 
    560561           tcrtl.SetBackgroundColour(wx.WHITE) 
    561562           tcrtl.Refresh()   
    562         self._onparamEnter_helper()     
     563        self._onparamEnter_helper()  
     564         
     565        ##compute chisqr for range change 
     566        temp_smearer = None 
     567        if self.enable_smearer.GetValue(): 
     568            msg="" 
     569            temp_smearer= self.smearer    
     570         ##Calculate chi2 
     571        self.compute_chisqr(smearer= temp_smearer)   
     572         
    563573         
    564574    def _onparamEnter(self,event): 
     
    747757        """ 
    748758        try: 
    749             self.tcChi.SetLabel(format_number(output)) 
     759            self.tcChi.SetLabel(str(output)) 
     760            
     761            self.sizer5.Layout() 
     762            self.Layout() 
     763            self.Refresh 
     764            ## post state to fit panel 
     765            self.state.tcChi =output 
     766            event = PageInfoEvent(page = self) 
     767            wx.PostEvent(self.parent, event) 
    750768        except: 
    751             raise 
     769            pass 
    752770         
    753771         
     
    809827            if self.calc_Chisqr!= None and self.calc_Chisqr.isrunning(): 
    810828                self.calc_Chisqr.stop() 
    811                  
     829            
    812830            self.calc_Chisqr= CalcChisqr2D( x_bins= self.data.x_bins, 
    813831                                            y_bins= self.data.y_bins, 
  • sansview/perspectives/fitting/fitpanel.py

    r71f0373 r0aeabc6  
    332332        self.model_page_number=self.GetSelection() 
    333333        self.model_page=self.GetPage(self.GetSelection()) 
    334         # Set the range used to plot models 
    335         self.model_page.set_range(qmin, qmax, npts) 
     334      
    336335        ##  resetting page 
    337336        if reset: 
     
    339338 
    340339                memento= self.fit_page_name[page_title][0] 
    341                  
    342340                panel.reset_page(memento) 
    343341        else: 
    344342            self.fit_page_name[page_title]=[] 
    345343            self.fit_page_name[page_title].insert(0,panel.createMemento()) 
    346             ## We just created a model page, we are ready to plot the model 
    347             self.manager.draw_model(model, qmin=qmin, qmax=qmax) 
     344        
    348345   
    349    
  • sansview/perspectives/fitting/gui_thread.py

    r6dd2be3 r0aeabc6  
    149149        """ 
    150150        self.starttime = time.time() 
     151        if self.model ==None: 
     152            return 
     153        if self.data==None: 
     154            return 
    151155        if self.err_data==None or self.err_data==[]: 
    152156            self.err_data= numpy.zeros(len(self.x_bins),len(self.y_bins)) 
  • sansview/perspectives/fitting/pagestate.py

    r71f0373 r0aeabc6  
    2323        # model on which the fit would be performed 
    2424        self.model = model 
    25         if not hasattr(self.model, "_persistency_dict"): 
    26             self.model._persistency_dict = {} 
    27         self.model._persistency_dict = copy.deepcopy(model._persistency_dict) 
     25        #if not hasattr(self.model, "_persistency_dict"): 
     26        #    self.model._persistency_dict = {} 
     27        #self.model._persistency_dict = copy.deepcopy(model._persistency_dict) 
    2828        #fit page manager  
    2929        self.manager = None 
     
    8484        ## state of selected all check button 
    8585        self.cb1 = False 
     86        ## store value of chisqr 
     87        self.tcChi= None 
    8688        
    8789    
     
    115117        obj.enable_disp = copy.deepcopy(self.enable_disp) 
    116118        obj.disable_disp = copy.deepcopy(self.disable_disp) 
    117         if self.model !=None and len(self.model._persistency_dict)>0: 
    118             for k, v in self.model._persistency_dict.iteritems(): 
    119                 obj.model._persistency_dict[k] = copy.deepcopy(v) 
     119        obj.tcChi = self.tcChi 
     120   
    120121        if len(self._disp_obj_dict)>0: 
    121122            for k , v in self._disp_obj_dict.iteritems(): 
Note: See TracChangeset for help on using the changeset viewer.