Index: Invariant/invariant.py
===================================================================
--- Invariant/invariant.py	(revision 59a4106656a4ebb744b9755380053717c4b6c5ac)
+++ Invariant/invariant.py	(revision 82703a1436245a2f89e02339a0e448970b4674c7)
@@ -9,5 +9,4 @@
 from DataLoader.data_info import Data1D as LoaderData1D
 from DataLoader.qsmearing import smear_selection
-
 
 # The minimum q-value to be used when extrapolating
@@ -25,24 +24,17 @@
         function given some x, y 
     """
-    def set_value(self, a, b):
+    def transform_values(self, a, b):
         """
             set private member
         """
+        return NotImplemented
+    
     def transform_value(self, value):
         """
-            Can use one of the function transform_x2 or transform_logx
-        """
-    def transform_x2(self, value):
-        """
             @param value: float
-        """
-        return value **2
-    
-    def transform_to_logx(self, value):
-        """
-            @param value: float
-        """
-        return math.log(value)
-        
+            return f(value)
+        """
+        return NotImplemented
+     
     def inverse_transform_value(self, value):
         """
@@ -51,8 +43,12 @@
             @param value : float
         """
+        return NotImplemented
+    
     def get_extrapolated_data(self, data, q_start=Q_MINIMUM, q_end=Q_MAXIMUM):
         """
             @return extrapolate data create from data
         """
+        return NotImplemented
+    
     def transform_data(self, x):
         """
@@ -61,8 +57,12 @@
             return x, y transform given a specific function
         """
+        return NotImplemented
+    
     def inverse_transform_data(self, x, y):
         """
             reverse transform x, y given a specific function
         """
+        return NotImplemented
+    
     def transform_error(self, y , dy=None):
         if dy is None:
@@ -96,6 +96,4 @@
         result_data.dxl = dxl
         result_data.dxw = dxw
-        
-       
         return result_data
   
@@ -111,21 +109,23 @@
     
     def transform_value(self, value):
-        return self.transform_x2(value)
-    
-    def set_value(self, a, b):
-    	# b is the radius value of the guinier function
-     	if b >=0 :
-     		raise ValueError("Guinier fit was not converged")
-        else:
-        	b = math.sqrt(-3 * b)
+        """
+            Square input value
+            @param value: of type float
+        """
+        return value * value
+    
+    def transform_values(self, a, b):
+    	"""
+    	   assign new value to the scale and the radius
+    	"""
+     	b = math.sqrt(-3 * b)
         a = math.exp(a)
-    
         self.scale = a
         self.radius = b
+        return a, b
         
     def transform_data(self, x):
         """
-            given a scale and a radius transform x, y using a guinier
-            function
+            return F(x)= scale* e-((radius*x)**2/3)
         """
         return self._guinier(x)
@@ -133,10 +133,15 @@
     def inverse_transform_data(self, x, y):
         """
-            given a scale and a radius transform x, y using a inverse guinier
-            function
+            this function finds x, y given equation1: y = ax + b
+            and equation2: y1 = scale* e-((radius*x1)**2/3).
+            where equation1, equation2 are equivalent
+            imply:  x = x1*x1
+                    y = ln(y1)
+                    b = math.exp(scale)
+                    a = -radius**2/3
+            @return  x, y
         """
         result_x = numpy.array([i * i for i in x])   
         result_y = numpy.array([math.log(j) for j in y])
-        
         return result_x, result_y 
         
@@ -155,7 +160,5 @@
         if self.radius <= 0:
             raise ValueError("Rg expected positive value, but got %s"%self.radius)  
-
         value = numpy.array([math.exp(-((self.radius * i)**2/3)) for i in x ]) 
-       
         return self.scale * value
 
@@ -170,22 +173,25 @@
         self.power = power
         
-    def set_value(self, a, b):
+    def transform_values(self, a, b):
+        """
+            Assign new value to the scale and the power 
+        """
         b = -1 * b
-        if b <= 0:
-        	raise ValueError("Power_law fit expected posive power, but got %s"%power)
         a = math.exp(a)
+        self.power = b
         self.scale = a
-        self.power = b
-        
-    def transform_data(self, x, a=None, b=None):
+        return a, b
+        
+    def transform_value(self, value):
+        """
+            compute log(value)
+        """
+        return math.log(value)
+        
+    def transform_data(self, x):
         """
             given a scale and a radius transform x, y using a power_law
             function
         """
-        if  a is not None:
-            self.scale = a
-        if  b is not None:
-            self.power = b
-            
         return self._power_law(x)
        
@@ -195,5 +201,5 @@
             function
         """
-        result_x = numpy.array([i * i for i in x])   
+        result_x = numpy.array([math.log(i) for i in x])   
         result_y = numpy.array([math.log(j) for j in y])
         
@@ -212,5 +218,5 @@
         """
         if self.power <= 0:
