Index: park_integration/AbstractFitEngine.py
===================================================================
--- park_integration/AbstractFitEngine.py	(revision b2f25dc5befcce6b90b54eb667869a52222abf16)
+++ park_integration/AbstractFitEngine.py	(revision c4d6900c7e4f190062574bc6b0b22a247c5224b0)
@@ -1,6 +1,6 @@
 
 import  copy
-import logging
-import sys
+#import logging
+#import sys
 import numpy
 import math
@@ -23,4 +23,5 @@
         
         """
+        park.Parameter.__init__(self, name)
         self._model, self._name = model, name
         #set the value for the parameter of the given name
@@ -45,5 +46,5 @@
         self._model.setParam(self.name, value)
         
-    value = property(_getvalue,_setvalue)
+    value = property(_getvalue, _setvalue)
     
     def _getrange(self):
@@ -95,10 +96,10 @@
         self.sansp = sans_model.getParamList()
         #list of park parameter
-        self.parkp = [SansParameter(p,sans_model) for p in self.sansp]
+        self.parkp = [SansParameter(p, sans_model) for p in self.sansp]
         #list of parameterset 
         self.parameterset = park.ParameterSet(sans_model.name, pars=self.parkp)
         self.pars = []
   
-    def getParams(self, fitparams):
+    def get_params(self, fitparams):
         """
         return a list of value of paramter to fit
@@ -107,14 +108,14 @@
         
         """
-        list = []
+        list_params = []
         self.pars = []
         self.pars = fitparams
         for item in fitparams:
             for element in self.parkp:
-                 if element.name == str(item):
-                     list.append(element.value)
-        return list
-    
-    def setParams(self, paramlist, params):
+                if element.name == str(item):
+                    list_params.append(element.value)
+        return list_params
+    
+    def set_params(self, paramlist, params):
         """
         Set value for parameters to fit
@@ -143,4 +144,19 @@
         except:
             raise
+        
+    def eval_derivs(self, x, pars=[]):
+        """
+        Evaluate the model and derivatives wrt pars at x.
+
+        pars is a list of the names of the parameters for which derivatives
+        are desired.
+
+        This method needs to be specialized in the model to evaluate the
+        model function.  Alternatively, the model can implement is own
+        version of residuals which calculates the residuals directly
+        instead of calling eval.
+        """
+        return []
+
 
     
@@ -174,7 +190,9 @@
         
         self.smearer = smearer
-        
+        self._first_unsmeared_bin = None
+        self._last_unsmeared_bin = None
         # Check error bar; if no error bar found, set it constant(=1)
-        # TODO: Should provide an option for users to set it like percent, constant, or dy data
+        # TODO: Should provide an option for users to set it like percent,
+        # constant, or dy data
         if dy == None or dy == [] or dy.all() == 0:
             self.dy = numpy.ones(len(y))  
@@ -200,5 +218,5 @@
                             & (self.x <= self._qmax_unsmeared)
   
-    def setFitRange(self, qmin=None, qmax=None):
+    def set_fit_range(self, qmin=None, qmax=None):
         """ to set the fit range"""
         # Skip Q=0 point, (especially for y(q=0)=None at x[0]).
@@ -218,5 +236,5 @@
         self._last_unsmeared_bin  = len(self.x) - 1
         
-        if self.smearer!=None:
+        if self.smearer != None:
             self._first_unsmeared_bin, self._last_unsmeared_bin = \
                     self.smearer.get_bin_range(self.qmin, self.qmax)
@@ -231,5 +249,5 @@
                             & (self.x <= self._qmax_unsmeared)
   
-    def getFitRange(self):
+    def get_fit_range(self):
         """
         return the range of data.x to fit
@@ -276,5 +294,5 @@
     """ Wrapper class  for SANS data """
     def __init__(self, sans_data2d, data=None, err_data=None):
-        Data2D.__init__(self, data=data, err_data= err_data)
+        Data2D.__init__(self, data=data, err_data=err_data)
         """
         Data can be initital with a data (sans plottable)
@@ -286,7 +304,8 @@
         self.qmax = None
         self.smearer = None
+        self.radius = 0
+        self.res_err_data = []
         self.set_data(sans_data2d)
 
