Index: Invariant/invariant.py
===================================================================
--- Invariant/invariant.py	(revision 9b6497bb77e9fe4f94a1caa9f3b72552d19deb2a)
+++ Invariant/invariant.py	(revision 472b11ca26c3e9b7856f844f6f60ab877c6da388)
@@ -115,10 +115,10 @@
                                 & (self.data.x <= self._qmax_unsmeared)
   
-    def fit(self):
+    def fit(self, power =None):
         """
            Fit data for y = ax + b  return a and b
-           
-        """
-        
+           @param power = a fixed, otherwise None
+        """
+        power = power
         fx = numpy.zeros(len(self.data.x))
         sigma = numpy.zeros(len(self.data.x))
@@ -133,10 +133,16 @@
         if self.smearer is not None:
             fx = self.smearer(fx, self._first_unsmeared_bin,self._last_unsmeared_bin)
-    
-        A = numpy.vstack([ self.data.x[self.idx]/sigma2,
-                           numpy.ones(len(self.data.x[self.idx]))/sigma2]).T
-
-        a, b = numpy.linalg.lstsq(A, fx)[0]
-        return a, b
+        
+        ##power is given only for function = power_law    
+        if power != None:
+            a = -math.fabs(power)
+            b = (scipy.sum(fx) - a*scipy.sum(self.data.x[self.idx]/sigma2))/scipy.sum(numpy.ones(len(sigma2))/sigma2)
+            return a, b
+        else:
+            A = numpy.vstack([ self.data.x[self.idx]/sigma2,
+                               numpy.ones(len(self.data.x[self.idx]))/sigma2]).T
+    
+            a, b = numpy.linalg.lstsq(A, fx)[0]
+            return a, b
 
 class InvariantCalculator(object):
@@ -214,7 +220,6 @@
                     for power_law will be the power value
         """
-        if function.__name__ == "guinier":
-            fit_x = numpy.array([x * x for x in self._data.x])
-            
+        fit_x = numpy.array([math.log(x) for x in self._data.x])
+        if function.__name__ == "guinier":        
             qmin = qmin**2
             qmax = qmax**2
@@ -224,9 +229,6 @@
 
         elif function.__name__ == "power_law":
-            if power is None:
-                fit_x = numpy.array([math.log(x) for x in self._data.x])
-
-                qmin = math.log(qmin)
-                qmax = math.log(qmax)
+            qmin = math.log(qmin)
+            qmax = math.log(qmax)
             fit_y = numpy.array([math.log(y) for y in self._data.y])
             fit_dy = numpy.array([y for y in self._data.y])
@@ -235,20 +237,14 @@
         else:
             raise ValueError("Unknown function used to fit %s"%function.__name__)
-        
-        if function.__name__ == "power_law" and  power != None:
-            b = math.fabs(power)
-            fit_y = numpy.array([math.log(y) for y in self._data.y])
-            fit_dy = numpy.array([y for y in self._data.y])
-            fit_dy = numpy.array([dy for dy in self._data.dy])/fit_dy
-            sigma2 = fit_dy*fit_dy
-            a = scipy.sum(fit_y/sigma2) - scipy.sum(fit_x/sigma2*b)/scipy.sum(sigma2)
-        else:
-            fit_data = LoaderData1D(x=fit_x, y=fit_y, dy=fit_dy)
-            fit_data.dxl = self._data.dxl
-            fit_data.dxw = self._data.dxw   
-            functor = FitFunctor(data=fit_data)
-            functor.set_fit_range(qmin=qmin, qmax=qmax)
-            b, a = functor.fit()
-        
+       
+        
+        #else:
+        fit_data = LoaderData1D(x=fit_x, y=fit_y, dy=fit_dy)
+        fit_data.dxl = self._data.dxl
+        fit_data.dxw = self._data.dxw   
+        functor = FitFunctor(data=fit_data)
+        functor.set_fit_range(qmin=qmin, qmax=qmax)
+        b, a = functor.fit(power=power)         
+      
                   
         if function.__name__ == "guinier":
@@ -261,11 +257,10 @@
 
         if function.__name__ == "power_law":
-            if power == None:
-                b = -1 * b
+            b = -1 * b
             if b <= 0:
                 raise ValueError("Power_law fit expected posive power, but got %s"%power)
         # a is the scale of the guinier function
         a = math.exp(a)
-        
+
         return a, b
     