-            raise ValueError("Power_law function expected positive power, but got %s"%power)
+            raise ValueError("Power_law function expected positive power, but got %s"%self.power)
         if self.scale <= 0:
             raise ValueError("scale expected positive value, but got %s"%self.scale) 
@@ -297,4 +303,5 @@
            
             a, b = numpy.linalg.lstsq(A, fx[self.idx])[0]
+            
             return a, b
 
@@ -352,14 +359,9 @@
             #Process only data that inherited from DataLoader.Data_info.Data1D
             raise ValueError,"Data must be of type DataLoader.Data1D"
-            
-        new_data = (self._scale * data) - self._background
-        
-        # Copy data that is not copied by the operations
-        #TODO: fix this in DataLoader
-        #new_data.dxl = data.dxl
-        #new_data.dxw = data.dxw        
-
-        return new_data
-        
+        new_data = (self._scale * data) - self._background   
+        new_data.dxl = data.dxl
+        new_data.dxw = data.dxw 
+        return  new_data
+     
     def _fit(self, function, qmin=Q_MINIMUM, qmax=Q_MAXIMUM, power=None):
         """
@@ -386,8 +388,9 @@
         fit_data.dxl = self._data.dxl
         fit_data.dxw = self._data.dxw   
-        functor = Extrapolator(data=fit_data)
-        functor.set_fit_range(qmin=qmin, qmax=qmax)
-        b, a = functor.fit(power=power)         
-        return b, a
+        extrapolator = Extrapolator(data=fit_data)
+        extrapolator.set_fit_range(qmin=qmin, qmax=qmax)
+        b, a = extrapolator.fit(power=power) 
+        
+        return function.transform_values(a=a, b=b)
     
     def _get_qstar(self, data):
@@ -502,6 +505,5 @@
         """
         if data is None:
-            data = self.data
-    
+            data = self._data
         if data.is_slit_smeared():
             return self._get_qstar_smear_uncertainty(data)
@@ -509,5 +511,5 @@
             return self._get_qstar_unsmear_uncertainty(data)
         
-    def _get_qstar_unsmear_uncertainty(self, data=None):
+    def _get_qstar_unsmear_uncertainty(self, data):
         """
             Compute invariant uncertainty with with pinhole data.
@@ -554,5 +556,5 @@
                 return math.sqrt(sum)
         
-    def _get_qstar_smear_uncertainty(self):
+    def _get_qstar_smear_uncertainty(self, data):
         """
             Compute invariant uncertainty with slit smeared data.
@@ -571,7 +573,4 @@
             note: if data doesn't contain dy assume dy= math.sqrt(data.y)
         """
-        #if data is None:
-        #    data = self._data
-            
         if not data.is_slit_smeared():
             msg = "_get_qstar_smear_uncertainty need slit smear data "
@@ -659,22 +658,18 @@
         qmin = self._data.x[0]
         qmax = self._data.x[self._low_extrapolation_npts - 1]
-        
         # Extrapolate the low-Q data
         #TODO: this fit fails. Fix it.
-        b, a = self._fit(function=self._low_extrapolation_function,
+        a, b = self._fit(function=self._low_extrapolation_function,
                           qmin=qmin,
                           qmax=qmax,
                           power=self._low_extrapolation_power)
-        
         #q_start point
         q_start = Q_MINIMUM
         if Q_MINIMUM >= qmin:
             q_start = qmin/10
-            
-        self._low_extrapolation_function.set_value(a= a, b=b)
+        
         data_min = self._low_extrapolation_function.get_extrapolated_data(data=self._data, 
                                             npts=INTEGRATION_NSTEPS,
                               q_start=q_start, q_end=qmin, smear_indice=0)
-       
         return data_min
           
@@ -693,21 +688,22 @@
             @return: a new data of type Data1D
         """
-        # Data boundaries for fiiting
+        # Data boundaries for fitting
         x_len = len(self._data.x) - 1
-        q_start = self._data.x[x_len - (self._high_extrapolation_npts - 1)]
+        qmin = self._data.x[x_len - (self._high_extrapolation_npts - 1)]
         qmax = self._data.x[x_len]
-        smear_indice = x_len
+        q_end = Q_MAXIMUM
+        smear_indice = 0
+        if self._data.dxl is not None:
+            smear_indice = len(self._data.dxl) - 1
         
         # fit the data with a model to get the appropriate parameters
-        b, a = self._fit(function=self._high_extrapolation_function,
-                               qmin=q_start,
+        a, b = self._fit(function=self._high_extrapolation_function,
+                               qmin=qmin,
                                 qmax=qmax,
                                 power=self._high_extrapolation_power)
-  
         #create new Data1D to compute the invariant
-        self._high_extrapolation_function.set_value(a=a, b=b)
         data_max = self._high_extrapolation_function.get_extrapolated_data(data=self._data, 
                                             npts=INTEGRATION_NSTEPS,
-                                            q_start=q_start, q_end=qmax,
+                                            q_start=qmax, q_end=q_end,
                                             smear_indice=smear_indice)
         return data_max
