Index: fittingview/src/sans/perspectives/fitting/model_thread.py
===================================================================
--- fittingview/src/sans/perspectives/fitting/model_thread.py	(revision 49c69de79aac6bbde0711203fe50ff3af1f0bb81)
+++ fittingview/src/sans/perspectives/fitting/model_thread.py	(revision 7e7e806d47f3dbc7bcfbd81a9b77a10dcf58eccb)
@@ -2,8 +2,9 @@
 
 import time
+import sys
+import numpy
+import math
+from sans.models.smearing_2d import Smearer2D
 from data_util.calcthread import CalcThread
-import sys
-import numpy,math
-from sans.models.smearing_2d import Smearer2D
 
 class Calc2D(CalcThread):
@@ -14,13 +15,12 @@
     and I(qx, qy) = I(-qx, -qy) is assumed.
     """
-    def __init__(self, x, y, data,model,smearer,qmin, qmax,qstep,
-                 page_id ,
+    def __init__(self, data, model, smearer, qmin, qmax,  page_id,
                  state=None,
                  toggle_mode_on=False,
-                 completefn = None,
-                 updatefn   = None,
+                 completefn=None,
+                 updatefn=None,
                  update_chisqr=True,
-                 yieldtime  = 0.04,
-                 worktime   = 0.04
+                 yieldtime=0.04,
+                 worktime=0.04
                  ):
         CalcThread.__init__(self,completefn,
@@ -28,16 +28,14 @@
                  yieldtime,
                  worktime)
-        self.qmin= qmin
-        self.qmax= qmax
-        self.qstep= qstep
+        self.qmin = qmin
+        self.qmax = qmax
+        #self.qstep = qstep
         self.toggle_mode_on = toggle_mode_on
-        self.x = x
-        self.y = y
-        self.data= data
+        self.data = data
         self.page_id = page_id
         self.state = None
         # the model on to calculate
         self.model = model
-        self.smearer = smearer#(data=self.data,model=self.model)
+        self.smearer = smearer
         self.starttime = 0  
         self.update_chisqr = update_chisqr
@@ -49,55 +47,30 @@
         self.starttime = time.time()
         # Determine appropriate q range
-        if self.qmin==None:
+        if self.qmin == None:
             self.qmin = 0
-        if self.qmax== None:
-            if self.data !=None:
-                newx= math.pow(max(math.fabs(self.data.xmax),math.fabs(self.data.xmin)),2)
-                newy= math.pow(max(math.fabs(self.data.ymax),math.fabs(self.data.ymin)),2)
-                self.qmax=math.sqrt( newx + newy )
-        
-        if self.data != None:
-            self.I_data = self.data.data
-            self.qx_data = self.data.qx_data
-            self.qy_data = self.data.qy_data
-            self.dqx_data = self.data.dqx_data
-            self.dqy_data = self.data.dqy_data
-            self.mask    = self.data.mask
-        else:          
-            xbin =  numpy.linspace(start= -1*self.qmax,
-                                   stop= self.qmax,
-                                   num= self.qstep,
-                                   endpoint=True )  
-            ybin = numpy.linspace(start= -1*self.qmax,
-                                   stop= self.qmax,
-                                   num= self.qstep,
-                                   endpoint=True )            
-            
-            new_xbin = numpy.tile(xbin, (len(ybin),1))
-            new_ybin = numpy.tile(ybin, (len(xbin),1))
-            new_ybin = new_ybin.swapaxes(0,1)
-            new_xbin = new_xbin.flatten()
-            new_ybin = new_ybin.flatten()
-            self.qy_data = new_ybin
-            self.qx_data = new_xbin
-            # fake data
-            self.I_data = numpy.ones(len(self.qx_data))
-           
-            self.mask = numpy.ones(len(self.qx_data),dtype=bool)
-            
-        # Define matrix where data will be plotted    
-        radius= numpy.sqrt( self.qx_data*self.qx_data + self.qy_data*self.qy_data )
-        index_data= (self.qmin<= radius)&(self.mask)
+        if self.qmax == None:
+            if self.data != None:
+                newx = math.pow(max(math.fabs(self.data.xmax),
+                                   math.fabs(self.data.xmin)), 2)
+                newy = math.pow(max(math.fabs(self.data.ymax),
+                                   math.fabs(self.data.ymin)), 2)
+                self.qmax = math.sqrt(newx + newy)
+        
+        if self.data is None:
+            msg = "Compute Calc2D receive data = %s.\n" % str(self.data)    
+            raise ValueError, msg
+            
+        # Define matrix where data will be plotted 
+        radius= numpy.sqrt((self.data.qx_data * self.data.qx_data) + \
+                    (self.data.qy_data * self.data.qy_data))
+        index_data = (self.qmin <= radius) & self.data.mask
 
         # For theory, qmax is based on 1d qmax 
         # so that must be mulitified by sqrt(2) to get actual max for 2d
-        index_model = ((self.qmin <= radius)&(radius<= self.qmax))
-        index_model = (index_model)&(self.mask)
-        index_model = (index_model)&(numpy.isfinite(self.I_data))
-        if self.data ==None:
-            # Only qmin value will be consider for the detector
-            index_model = index_data  
-
-        if self.smearer != None:
+        index_model = (self.qmin <= radius) & (radius <= self.qmax)
+        index_model = index_model & self.data.mask
+        index_model = index_model & numpy.isfinite(self.data.data)
+      
+        if self.smearer is not None:
             # Set smearer w/ data, model and index.
             fn = self.smearer
@@ -106,19 +79,18 @@
             # Get necessary data from self.data and set the data for smearing
             fn.get_data()
-            # Calculate smeared Intensity (by Gaussian averaging): DataLoader/smearing2d/Smearer2D()
+            # Calculate smeared Intensity 
+            #(by Gaussian averaging): DataLoader/smearing2d/Smearer2D()
             value = fn.get_value()
-
         else:    
             # calculation w/o smearing
-            value =  self.model.evalDistribution([self.qx_data[index_model],self.qy_data[index_model]])
-
-        output = numpy.zeros(len(self.qx_data))
-        
+            value =  self.model.evalDistribution([self.data.qx_data[index_model],
+                                                self.data.qy_data[index_model]])
+        output = numpy.zeros(len(self.data.qx_data))
         # output default is None
-        # This method is to distinguish between masked point(nan) and data point = 0.
+        # This method is to distinguish between masked 
+        #point(nan) and data point = 0.
         output = output/output
         # set value for self.mask==True, else still None to Plottools
         output[index_model] = value 
-
         elapsed = time.time()-self.starttime
         self.complete(image=output,
@@ -132,6 +104,6 @@
                        qmin=self.qmin,
                        qmax=self.qmax,
-                       qstep=self.qstep,
-                       update_chisqr = self.update_chisqr )
+                       #qstep=self.qstep,
+                       update_chisqr = self.update_chisqr)
         
 
@@ -140,7 +112,7 @@
     Compute 1D data
     """
