Changeset 1c94a9f1 in sasview for guitools/fitDialog.py


Ignore:
Timestamp:
Jul 8, 2008 11:40:33 AM (16 years ago)
Author:
Mathieu Doucet <doucetm@…>
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:
792db7d5
Parents:
9a3adab
Message:

Fixed all sorts of bugs: replotting problems, bad logic in rescaling function, removed buggy field in dialog box, improved usability for linear fit.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • guitools/fitDialog.py

    rad8bcd6 r1c94a9f1  
    2727class LinearFit(wx.Dialog): 
    2828    def __init__(self, parent, plottable, push_data,transform, id, title): 
    29         wx.Dialog.__init__(self, parent, id, title, size=(400, 380)) 
     29        wx.Dialog.__init__(self, parent, id, title, size=(400, 350)) 
    3030 
    3131        """ 
     
    3535        self.parent = parent 
    3636        self.transform = transform 
     37         
     38        # Registered owner for close event 
     39        self._registered_close = None 
    3740         
    3841        #dialog panel self call function to plot the fitting function 
     
    6568        self.xmaxFit  = wx.TextCtrl(self,-1,size=(_BOX_WIDTH,20)) 
    6669        self.xmaxFit.SetToolTipString("Enter the maximum value on the x-axis to be included in the fit.") 
    67         self.xminTransFit = wx.TextCtrl(self,-1,size=(_BOX_WIDTH,20)) 
    68         self.xminTransFit.SetToolTipString("Minimum value on the x-axis for the plotted data.") 
    69         self.xmaxTransFit = wx.TextCtrl(self,-1,size=(_BOX_WIDTH,20)) 
    70         self.xmaxTransFit.SetToolTipString("Maximum value on the x-axis for the plotted data.") 
    7170        self.initXmin = wx.TextCtrl(self,-1,size=(_BOX_WIDTH,20)) 
    72         self.initXmin.SetToolTipString("Minimum value available on the x-axis for the plotted data.") 
     71        self.initXmin.SetToolTipString("Minimum value on the x-axis for the plotted data.") 
    7372        self.initXmax = wx.TextCtrl(self,-1,size=(_BOX_WIDTH,20)) 
    74         self.initXmax.SetToolTipString("Maximum value available on the x-axis for the plotted data.") 
     73        self.initXmax.SetToolTipString("Maximum value on the x-axis for the plotted data.") 
    7574 
    7675        # Make the info box not editable 
    7776        #_BACKGROUND_COLOR = '#ffdf85' 
    7877        _BACKGROUND_COLOR = self.GetBackgroundColour() 
    79         self.xminTransFit.SetEditable(False) 
    80         self.xminTransFit.SetBackgroundColour(_BACKGROUND_COLOR) 
    81         self.xmaxTransFit.SetEditable(False) 
    82         self.xmaxTransFit.SetBackgroundColour(_BACKGROUND_COLOR) 
    8378        self.initXmin.SetEditable(False) 
    8479        self.initXmin.SetBackgroundColour(_BACKGROUND_COLOR) 
     
    9388        self.btFit.SetToolTipString("Perform fit.") 
    9489        self.btClose =wx.Button(self, wx.ID_CANCEL,'Close') 
     90        self.btClose.Bind(wx.EVT_BUTTON, self._on_close) 
    9591         
    9692        # Intro 
     
    136132        iy += 1 
    137133        ix = 0 
    138         sizer.Add(wx.StaticText(self, -1, 'Maximum range'),(iy, ix),(1,1),\ 
     134        sizer.Add(wx.StaticText(self, -1, 'Maximum range (linear scale)'),(iy, ix),(1,1),\ 
    139135                   wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15) 
    140136        ix +=1 
     
    147143        ix = 0 
    148144        sizer.Add(wx.StaticText(self, -1, 'Fit range of '+self.xLabel),(iy, ix),(1,1),\ 
    149                    wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15) 
    150         ix += 1 
    151         sizer.Add(self.xminTransFit, (iy, ix),(1,1),\ 
    152                    wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 0) 
    153         ix += 2 
    154         sizer.Add(self.xmaxTransFit, (iy, ix),(1,1), wx.EXPAND|wx.ADJUST_MINSIZE, 0) 
    155        
    156         iy += 1 
    157         ix = 0 
    158         sizer.Add(wx.StaticText(self, -1, 'Fit range of x'),(iy, ix),(1,1),\ 
    159145                   wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15) 
    160146        ix += 1 
     
    216202            self.tcChi.SetLabel(format_number(self.Chivalue)) 
    217203        if self.plottable.x !=[]: 
    218             self.mini =min(self.plottable.x) 
    219             self.maxi =max(self.plottable.x) 
    220204            #store the values of View in self.x,self.y,self.dx,self.dy 
    221205            self.x,self.y,self.dx,self.dy= self.plottable.returnValuesOfView() 
    222206             
    223              
    224             self.xminTransFit.SetLabel(format_number(min(self.x))) 
    225             self.xmaxTransFit.SetLabel(format_number(max(self.x))) 
    226              
    227             self.initXmin.SetValue(format_number(self.mini)) 
    228             self.initXmax.SetValue(format_number(self.maxi)) 
     207            self.mini =min(self.x) 
     208            self.maxi =max(self.x) 
     209             
     210             
     211            self.initXmin.SetValue(format_number(min(self.plottable.x))) 
     212            self.initXmax.SetValue(format_number(max(self.plottable.x))) 
    229213             
    230214            self.xminFit.SetLabel(format_number(self.mini)) 
     
    232216         
    233217       
     218    def register_close(self, owner): 
     219        """ 
     220            Method to register the close event to a parent 
     221            window that needs notification when the dialog 
     222            is closed 
     223            @param owner: parent window 
     224        """ 
     225        self._registered_close = owner 
     226         
     227    def _on_close(self, event): 
     228        """ 
     229            Close event.  
     230            Notify registered owner if available. 
     231        """ 
     232        event.Skip() 
     233        if self._registered_close is not None: 
     234            self._registered_close() 
     235         
    234236    def _onFit(self ,event): 
    235237        """ 
     
    252254            if(self.checkFitValues(self.xminFit) == True): 
    253255                #Check if the field of Fit Dialog contain values and use the x max and min of the user 
    254                 xmin,xmax = self._checkVal(self.xminFit.GetValue(),self.xmaxFit.GetValue()) 
    255                  
    256                 xminView=self.floatTransform(xmin) 
    257                 xmaxView=self.floatTransform(xmax) 
    258                 if (self.xLabel=="log10(x)"): 
    259                     self.xminTransFit.SetValue(format_number(math.log10(xminView))) 
    260                     self.xmaxTransFit.SetValue(format_number(math.log10(xmaxView))) 
    261                 else: 
    262                     self.xminTransFit.SetValue(format_number(xminView)) 
    263                     self.xmaxTransFit.SetValue(format_number(xmaxView)) 
     256                xminView,xmaxView = self._checkVal(self.xminFit.GetValue(),self.xmaxFit.GetValue()) 
     257                xmin = self.floatInvTransform(xminView) 
     258                xmax = self.floatInvTransform(xmaxView) 
     259                 
     260                 
    264261                # Store the transformed values of view x, y,dy in variables  before the fit 
    265262                if  self.yLabel.lower() == "log10(y)": 
     
    402399             not in x 
    403400        """ 
     401        #TODO: refactor this with proper object-oriented design 
     402        # This code stinks. 
     403         
    404404        if ( self.xLabel=="x" ): 
    405405            return transform.toX(x) 
     
    413413            else: 
    414414                raise ValueError,"cannot compute log of a negative number" 
     415             
     416    def floatInvTransform(self,x): 
     417        """ 
     418             transform a float.It is use to determine the x.View min and x.View max for values 
     419             not in x 
     420        """ 
     421        #TODO: refactor this. This is just a hack to make the 
     422        # functionality work without rewritting the whole code 
     423        # with good design (which really should be done...). 
     424         
     425        if ( self.xLabel=="x^(2)" ):  
     426            return math.sqrt(x) 
     427         
     428        elif (self.xLabel=="log10(x)" ): 
     429            return math.pow(10, x) 
     430         
     431        return x 
    415432             
    416433    def checkFitValues(self,item): 
     
    438455        self.xminFit.SetValue(format_number(xmin)) 
    439456        self.xmaxFit.SetValue(format_number(xmax)) 
    440         self.xminTransFit.SetValue(format_number(xminTrans)) 
    441         self.xmaxTransFit.SetValue(format_number(xmaxTrans)) 
    442          
     457         
     458    def set_fit_region(self, xmin, xmax): 
     459        """ 
     460            Set the fit region 
     461            @param xmin: minimum x-value to be included in fit 
     462            @param xmax: maximum x-value to be included in fit  
     463        """ 
     464        # Check values 
     465        try: 
     466            float(xmin) 
     467            float(xmax) 
     468        except: 
     469            raise ValueError, "LinearFit.set_fit_region: fit range must be floats" 
     470        self.xminFit.SetValue(format_number(xmin)) 
     471        self.xmaxFit.SetValue(format_number(xmax)) 
    443472   
    444473class MyApp(wx.App): 
Note: See TracChangeset for help on using the changeset viewer.