Changeset f193585 in sasview for guitools/fitDialog.py


Ignore:
Timestamp:
Apr 28, 2008 3:48:59 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:
6ed101a
Parents:
9e8dc22
Message:

some changes

File:
1 edited

Legend:

Unmodified
Added
Removed
  • guitools/fitDialog.py

    r46693050 rf193585  
    140140        self.file_data1 = Theory1D(x=[], y=[], dy=None) 
    141141        self.file_data1.name = "Fit" 
    142          
     142        # Receive transformations of x and y 
     143        self.xtrans,self.ytrans= self.transform() 
    143144    def _onFit(self ,event): 
    144145        """ 
     
    152153        tempdy = [] 
    153154         
    154         #Check if the field of Fit Dialog contain values and use the x max and min of the user 
    155         xmin,xmax = self._checkVal(self.FXmin.GetValue(),self.FXmax.GetValue()) 
    156155        #store the values of View in x,y, dx,dy 
    157156        x,y,dx,dy=self.plottable.returnValuesOfView() 
     
    162161        # makes transformation for y as a line to fit 
    163162        if x != []:  
    164             xminView=self.floatTransform(xmin) 
    165             xmaxView=self.floatTransform(xmax) 
    166          
    167             # Store the transformed values of view x, y,dy in variables  before the fit 
    168             if  self.ytrans.lower() == "log10(y)": 
    169                 for y_i in y: 
    170                     tempy.append(math.log10(y_i))  
    171             else: 
    172                 tempy = y 
    173             if  self.xtrans.lower() == "log10(x)": 
    174                 for x_i in x: 
    175                     tempx.append(math.log10(x_i))  
    176             else: 
    177                 tempx = x 
    178                     
    179             for y_i in y: 
    180                 dy = 1/y_i 
    181                 if dy >= y_i: 
    182                     dy = 0.9*y_i 
    183                 tempdy.append(dy) 
    184                     
    185             #Find the fitting parameters 
    186             chisqr, out, cov = fittings.sansfit(self.model,  
    187                             [self.cstA, self.cstB],tempx, tempy,tempdy,xminView,xmaxView) 
     163            if(self.checkFitValues(self.FXmin) == True): 
     164                #Check if the field of Fit Dialog contain values and use the x max and min of the user 
     165                xmin,xmax = self._checkVal(self.FXmin.GetValue(),self.FXmax.GetValue()) 
     166                xminView=self.floatTransform(xmin) 
     167                xmaxView=self.floatTransform(xmax) 
     168                 
     169                # Store the transformed values of view x, y,dy in variables  before the fit 
     170                if  self.ytrans.lower() == "log10(y)": 
     171                    if (self.xtrans.lower() == "log10(x)"): 
     172                        for i in range(len(x)): 
     173                            if x[i]>=xmin: 
     174                                tempy.append(math.log10(y[i]))  
     175                                tempdy.append(transform.errToLogX(y[i],0,dy[i],0)) 
     176                    else: 
     177                        for y_i in y: 
     178                            tempy.append(math.log10(y_i))  
     179                            tempdy.append(transform.errToLogX(y[i],0,dy[i],0)) 
     180                else: 
     181                    tempy = y 
     182                    tempdy = dy 
     183                
     184                if (self.xtrans.lower() == "log10(x)"): 
     185                    for x_i in x: 
     186                        if x_i >= xmin: 
     187                            tempx.append(math.log10(x_i))  
     188                else: 
     189                    tempx = x 
     190                        
     191                #for y_i in y: 
     192                #    dy = math.sqrt(math.fabs(y_i)) 
     193                #    if dy >= y_i: 
     194                #        dy = 0.9*y_i 
     195                #    tempdy.append(dy) 
     196                        
     197                #Find the fitting parameters 
     198 
     199                chisqr, out, cov = fittings.sansfit(self.model,  
     200                                [self.cstA, self.cstB],tempx, tempy,tempdy,xminView,xmaxView) 
     201                print "this out",out 
     202                #Check that cov and out are iterable before displaying them 
     203                if cov ==None: 
     204                    errA =0.0 
     205                    errB =0.0 
     206                else: 
     207                    errA= math.sqrt(cov[0][0]) 
     208                    errB= math.sqrt(cov[1][1]) 
     209                if out==None: 
     210                    cstA=0.0 
     211                    cstB=0.0 
     212                else: 
     213                    cstA=out[0] 
     214                    cstB=out[1] 
     215                # Reset model with the right values of A and B  
     216                self.model.setParam('A', float(cstA)) 
     217                self.model.setParam('B', float(cstB)) 
     218                 
     219                tempx = [] 
     220                tempy = [] 
     221                y_model = 0.0 
     222                # load tempy with the minimum transformation 
     223                
     224                if self.xtrans == "log10(x)": 
     225                    y_model = self.model.run(math.log10(xmin)) 
     226                    tempx.append(xmin) 
     227                else: 
     228                    y_model = self.model.run(xminView) 
     229                    tempx.append(xminView) 
     230                     
     231                if self.ytrans == "log10(y)": 
     232                    tempy.append(math.pow(10,y_model)) 
     233                    print "tempy",tempy 
     234                else: 
     235                    tempy.append(y_model) 
     236                     
     237                # load tempy with the maximum transformation 
     238                if self.xtrans == "log10(x)": 
     239                    y_model = self.model.run(math.log10(xmax)) 
     240                    tempx.append(xmax) 
     241                else: 
     242                    y_model = self.model.run(xmaxView) 
     243                    tempx.append(xmaxView) 
     244                     
     245                if self.ytrans == "log10(y)": 
     246                    tempy.append(math.pow(10,y_model)) 
     247                else:  
     248                    tempy.append(y_model) 
     249               
     250                # Create new data plottable with result 
     251                self.file_data1.x =[]  
     252                self.file_data1.y =[]  
     253                self.file_data1.x =tempx   
     254                self.file_data1.y =tempy      
     255                self.file_data1.dx=None 
     256                self.file_data1.dy=None 
     257                #Load the view with the new values 
     258                self.file_data1.reset_view() 
     259                 
     260                #Send the data to display to the PlotPanel 
     261                self.push_data(self.file_data1) 
     262                 
     263                # Display the fitting value on the Fit Dialog 
     264                self._onsetValues(cstA, cstB, errA,errB,chisqr) 
    188265             
    189             #Check that cov and out are iterable before displaying them 
    190             if cov ==None: 
    191                 errA =0.0 
    192                 errB =0.0 
    193             else: 
    194                 errA= math.sqrt(cov[0][0]) 
    195                 errB= math.sqrt(cov[1][1]) 
    196             if out==None: 
    197                 cstA=0.0 
    198                 cstB=0.0 
    199             else: 
    200                 cstA=out[0] 
    201                 cstB=out[1] 
    202             # Reset model with the right values of A and B  
    203             self.model.setParam('A', float(cstA)) 
    204             self.model.setParam('B', float(cstB)) 
    205              
    206             tempx = [] 
    207             tempy = [] 
    208             y_model = 0.0 
    209             # load tempy with the minimum transformation 
    210             
    211             if self.xtrans == "log10(x)": 
    212                 y_model = self.model.run(math.log10(xmin)) 
    213                 tempx.append(xmin) 
    214             else: 
    215                 y_model = self.model.run(xminView) 
    216                 tempx.append(xminView) 
    217                  
    218             if self.ytrans == "log10(y)": 
    219                 tempy.append(math.pow(10,y_model)) 
    220             else: 
    221                 tempy.append(y_model) 
    222                  
    223             # load tempy with the maximum transformation 
    224             if self.xtrans == "log10(x)": 
    225                 y_model = self.model.run(math.log10(xmax)) 
    226                 tempx.append(xmax) 
    227             else: 
    228                 y_model = self.model.run(xmaxView) 
    229                 tempx.append(xmaxView) 
    230                  
    231             if self.ytrans == "log10(y)": 
    232                 tempy.append(math.pow(10,y_model)) 
    233             else:  
    234                 tempy.append(y_model) 
    235            
    236             # Create new data plottable with result 
    237             self.file_data1.x =[]  
    238             self.file_data1.y =[]  
    239             self.file_data1.x =tempx   
    240             self.file_data1.y =tempy      
    241             self.file_data1.dx=None 
    242             self.file_data1.dy=None 
    243             #Load the view with the new values 
    244             self.file_data1.reset_view() 
    245              
    246             #Send the data to display to the PlotPanel 
    247             self.push_data(self.file_data1,xminView, xmaxView) 
    248              
    249             # Display the fitting value on the Fit Dialog 
    250             self._onsetValues(cstA, cstB, errA,errB,chisqr) 
    251     
    252266    def _onsetValues(self,cstA,cstB,errA,errB,Chi): 
    253267         """ 
     
    291305            return transform.toX(x) 
    292306         
    293         if ( self.xtrans=="x^(2)" ): 
     307        if ( self.xtrans=="x^(2)" ):  
    294308            return transform.toX2(x) 
    295309         
     
    299313            else: 
    300314                raise ValueError,"cannot compute log of a negative number" 
     315             
     316    def checkFitValues(self,item): 
     317        """ 
     318            Check the validity of input values 
     319        """ 
     320        flag = True 
     321        value = item.GetValue() 
     322        # Check for possible values entered 
     323        if (self.xtrans=="log10(x)"): 
     324            if (float(value) > 0): 
     325                item.SetBackgroundColour(wx.WHITE) 
     326                item.Refresh() 
     327            else: 
     328                flag = False 
     329                item.SetBackgroundColour("pink") 
     330                item.Refresh() 
     331       
     332        return flag 
    301333        
    302334                 
Note: See TracChangeset for help on using the changeset viewer.