Changeset 058b2d7 in sasview
- Timestamp:
- Jul 15, 2009 11:31:11 AM (15 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:
- 730c9eb
- Parents:
- 342d9197
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
park_integration/AbstractFitEngine.py
r70bf68c r058b2d7 205 205 # Initialize from Data1D object 206 206 self.data=sans_data1d 207 self.x= sans_data1d.x 208 self.y= sans_data1d.y 209 self.dx= sans_data1d.dx 210 self.dy= sans_data1d.dy 211 207 self.x= numpy.array(sans_data1d.x) 208 self.y= numpy.array(sans_data1d.y) 209 self.dx= numpy.array(sans_data1d.dx) 210 self.dy= numpy.array(sans_data1d.dy) 211 212 213 if self.dy ==None or len(self.dy)==0: 214 self.res_dy= numpy.zeros(len(self.y)) 215 else: 216 self.res_dy= copy.deepcopy(self.dy) 217 self.res_dy= numpy.asarray(self.res_dy) 218 219 self.res_dy[self.res_dy==0]=1 212 220 ## Min Q-value 213 221 #Skip the Q=0 point, especially when y(q=0)=None at x[0]. … … 218 226 ## Max Q-value 219 227 self.qmax= max (self.data.x) 220 221 228 229 222 230 def setFitRange(self,qmin=None,qmax=None): 223 231 """ to set the fit range""" 224 225 232 # Skip Q=0 point, (especially for y(q=0)=None at x[0]). 226 233 #ToDo: Fix this. … … 232 239 if qmax !=None: 233 240 self.qmax = qmax 234 241 235 242 236 243 def getFitRange(self): … … 242 249 243 250 def residuals(self, fn): 244 """ 245 Compute residuals. 246 247 If self.smearer has been set, use if to smear 248 the data before computing chi squared. 249 250 @param fn: function that return model value 251 @return residuals 252 """ 253 x,y = [numpy.asarray(v) for v in (self.x,self.y)] 254 if self.dy ==None or self.dy==[]: 255 dy= numpy.zeros(len(y)) 256 else: 257 dy= copy.deepcopy(self.dy) 258 dy= numpy.asarray(dy) 259 260 dy[dy==0]=1 261 251 """ 252 Compute residuals. 253 254 If self.smearer has been set, use if to smear the data before computing chi squared. 255 256 @param fn: function that return model value @return residuals """ 257 # Get the indices of the selected range 258 idx = (self.x>=self.qmin) & (self.x <= self.qmax) 259 262 260 # Compute theory data f(x) 263 tempy=[] 264 fx=numpy.zeros(len(y)) 265 tempdy=[] 266 index=[] 267 tempfx=[] 268 for i_x in range(len(x)): 261 newy = numpy.zeros(len(self.x)) 262 newfx= numpy.zeros(len(self.x)) 263 newdy= numpy.zeros(len(self.x)) 264 265 for i_x in range(len(self.x)): 269 266 try: 270 if self.qmin <=x[i_x] and x[i_x]<=self.qmax:271 value= fn(x[i_x])272 fx[i_x] =value273 tempy.append(y[i_x])274 tempdy.append(dy[i_x])275 index.append(i_x)267 # Skip the selection here since we want all the contribution from the theory bins #if self.qmin <=x[i_x] and x[i_x]<=self.qmax: 268 value = fn(self.x[i_x]) 269 newfx[i_x] = value 270 newy[i_x] = self.y[i_x] 271 newdy[i_x] = self.res_dy[i_x] 272 276 273 except: 277 274 ## skip error for model.run(x) 278 275 pass 279 276 280 277 ## Smear theory data 281 278 if self.smearer is not None: 282 fx = self.smearer(fx) 283 284 for i in index: 285 tempfx.append(fx[i]) 279 280 newfx = self.smearer(newfx) 286 281 287 newy= numpy.asarray(tempy)288 newfx= numpy.asarray(tempfx)289 newdy= numpy.asarray(tempdy)290 291 282 ## Sanity check 292 283 if numpy.size(newdy)!= numpy.size(newfx): 293 284 raise RuntimeError, "FitData1D: invalid error array" 294 295 return (newy- newfx)/newdy296 297 298 285 286 # Sum over the selected range 287 return (newy[idx]- newfx[idx])/newdy[idx] 288 289 299 290 def residuals_deriv(self, model, pars=[]): 300 291 """ … … 637 628 """ 638 629 return self.selected 639 640 641 642
Note: See TracChangeset
for help on using the changeset viewer.