Changeset 106ef4d in sasview for guitools


Ignore:
Timestamp:
Apr 11, 2008 4:49:27 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:
bceddd6
Parents:
1fdb81d
Message:

fitDialog modified

File:
1 edited

Legend:

Unmodified
Added
Removed
  • guitools/fitDialog.py

    r1fdb81d r106ef4d  
    1010    #def __init__(self, parent, id, title): 
    1111    def __init__(self, parent, plottable, push_data,transform, id, title): 
    12         wx.Dialog.__init__(self, parent, id, title, size=(550, 300)) 
     12        wx.Dialog.__init__(self, parent, id, title, size=(450, 300)) 
    1313        """ 
    1414            for the fit window 
     
    2424        panel = wx.Panel(self, -1, style=wx.SIMPLE_BORDER)    
    2525        vbox  = wx.BoxSizer(wx.VERTICAL) 
    26         sizer = wx.GridBagSizer(5,0) 
     26        sizer = wx.GridBagSizer(5,5) 
     27        
    2728        vbox.Add(panel, 1, wx.EXPAND | wx.ALL) 
    2829  
     
    3435        self.tcXmin = wx.TextCtrl(panel,-1,size=(120,20),style=wx.SIMPLE_BORDER) 
    3536        self.tcXmax = wx.TextCtrl(panel,-1,size=(120,20),style=wx.SIMPLE_BORDER) 
    36         self.btFit =wx.Button(panel,-1,'Fit' ) 
    37         btClose =wx.Button(panel, wx.ID_CANCEL,'Close' ) 
    38          
     37        self.btFit =wx.Button(panel,-1,'Fit',size=(120, 30)) 
     38        self.btClose =wx.Button(panel, wx.ID_CANCEL,'Close',size=(90, 30) ) 
     39        self.static_line_1 = wx.StaticLine(panel, -1) 
     40        ix = 0 
     41        iy = 1 
     42         
     43        sizer.Add(wx.StaticText(panel, -1, 'y = Ax +B'),(iy, ix),(1,1),\ 
     44                   wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15) 
     45         
     46        iy+=1 
     47        sizer.Add(wx.StaticText(panel, -1, 'Param A'),(iy, ix),\ 
     48                 (1,1), wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15) 
     49        ix += 1 
     50        sizer.Add(self.tcA,(iy, ix),(1,1), wx.EXPAND|wx.ADJUST_MINSIZE, 0) 
     51        ix += 1 
     52        sizer.Add(wx.StaticText(panel, -1, '+/-'),(iy, ix),(1,1), wx.EXPAND|wx.ADJUST_MINSIZE, 0) 
     53        ix += 1 
     54        sizer.Add(self.tcErrA, (iy, ix),(1,1), wx.EXPAND|wx.ADJUST_MINSIZE, 0) 
     55        
     56        iy += 1 
     57        ix = 0 
     58        sizer.Add(wx.StaticText(panel, -1, 'Param B'),(iy, ix),(1,1),\ 
     59                   wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15) 
     60        ix += 1 
     61        sizer.Add(self.tcB, (iy, ix),(1,1), wx.EXPAND|wx.ADJUST_MINSIZE, 0) 
     62        ix += 1 
     63        sizer.Add(wx.StaticText(panel, -1, '+/-'),(iy, ix),(1,1), wx.EXPAND|wx.ADJUST_MINSIZE, 0) 
     64        ix += 1 
     65        sizer.Add(self.tcErrB, (iy, ix),(1,1), wx.EXPAND|wx.ADJUST_MINSIZE, 0) 
     66        iy += 1 
     67        ix = 0 
     68        sizer.Add(wx.StaticText(panel, -1, 'Chi ^{2}'),(iy, ix),(1,1),\ 
     69                   wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15) 
     70        ix += 1 
     71        sizer.Add(self.tcChi, (iy, ix),(1,1), wx.EXPAND|wx.ADJUST_MINSIZE, 0) 
     72        iy += 1 
    3973        ix = 1 
    40         iy = 1 
    41          
    42         sizer.Add(wx.StaticText(panel, -1, 'y = Ax +B'),(iy, ix)) 
     74        sizer.Add(wx.StaticText(panel, -1, 'Xmin'),(iy, ix),(1,1),\ 
     75                   wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 0) 
     76        ix += 2 
     77        sizer.Add(wx.StaticText(panel, -1, 'Xmax'),(iy, ix),(1,1), wx.EXPAND|wx.ADJUST_MINSIZE, 0) 
     78        iy += 1 
    4379        ix = 1 
    44         iy += 2 
    45         
    46         sizer.Add(wx.StaticText(panel, -1, 'Param A'),(iy, ix)) 
    47         ix += 1 
    48         sizer.Add(self.tcA, (iy, ix)) 
    49         ix += 1 
    50         sizer.Add(wx.StaticText(panel, -1, '+/-'),(iy, ix)) 
    51         ix += 1 
    52         sizer.Add(self.tcErrA, (iy, ix)) 
     80        sizer.Add(self.tcXmin, (iy, ix),(1,1),\ 
     81                   wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 0) 
     82        ix += 2 
     83        sizer.Add(self.tcXmax, (iy, ix),(1,1), wx.EXPAND|wx.ADJUST_MINSIZE, 0) 
    5384        iy += 1 
    5485        ix = 1 
    55         sizer.Add(wx.StaticText(panel, -1, 'Param B'),(iy, ix)) 
    56         ix += 1 
    57         sizer.Add(self.tcB, (iy, ix)) 
    58         ix += 1 
    59         sizer.Add(wx.StaticText(panel, -1, '+/-'),(iy, ix)) 
    60         ix += 1 
    61         sizer.Add(self.tcErrB, (iy, ix)) 
    62         iy += 1 
    63         ix = 1 
    64         sizer.Add(wx.StaticText(panel, -1, 'Chi ^{2}'),(iy, ix)) 
    65         ix += 1 
    66         sizer.Add(self.tcChi, (iy, ix)) 
    67         iy += 1 
    68         ix = 1 
    69         sizer.Add(wx.StaticText(panel, -1, 'Xmin'),(iy, ix)) 
     86         
     87        sizer.Add(self.btFit, (iy, ix),(1,1), wx.LEFT|wx.ADJUST_MINSIZE, 0) 
     88        self.btFit.Bind(wx.EVT_BUTTON, self._onFit) 
    7089        ix += 2 
    71         sizer.Add(wx.StaticText(panel, -1, 'Xmax'),(iy, ix)) 
    72         iy += 1 
    73         ix = 1 
    74         sizer.Add(self.tcXmin, (iy, ix)) 
    75         ix += 2 
    76         sizer.Add(self.tcXmax, (iy, ix)) 
    77         iy += 1 
    78         ix = 3 
    79         sizer.Add(self.btFit, (iy, ix)) 
    80         self.btFit.Bind(wx.EVT_BUTTON, self._onFit) 
    81         iy +=1 
    82         ix = 3 
    83         sizer.Add(btClose, (iy, ix)) 
     90        sizer.Add(self.btClose, (iy, ix),(1,1),\ 
     91                  wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 0) 
     92         
    8493        
    8594        panel.SetSizer(sizer) 
     
    103112        self.tcErrB.SetLabel(str(0.0)) 
    104113        self.tcChi.SetLabel(str(0.0)) 
    105         self.tcXmin.SetLabel(str(0.0)) 
    106         self.tcXmax.SetLabel(str(0.0)) 
     114         
     115        
    107116         
    108117        # new data for the fit  
     
    130139        self.xtrans,self.ytrans= self.transform() 
    131140         
    132                          
    133         if (xmin ==None)and (xmax == None): 
    134             #Display the min and the max of x on fit dialog fields 
    135             self.tcXmin.SetValue(str(min(x))) 
    136             self.tcXmax.SetValue(str(max(x))) 
    137        
    138          
    139         # Store the transformed values of view x, y,dy in variables  before the fit 
    140         if  self.ytrans == "Log(y)": 
     141        # Check if View contains a x array .we online fit when x exits 
     142        # makes transformation for y as a line to fit 
     143        if x != []:                 
     144            if (xmin ==None)and (xmax == None): 
     145                #Display the min and the max of x on fit dialog fields 
     146                self.tcXmin.SetValue(str(min(x))) 
     147                self.tcXmax.SetValue(str(max(x))) 
     148           
     149             
     150            # Store the transformed values of view x, y,dy in variables  before the fit 
     151            if  self.ytrans == "Log(y)": 
     152                for y_i in y: 
     153                    tempy.append(math.log(y_i))  
     154            else: 
     155                tempy = y 
     156                 
    141157            for y_i in y: 
    142                 tempy.append(math.log(y_i))  
    143158                dy = 1/y_i 
    144159                if dy >= y_i: 
    145160                    dy = 0.9*y_i 
    146161                tempdy.append(dy) 
    147         else: 
    148             tempy = y 
    149         if  self.xtrans == "Log(x)": 
    150             for x_i in x: 
    151                 tempx.append(math.log(x_i))  
    152         else: 
    153             tempx = x 
    154              
    155         #Find the fitting parameters 
    156         if (xmin !=None and xmin >= min(tempx) ) and (xmax != None and xmax <= max(tempx)):    
    157             chisqr, out, cov = fittings.sansfit(self.model,  
    158                         [self.cstA, self.cstB],tempx, tempy,tempdy,xmin,xmax) 
    159         else: 
    160             chisqr, out, cov = fittings.sansfit(self.model,  
    161                         [self.cstA, self.cstB],tempx, tempy,tempdy,min(tempx),max(tempx)) 
    162         
    163         #Check that cov and out are iterable before displaying them 
    164         if cov ==None: 
    165             errA =0.0 
    166             errB =0.0 
    167         else: 
    168             errA= math.sqrt(cov[0][0]) 
    169             errB= math.sqrt(cov[1][1]) 
    170         if out==None: 
    171             cstA=0.0 
    172             cstB=0.0 
    173         else: 
    174             cstA=out[0] 
    175             cstB=out[1] 
    176         # Reset model with the right values of A and B  
    177         self.model.setParam('A', float(cstA)) 
    178         self.model.setParam('B', float(cstB)) 
    179         tempy = [] 
    180         # Check if View contains a x array .we online fit when x exits 
    181         # makes transformation for y as a line to fit 
    182         if x != []: 
     162                    
     163             
     164            if  self.xtrans == "Log(x)": 
     165                for x_i in x: 
     166                    tempx.append(math.log(x_i))  
     167            else: 
     168                tempx = x 
     169                 
     170            #Find the fitting parameters 
     171            if (xmin !=None and xmin >= min(tempx) ) and (xmax !=None and xmax <= max(tempx)):    
     172                chisqr, out, cov = fittings.sansfit(self.model,  
     173                            [self.cstA, self.cstB],tempx, tempy,tempdy,xmin,xmax) 
     174            else: 
     175                chisqr, out, cov = fittings.sansfit(self.model,  
     176                            [self.cstA, self.cstB],tempx, tempy,tempdy,min(tempx),max(tempx)) 
     177             
     178            #Check that cov and out are iterable before displaying them 
     179            if cov ==None: 
     180                errA =0.0 
     181                errB =0.0 
     182            else: 
     183                errA= math.sqrt(cov[0][0]) 
     184                errB= math.sqrt(cov[1][1]) 
     185            if out==None: 
     186                cstA=0.0 
     187                cstB=0.0 
     188            else: 
     189                cstA=out[0] 
     190                cstB=out[1] 
     191            # Reset model with the right values of A and B  
     192            self.model.setParam('A', float(cstA)) 
     193            self.model.setParam('B', float(cstB)) 
     194            tempy = [] 
     195            y_model = 0.0 
     196             
    183197            for j in range(len(x)):  
    184198                    if (xmin !=None)and (xmax != None): 
     
    203217            self.file_data1.dx=None 
    204218            self.file_data1.dy=None 
    205             
     219             
    206220            #Load the view with the new values 
    207221            self.file_data1.reset_view() 
     
    228242    def _checkVal(self,value): 
    229243        """ 
    230                 Ensure that field parameter contains a value  
    231                 before sending to fit  
     244                Ensure that fields parameter contains a value  
     245                before sending to fit in Plotter1D 
    232246        """ 
    233247        try: 
     
    236250            param = None 
    237251        return param 
     252    
    238253if __name__ == "__main__":  
    239254    app = wx.App() 
Note: See TracChangeset for help on using the changeset viewer.