Index: sansview/perspectives/fitting/fitpage1D.py
===================================================================
--- sansview/perspectives/fitting/fitpage1D.py	(revision b491d6eaf39336ad983e4d15887bfc94c47da57b)
+++ sansview/perspectives/fitting/fitpage1D.py	(revision 22e8d498e1a0f94d414db18741b55f74da1511b3)
@@ -20,5 +20,4 @@
         @note: For Fit to be performed the user should check at least one parameter
         on fit Panel window.
-  
     """
     ## Internal name for the AUI manager
@@ -26,4 +25,5 @@
     ## Title to appear on top of the window
     window_caption = "Fit Page"
+    
     name=None
     
@@ -34,8 +34,14 @@
             Initialization of the Panel
         """
+        #Data used for fitting 
         self.data = data
+        # flag to allow data2D plot
         self.enable2D=False
+        #fit page manager 
         self.manager = None
+        #Store the parent of this panel parent
+        # For this application fitpanel is the parent
         self.parent  = parent
+        # Event_owner is the owner of model event
         self.event_owner = None
         #panel interface
@@ -73,14 +79,11 @@
         self.vbox.Add(wx.StaticLine(self, -1), 0, wx.EXPAND, 0)
         self.vbox.Add(self.sizer9)
-       
-        
         #---------sizer 1 draw--------------------------------
+        #Filling the sizer containing data related fields
         self.DataSource  =wx.StaticText(self, -1,str(data.name))
-        #Filing the sizer containing data related fields
         ix = 0
         iy = 1
         self.sizer1.Add(wx.StaticText(self, -1, 'Data Source Name : '),(iy,ix),\
                  (1,1), wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15)
-       
         ix += 1
         self.sizer1.Add(self.DataSource,(iy,ix),(1,1), wx.EXPAND|wx.ADJUST_MINSIZE, 0)
@@ -111,4 +114,5 @@
         
         #----sizer 3 draw--------------------------------
+        #Filling the sizer containing instruments smearing info.
         self.disable_smearer = wx.RadioButton(self, -1, 'No', (10, 10), style=wx.RB_GROUP)
         self.enable_smearer = wx.RadioButton(self, -1, 'Yes', (10, 30))
@@ -128,4 +132,6 @@
             
         #------------------ sizer 4  draw------------------------   
+        # This sizer contains model list and chisqr value 
+        #filling sizer4
         self.modelbox = wx.ComboBox(self, -1)
         self.tcChi    =  wx.StaticText(self, -1, str(0), style=wx.ALIGN_LEFT)
@@ -133,5 +139,4 @@
         self.text1_1 = wx.StaticText(self, -1, 'Chi2/dof', style=wx.ALIGN_LEFT)
         self.text1_1.Hide()
-        #filling sizer2
         ix = 0
         iy = 1
@@ -146,4 +151,5 @@
         self.sizer4.Add(self.tcChi,(iy,ix),(1,1), wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 0)
         #----------sizer6-------------------------------------------------
+        #Sizer containing info on polydispersity
         self.disable_disp = wx.RadioButton(self, -1, 'No', (10, 10), style=wx.RB_GROUP)
         self.enable_disp = wx.RadioButton(self, -1, 'Yes', (10, 30))
@@ -161,6 +167,4 @@
         iy+=1
         self.sizer6.Add((20,20),(iy,ix),(1,1),wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15)  
-
-        
         #---------sizer 9 draw----------------------------------------
         
@@ -170,6 +174,5 @@
         self.btFit.Bind(wx.EVT_BUTTON, self.onFit,id=id)
         self.btFit.SetToolTipString("Perform fit.")
-         ## Q range
-        #print "self.data fitpage1D" , self.data,hasattr(self.data,"data")
+        ## Q range
         # Reversed to the codes; Need to think  carefully about consistency in q between 2D plot and fitting
         if not hasattr(self.data,"data"):
@@ -183,15 +186,11 @@
             radius3= math.sqrt(math.pow(self.data.xmin, 2)+ math.pow(self.data.ymax, 2))
             radius4= math.sqrt(math.pow(self.data.xmax, 2)+ math.pow(self.data.ymax, 2))
-            #self.qmin_x = 0
-            #self.qmax_x = max(radius1, radius2, radius3, radius4)
-            self.qmin_x= 0#self.data.xmin
+            
+            self.qmin_x= 0
             self.qmax_x= math.sqrt(math.pow(max(math.fabs(self.data.xmax),math.fabs(self.data.xmin)),2)
                             +math.pow(max(math.fabs(self.data.ymax),math.fabs(self.data.ymin)),2))#self.data.xmax           
-            #print "data2D range",self.qmax_x
         
         self.num_points= 100
-         
-        
-        
+        # The minimum fitting range
         self.qmin    = wx.TextCtrl(self, -1,size=(_BOX_WIDTH,20))
         self.qmin.SetValue(str(format_number(self.qmin_x)))