-    def __init__(self, x, model,
+    def __init__(self, model,
                  page_id,
-                 data=None,
+                 data,
                  qmin=None,
                  qmax=None,
@@ -150,7 +122,7 @@
                  completefn = None,
                  update_chisqr=True,
-                 updatefn   = None,
-                 yieldtime  = 0.01,
-                 worktime   = 0.01
+                 updatefn=None,
+                 yieldtime=0.01,
+                 worktime=0.01
                  ):
         """
@@ -160,5 +132,4 @@
                  yieldtime,
                  worktime)
-        self.x = numpy.array(x)
         self.data = data
         self.qmin = qmin
@@ -177,18 +148,20 @@
         """
         self.starttime = time.time()
-        output = numpy.zeros((len(self.x)))
-        index= (self.qmin <= self.x)& (self.x <= self.qmax)
+        output = numpy.zeros((len(self.data.x)))
+        index= (self.qmin <= self.data.x)& (self.data.x <= self.qmax)
      
         ##smearer the ouput of the plot    
-        if self.smearer!=None:
-            first_bin, last_bin = self.smearer.get_bin_range(self.qmin, self.qmax)
-            output[first_bin:last_bin] = self.model.evalDistribution(self.x[first_bin:last_bin])
+        if self.smearer is not None:
+            first_bin, last_bin = self.smearer.get_bin_range(self.qmin, 
+                                                             self.qmax)
+            mask = self.data.x[first_bin:last_bin]
+            output[first_bin:last_bin] = self.model.evalDistribution(mask)
             output = self.smearer(output, first_bin, last_bin) 
         else:
-            output[index] = self.model.evalDistribution(self.x[index])
+            output[index] = self.model.evalDistribution(self.data.x[index])
          
         elapsed = time.time() - self.starttime
        
-        self.complete(x=self.x[index], y=output[index], 
+        self.complete(x=self.data.x[index], y=output[index], 
                       page_id=self.page_id,
                       state=self.state,
@@ -196,5 +169,5 @@
                       elapsed=elapsed,index=index, model=self.model,
                       data=self.data, 
-                      update_chisqr = self.update_chisqr )
+                      update_chisqr = self.update_chisqr)
         
     def results(self):
