Changeset e40b651 in sasview for guitools


Ignore:
Timestamp:
Mar 31, 2008 3:51:17 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:
8e4516f
Parents:
6cfe703
Message:

fixing load file

File:
1 edited

Legend:

Unmodified
Added
Removed
  • guitools/fitDialog.py

    r6cfe703 re40b651  
    44 
    55import wx 
    6 from sans.guitools.PlotPanel import PlotPanel 
    7  
     6from PlotPanel import PlotPanel 
     7from plottables import Theory1D 
     8import math,pylab,fittings 
    89class LinearFit(wx.Dialog): 
    9     def __init__(self, parent, id, title): 
     10    #def __init__(self, parent, id, title): 
     11    def __init__(self, parent, plottable, push_data, id, title): 
    1012        wx.Dialog.__init__(self, parent, id, title, size=(500, 300)) 
    1113        """ 
     
    1315        """ 
    1416        self.parent = parent 
     17        #dialog panel self call function to plot the fitting function 
     18        self.push_data = push_data 
     19        #dialog self plottable 
     20        self.plottable = plottable 
     21         
     22        #Dialog interface 
    1523        panel = wx.Panel(self, -1, style=wx.SIMPLE_BORDER)    
    1624        vbox  = wx.BoxSizer(wx.VERTICAL) 
     
    4048        ix += 1 
    4149        sizer.Add(self.tcErrA, (iy, ix)) 
    42         #self.tcErrA.Bind(wx.EVT_KILL_FOCUS, self._onTextEnter) 
    4350        iy += 1 
    4451        ix = 1 
     
    4653        ix += 1 
    4754        sizer.Add(self.tcB, (iy, ix)) 
    48         #self.tcB.Bind(wx.EVT_KILL_FOCUS, self._onTextEnter) 
    4955        ix += 1 
    50         # sizer.Add(wx.StaticText(panel, -1, '+/-'),(iy, ix)) 
     56        sizer.Add(wx.StaticText(panel, -1, '+/-'),(iy, ix)) 
    5157        ix += 1 
    5258        sizer.Add(self.tcErrB, (iy, ix)) 
    53         self.tcErrB.Bind(wx.EVT_KILL_FOCUS, self._onTextEnter) 
    5459        iy += 1 
    5560        ix = 1 
     
    5762        ix += 1 
    5863        sizer.Add(self.tcChi, (iy, ix)) 
    59         #self.tcChi.Bind(wx.EVT_KILL_FOCUS, self._onTextEnter) 
    6064        iy += 1 
    6165        ix = 1 
     
    6670        ix = 1 
    6771        sizer.Add(self.tcXmin, (iy, ix)) 
    68         #self.tcXmin.Bind(wx.EVT_KILL_FOCUS, self._onTextEnter) 
    6972        ix += 2 
    7073        sizer.Add(self.tcXmax, (iy, ix)) 
    71         #self.tcXmax.Bind(wx.EVT_KILL_FOCUS, self._onTextEnter) 
    7274        iy += 1 
    7375        ix = 1 
    7476        sizer.Add(self.btFit, (iy, ix)) 
    75         self.tcXmax.Bind(wx.EVT_KILL_FOCUS, self._onFit) 
     77        self.btFit.Bind(wx.EVT_BUTTON, self._onFit) 
    7678        ix += 2 
    7779        sizer.Add(btClose, (iy, ix)) 
     
    8082        self.SetSizer(vbox) 
    8183        self.Centre() 
     84        # Receives the type of model for the fitting 
     85        from LineModel import LineModel 
     86        self.model  = LineModel() 
     87        # new data for the fit  
     88        self.file_data1 = Theory1D(x=[], y=[], dy=None) 
     89        self.file_data1.name = "y= exp(A + bx**2)" 
     90         
    8291    def _onFit(self ,event): 
    83          param_evt1 = PlotPanel.FunctionFitEvent(\ 
    84             Xmin=self._checkVal(self.tcXmin.GetValue()),\ 
    85             Xmax=self._checkVal(self.tcXmax.GetValue())                                     ) 
    86          wx.PostEvent(self, param_evt1) 
    87      
     92        
     93        print "we are on fit" 
     94        temp =[] 
     95        tempdx =[] 
     96        tempdy =[] 
     97        xmin = self._checkVal(self.tcXmin.GetValue()) 
     98        xmax = self._checkVal(self.tcXmax.GetValue()) 
     99        x= self.plottable.x 
     100        if x: 
     101            if xmin !=None  and xmax != None: 
     102                for j in range(len(x)): 
     103                    if x[j]>xmin and x[j]<xmax: 
     104                        temp.append(self.model.run(x[j])) 
     105                        tempdx.append(math.sqrt(x[j])) 
     106                        for y_i in temp: 
     107                            tempdy.append(math.sqrt(y_i))  
     108            else: 
     109                # x has a default value in case the user doesn't load data 
     110                for x_i in x: 
     111                    temp.append(self.model.run(x_i)) 
     112                    tempdx.append(math.sqrt(x_i)) 
     113                for y_i in temp: 
     114                    tempdy.append(math.sqrt(y_i)) 
     115                    self.tcXmin.SetValue(str(min(self.plottable.x))) 
     116                    self.tcXmax.SetValue(str(max(self.plottable.x))) 
     117                    xmin = self._checkVal(self.tcXmin.GetValue()) 
     118                    xmax = self._checkVal(self.tcXmax.GetValue()) 
     119                 
     120            self.file_data1.x =x 
     121            self.file_data1.y =temp 
     122            self.file_data1.dx=tempdx 
     123            self.file_data1.dy=tempdy 
     124             
     125         
     126            # Display the fittings values 
     127            default_A = self.model.getParam('A')  
     128            default_B = self.model.getParam('B')  
     129            cstA = fittings.Parameter(self.model, 'A', default_A) 
     130            cstB  = fittings.Parameter(self.model, 'B', default_B)         
     131            chisqr, out, cov = fittings.sansfit(self.model,  
     132                [cstA, cstB], self.plottable.x,  
     133                self.plottable.y, self.plottable.dy,xmin,xmax) 
     134            # Create new data plottable with result 
     135             
     136            self.file_data1.y = [] 
     137            for x_i in self.file_data1.x: 
     138                self.file_data1.y.append(self.model.run(x_i)) 
     139                 
     140            self.push_data(self.file_data1) 
     141             
     142            self._onsetValues(str(out[0]),str(out[1]),\ 
     143            str(math.sqrt(cov[0][0])),str(math.sqrt(cov[1][1])),str(chisqr)) 
     144        
    88145    def _onsetValues(self,cstA,cstB,errA,errB,Chi): 
    89146         
     
    93150         self.tcErrB.SetValue(cstA) 
    94151         self.tcChi.SetValue(Chi) 
    95     def _getXrange(self): 
    96         if self.tcXmin.GetValue() and self.tcXmax.GetValue(): 
    97             return float(),float(self.tcXmax.GetValue()) 
    98         else: 
    99             return None, None 
     152          
     153    def _returnPlottable(self): 
     154        return self.file_data1 
     155     
    100156    def _checkVal(self,value): 
    101157        """ 
Note: See TracChangeset for help on using the changeset viewer.