Changeset d4b0687 in sasview for park_integration/ScipyFitting.py
- Timestamp:
- Jul 11, 2008 11:16:18 AM (16 years ago)
- 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
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
park_integration/ScipyFitting.py
r4c718654 rd4b0687 8 8 from scipy import optimize 9 9 from AbstractFitEngine import FitEngine, Parameter 10 from AbstractFitEngine import FitArrange 10 11 11 class FitArrange:12 def __init__(self):13 """14 Class FitArrange contains a set of data for a given model15 to perform the Fit.FitArrange must contain exactly one model16 and at least one data for the fit to be performed.17 model: the model selected by the user18 Ldata: a list of data what the user wants to fit19 20 """21 self.model = None22 self.dList =[]23 24 def set_model(self,model):25 """26 set_model save a copy of the model27 @param model: the model being set28 """29 self.model = model30 31 def add_data(self,data):32 """33 add_data fill a self.dList with data to fit34 @param data: Data to add in the list35 """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.model42 43 def get_data(self):44 """ @return: list of data dList"""45 return self.dList46 47 def remove_data(self,data):48 """49 Remove one element from the list50 @param data: Data to remove from dList51 """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 58 12 class ScipyFit(FitEngine): 59 13 """ … … 123 77 return chisqr, out, cov 124 78 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 191 80 def fitHelper(model, pars, x, y, err_y ,qmin=None, qmax=None): 192 81 """
Note: See TracChangeset
for help on using the changeset viewer.