-        
     def set_data(self, sans_data2d, qmin=None, qmax=None):
         """
@@ -322,5 +341,5 @@
         self.index_model = (self.index_model) & (numpy.isfinite(self.data))
         
-    def set_smearer(self,smearer):  
+    def set_smearer(self, smearer):  
         """
         Set smearer
@@ -332,5 +351,5 @@
         self.smearer.get_data()
 
-    def setFitRange(self, qmin=None, qmax=None):
+    def set_fit_range(self, qmin=None, qmax=None):
         """ to set the fit range"""
         if qmin == 0.0:
@@ -345,7 +364,7 @@
         self.index_model = (self.index_model) &(self.mask)
         self.index_model = (self.index_model) & (numpy.isfinite(self.data))
-        self.index_model = (self.index_model) & (self.res_err_data!=0)
-        
-    def getFitRange(self):
+        self.index_model = (self.index_model) & (self.res_err_data != 0)
+        
+    def get_fit_range(self):
         """
         return the range of data.x to fit
@@ -407,5 +426,6 @@
         self.func_name = "Functor"
         
-    def chisq(self, params):
+    #def chisq(self, params):
+    def chisq(self):
         """
         Calculates chi^2
@@ -418,10 +438,10 @@
         sum = 0
         for item in self.res:
-            sum += item*item
-        if len(self.res)==0:
+            sum += item * item
+        if len(self.res) == 0:
             return None
-        return sum/ len(self.res)
-    
-    def __call__(self,params):
+        return sum / len(self.res)
+    
+    def __call__(self, params):
         """
         Compute residuals
@@ -431,9 +451,10 @@
         """
         #import thread
-        self.model.setParams(self.paramlist,params)
+        self.model.set_params(self.paramlist,params)
         self.res = self.data.residuals(self.model.eval)
         if self.fitresult is not None and  self.handler is not None:
             self.fitresult.set_model(model=self.model)
-            fitness = self.chisq(params=params)
+            #fitness = self.chisq(params=params)
+            fitness = self.chisq()
             self.fitresult.set_fitness(fitness=fitness)
             self.handler.set_result(result=self.fitresult)
@@ -456,68 +477,11 @@
         #Dictionnary of fitArrange element (fit problems)
         self.fit_arrange_dict = {}
-        
-    def _concatenateData(self, listdata=[]):
-        """  
-        _concatenateData method concatenates each fields of all data 
-        contains ins listdata.
-        
-        :param listdata: list of data 
-        
-        :return Data: Data is wrapper class for sans plottable.
-         it is created with all parameters of data concatenanted
-            
-        :raise: if listdata is empty  will return None
-        :raise: if data in listdata don't contain dy field ,
-        will create an error during fitting
-            
-        """
-        #TODO: we have to refactor the way we handle data.
-        # We should move away from plottables and move towards the Data1D objects
-        # defined in DataLoader. Data1D allows data manipulations, which should be
-        # used to concatenate. 
-        # In the meantime we should switch off the concatenation.
-        #if len(listdata)>1:
-        #    raise RuntimeError, "FitEngine._concatenateData: Multiple data files is not currently supported"
-        #return listdata[0]
-        
-        if listdata == []:
-            raise ValueError, " data list missing"
-        else:
-            xtemp = []
-            ytemp = []
-            dytemp = []
-            self.mini = None
-            self.maxi = None
-               
-            for item in listdata:
-                data = item.data
-                mini, maxi = data.getFitRange()
-                if self.mini == None and self.maxi == None:
-                    self.mini = mini
-                    self.maxi = maxi
-                else:
-                    if mini < self.mini:
-                        self.mini = mini
-                    if self.maxi < maxi:
-                        self.maxi = maxi
-                for i in range(len(data.x)):
-                    xtemp.append(data.x[i])
-                    ytemp.append(data.y[i])
-                    if data.dy is not None and len(data.dy) == len(data.y):   
-                        dytemp.append(data.dy[i])
-                    else:
-                        msg = "Fit._concatenateData: y-errors missing"
-                        raise RuntimeError, msg
-            data = Data(x=xtemp, y=ytemp, dy=dytemp)
-            data.setFitRange(self.mini, self.maxi)
-            return data
-        
-        
-    def set_model(self, model, Uid, pars=[], constraints=[]):
-        """
-        set a model on a given uid in the fit engine.
+  
+    def set_model(self, model, id, pars=[], constraints=[]):
+        """
+        set a model on a given  in the fit engine.
         
         :param model: sans.models type 
