Changeset 7d0c1a8 in sasview
- Timestamp:
- Oct 9, 2008 2:33:14 PM (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:
- 385d464
- Parents:
- fb8d4050
- Location:
- park_integration
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
park_integration/AbstractFitEngine.py
ra9e04aa r7d0c1a8 167 167 """ 168 168 return [] 169 class FitData1D(object): 170 """ Wrapper class for SANS data """ 171 def __init__(self,sans_data1d): 172 """ 173 Data can be initital with a data (sans plottable) 174 or with vectors. 175 """ 176 self.data=sans_data1d 177 self.x= sans_data1d.x 178 self.y= sans_data1d.y 179 self.dx= sans_data1d.dx 180 self.dy= sans_data1d.dy 181 self.qmin=None 182 self.qmax=None 183 184 185 def setFitRange(self,mini=None,maxi=None): 186 """ to set the fit range""" 187 self.qmin=mini 188 self.qmax=maxi 189 190 191 def getFitRange(self): 192 """ 193 @return the range of data.x to fit 194 """ 195 return self.qmin, self.qmax 196 197 198 def residuals(self, fn): 199 """ @param fn: function that return model value 200 @return residuals 201 """ 202 x,y,dy = [numpy.asarray(v) for v in (self.x,self.y,self.dy)] 203 if self.qmin==None and self.qmax==None: 204 fx =numpy.asarray([fn(v) for v in x]) 205 return (y - fx)/dy 206 else: 207 idx = (x>=self.qmin) & (x <= self.qmax) 208 fx = numpy.asarray([fn(item)for item in x[idx ]]) 209 return (y[idx] - fx)/dy[idx] 210 211 def residuals_deriv(self, model, pars=[]): 212 """ 213 @return residuals derivatives . 214 @note: in this case just return empty array 215 """ 216 return [] 217 218 219 class FitData2D(object): 220 """ Wrapper class for SANS data """ 221 def __init__(self,sans_data2d): 222 """ 223 Data can be initital with a data (sans plottable) 224 or with vectors. 225 """ 226 self.data=sans_data2d 227 self.image = sans_data2d.image 228 self.err_image = sans_data2d.err_image 229 self.x_bins= sans_data2d.x_bins 230 self.y_bins= sans_data2d.y_bins 231 232 self.qmin= None 233 self.qmax= None 234 235 236 def setFitRange(self,mini=None,maxi=None): 237 """ to set the fit range""" 238 self.qmin= mini 239 self.qmax= maxi 240 241 242 def getFitRange(self): 243 """ 244 @return the range of data.x to fit 245 """ 246 return self.qmin, self.qmax 247 248 249 def residuals(self, fn): 250 """ @param fn: function that return model value 251 @return residuals 252 """ 253 res=[] 254 if self.qmin==None and self.qmax==None: 255 for i in range(len(self.x_bins)): 256 res.append( (self.image[i][i]- fn([self.x_bins[i],self.y_bins[i]]))\ 257 /self.err_image[i][i] ) 258 return numpy.array(res) 259 else: 260 #idx = (x>=self.qmin) & (x <= self.qmax) 261 #fx = numpy.asarray([fn(item)for item in x[idx ]]) 262 #return (y[idx] - fx)/dy[idx] 263 for i in range(len(self.x_bins)): 264 res.append( (self.image[i][i]- fn([self.x_bins[i],self.y_bins[i]]))\ 265 /self.err_image[i][i] ) 266 return numpy.array(res) 267 def residuals_deriv(self, model, pars=[]): 268 """ 269 @return residuals derivatives . 270 @note: in this case just return empty array 271 """ 272 return [] 169 273 170 274 class sansAssembly: … … 229 333 self.maxi=None 230 334 231 for data in listdata: 335 for item in listdata: 336 data=item.data 232 337 mini,maxi=data.getFitRange() 233 338 if self.mini==None and self.maxi==None: … … 370 475 def get_data(self): 371 476 """ @return: list of data dList""" 372 return self.dList 477 #return self.dList 478 return self.dList[0] 373 479 374 480 def remove_data(self,data): -
park_integration/ParkFitting.py
ra9e04aa r7d0c1a8 10 10 from park import assembly 11 11 from park.fitmc import FitSimplex, FitMC 12 from sans.guitools.plottables import Data1D 12 13 13 from Loader import Load 14 from AbstractFitEngine import FitEngine ,FitArrange,Model14 from AbstractFitEngine import FitEngine 15 15 16 16 … … 75 75 i+=1 76 76 Ldata=item.get_data() 77 parkdata=self._concatenateData(Ldata)78 77 #parkdata=self._concatenateData(Ldata) 78 parkdata=Ldata 79 79 fitness=(parkmodel,parkdata) 80 80 mylist.append(fitness) … … 120 120 fitter=fitter, 121 121 handler= fitresult.ConsoleUpdate(improvement_delta=0.1)) 122 #handler = fitresult.ConsoleUpdate(improvement_delta=0.1) 123 #models=self.problem 124 #service=None 125 #if models is None: raise RuntimeError('fit expected a list of models') 126 #from park.fit import LocalQueue,FitJob 127 #if service is None: service = LocalQueue() 128 #if fitter is None: fitter = fitmc.FitMC() 129 #if handler is None: handler = fitresult.FitHandler() 130 131 #objective = assembly.Assembly(models) if isinstance(models,list) else models 132 #job = FitJob(self.problem,fitter,handler) 133 #service.start(job) 134 #import wx 135 #while not self.job.handler.done: 136 # time.sleep(interval) 137 # wx.Yield() 138 #result=service.job.handler.result 139 122 140 if result !=None: 123 141 return result -
park_integration/ScipyFitting.py
ra9e04aa r7d0c1a8 81 81 listdata = fitproblem[0].get_data() 82 82 # Concatenate dList set (contains one or more data)before fitting 83 data=self._concatenateData( listdata) 83 #data=self._concatenateData( listdata) 84 data=listdata 84 85 #Assign a fit range is not boundaries were given 85 if qmin==None: 86 qmin= min(data.x) 87 if qmax==None: 88 qmax= max(data.x) 86 if data.__class__.__name__=='Data1D': 87 if qmin==None: 88 qmin= min(data.x) 89 if qmax==None: 90 qmax= max(data.x) 91 else: 92 if qmin==None: 93 qmin= numpy.min(data.image) 94 if qmax==None: 95 qmax= numpy.max(data.image) 89 96 functor= sansAssembly(self.paramList,model,data) 90 97 out, cov_x, info, mesg, success = optimize.leastsq(functor,model.getParams(self.paramList), full_output=1, warning=True) -
park_integration/test/test_fit_line.py
r8bbab51 r7d0c1a8 5 5 from sans.guitools.plottables import Theory1D 6 6 from sans.guitools.plottables import Data1D 7 from sans.fit.AbstractFitEngine import Data, Model 7 from sans.fit.AbstractFitEngine import Data, Model,FitData1D 8 8 import math 9 9 class testFitModule(unittest.TestCase): … … 21 21 model1 = LineModel() 22 22 model1.name = "M1" 23 data = Data(sans_data=data1 ) 23 #data = Data(sans_data=data1 ) 24 data = FitData1D(data1 ) 24 25 model = Model(model1) 25 26 #fit with scipy test … … 85 86 model22 = LineModel() 86 87 model11.name= "M2" 87 data1 = Data(sans_data=data11 ) 88 data2 = Data(sans_data=data22 ) 88 #data1 = Data(sans_data=data11 ) 89 #data2 = Data(sans_data=data22 ) 90 data1 = FitData1D(data11 ) 91 data2 = FitData1D(data22 ) 92 89 93 model1 = Model(model11) 90 94 model2 = Model(model22) … … 150 154 # Constrain the constant value to be equal to parameter B (the real value is 2.5) 151 155 152 153 data1 = Data(sans_data=data11 ) 154 data2 = Data(sans_data=data22 ) 156 #data1 = Data(sans_data=data11 ) 157 #data2 = Data(sans_data=data22 ) 158 159 data1 = FitData1D(data11 ) 160 data2 = FitData1D(data22 ) 155 161 model1 = Model(model11) 156 162 model2 = Model(model22) … … 194 200 model1.name= "M1" 195 201 196 data1 = Data(sans_data=data11 ) 197 data2 = Data(sans_data=data22 ) 202 #data1 = Data(sans_data=data11 ) 203 #data2 = Data(sans_data=data22 ) 204 data1 = FitData1D(data11 ) 205 data2 = FitData1D(data22 ) 198 206 model = Model(model1) 199 207
Note: See TracChangeset
for help on using the changeset viewer.