@@ -200,5 +199,5 @@
         self.qmin.Bind(wx.EVT_TEXT_ENTER, self._onparamEnter)
         self.qmin.Enable()
-        
+        #The maximum fitting range
         self.qmax    = wx.TextCtrl(self, -1,size=(_BOX_WIDTH,20))
         self.qmax.SetValue(str(format_number(self.qmax_x)))
@@ -207,5 +206,5 @@
         self.qmax.Bind(wx.EVT_TEXT_ENTER, self._onparamEnter)
         self.qmax.Enable()
-
+        #The number of points to plots
         self.npts    = wx.TextCtrl(self, -1,size=(_BOX_WIDTH,20))
         self.npts.SetValue(format_number(self.num_points))
@@ -225,7 +224,4 @@
         self.sizer9.Add(wx.StaticText(self, -1, 'Max'),(iy, ix),(1,1),\
                             wx.EXPAND|wx.ADJUST_MINSIZE, 0)
-        #ix += 1
-        #self.sizer9.Add(wx.StaticText(self, -1, 'Npts'),(iy, ix),(1,1),\
-        #                    wx.EXPAND|wx.ADJUST_MINSIZE, 0)
         ix = 0
         iy += 1
@@ -241,20 +237,16 @@
         ix += 1
         self.sizer9.Add(self.btFit,(iy,ix),(1,1), wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 0)
-        """
-        id = wx.NewId()
-        self.btStopFit =wx.Button(self,id,'Stop')
-        self.btStopFit.Bind(wx.EVT_BUTTON, self.onStopFit,id=id)
-        self.btStopFit.SetToolTipString("Stop the current fitting job.")
-        self.btStopFit.Hide()
-        ix += 1
-        self.sizer9.Add(self.btStopFit,(iy,ix),(1,1), wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 0)
-        """
+       
         ix =0
         iy+=1 
         self.sizer9.Add((20,20),(iy,ix),(1,1), wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 0)
         
-        # contains link between  model ,all its parameters, and panel organization
+        # Contains link between  model ,all its parameters, and panel organization
         self.parameters=[]
+        # Contains list of parameters that cannot be fitted and reference to 
+        #panel objects 
         self.fixed_param=[]
+        # Contains list of parameters with dispersity and reference to 
+        #panel objects 
         self.fittable_param=[]
         #list of dispersion paramaters
@@ -264,4 +256,5 @@
         # model on which the fit would be performed
         self.model=None
+        
         self.back_up_model= None
         #dictionary of model name and model class
@@ -275,5 +268,5 @@
             self.qmax.Enable() 
 
-       
+    
         self.vbox.Layout()
         self.vbox.Fit(self) 
@@ -286,6 +279,7 @@
    
     def compute_chisqr2D(self):
