Changeset d4b0687 in sasview for park_integration/ScipyFitting.py


Ignore:
Timestamp:
Jul 11, 2008 11:16:18 AM (16 years ago)
Author:
Gervaise Alina <gervyh@…>
Branches:
master, ESS_GUI, ESS_GUI_Docs, ESS_GUI_batch_fitting, ESS_GUI_bumps_abstraction, ESS_GUI_iss1116, ESS_GUI_iss879, ESS_GUI_iss959, ESS_GUI_opencl, ESS_GUI_ordering, ESS_GUI_sync_sascalc, costrafo411, magnetic_scatt, release-4.1.1, release-4.1.2, release-4.2.2, release_4.0.1, ticket-1009, ticket-1094-headless, ticket-1242-2d-resolution, ticket-1243, ticket-1249, ticket885, unittest-saveload
Children:
94b44293
Parents:
4c718654
Message:

changed done on AbstractFit? engine scipyfit parkfit

File:
1 edited

Legend:

Unmodified
Added
Removed
  • park_integration/ScipyFitting.py

    r4c718654 rd4b0687  
    88from scipy import optimize 
    99from AbstractFitEngine import FitEngine, Parameter 
     10from AbstractFitEngine import FitArrange 
    1011 
    11 class FitArrange: 
    12     def __init__(self): 
    13         """ 
    14             Class FitArrange contains a set of data for a given model 
    15             to perform the Fit.FitArrange must contain exactly one model 
    16             and at least one data for the fit to be performed. 
    17             model: the model selected by the user 
    18             Ldata: a list of data what the user wants to fit 
    19              
    20         """ 
    21         self.model = None 
    22         self.dList =[] 
    23          
    24     def set_model(self,model): 
    25         """  
    26             set_model save a copy of the model 
    27             @param model: the model being set 
    28         """ 
    29         self.model = model 
    30          
    31     def add_data(self,data): 
    32         """  
    33             add_data fill a self.dList with data to fit 
    34             @param data: Data to add in the list   
    35         """ 
    36         if not data in self.dList: 
    37             self.dList.append(data) 
    38              
    39     def get_model(self): 
    40         """ @return: saved model """ 
    41         return self.model    
    42       
    43     def get_data(self): 
    44         """ @return:  list of data dList""" 
    45         return self.dList  
    46        
    47     def remove_data(self,data): 
    48         """ 
    49             Remove one element from the list 
    50             @param data: Data to remove from dList 
    51         """ 
    52         if data in self.dList: 
    53             self.dList.remove(data) 
    54     def remove_datalist(self): 
    55         """ empty the complet list dLst""" 
    56         self.dList=[] 
    57              
    5812class ScipyFit(FitEngine): 
    5913    """  
     
    12377        return chisqr, out, cov 
    12478     
    125     def set_model(self,model,name,Uid,pars={}): 
    126         """  
    127        
    128             Receive a dictionary of parameter and save it Parameter list 
    129             For scipy.fit use. 
    130             Set model in a FitArrange object and add that object in a dictionary 
    131             with key Uid. 
    132             @param model: model on with parameter values are set 
    133             @param name: model name 
    134             @param Uid: unique key corresponding to a fitArrange object with model 
    135             @param pars: dictionary of paramaters name and value 
    136             pars={parameter's name: parameter's value} 
    137              
    138         """ 
    139         self.parameters=[] 
    140         if model==None: 
    141             raise ValueError, "Cannot set parameters for empty model" 
    142         else: 
    143             model.name=name 
    144             for key, value in pars.iteritems(): 
    145                 param = Parameter(model, key, value) 
    146                 self.parameters.append(param) 
    147          
    148         #A fitArrange is already created but contains dList only at Uid 
    149         if self.fitArrangeList.has_key(Uid): 
    150             self.fitArrangeList[Uid].set_model(model) 
    151         else: 
    152         #no fitArrange object has been create with this Uid 
    153             fitproblem= FitArrange() 
    154             fitproblem.set_model(model) 
    155             self.fitArrangeList[Uid]=fitproblem 
    156          
    157     def set_data(self,data,Uid): 
    158         """ Receives plottable, creates a list of data to fit,set data 
    159             in a FitArrange object and adds that object in a dictionary  
    160             with key Uid. 
    161             @param data: data added 
    162             @param Uid: unique key corresponding to a fitArrange object with data 
    163             """ 
    164         #A fitArrange is already created but contains model only at Uid 
    165         if self.fitArrangeList.has_key(Uid): 
    166             self.fitArrangeList[Uid].add_data(data) 
    167         else: 
    168         #no fitArrange object has been create with this Uid 
    169             fitproblem= FitArrange() 
    170             fitproblem.add_data(data) 
    171             self.fitArrangeList[Uid]=fitproblem 
    172              
    173     def get_model(self,Uid): 
    174         """  
    175             @param Uid: Uid is key in the dictionary containing the model to return 
    176             @return  a model at this uid or None if no FitArrange element was created 
    177             with this Uid 
    178         """ 
    179         if self.fitArrangeList.has_key(Uid): 
    180             return self.fitArrangeList[Uid].get_model() 
    181         else: 
    182             return None 
    183      
    184      
    185      
    186     def remove_Fit_Problem(self,Uid): 
    187         """remove   fitarrange in Uid""" 
    188         if self.fitArrangeList.has_key(Uid): 
    189             del self.fitArrangeList[Uid] 
    190        
     79 
    19180def fitHelper(model, pars, x, y, err_y ,qmin=None, qmax=None): 
    19281    """ 
Note: See TracChangeset for help on using the changeset viewer.