Changeset f52bea1 in sasview for guitools/fitDialog.py


Ignore:
Timestamp:
Apr 8, 2008 5:04:51 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:
3d3a0e5
Parents:
8742751
Message:

Plotpanel plottable fitdialog req modified

File:
1 edited

Legend:

Unmodified
Added
Removed
  • guitools/fitDialog.py

    r5789654 rf52bea1  
    99class LinearFit(wx.Dialog): 
    1010    #def __init__(self, parent, id, title): 
    11     def __init__(self, parent, plottable, push_data, id, title): 
     11    def __init__(self, parent, plottable, push_data,transform, id, title): 
    1212        wx.Dialog.__init__(self, parent, id, title, size=(550, 300)) 
    1313        """ 
     
    1515        """ 
    1616        self.parent = parent 
     17        self.transform = transform 
    1718        #dialog panel self call function to plot the fitting function 
    1819        self.push_data = push_data 
    1920        #dialog self plottable 
    2021        self.plottable = plottable 
     22         
    2123         
    2224        #Dialog interface 
     
    7577        sizer.Add(self.tcXmax, (iy, ix)) 
    7678        iy += 1 
    77         ix = 1 
     79        ix = 3 
    7880        sizer.Add(self.btFit, (iy, ix)) 
    7981        self.btFit.Bind(wx.EVT_BUTTON, self._onFit) 
    80         ix += 2 
     82        iy +=1 
     83        ix = 3 
    8184        sizer.Add(btClose, (iy, ix)) 
    8285        
     
    9295         
    9396    def _onFit(self ,event): 
    94         
    95         print "we are on fit" 
     97        """ 
     98            Performs the fit. Receive an event when clicking on the button Fit.Computes chisqr , 
     99            A and B parameters of the best linear fit y=Ax +B 
     100            Push a plottable to  
     101        """ 
     102        
    96103        temp =[] 
     104        tempx=[] 
     105        tempy=[] 
    97106        xmin = self._checkVal(self.tcXmin.GetValue()) 
    98107        xmax = self._checkVal(self.tcXmax.GetValue()) 
     
    100109        #store the values of View in x,y, dx,dy 
    101110        x,y,dx,dy=self.plottable.returnValuesOfView() 
    102         
     111        self.xtrans,self.ytrans= self.transform() 
     112        #Display the fittings values 
     113        default_A = self.model.getParam('A')  
     114        default_B = self.model.getParam('B')  
     115        cstA = fittings.Parameter(self.model, 'A', default_A) 
     116        cstB  = fittings.Parameter(self.model, 'B', default_B) 
     117        if  self.ytrans == "Log(y)": 
     118            for y_i in y: 
     119                tempy.append(log(y_i))        
     120            chisqr, out, cov = fittings.sansfit(self.model,  
     121                            [cstA, cstB],x, tempy,dy,min(x),max(x)) 
     122        else : 
     123            chisqr, out, cov = fittings.sansfit(self.model,  
     124                            [cstA, cstB],x, y,dy,min(x),max(x)) 
     125        #Check that cov and out are iterable before displaying them 
     126        if cov ==None: 
     127            errA =0.0 
     128            errB =0.0 
     129        else: 
     130            errA= math.sqrt(cov[0][0]) 
     131            errB= math.sqrt(cov[1][1]) 
     132        if out==None: 
     133            cstA=0.0 
     134            cstB=0.0 
     135        else: 
     136            cstA=out[0] 
     137            cstB=out[1] 
     138        self.model.setParam('A', float(cstA)) 
     139        self.model.setParam('B', float(cstB)) 
     140         
    103141        if x != []: 
    104142            if xmin !=None  and xmax != None: 
    105143                for j in range(len(x)): 
    106                     if x[j]>xmin and x[j]<xmax: 
     144                    if x[j] > xmin and x[j] < xmax: 
    107145                        temp.append(self.model.run(x[j])) 
    108                      
    109                         for y_i in temp: 
    110                             tempdy.append(math.sqrt(y_i))  
    111146            else: 
    112147                # x has a default value in case the user doesn't load data 
    113148                for x_i in x: 
    114149                    temp.append(self.model.run(x_i)) 
    115          
    116                     self.tcXmin.SetValue(str(min(x))) 
    117                     self.tcXmax.SetValue(str(max(x))) 
    118                     xmin = self._checkVal(self.tcXmin.GetValue()) 
    119                     xmax = self._checkVal(self.tcXmax.GetValue()) 
     150                self.tcXmin.SetValue(str(min(x))) 
     151                self.tcXmax.SetValue(str(max(x))) 
     152                xmin = self._checkVal(self.tcXmin.GetValue()) 
     153                xmax = self._checkVal(self.tcXmax.GetValue()) 
    120154                 
    121155            self.file_data1.x =x 
    122             self.file_data1.y =temp 
    123            
     156            # Create new data plottable with result 
     157            self.file_data1.y =[] 
     158            self.xtrans, self.ytrans= self.transform() 
     159             
     160            if self.ytrans == "Log(y)": 
     161                for x_i in x: 
     162                    self.file_data1.y.append(exp(self.model.run(x_i))) 
     163            else: 
     164                self.file_data1.y =temp      
    124165            self.file_data1.dx=None 
    125166            self.file_data1.dy=None 
     167             
    126168            self.file_data1.reset_view() 
    127          
    128             # Display the fittings values 
    129             default_A = self.model.getParam('A')  
    130             default_B = self.model.getParam('B')  
    131             cstA = fittings.Parameter(self.model, 'A', default_A) 
    132             cstB  = fittings.Parameter(self.model, 'B', default_B)         
    133             chisqr, out, cov = fittings.sansfit(self.model,  
    134                [cstA, cstB],x, y,dy,min(x),max(x)) 
    135169             
    136             
    137             #Check that cov and out are iterable before displaying them 
    138             if cov ==None: 
    139                 errA =str(0.0) 
    140                 errB =str(0.0) 
    141             else: 
    142                 errA= str(math.sqrt(cov[0][0])) 
    143                 errB= str(math.sqrt(cov[1][1])) 
    144             if out==None: 
    145                 cstA=str(0.0) 
    146                 cstB=str(0.0) 
    147             else: 
    148                 cstA=str(out[0]) 
    149                 cstB=str(out[1]) 
    150             
    151             self.model.setParam('A', float(cstA)) 
    152             self.model.setParam('B', float(cstB)) 
    153              # Create new data plottable with result 
    154             self.file_data1.y = [] 
    155             
    156             for x_i in x: 
    157                 self.file_data1.y.append(self.model.run(x_i)) 
    158170            #Send the data to display to the PlotPanel 
    159             self.file_data1.reset_view() 
     171            # 
    160172            self.push_data(self.file_data1) 
    161173            # Display the fitting value on the Fit Dialog 
    162             self._onsetValues(cstA, cstB, errA,errB,str(chisqr)) 
     174            self._onsetValues(cstA, cstB, errA,errB,chisqr) 
    163175        
    164176    def _onsetValues(self,cstA,cstB,errA,errB,Chi): 
    165          
    166          self.tcA.SetValue(cstA) 
    167          self.tcB.SetValue(cstB) 
    168          self.tcErrA.SetValue(errA) 
    169          self.tcErrB.SetValue(errB) 
    170          self.tcChi.SetValue(Chi) 
     177         """ 
     178              Display  the value on fit Dialog  
     179         """ 
     180         self.tcA.SetValue(str(cstA)) 
     181         self.tcB.SetValue(str(cstB)) 
     182         self.tcErrA.SetValue(str(errA)) 
     183         self.tcErrB.SetValue(str(errB)) 
     184         self.tcChi.SetValue(str(Chi)) 
    171185          
    172186    def _returnPlottable(self): 
     
    175189    def _checkVal(self,value): 
    176190        """ 
    177                 Ensure that fields parameter contains a value  
    178                 before sending to fit in Plotter1D 
     191                Ensure that field parameter contains a value  
     192                before sending to fit  
    179193        """ 
    180194        try: 
Note: See TracChangeset for help on using the changeset viewer.