-        :param Uid: is the key of the fitArrange dictionary where model is 
+        :param : is the key of the fitArrange dictionary where model is 
                 saved as a value
         :param pars: the list of parameters to fit 
@@ -549,5 +513,5 @@
                 except:
                     msg = "Fit Engine: Error occurs when setting the constraint"
-                    msg += " %s for parameter %s "%(value, name)
+                    msg += " %s for parameter %s " % (value, name)
                     raise ValueError, msg
                 
@@ -566,26 +530,26 @@
                     raise ValueError, msg
               
-            #A fitArrange is already created but contains dList only at Uid
-            if self.fit_arrange_dict.has_key(Uid):
-                self.fit_arrange_dict[Uid].set_model(new_model)
-                self.fit_arrange_dict[Uid].pars = pars
+            #A fitArrange is already created but contains data_list only at id
+            if self.fit_arrange_dict.has_key(id):
+                self.fit_arrange_dict[id].set_model(new_model)
+                self.fit_arrange_dict[id].pars = pars
             else:
-            #no fitArrange object has been create with this Uid
+            #no fitArrange object has been create with this id
                 fitproblem = FitArrange()
                 fitproblem.set_model(new_model)
                 fitproblem.pars = pars
-                self.fit_arrange_dict[Uid] = fitproblem
+                self.fit_arrange_dict[id] = fitproblem
                 
         else:
             raise ValueError, "park_integration:missing parameters"
     
-    def set_data(self, data, Uid, smearer=None, qmin=None, qmax=None):
+    def set_data(self, data, id, smearer=None, qmin=None, qmax=None):
         """ 
         Receives plottable, creates a list of data to fit,set data
         in a FitArrange object and adds that object in a dictionary 
-        with key Uid.
+        with key id.
         
         :param data: data added
-        :param Uid: unique key corresponding to a fitArrange object with data
+        :param id: unique key corresponding to a fitArrange object with data
         
         """
@@ -597,36 +561,36 @@
                                  dx=data.dx, dy=data.dy, smearer=smearer)
        
-        fitdata.setFitRange(qmin=qmin, qmax=qmax)
-        #A fitArrange is already created but contains model only at Uid
-        if self.fit_arrange_dict.has_key(Uid):
-            self.fit_arrange_dict[Uid].add_data(fitdata)
+        fitdata.set_fit_range(qmin=qmin, qmax=qmax)
+        #A fitArrange is already created but contains model only at id
+        if self.fit_arrange_dict.has_key(id):
+            self.fit_arrange_dict[id].add_data(fitdata)
         else:
-        #no fitArrange object has been create with this Uid
+        #no fitArrange object has been create with this id
             fitproblem = FitArrange()
             fitproblem.add_data(fitdata)
-            self.fit_arrange_dict[Uid] = fitproblem    
+            self.fit_arrange_dict[id] = fitproblem    
    
-    def get_model(self, Uid):
-        """ 
-        
-        :param Uid: Uid is key in the dictionary containing the model to return
-        
-        :return:  a model at this uid or None if no FitArrange element was created
-            with this Uid
-            
-        """
-        if self.fit_arrange_dict.has_key(Uid):
-            return self.fit_arrange_dict[Uid].get_model()
+    def get_model(self, id):
+        """ 
+        
+        :param id: id is key in the dictionary containing the model to return
+        
+        :return:  a model at this id or None if no FitArrange element was 
+            created with this id
+            
+        """
+        if self.fit_arrange_dict.has_key(id):
+            return self.fit_arrange_dict[id].get_model()
         else:
             return None
     
