Changeset 1fdb81d in sasview for guitools


Ignore:
Timestamp:
Apr 11, 2008 2:53:40 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:
106ef4d
Parents:
370e587
Message:

modified plotpanel and fitdialog

Location:
guitools
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • guitools/PlotPanel.py

    r7a03e65 r1fdb81d  
    623623        self.graph.add(plottable) 
    624624        self.graph.render(self) 
     625         
    625626        self.subplot.figure.canvas.draw_idle() 
    626627        self.graph.delete(plottable) 
     628       
    627629         
    628630      
  • guitools/fitDialog.py

    r7a03e65 r1fdb81d  
    8989        from LineModel import LineModel 
    9090        self.model  = LineModel() 
     91           
     92           
     93        #Display the fittings values 
     94        self.default_A = self.model.getParam('A')  
     95        self.default_B = self.model.getParam('B')  
     96        self.cstA = fittings.Parameter(self.model, 'A', self.default_A) 
     97        self.cstB  = fittings.Parameter(self.model, 'B', self.default_B) 
     98         
     99        # Set default value of parameter in fit dialog 
     100        self.tcA.SetLabel(str(self.default_A)) 
     101        self.tcB.SetLabel(str(self.default_B)) 
     102        self.tcErrA.SetLabel(str(0.0)) 
     103        self.tcErrB.SetLabel(str(0.0)) 
     104        self.tcChi.SetLabel(str(0.0)) 
     105        self.tcXmin.SetLabel(str(0.0)) 
     106        self.tcXmax.SetLabel(str(0.0)) 
     107         
    91108        # new data for the fit  
    92109        self.file_data1 = Theory1D(x=[], y=[], dy=None) 
     
    99116            Push a plottable to  
    100117        """ 
    101         temp=[] 
     118         
    102119        tempx=[] 
    103120        tempy=[] 
     
    112129        # Receive transformations of x and y 
    113130        self.xtrans,self.ytrans= self.transform() 
    114         # The x array min and max 
    115         _min = min(x) 
    116         _max = max(x) 
    117         
     131         
    118132                         
    119133        if (xmin ==None)and (xmax == None): 
     
    121135            self.tcXmin.SetValue(str(min(x))) 
    122136            self.tcXmax.SetValue(str(max(x))) 
    123          
    124            
    125         #Display the fittings values 
    126         default_A = self.model.getParam('A')  
    127         default_B = self.model.getParam('B')  
    128         cstA = fittings.Parameter(self.model, 'A', default_A) 
    129         cstB  = fittings.Parameter(self.model, 'B', default_B) 
    130                    
     137       
     138         
     139        # Store the transformed values of view x, y,dy in variables  before the fit 
    131140        if  self.ytrans == "Log(y)": 
    132141            for y_i in y: 
    133                 temp.append(math.log(y_i))  
    134                 tempdy.append(1.0) 
    135             if (xmin !=None and xmin>= _min) and (xmax != None and xmax<= _max):    
    136                 chisqr, out, cov = fittings.sansfit(self.model,  
    137                             [cstA, cstB],x, temp,tempdy,xmin,xmax) 
    138             else: 
    139                 chisqr, out, cov = fittings.sansfit(self.model,  
    140                             [cstA, cstB],x, temp,tempdy,_min,_max) 
    141         else : 
    142             if (xmin !=None and xmin >= _min) and (xmax != None and xmax <= _max):    
    143                 chisqr, out, cov = fittings.sansfit(self.model,  
    144                             [cstA, cstB],x, y,dy,xmin,xmax) 
    145             else: 
    146                 chisqr, out, cov = fittings.sansfit(self.model,  
    147                             [cstA, cstB],x, y,dy,_min,_max) 
     142                tempy.append(math.log(y_i))  
     143                dy = 1/y_i 
     144                if dy >= y_i: 
     145                    dy = 0.9*y_i 
     146                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        
    148163        #Check that cov and out are iterable before displaying them 
    149164        if cov ==None: 
     
    159174            cstA=out[0] 
    160175            cstB=out[1] 
     176        # Reset model with the right values of A and B  
    161177        self.model.setParam('A', float(cstA)) 
    162178        self.model.setParam('B', float(cstB)) 
    163          
    164         #Check if View contains a x array and makes transformation for y as a line to fit 
     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 
    165182        if x != []: 
    166183            for j in range(len(x)):  
     
    170187                    else: 
    171188                        # x has a default value in case the user doesn't load data 
    172                         y_model = self.model.run(x[j]) 
     189                        if self.xtrans == "Log(x)": 
     190                            y_model = self.model.run(math.log(x[j])) 
     191                        else: 
     192                            y_model = self.model.run(x[j]) 
     193                     
    173194                    if self.ytrans == "Log(y)": 
    174195                        tempy.append(math.exp(y_model)) 
    175196                    else: 
    176197                        tempy.append(y_model) 
    177             
     198                         
    178199            # Create new data plottable with result 
    179             self.file_data1.y =[] 
    180             self.file_data1.x =x 
     200            self.file_data1.x =x  
     201            self.file_data1.y =[]   
    181202            self.file_data1.y =tempy      
    182203            self.file_data1.dx=None 
    183204            self.file_data1.dy=None 
    184              
     205            
    185206            #Load the view with the new values 
    186207            self.file_data1.reset_view() 
Note: See TracChangeset for help on using the changeset viewer.