Ignore:
Timestamp:
Mar 6, 2009 9:19:16 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:
bdb27e6
Parents:
0b99881
Message:

go back to version 1617 for fitpage1D and modelpage.py

File:
1 edited

Legend:

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

    r0b99881 rfbc3e04  
    1818class FitPage1D(ModelPage): 
    1919    """ 
    20         FitPage1D class contains fields allowing to display results when 
    21         fitting  a model and one data. 
    22         This class used most of the methods of ModelPage class. 
     20        FitPanel class contains fields allowing to display results when 
     21        fitting  a model and one data 
    2322        @note: For Fit to be performed the user should check at least one parameter 
    2423        on fit Panel window. 
     
    3130    name=None 
    3231     
    33     def __init__(self, parent,data,model=None, name=None, *args, **kwargs): 
     32    def __init__(self, parent,data, *args, **kwargs): 
     33        wx.ScrolledWindow.__init__(self, parent, *args, **kwargs) 
     34         
    3435        """  
    3536            Initialization of the Panel 
    3637        """ 
    37         ModelPage.__init__(self, parent,model,name,data,*args, **kwargs) 
    38         
    3938        #TODO: remove this once the inheritence is cleaned up 
    4039        ## Data member to store the dispersion object created 
    41          
    42      
    43          
    44     def draw_panel(self): 
     40        self._disp_obj_dict = {} 
     41 
     42        #Data used for fitting  
     43        self.data = data 
     44        # flag to allow data2D plot 
     45        self.enable2D=False 
     46        #fit page manager  
     47        self.manager = None 
     48        #Store the parent of this panel parent 
     49        # For this application fitpanel is the parent 
     50        self.parent  = parent 
     51        # Event_owner is the owner of model event 
     52        self.event_owner = None 
    4553        #panel interface 
    4654        self.vbox  = wx.BoxSizer(wx.VERTICAL) 
     
    7987        #---------sizer 1 draw-------------------------------- 
    8088        #Filling the sizer containing data related fields 
    81         self.DataSource  =wx.StaticText(self, -1,str(self.data.name)) 
     89        self.DataSource  =wx.StaticText(self, -1,str(data.name)) 
    8290        ix = 0 
    8391        iy = 1 
     
    93101            iy = 1 
    94102            # Minimum value of data    
    95             self.data_min = wx.StaticText(self, -1,str(format_number(numpy.min(self.data.x)))) 
     103            self.data_min    = wx.StaticText(self, -1,str(format_number(numpy.min(data.x)))) 
    96104            # Maximum value of data   
    97             self.data_max =  wx.StaticText(self, -1,str(format_number(numpy.max(self.data.x))))    
     105            self.data_max    =  wx.StaticText(self, -1,str(format_number(numpy.max(data.x))))    
    98106            self.text4_3 = wx.StaticText(self, -1, 'Maximum Data Range(Linear)', style=wx.ALIGN_LEFT) 
    99107            self.sizer2.Add(self.text4_3,(iy,ix),(1,1),\ 
     
    152160        self.disable_disp = wx.RadioButton(self, -1, 'No', (10, 10), style=wx.RB_GROUP) 
    153161        self.enable_disp = wx.RadioButton(self, -1, 'Yes', (10, 30)) 
    154         self.Bind(wx.EVT_RADIOBUTTON, self.set_Dispers_Param, id=self.disable_disp.GetId()) 
    155         self.Bind(wx.EVT_RADIOBUTTON, self.set_Dispers_Param, id=self.enable_disp.GetId()) 
     162        self.Bind(wx.EVT_RADIOBUTTON, self.Set_DipersParam, id=self.disable_disp.GetId()) 
     163        self.Bind(wx.EVT_RADIOBUTTON, self.Set_DipersParam, id=self.enable_disp.GetId()) 
    156164        ix= 0 
    157165        iy=1 
     
    239247        iy+=1  
    240248        self.sizer9.Add((20,20),(iy,ix),(1,1), wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 0) 
    241         
     249         
     250        # Contains link between  model ,all its parameters, and panel organization 
     251        self.parameters=[] 
     252        # Contains list of parameters that cannot be fitted and reference to  
     253        #panel objects  
     254        self.fixed_param=[] 
     255        # Contains list of parameters with dispersity and reference to  
     256        #panel objects  
     257        self.fittable_param=[] 
     258        #list of dispersion paramaters 
     259        self.disp_list=[] 
     260        #contains link between a model and selected parameters to fit  
     261        self.param_toFit=[] 
     262        # model on which the fit would be performed 
     263        self.model=None 
     264         
     265        self.back_up_model= None 
     266        #dictionary of model name and model class 
     267        self.model_list_box={}     
     268                      
     269        if self.model == None: 
     270            self.qmin.Disable() 
     271            self.qmax.Disable()  
     272        else: 
     273            self.qmin.Enable() 
     274            self.qmax.Enable()  
     275 
    242276     
    243277        self.vbox.Layout() 
     
    246280        self.SetScrollbars(20,20,55,40) 
    247281         
     282        self.Centre() 
     283        self.Layout() 
     284        self.GrandParent.GetSizer().Layout() 
     285    
    248286    def compute_chisqr2D(self): 
    249287        """  
     
    260298                    for j in range(len(self.data.y_bins)): 
    261299                        #Check the range containing data between self.qmin_x and self.qmax_x 
    262                         radius = math.pow(self.data.x_bins[i],2)\ 
    263                             + math.pow(self.data.y_bins[j],2) 
    264                              
    265                         if radius >= math.pow(self.qmin_x,2): 
    266                             if radius <=math.pow(self.qmax_x,2): 
    267                                 temp= self.model.runXY( [self.data.y_bins[j],self.data.x_bins[i]] ) 
    268                                 chisqrji=(self.data.data[j][i]- temp)/self.data.err_data[j][i] 
     300                        if math.pow(self.data.x_bins[i],2)+math.pow(self.data.y_bins[j],2)>=math.pow(self.qmin_x,2): 
     301                            if math.pow(self.data.x_bins[i],2)+math.pow(self.data.y_bins[j],2)<=math.pow(self.qmax_x,2): 
     302                                chisqrji=(self.data.data[j][i]- self.model.runXY(\ 
     303                                                                                    [self.data.y_bins[j],self.data.x_bins[i]]))\ 
     304                                                                                    /self.data.err_data[j][i] 
    269305                                #Vector containing residuals 
    270306                                res.append( math.pow(chisqrji,2) ) 
     
    276312                self.tcChi.SetLabel(format_number(math.fabs(sum/ len(res)))) 
    277313            except: 
    278                 msg= "Chisqr cannot be compute: %s"% sys.exc_value 
    279                 wx.PostEvent(self.parent.GrandParent, StatusEvent(status= msg )) 
     314                wx.PostEvent(self.parent.GrandParent, StatusEvent(status=\ 
     315                            "Chisqr cannot be compute: %s"% sys.exc_value)) 
    280316                return 
    281317     
     
    295331                    self.qmin_x = float(self.qmin.GetValue()) 
    296332                    self.qmax_x = float(self.qmax.GetValue()) 
    297                     # Compute residuals within self.qmin_x and self.qmax_x 
     333                    # return residuals within self.qmin_x and self.qmax_x 
    298334                    x,y,dy = [numpy.asarray(v) for v in (self.data.x,self.data.y,self.data.dy)] 
    299335                    if self.qmin_x==None and self.qmax_x==None:  
     
    313349                    self.tcChi.SetLabel(format_number(math.fabs(sum/ len(res)))) 
    314350            except: 
    315                 msg=  "Chisqr cannot be compute: %s"% sys.exc_value 
    316                 wx.PostEvent(self.parent.GrandParent, StatusEvent(status= msg)) 
     351                wx.PostEvent(self.parent.GrandParent, StatusEvent(status=\ 
     352                            "Chisqr cannot be compute: %s"% sys.exc_value)) 
    317353                return  
    318              
    319354             
    320355    def _on_select_model(self,event): 
     
    345380             
    346381            if name ==event.GetString(): 
    347                 self.model=item() 
    348                 self.back_up_model= self.model.clone() 
    349                 evt = ModelEventbox(model=self.model,name=name) 
    350                 wx.PostEvent(self.event_owner, evt) 
    351382                try: 
     383                    self.model=item() 
     384                    self.back_up_model= self.model.clone() 
     385                    evt = ModelEventbox(model=self.model,name=name) 
     386                    wx.PostEvent(self.event_owner, evt) 
     387                    self.text1_1.Show() 
    352388                    self.compute_chisqr() 
    353389                    self.tcChi.Show() 
    354                     self.text1_1.Show() 
    355390                except: 
    356                     self.text1_1.Hide() 
    357                     pass 
     391                    raise #ValueError,"model.name is not equal to model class name" 
    358392                break   
    359                   
     393             
    360394                  
    361395    def onFit(self,event): 
     
    383417            self.parent.GetSizer().Layout() 
    384418        else: 
    385             msg= "Select at least one parameter to fit " 
    386             wx.PostEvent(self.parent.parent, StatusEvent(status= msg )) 
     419            wx.PostEvent(self.parent.parent, StatusEvent(status=\ 
     420                            "Select at least one parameter to fit ")) 
    387421   
     422    
     423    def _onTextEnter(self,event): 
     424        """ 
     425            set a flag to determine if the fitting range entered by the user is valid 
     426        """ 
     427       
     428        try: 
     429            flag=self.checkFitRange() 
     430            if flag==True and self.model!=None: 
     431                self.manager.redraw_model(float(self.xmin.GetValue())\ 
     432                                               ,float(self.xmax.GetValue())) 
     433        except: 
     434 
     435            wx.PostEvent(self.parent.GrandParent, StatusEvent(status=\ 
     436                            "Drawing  Error:wrong value entered %s"% sys.exc_value)) 
     437         
     438    
    388439     
    389440    def get_param_list(self): 
     
    408459            self.compute_chisqr() 
    409460        except: 
    410             self.text1_1.Hide() 
    411461            pass 
    412462         
     
    462512                if item in self.param_toFit: 
    463513                    self.param_toFit.remove(item)            
    464         #Set the value of checkbox that selected all checkboxes or not to true or false            
     514        #Set the value of checkbox that selected every checkbox or not             
    465515        if len(self.parameters)+len(self.fittable_param) ==len(self.param_toFit): 
    466516            self.cb1.SetValue(True) 
Note: See TracChangeset for help on using the changeset viewer.