Changeset b43a009 in sasview for guitools/fitDialog.py


Ignore:
Timestamp:
May 5, 2008 2:44: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:
edce46e
Parents:
2d06beb
Message:

some modificatiosn made

File:
1 edited

Legend:

Unmodified
Added
Removed
  • guitools/fitDialog.py

    r416223d rb43a009  
    1111 
    1212class LinearFit(wx.Dialog): 
    13     #def __init__(self, parent, id, title): 
    1413    def __init__(self, parent, plottable, push_data,transform, id, title): 
    1514        wx.Dialog.__init__(self, parent, id, title, size=(450, 400)) 
    1615        """ 
    17             for the fit window 
     16            Dialog window pops- up when select Linear fit on Context menu 
     17            Displays fitting parameters 
    1818        """ 
    1919        self.parent = parent 
     
    2222        self.push_data = push_data 
    2323        #dialog self plottable 
     24         
    2425        self.plottable = plottable 
    2526        # Receive transformations of x and y 
    26         self.xtrans,self.ytrans= self.transform() 
     27        self.xLabel,self.yLabel,self.Avalue,self.Bvalue,\ 
     28        self.ErrAvalue,self.ErrBvalue,self.Chivalue= self.transform() 
    2729        #Dialog interface 
    2830        panel = wx.Panel(self, -1, style=wx.SIMPLE_BORDER)    
     
    9193        ix += 2 
    9294        sizer.Add(self.PXmax, (iy, ix),(1,1), wx.EXPAND|wx.ADJUST_MINSIZE, 0) 
    93         iy += 1 
    94         ix = 1 
    95         sizer.Add(wx.StaticText(panel, -1,"x transofrmation is: "+self.xtrans ),(iy, ix),(1,1),\ 
    96                    wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15) 
    97         iy += 1 
    98         ix = 0 
    99         sizer.Add(wx.StaticText(panel, -1, 'Fit Range'),(iy, ix),(1,1),\ 
     95        
     96        iy += 1 
     97        ix = 0 
     98        sizer.Add(wx.StaticText(panel, -1, 'Fit Range of '+self.xLabel),(iy, ix),(1,1),\ 
    10099                   wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15) 
    101100        ix += 1 
     
    138137         
    139138        # Set default value of parameter in fit dialog 
    140         self.tcA.SetLabel(str(self.default_A)) 
    141         self.tcB.SetLabel(str(self.default_B)) 
    142         self.tcErrA.SetLabel(str(0.0)) 
    143         self.tcErrB.SetLabel(str(0.0)) 
    144         self.tcChi.SetLabel(str(0.0)) 
    145          
     139         
     140        if self.Avalue==None: 
     141            self.tcA.SetLabel(str(self.default_A)) 
     142        else : 
     143            self.tcA.SetLabel(str(self.Avalue)) 
     144        if self.Bvalue==None: 
     145            self.tcB.SetLabel(str(self.default_B)) 
     146        else: 
     147            self.tcB.SetLabel(str(self.Bvalue)) 
     148        if self.ErrAvalue==None: 
     149            self.tcErrA.SetLabel(str(0.0)) 
     150        else: 
     151            self.tcErrA.SetLabel(str(self.ErrAvalue)) 
     152        if self.ErrBvalue==None: 
     153            self.tcErrB.SetLabel(str(0.0)) 
     154        else: 
     155            self.tcErrB.SetLabel(str(self.ErrBvalue)) 
     156        if self.Chivalue==None: 
     157            self.tcChi.SetLabel(str(0.0)) 
     158        else: 
     159            self.tcChi.SetLabel(str(self.Chivalue)) 
    146160        if self.plottable.x !=[]: 
    147161            self.mini =min(self.plottable.x) 
     
    186200                xminView=self.floatTransform(xmin) 
    187201                xmaxView=self.floatTransform(xmax) 
    188                 if (self.xtrans=="log10(x)"): 
     202                if (self.xLabel=="log10(x)"): 
    189203                    self.FXmin.SetValue(str(math.log10(xminView))) 
    190204                    self.FXmax.SetValue(str(math.log10(xmaxView))) 
     
    195209                self.FXmax.Disable() 
    196210                # Store the transformed values of view x, y,dy in variables  before the fit 
    197                 if  self.ytrans.lower() == "log10(y)": 
    198                     if (self.xtrans.lower() == "log10(x)"): 
     211                if  self.yLabel.lower() == "log10(y)": 
     212                    if (self.xLabel.lower() == "log10(x)"): 
    199213                        for i in range(len(x)): 
    200214                            if x[i]>= math.log10(xmin): 
     
    209223                    tempdy = dy 
    210224                
    211                 if (self.xtrans.lower() == "log10(x)"): 
     225                if (self.xLabel.lower() == "log10(x)"): 
    212226                    for x_i in x: 
    213227                        if x_i >= math.log10(xmin): 
     
    215229                else: 
    216230                    tempx = x 
    217                         
    218                 #for y_i in y: 
    219                 #    dy = math.sqrt(math.fabs(y_i)) 
    220                 #    if dy >= y_i: 
    221                 #        dy = 0.9*y_i 
    222                 #    tempdy.append(dy) 
    223                         
     231               
    224232                #Find the fitting parameters 
    225233                 
    226                 if (self.xtrans.lower() == "log10(x)"): 
     234                if (self.xLabel.lower() == "log10(x)"): 
    227235                    chisqr, out, cov = fittings.sansfit(self.model, [self.cstA, self.cstB], 
    228236                    tempx, tempy,tempdy,math.log10(xmin),math.log10(xmax)) 
     
    230238                    chisqr, out, cov = fittings.sansfit(self.model,  
    231239                                [self.cstA, self.cstB],tempx, tempy,tempdy,xminView,xmaxView) 
    232                 print "this out",out 
     240                #print "this out",out 
    233241                #Check that cov and out are iterable before displaying them 
    234242                if cov ==None: 
     
    253261                # load tempy with the minimum transformation 
    254262                
    255                 if self.xtrans == "log10(x)": 
     263                if self.xLabel == "log10(x)": 
    256264                    y_model = self.model.run(math.log10(xmin)) 
    257265                    tempx.append(xmin) 
     
    260268                    tempx.append(xminView) 
    261269                     
    262                 if self.ytrans == "log10(y)": 
     270                if self.yLabel == "log10(y)": 
    263271                    tempy.append(math.pow(10,y_model)) 
    264272                    print "tempy",tempy 
     
    267275                     
    268276                # load tempy with the maximum transformation 
    269                 if self.xtrans == "log10(x)": 
     277                if self.xLabel == "log10(x)": 
    270278                    y_model = self.model.run(math.log10(xmax)) 
    271279                    tempx.append(xmax) 
     
    274282                    tempx.append(xmaxView) 
    275283                     
    276                 if self.ytrans == "log10(y)": 
     284                if self.yLabel == "log10(y)": 
    277285                    tempy.append(math.pow(10,y_model)) 
    278286                else:  
    279287                    tempy.append(y_model) 
    280                 
    281                 self.push_data(tempx,tempy,xminView,xmaxView,xmin,xmax) 
     288                self.Avalue=cstA 
     289                self.Bvalue=cstB 
     290                self.ErrAvalue=errA 
     291                self.ErrBvalue=errB 
     292                self.Chivalue=chisqr 
     293                self.push_data(tempx,tempy,xminView,xmaxView,xmin,xmax,self._ongetValues()) 
    282294                 
    283295                # Display the fitting value on the Fit Dialog 
    284296                self._onsetValues(cstA, cstB, errA,errB,chisqr) 
     297                
     298                
    285299             
    286300    def _onsetValues(self,cstA,cstB,errA,errB,Chi): 
     
    293307         self.tcErrB.SetValue(str(errB)) 
    294308         self.tcChi.SetValue(str(Chi)) 
     309         
     310    def _ongetValues(self): 
     311         """ 
     312              Display  the value on fit Dialog  
     313         """ 
     314         return self.Avalue, self.Bvalue,self.ErrAvalue,self.ErrBvalue,self.Chivalue 
    295315          
    296316    def _returnPlottable(self): 
     
    322342             not in x 
    323343        """ 
    324         if ( self.xtrans=="x" ): 
     344        if ( self.xLabel=="x" ): 
    325345            return transform.toX(x) 
    326346         
    327         if ( self.xtrans=="x^(2)" ):  
     347        if ( self.xLabel=="x^(2)" ):  
    328348            return transform.toX2(x) 
    329349         
    330         if (self.xtrans=="log10(x)" ): 
     350        if (self.xLabel=="log10(x)" ): 
    331351            if x >0: 
    332352                return x 
     
    341361        value = item.GetValue() 
    342362        # Check for possible values entered 
    343         if (self.xtrans=="log10(x)"): 
     363        if (self.xLabel=="log10(x)"): 
    344364            if (float(value) > 0): 
    345365                item.SetBackgroundColour(wx.WHITE) 
     
    353373        
    354374    def setFitRange(self,xmin,xmax,Reelxmin,Reelxmax): 
    355         if (self.xtrans=="log10(x)"): 
     375        if (self.xLabel=="log10(x)"): 
    356376            self.FXmin.SetValue(str(math.log10(xmin))) 
    357377            self.FXmax.SetValue(str(math.log10(xmax))) 
Note: See TracChangeset for help on using the changeset viewer.