Changeset 20d30e9 in sasview
- Timestamp:
- Mar 20, 2009 8:29:58 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:
- 858fabed
- Parents:
- c77d859
- Location:
- park_integration
- Files:
-
- 1 added
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
park_integration/AbstractFitEngine.py
ra7abdb1 r20d30e9 46 46 hi= numpy.inf 47 47 return lo,hi 48 49 48 50 49 def _setrange(self,r): … … 157 156 @return residuals 158 157 """ 159 160 158 x,y,dy = [numpy.asarray(v) for v in (self.x,self.y,self.dy)] 161 159 if self.qmin==None and self.qmax==None: … … 207 205 208 206 ## Min Q-value 209 self.qmin= None207 self.qmin= min (self.data.x) 210 208 ## Max Q-value 211 self.qmax= None212 213 214 def setFitRange(self,qmin=None,qmax=None ,ymin=None,ymax=None,):209 self.qmax= max (self.data.x) 210 211 212 def setFitRange(self,qmin=None,qmax=None): 215 213 """ to set the fit range""" 216 self.qmin =qmin217 self.qmax =qmax214 self.qmin = qmin 215 self.qmax = qmax 218 216 219 217 … … 238 236 239 237 # Find entries to consider 240 if self.qmin==None and self.qmax==None: 241 idx = Ellipsis 242 else: 243 idx = (x>=self.qmin) & (x <= self.qmax) 244 238 if self.qmin==None: 239 self.qmin= min(self.data.x) 240 if self.qmax==None: 241 self.qmin= max(self.data.x) 242 243 idx = (x>=self.qmin) & (x <= self.qmax) 244 245 245 # Compute theory data f(x) 246 246 fx = numpy.zeros(len(x)) … … 250 250 if self.smearer is not None: 251 251 fx = self.smearer(fx) 252 252 253 # Sanity check 253 254 if numpy.size(dy) < numpy.size(x): … … 256 257 return (y[idx] - fx[idx])/dy[idx] 257 258 258 def residuals_old(self, fn): 259 """ @param fn: function that return model value 260 @return residuals 261 """ 262 x,y,dy = [numpy.asarray(v) for v in (self.x,self.y,self.dy)] 263 if self.qmin==None and self.qmax==None: 264 fx =numpy.asarray([fn(v) for v in x]) 265 return (y - fx)/dy 266 else: 267 idx = (x>=self.qmin) & (x <= self.qmax) 268 fx = numpy.asarray([fn(item)for item in x[idx ]]) 269 return (y[idx] - fx)/dy[idx] 259 270 260 271 261 def residuals_deriv(self, model, pars=[]): … … 290 280 self.y_bins= sans_data2d.y_bins 291 281 292 self.xmin= self.data.xmin 293 self.xmax= self.data.xmax 294 self.ymin= self.data.ymin 295 self.ymax= self.data.ymax 296 297 298 def setFitRange(self,qmin=None,qmax=None,ymin=None,ymax=None): 282 x = max(self.data.xmin, self.data.xmax) 283 y = max(self.data.ymin, self.data.ymax) 284 285 ## fitting range 286 self.qmin = 0 287 self.qmax = math.sqrt(x*x +y*y) 288 289 290 291 def setFitRange(self,qmin=None,qmax=None): 299 292 """ to set the fit range""" 300 self.xmin= qmin 301 self.xmax= qmax 302 self.ymin= ymin 303 self.ymax= ymax 293 self.qmin= qmin 294 self.qmax= qmax 295 304 296 305 297 def getFitRange(self): … … 307 299 @return the range of data.x to fit 308 300 """ 309 return self. xmin, self.xmax,self.ymin, self.ymax301 return self.qmin, self.qmax 310 302 311 303 … … 315 307 """ 316 308 res=[] 317 if self.xmin==None: #Here we define that xmin = qmin >=0 and xmax=qmax>=qmain 318 self.xmin= 0 #self.data.xmin 319 if self.xmax==None: 320 self.xmax= self.data.xmax 321 if self.ymin==None: 322 self.ymin= self.data.ymin 323 if self.ymax==None: 324 self.ymax= self.data.ymax 309 #Here we define that qmin >=0 and qmax>=qmain 310 x = max(self.data.xmin, self.data.xmax) 311 y = max(self.data.ymin, self.data.ymax) 312 313 ## fitting range 314 if self.qmin == None: 315 self.qmin = 0 316 if self.qmax == None: 317 self.qmax = math.sqrt(x*x +y*y) 318 319 325 320 for i in range(len(self.y_bins)): 326 #if self.y_bins[i]>= self.ymin and self.y_bins[i]<= self.ymax:327 321 for j in range(len(self.x_bins)): 328 if math.pow(self.data.x_bins[i],2)+math.pow(self.data.y_bins[j],2)>=math.pow(self.xmin,2): 329 if math.pow(self.data.x_bins[i],2)+math.pow(self.data.y_bins[j],2)<=math.pow(self.xmax,2): 330 #if self.x_bins[j]>= self.xmin and self.x_bins[j]<= self.xmax: 331 res.append( (self.image[i][j]- fn([self.x_bins[i],self.y_bins[j]]))\ 332 /self.err_image[i][j] ) 322 radius = math.pow(self.data.x_bins[i],2)+math.pow(self.data.y_bins[j],2) 323 if self.qmin <= radius and radius <= self.qmax: 324 res.append( (self.image[j][i]- fn([self.x_bins[i],self.y_bins[j]]))\ 325 /self.err_image[j][i] ) 333 326 334 327 return numpy.array(res) … … 346 339 Sans Assembly class a class wrapper to be call in optimizer.leastsq method 347 340 """ 348 349 341 def __init__(self,paramlist,Model=None , Data=None): 350 342 """ … … 365 357 for item in self.res: 366 358 sum += item*item 367 #print "length of data =",len(self.res)359 368 360 return sum/ len(self.res) 361 369 362 def __call__(self,params): 370 363 """ … … 413 406 ytemp=[] 414 407 dytemp=[] 415 dxtemp=[]416 408 self.mini=None 417 409 self.maxi=None … … 437 429 else: 438 430 raise RuntimeError, "Fit._concatenateData: y-errors missing" 439 if data.dx is not None and len(data.dx)==len(data.x): 440 dxtemp.append(data.dx[i]) 441 else: 442 raise RuntimeError, "Fit._concatenateData: dQ-errors missing" 443 data= Data(x=xtemp,y=ytemp,dy=dytemp, dx=dxtemp) 431 data= Data(x=xtemp,y=ytemp,dy=dytemp) 444 432 data.setFitRange(self.mini, self.maxi) 445 433 return data … … 476 464 raise ValueError, "park_integration:missing parameters" 477 465 478 def set_data(self,data,Uid,smearer=None,qmin=None,qmax=None ,ymin=None,ymax=None):466 def set_data(self,data,Uid,smearer=None,qmin=None,qmax=None): 479 467 """ Receives plottable, creates a list of data to fit,set data 480 468 in a FitArrange object and adds that object in a dictionary … … 487 475 else: 488 476 fitdata=FitData1D(data, smearer) 489 fitdata.setFitRange(qmin=qmin,qmax=qmax, ymin=ymin,ymax=ymax) 477 478 fitdata.setFitRange(qmin=qmin,qmax=qmax) 490 479 #A fitArrange is already created but contains model only at Uid 491 480 if self.fitArrangeDict.has_key(Uid): … … 496 485 fitproblem.add_data(fitdata) 497 486 self.fitArrangeDict[Uid]=fitproblem 498 487 499 488 def get_model(self,Uid): 500 489 """ -
park_integration/Fitting.py
ra2b6c05f r20d30e9 31 31 self._engine will contain an instance of ScipyFit or ParkFit 32 32 """ 33 self._engine =None33 self._engine = None 34 34 self.set_engine(engine) 35 35 36 36 37 def set_engine(self,word): … … 48 49 raise ValueError, "enter the keyword scipy or park" 49 50 50 def returnEngine(self): 51 """ @return self._engine""" 52 return self._engine 51 53 52 54 53 def fit(self,handler=None): … … 57 56 return self._engine.fit(handler) 58 57 58 59 59 def set_model(self,model,Uid,pars=[]): 60 self._engine.set_model(model,Uid,pars) 60 """ 61 store a model model to fit at the position Uid of the fit engine 62 """ 63 self._engine.set_model(model,Uid,pars) 61 64 62 def set_data(self,data,Uid,smearer=None,qmin=None, qmax=None,ymin=None, ymax=None): 63 self._engine.set_data(data,Uid,smearer,qmin,qmax,ymin,ymax) 65 66 def set_data(self,data,Uid,smearer=None,qmin=None, qmax=None): 67 """ 68 Store data to fit at the psotion Uid of the fit engine 69 @param data: data to fit 70 @param smearer: smearerobject to smear data 71 @param qmin: the minimum q range to fit 72 @param qmax: the minimum q range to fit 73 """ 74 self._engine.set_data(data,Uid,smearer,qmin, qmax) 75 64 76 65 77 def get_model(self,Uid): … … 67 79 self._engine.get_model(Uid) 68 80 81 69 82 def remove_Fit_Problem(self,Uid): 70 83 """remove fitarrange in Uid""" 71 84 self._engine.remove_Fit_Problem(Uid) 85 72 86 73 87 def select_problem_for_fit(self,Uid,value): … … 79 93 self._engine.select_problem_for_fit(Uid,value) 80 94 95 81 96 def get_problem_to_fit(self,Uid): 82 97 """
Note: See TracChangeset
for help on using the changeset viewer.