Index: sansmodels/src/sans/models/smearing_2d.py
===================================================================
--- sansmodels/src/sans/models/smearing_2d.py	(revision 1aa80846b19de1e0a3b2005071561a93a2b5ba17)
+++ sansmodels/src/sans/models/smearing_2d.py	(revision fd1aec6f324f91dc2e97d5cad4f69b180d3b77f5)
@@ -1,11 +1,8 @@
-#####################################################################
+"""
 #This software was developed by the University of Tennessee as part of the
 #Distributed Data Analysis of Neutron Scattering Experiments (DANSE)
 #project funded by the US National Science Foundation. 
 #See the license text in license.txt
-#copyright 2008, University of Tennessee
-######################################################################
-
-## TODO: Need test,and check Gaussian averaging
+"""
 import numpy
 import math
@@ -17,6 +14,6 @@
 LIMIT = 3.0
 ## Defaults
-R_BIN = {'Xhigh':10, 'High':5,'Med':5,'Low':3}
-PHI_BIN ={'Xhigh':20,'High':12,'Med':6,'Low':4}   
+R_BIN = {'Xhigh':10, 'High':5, 'Med':5, 'Low':3}
+PHI_BIN ={'Xhigh':20, 'High':12, 'Med':6, 'Low':4}   
 
 class Smearer2D:
@@ -32,5 +29,6 @@
         :param data: 2d data used to set the smearing parameters
         :param model: model function
-        :param index: 1d array with len(data) to define the range of the calculation: elements are given as True or False
+        :param index: 1d array with len(data) to define the range 
+         of the calculation: elements are given as True or False
         :param nr: number of bins in dq_r-axis
         :param nphi: number of bins in dq_phi-axis
@@ -42,5 +40,6 @@
         ## model
         self.model = model
-        ## Accuracy: Higher stands for more sampling points in both directions of r and phi.
+        ## Accuracy: Higher stands for more sampling points in both directions 
+        ## of r and phi.
         self.accuracy = accuracy
         ## number of bins in r axis for over-sampling 
@@ -54,9 +53,16 @@
         self.smearer = True
         self._engine = engine
-        
+        self.qx_data = None
+        self.qy_data = None
+        self.q_data = None
+        # dqx and dqy mean dq_parr and dq_perp
+        self.dqx_data = None
+        self.dqy_data = None
+        self.phi_data = None
         
     def get_data(self):   
         """
-        get qx_data, qy_data, dqx_data,dqy_data,and calculate phi_data=arctan(qx_data/qy_data)
+        Get qx_data, qy_data, dqx_data,dqy_data,
+        and calculate phi_data=arctan(qx_data/qy_data)
         """
         if self.data == None or self.data.__class__.__name__ == 'Data1D':
@@ -70,8 +76,8 @@
         self.dqx_data = self.data.dqx_data[self.index]
         self.dqy_data = self.data.dqy_data[self.index]
-        self.phi_data = numpy.arctan(self.qx_data/self.qy_data)
+        self.phi_data = numpy.arctan(self.qx_data / self.qy_data)
         ## Remove singular points if exists
-        self.dqx_data[self.dqx_data<SIGMA_ZERO]=SIGMA_ZERO
-        self.dqy_data[self.dqy_data<SIGMA_ZERO]=SIGMA_ZERO
+        self.dqx_data[self.dqx_data < SIGMA_ZERO] = SIGMA_ZERO
+        self.dqy_data[self.dqy_data < SIGMA_ZERO] = SIGMA_ZERO
         return True
     
@@ -143,12 +149,13 @@
         # data length in the range of self.index
         len_data = len(self.qx_data)
-        len_datay = len(self.qy_data)
-
+        #len_datay = len(self.qy_data)
         if self._engine == 'c' and self.coords == 'polar':
             try:
                 import sans.models.sans_extension.smearer2d_helper as smearer2dc
-                smearc = smearer2dc.new_Smearer_helper(self.qx_data, self.qy_data,
+                smearc = smearer2dc.new_Smearer_helper(self.qx_data, 
+                                              self.qy_data,
                                               self.dqx_data, self.dqy_data,
-                                              self.limit, nr, nphi, int(len_data))
+                                              self.limit, nr, nphi, 
+                                              int(len_data))
                 weight_res = numpy.zeros(nr * nphi )
                 qx_res = numpy.zeros(nr * nphi * int(len_data))
@@ -158,5 +165,6 @@
                 raise 
         else:
-            # Mean values of dqr at each bins ,starting from the half of bin size
+            # Mean values of dqr at each bins 
+            # starting from the half of bin size
             r = bin_size / 2.0 + numpy.arange(nr) * bin_size
             # mean values of qphi at each bines