-        """ @param fn: function that return model value
-            @return residuals
+        """ 
+            compute chi square given a model and data 2D and set the value
+            to the tcChi txtcrl
         """
         flag=self.checkFitRange()
@@ -293,46 +287,34 @@
         if flag== True:
             try:
-                #print "compute",self.data.err_data
                 self.qmin_x = float(self.qmin.GetValue())
                 self.qmax_x = float(self.qmax.GetValue())
                 for i in range(len(self.data.x_bins)):
-                    #if self.data.x_bins[i]>= self.qmin_x and self.data.x_bins[i]<= self.qmax_x:
-                        for j in range(len(self.data.y_bins)):
-                            if math.pow(self.data.x_bins[i],2)+math.pow(self.data.y_bins[j],2)>=math.pow(self.qmin_x,2):
-                                if math.pow(self.data.x_bins[i],2)+math.pow(self.data.y_bins[j],2)<=math.pow(self.qmax_x,2):
-                            #if self.data.y_bins[j]>= self.qmin_x and self.data.y_bins[j]<= self.qmax_x:
-                                    chisqrji=(self.data.data[j][i]- self.model.runXY(\
-                                                                                        [self.data.y_bins[j],self.data.x_bins[i]]))\
-                                                                                        /self.data.err_data[j][i]
-                                    res.append( math.pow(chisqrji,2) )
+                    for j in range(len(self.data.y_bins)):
+                        #Check the range containing data between self.qmin_x and self.qmax_x
+                        if math.pow(self.data.x_bins[i],2)+math.pow(self.data.y_bins[j],2)>=math.pow(self.qmin_x,2):
+                            if math.pow(self.data.x_bins[i],2)+math.pow(self.data.y_bins[j],2)<=math.pow(self.qmax_x,2):
+                                chisqrji=(self.data.data[j][i]- self.model.runXY(\
+                                                                                    [self.data.y_bins[j],self.data.x_bins[i]]))\
+                                                                                    /self.data.err_data[j][i]
+                                #Vector containing residuals
+                                res.append( math.pow(chisqrji,2) )
+                # compute sum of residual
                 sum=0
-               
                 for item in res:
                     if numpy.isfinite(item):
                         sum +=item
-                #print "chisqr : sum 2D", xmin, xmax, ymin, ymax,sum
-                #print len(res)
                 self.tcChi.SetLabel(format_number(math.fabs(sum/ len(res))))
             except:
-                raise
                 wx.PostEvent(self.parent.GrandParent, StatusEvent(status=\
                             "Chisqr cannot be compute: %s"% sys.exc_value))
-        
-    def onStopFit(self, event):
-        self.manager.stop_fit()
-        self.btStopFit.Hide()
-        self.btFit.Show(True)
-        self.vbox.Layout()
-        self.SetScrollbars(20,20,55,40)
-        self.Layout()
-        self.parent.GetSizer().Layout()
+                return
+    
         
     def compute_chisqr(self):
-        """ @param fn: function that return model value
-            @return residuals
-        """
-        
+        """ 
+            compute chi square given a model and data 1D and set the value
+            to the tcChi txtcrl
+        """
         flag=self.checkFitRange()
-        #print "flag", flag
         if flag== True:
             try:
@@ -343,5 +325,5 @@
                     self.qmin_x = float(self.qmin.GetValue())
                     self.qmax_x = float(self.qmax.GetValue())
-                    #print "self.qmin_x, self.qmax_x",self.qmin_x,self.qmax_x
+                    # return residuals within self.qmin_x and self.qmax_x
                     x,y,dy = [numpy.asarray(v) for v in (self.data.x,self.data.y,self.data.dy)]
                     if self.qmin_x==None and self.qmax_x==None: 
@@ -354,5 +336,5 @@
                         temp=(y[idx] - fx)/dy[idx]
                         res= temp*temp
-                   
+                    #sum of residuals
                     sum=0
                     for item in res:
@@ -363,4 +345,5 @@
                 wx.PostEvent(self.parent.GrandParent, StatusEvent(status=\
                             "Chisqr cannot be compute: %s"% sys.exc_value))
+                return 
             
     def _on_select_model(self,event):
@@ -382,5 +365,5 @@
             if hasattr(item, "name"):
                 name = item.name
-            #print "fitpage: _on_select_model model name",name ,event.GetString()
+            
             if name == None:
                 self.qmin.Disable()
@@ -401,5 +384,7 @@
                 except:
                     raise #ValueError,"model.name is not equal to model class name"
-                break       
+                break  
+            
+                 
     def onFit(self,event):
         """ signal for fitting"""
@@ -411,21 +396,14 @@
         self.qmax_x =float( self.qmax.GetValue())
         if len(self.param_toFit) >0 and flag==True:
-            #if self.data.name == self.model.__class__.__name__:
-                #print "when here have the same name "
-                #wx.PostEvent(self.parent.parent, StatusEvent(status=\
-                            #"Attempt to fit model %s with itself. fit will\
-                            #not be performed"%self.data.name))
-                #return 
             self.manager.schedule_for_fit( value=1,fitproblem =None) 
             if hasattr(self.data, "data"):
+                #single fit for Data2D
                 self.manager._on_single_fit(qmin=self.qmin_x,qmax=self.qmax_x,
                                             ymin=self.data.ymin, ymax=self.data.ymax,
                                             xmin=self.data.xmin,xmax=self.data.xmax)
-                #self.btStopFit.Show()
-                #self.btFit.Hide()
             else:
-                 self.manager._on_single_fit(qmin=self.qmin_x,qmax=self.qmax_x)
-                 #self.btStopFit.Show()
-                 #self.btFit.Hide()
+                #single fit for Data1D
+                self.manager._on_single_fit(qmin=self.qmin_x,qmax=self.qmax_x)
+                
             self.vbox.Layout()
             self.SetScrollbars(20,20,55,40)
@@ -433,5 +411,5 @@
             self.parent.GetSizer().Layout()
         else:
-              wx.PostEvent(self.parent.parent, StatusEvent(status=\
+            wx.PostEvent(self.parent.parent, StatusEvent(status=\
                             "Select at least one parameter to fit "))
   
@@ -445,5 +423,4 @@
             flag=self.checkFitRange()
             if flag==True and self.model!=None:
-                #print"fit page",self.xmin.GetValue(),self.xmax.GetValue()
                 self.manager.redraw_model(float(self.xmin.GetValue())\
                                                ,float(self.xmax.GetValue()))
@@ -473,5 +450,8 @@
         """
         self.set_model()
-        self.compute_chisqr()
+        try:
+            self.compute_chisqr()
+        except:
+            pass
         
     def set_model(self): 
@@ -526,10 +506,6 @@
         else:
             self.cb1.SetValue(False)
-        """    
-        #qmax, qmin Input enabled all the time   
-        self.qmin.Enable()
-        self.qmax.Enable()      
-        """
-  
+       
+       
     def onsetValues(self,chisqr, out,cov):
         """
@@ -540,5 +516,4 @@
        
         """
-        #print "fitting : onsetvalues out",out
         self.tcChi.SetLabel(format_number(chisqr))
         params = {}