-    def remove_Fit_Problem(self, Uid):
-        """remove   fitarrange in Uid"""
-        if self.fit_arrange_dict.has_key(Uid):
-            del self.fit_arrange_dict[Uid]
-            
-    def select_problem_for_fit(self, Uid, value):
-        """
-        select a couple of model and data at the Uid position in dictionary
+    def remove_fit_problem(self, id):
+        """remove   fitarrange in id"""
+        if self.fit_arrange_dict.has_key(id):
+            del self.fit_arrange_dict[id]
+            
+    def select_problem_for_fit(self, id, value):
+        """
+        select a couple of model and data at the id position in dictionary
         and set in self.selected value to value
         
@@ -635,16 +599,16 @@
                 
         """
-        if self.fit_arrange_dict.has_key(Uid):
-             self.fit_arrange_dict[Uid].set_to_fit(value)
+        if self.fit_arrange_dict.has_key(id):
+            self.fit_arrange_dict[id].set_to_fit(value)
              
-    def get_problem_to_fit(self, Uid):
-        """
-        return the self.selected value of the fit problem of Uid
-        
-        :param Uid: the Uid of the problem
-        
-        """
-        if self.fit_arrange_dict.has_key(Uid):
-             self.fit_arrange_dict[Uid].get_to_fit()
+    def get_problem_to_fit(self, id):
+        """
+        return the self.selected value of the fit problem of id
+        
+        :param id: the id of the problem
+        
+        """
+        if self.fit_arrange_dict.has_key(id):
+            self.fit_arrange_dict[id].get_to_fit()
     
 class FitArrange:
@@ -660,5 +624,5 @@
         """
         self.model = None
-        self.dList = []
+        self.data_list = []
         self.pars = []
         #self.selected  is zero when this fit problem is not schedule to fit 
@@ -677,11 +641,11 @@
     def add_data(self, data):
         """ 
-        add_data fill a self.dList with data to fit
+        add_data fill a self.data_list with data to fit
         
         :param data: Data to add in the list  
         
         """
-        if not data in self.dList:
-            self.dList.append(data)
+        if not data in self.data_list:
+            self.data_list.append(data)
             
     def get_model(self):
@@ -696,9 +660,9 @@
         """ 
         
-        :return: list of data dList
-        
-        """
-        #return self.dList 
-        return self.dList[0] 
+        :return: list of data data_list
+        
+        """
+        #return self.data_list 
+        return self.data_list[0] 
       
     def remove_data(self, data):
@@ -706,9 +670,9 @@
         Remove one element from the list
         
-        :param data: Data to remove from dList
-        
-        """
-        if data in self.dList:
-            self.dList.remove(data)
+        :param data: Data to remove from data_list
+        
+        """
+        if data in self.data_list:
+            self.data_list.remove(data)
             
     def set_to_fit (self, value=0):
Index: park_integration/Fitting.py
===================================================================
--- park_integration/Fitting.py	(revision 89f3b661379c219e6763af21e8d87d6e236695b7)
+++ park_integration/Fitting.py	(revision c4d6900c7e4f190062574bc6b0b22a247c5224b0)
@@ -6,6 +6,6 @@
 
 #from scipy import optimize
-from ScipyFitting import ScipyFit
-from ParkFitting import ParkFit
+from sans.fit.ScipyFitting import ScipyFit
+from sans.fit.ParkFitting import ParkFit
 
 
@@ -19,7 +19,7 @@
         fitter.fit_engine('scipy') or fitter.fit_engine('park')
         engine = fitter.returnEngine()
-        engine.set_data(data,Uid)
+        engine.set_data(data,id)
         engine.set_param( model,model.name, pars)
-        engine.set_model(model,Uid)
+        engine.set_model(model,id)
         
         chisqr1, out1, cov1=engine.fit(pars,qmin,qmax)
@@ -46,5 +46,5 @@
             self._engine = ScipyFit()
         elif word == "park":
-            self._engine=ParkFit()
+            self._engine = ParkFit()
         else:
             raise ValueError, "enter the keyword scipy or park"
@@ -52,18 +52,18 @@
     def fit(self, q=None, handler=None, curr_thread=None):
         """Perform the fit """
-        try:
-            return self._engine.fit(q,handler, curr_thread=curr_thread)
-        except:
-            raise
+        #try:
+        return self._engine.fit(q, handler, curr_thread=curr_thread)
+        #except:
+        #    raise
     
-    def set_model(self, model, Uid, pars=[], constraints=[]):
+    def set_model(self, model, id, pars=[], constraints=[]):
         """