@@ -170,19 +178,20 @@
             q_phi = self.qy_data / self.qx_data
             
-            # Starting angle is different between polar and cartesian coordinates.
+            # Starting angle is different between polar 
+            #  and cartesian coordinates.
             #if self.coords != 'polar':
             #    dphi += numpy.arctan( q_phi * self.dqx_data/ \
-            #                     self.dqy_data).repeat(n_bins).reshape(len_data,\
-            #                                        n_bins).transpose().flatten()
+            #                  self.dqy_data).repeat(n_bins).reshape(len_data,\
+            #                                n_bins).transpose().flatten()
     
             # The angle (phi) of the original q point
             q_phi = numpy.arctan(q_phi).repeat(n_bins).reshape(len_data,\
-                                                    n_bins).transpose().flatten()
+                                                n_bins).transpose().flatten()
             ## Find Gaussian weight for each dq bins: The weight depends only 
             #  on r-direction (The integration may not need)
             weight_res = numpy.exp(-0.5 * ((r - bin_size / 2.0) * \
-                                        (r - bin_size / 2.0)))- \
-                                        numpy.exp(-0.5 * ((r + bin_size / 2.0 ) *\
-                                        (r + bin_size / 2.0)))
+                                    (r - bin_size / 2.0)))- \
+                                    numpy.exp(-0.5 * ((r + bin_size / 2.0 ) *\
+                                    (r + bin_size / 2.0)))
             # No needs of normalization here.
             #weight_res /= numpy.sum(weight_res)
@@ -192,12 +201,12 @@
             
             ## Set dr for all dq bins for averaging
-            dr = r.repeat(nphi).reshape(nr,nphi).transpose().flatten()
+            dr = r.repeat(nphi).reshape(nr, nphi).transpose().flatten()
             ## Set dqr for all data points
-            dqx = numpy.outer(dr,self.dqx_data).flatten()
-            dqy = numpy.outer(dr,self.dqy_data).flatten()
-    
-            qx = self.qx_data.repeat(n_bins).reshape(len_data,\
+            dqx = numpy.outer(dr, self.dqx_data).flatten()
+            dqy = numpy.outer(dr, self.dqy_data).flatten()
+    
+            qx = self.qx_data.repeat(n_bins).reshape(len_data, \
                                                  n_bins).transpose().flatten()
-            qy = self.qy_data.repeat(n_bins).reshape(len_data,\
+            qy = self.qy_data.repeat(n_bins).reshape(len_data, \
                                                  n_bins).transpose().flatten()
     
@@ -216,15 +225,15 @@
         val = self.model.evalDistribution([qx_res, qy_res]) 
         ## Reshape into 2d array to use numpy weighted averaging
-        value_res= val.reshape(n_bins,len(self.qx_data))
+        value_res= val.reshape(n_bins, len(self.qx_data))
         ## Averaging with Gaussian weighting: normalization included.
         value =numpy.average(value_res,axis=0, weights=weight_res)
         ## Return the smeared values in the range of self.index
         return value
-    
+"""    
 if __name__ == '__main__':
     ## Test w/ 2D linear function
-    x = 0.001*numpy.arange(1,11)
+    x = 0.001*numpy.arange(1, 11)
     dx = numpy.ones(len(x))*0.0003
-    y = 0.001*numpy.arange(1,11)
+    y = 0.001*numpy.arange(1, 11)
     dy = numpy.ones(len(x))*0.001
     z = numpy.ones(10)
@@ -247,9 +256,9 @@
     model.setParam("A", 0)
 
-    smear = Smearer2D(out,model,index)
+    smear = Smearer2D(out, model, index)
     #smear.set_accuracy('Xhigh')
     value = smear.get_value()
     ## All data are ones, so the smeared should also be ones.
-    print "Data length =",len(value)
+    print "Data length =", len(value)
     print " 2D linear function, I = 0 + 1*qy"
     text = " Gaussian weighted averaging on a 2D linear function will "
@@ -258,14 +267,7 @@
     print "qx_data", "qy_data", "I_nonsmear", "I_smeared"
     for ind in range(len(value)):
-        print x[ind],y[ind],model.evalDistribution([x,y])[ind], value[ind]
-        
-"""
-for i in range(len(qx_res)/(128*128)):
-    k = i * 128*128 +64
-
-    print qx_res[k]-qqx[k], qy_res[k]-qqy[k]
-print qqx[64],qqy[64]
-""" 
-"""    
+        print x[ind], y[ind], model.evalDistribution([x, y])[ind], value[ind]
+        
+  
 if __name__ == '__main__':
     ## Another Test w/ constant function