-        store a model model to fit at the position Uid of the fit engine
+        store a model model to fit at the position id of the fit engine
         """
-        self._engine.set_model(model, Uid, pars, constraints)
+        self._engine.set_model(model, id, pars, constraints)
    
-    def set_data(self, data, Uid, smearer=None, qmin=None, qmax=None):
+    def set_data(self, data, id, smearer=None, qmin=None, qmax=None):
         """
-        Store data to fit at the psotion Uid of the fit engine
+        Store data to fit at the psotion id of the fit engine
         
         :param data: data to fit
@@ -73,18 +73,18 @@
         
         """
-        self._engine.set_data(data, Uid, smearer, qmin, qmax)
+        self._engine.set_data(data, id, smearer, qmin, qmax)
         
-    def get_model(self, Uid):
+    def get_model(self, id):
         """ return list of data"""
-        self._engine.get_model(Uid)
+        self._engine.get_model(id)
 
 
-    def remove_Fit_Problem(self, Uid):
-        """remove fitarrange in Uid"""
-        self._engine.remove_Fit_Problem(Uid)
+    def remove_fit_problem(self, id):
+        """remove fitarrange in id"""
+        self._engine.remove_fit_problem(id)
         
-    def select_problem_for_fit(self, Uid, value):
+    def select_problem_for_fit(self, id, value):
         """
-        select a couple of model and data at the Uid position in dictionary
+        select a couple of model and data at the id position in dictionary
         and set in self.selected value to value
         
@@ -92,12 +92,12 @@
              can only have the value one or zero
         """
-        self._engine.select_problem_for_fit(Uid, value)
+        self._engine.select_problem_for_fit(id, value)
         
-    def get_problem_to_fit(self, Uid):
+    def get_problem_to_fit(self, id):
         """
-        return the self.selected value of the fit problem of Uid
+        return the self.selected value of the fit problem of id
            
-        :param Uid: the Uid of the problem
+        :param id: the id of the problem
         
         """
-        return self._engine.get_problem_to_fit(Uid)
+        return self._engine.get_problem_to_fit(id)
Index: park_integration/Loader.py
===================================================================
--- park_integration/Loader.py	(revision 89f3b661379c219e6763af21e8d87d6e236695b7)
+++ park_integration/Loader.py	(revision c4d6900c7e4f190062574bc6b0b22a247c5224b0)
@@ -3,4 +3,5 @@
 #import string
 import numpy
+
 class Load:
     """
@@ -8,5 +9,5 @@
     """
     
-    def _init_(self, x=None, y=None, dx=None, dy=None):
+    def __init__(self, x=None, y=None, dx=None, dy=None):
         # variable to store loaded values
         self.x = x
@@ -18,5 +19,6 @@
     def set_filename(self, path=None):
         """
-        Store path into a variable.If the user doesn't give a path as a parameter a pop-up
+        Store path into a variable.If the user doesn't give 
+        a path as a parameter a pop-up
         window appears to select the file.
         
@@ -53,6 +55,4 @@
                 except:
                     print "READ ERROR", line
-            
-            
             # Sanity check
             if not len(self.x) == len(self.dx):
Index: park_integration/ScipyFitting.py
===================================================================
--- park_integration/ScipyFitting.py	(revision b2f25dc5befcce6b90b54eb667869a52222abf16)
+++ park_integration/ScipyFitting.py	(revision c4d6900c7e4f190062574bc6b0b22a247c5224b0)
@@ -12,5 +12,5 @@
 from sans.fit.AbstractFitEngine import FitEngine
 from sans.fit.AbstractFitEngine import SansAssembly
-from sans.fit.AbstractFitEngine import FitAbort
+#from sans.fit.AbstractFitEngine import FitAbort
 
 class fitresult(object):
@@ -18,5 +18,5 @@
     Storing fit result
     """
-    def __init__(self, model=None, paramList=None):
+    def __init__(self, model=None, param_list=None):
         self.calls = None
         self.fitness = None
@@ -30,5 +30,5 @@
         self.parameters = None
         self.model = model
-        self.param_list = paramList
+        self.param_list = param_list
      
     def set_model(self, model):
@@ -50,8 +50,8 @@
 
         result_param = zip(xrange(n), self.model.parameterset)
-        L = ["P%-3d  %s......|.....%s"%(p[0], p[1], p[1].value)\
+        msg = ["P%-3d  %s......|.....%s" % (p[0], p[1], p[1].value)\
               for p in result_param if p[1].name in self.param_list]
-        L.append("=== goodness of fit: %s" % (str(self.fitness)))
-        return "\n".join(L)
+        msg.append("=== goodness of fit: %s" % (str(self.fitness)))
+        return "\n".join(msg)
     
     def print_summary(self):
@@ -95,4 +95,5 @@
         self.fit_arrange_dict = {}
         self.param_list = []
+        self.curr_thread = None
     #def fit(self, *args, **kw):
     #    return profile(self._fit, *args, **kw)
@@ -102,5 +103,5 @@
         """
         fitproblem = []
-        for id, fproblem in self.fit_arrange_dict.iteritems():
+        for fproblem in self.fit_arrange_dict.itervalues():
             if fproblem.get_to_fit() == 1:
                 fitproblem.append(fproblem)
@@ -119,5 +120,5 @@
         data = listdata
         self.curr_thread = curr_thread
-        result = fitresult(model=model, paramList=self.param_list)
+        result = fitresult(model=model, param_list=self.param_list)
         if handler is not None:
             handler.set_result(result=result)
@@ -125,28 +126,27 @@
         functor = SansAssembly(self.param_list, model, data, handler=handler,
                          fitresult=result, curr_thread= self.curr_thread)
-       
-       
-        out, cov_x, info, mesg, success = optimize.leastsq(functor,
-                                                model.getParams(self.param_list),
-                                                    full_output=1, warning=True)
+        out, cov_x, _, _, success = optimize.leastsq(functor,
+                                            model.get_params(self.param_list),
+                                                    full_output=1,
+                                                    warning=True)
         
-        chisqr = functor.chisq(out)
-        
+        #chisqr = functor.chisq(out)
+        chisqr = functor.chisq()
         if cov_x is not None and numpy.isfinite(cov_x).all():
             stderr = numpy.sqrt(numpy.diag(cov_x))
         else:
             stderr = None
-        if not (numpy.isnan(out).any()) or ( cov_x !=None) :
-                result.fitness = chisqr
-                result.stderr  = stderr
-                result.pvec = out
-                result.success = success
-                #print result
-                if q is not  None:
-                    #print "went here"
-                    q.put(result)
-                    #print "get q scipy fit enfine",q.get()
-                    return q
-                return result
+        if not (numpy.isnan(out).any()) or (cov_x != None):
+            result.fitness = chisqr
+            result.stderr  = stderr
+            result.pvec = out
+            result.success = success
+            #print result
+            if q is not None:
+                #print "went here"
+                q.put(result)
+                #print "get q scipy fit enfine",q.get()
+                return q
+            return result
         else:  
             raise ValueError, "SVD did not converge" + str(success)
@@ -154,17 +154,17 @@
 
 
-def profile(fn, *args, **kw):
-    import cProfile, pstats, os
-    global call_result
-    def call():
-        global call_result
-        call_result = fn(*args, **kw)
-    cProfile.runctx('call()', dict(call=call), {}, 'profile.out')
-    stats = pstats.Stats('profile.out')
-    #stats.sort_stats('time')
-    stats.sort_stats('calls')
-    stats.print_stats()
-    os.unlink('profile.out')
-    return call_result
+#def profile(fn, *args, **kw):
+#    import cProfile, pstats, os
+#    global call_result
+#   def call():
+#        global call_result
+#        call_result = fn(*args, **kw)
+#    cProfile.runctx('call()', dict(call=call), {}, 'profile.out')
+#    stats = pstats.Stats('profile.out')
+#    stats.sort_stats('time')
+#    stats.sort_stats('calls')
+#    stats.print_stats()
+#    os.unlink('profile.out')
+#    return call_result
 
       
