Changeset 00d3528 in sasview
- Timestamp:
- Mar 12, 2010 11:20:32 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:
- edb30b66
- Parents:
- e575db9
- Location:
- theoryview/perspectives/theory
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
theoryview/perspectives/theory/model_thread.py
r0277d084 r00d3528 25 25 self.qmax= qmax 26 26 self.qstep= qstep 27 # Reshape dimensions of x and y to call evalDistribution 28 #self.x_array = numpy.reshape(x,[len(x),1]) 29 #self.y_array = numpy.reshape(y,[1,len(y)]) 30 self.x_array = numpy.reshape(x,[1,len(x)]) 31 self.y_array = numpy.reshape(y,[len(y),1]) 32 # Numpy array of dimensions 1 used for model.run method 33 self.x= numpy.array(x) 34 self.y= numpy.array(y) 27 28 self.x = x 29 self.y = y 35 30 self.data= data 36 # the model on to calculate37 31 self.model = model 38 32 self.starttime = 0 … … 51 45 newy= math.pow(max(math.fabs(self.data.ymax),math.fabs(self.data.ymin)),2) 52 46 self.qmax=math.sqrt( newx + newy ) 53 # Define matrix where data will be plotted 54 radius= numpy.sqrt( self.x_array**2 + self.y_array**2 ) 55 index_data= (self.qmin<= radius) 56 index_model = (self.qmin <= radius)&(radius<= self.qmax) 57 58 output = numpy.zeros((len(self.x),len(self.y))) 59 60 ## receive only list of 2 numpy array 61 ## One must reshape to vertical and the other to horizontal 62 value = self.model.evalDistribution([self.x_array,self.y_array] ) 63 ## for data ignore the qmax 64 if self.data == None: 47 48 if self.data != None: 49 self.qx_data = self.data.qx_data 50 self.qy_data = self.data.qy_data 51 self.mask = self.data.mask 52 else: 53 xbin = numpy.linspace(start= -1*self.qmax, 54 stop= self.qmax, 55 num= self.qstep, 56 endpoint=True ) 57 ybin = numpy.linspace(start= -1*self.qmax, 58 stop= self.qmax, 59 num= self.qstep, 60 endpoint=True ) 61 62 new_xbin = numpy.tile(xbin, (len(ybin),1)) 63 new_ybin = numpy.tile(ybin, (len(xbin),1)) 64 new_ybin = new_ybin.swapaxes(0,1) 65 new_xbin = new_xbin.flatten() 66 new_ybin = new_ybin.flatten() 67 self.qy_data = new_ybin 68 self.qx_data = new_xbin 69 70 self.mask = numpy.ones(len(self.qx_data),dtype=bool) 71 72 # Define matrix where data will be plotted 73 radius= numpy.sqrt( self.qx_data*self.qx_data + self.qy_data*self.qy_data ) 74 index_data= (self.qmin<= radius)&(self.mask) 75 76 # For theory, qmax is based on 1d qmax 77 # so that must be mulitified by sqrt(2) to get actual max for 2d 78 index_model = ((self.qmin <= radius)&(radius<= self.qmax)) 79 self.mask = (index_model)&(self.mask) 80 81 if self.data ==None: 65 82 # Only qmin value will be consider for the detector 66 output = value *index_data 67 else: 68 # The user can define qmin and qmax for the detector 69 output = index_model*value 70 83 self.mask = index_data 84 85 value = self.model.evalDistribution([self.qx_data[self.mask],self.qy_data[self.mask]] ) 86 87 output = numpy.zeros(len(self.mask)) 88 output[self.mask] = value 89 71 90 elapsed = time.time()-self.starttime 72 91 self.complete( image = output, … … 75 94 elapsed = elapsed, 76 95 qmin = self.qmin, 77 qmax = self.qmax,96 qmax = self.qmax, 78 97 qstep = self.qstep ) 79 98 -
theoryview/perspectives/theory/theory.py
r0277d084 r00d3528 198 198 num= qstep, 199 199 endpoint=True ) 200 200 201 ## use data info instead 201 202 if data !=None: … … 205 206 x= data.x_bins 206 207 y= data.y_bins 207 208 208 209 if not enable2D: 209 210 return … … 298 299 299 300 detector = Detector() 300 theory.detector.append(detector) 301 302 theory.detector[0].distance=1e+32 301 theory.detector.append(detector) 303 302 theory.source= Source() 304 theory.source.wavelength=2*math.pi/1e+32 305 306 ## Create detector for Model 2D 307 xmax=2*theory.detector[0].distance*math.atan(\ 308 qmax/(4*math.pi/theory.source.wavelength)) 309 310 theory.detector[0].pixel_size.x= xmax/(qstep/2-0.5) 311 theory.detector[0].pixel_size.y= xmax/(qstep/2-0.5) 303 304 ## Default values 305 theory.detector[0].distance= 8000 # mm 306 theory.source.wavelength= 6 # A 307 theory.detector[0].pixel_size.x= 5 # mm 308 theory.detector[0].pixel_size.y= 5 # mm 309 312 310 theory.detector[0].beam_center.x= qmax 313 311 theory.detector[0].beam_center.y= qmax 312 313 314 314 ## create x_bins and y_bins of the model 2D 315 distance = theory.detector[0].distance316 pixel = qstep/2-1317 theta = pixel / distance / qstep#100.0318 wavelength = theory.source.wavelength319 315 pixel_width_x = theory.detector[0].pixel_size.x 320 316 pixel_width_y = theory.detector[0].pixel_size.y 321 317 center_x = theory.detector[0].beam_center.x/pixel_width_x 322 318 center_y = theory.detector[0].beam_center.y/pixel_width_y 323 324 325 size_x, size_y= numpy.shape(theory.data) 326 for i_x in range(size_x): 327 theta = (i_x-center_x)*pixel_width_x / distance 328 qx = 4.0*math.pi/wavelength * math.tan(theta/2.0) 329 theory.x_bins.append(qx) 330 for i_y in range(size_y): 331 theta = (i_y-center_y)*pixel_width_y / distance 332 qy =4.0*math.pi/wavelength * math.tan(theta/2.0) 333 theory.y_bins.append(qy) 334 319 320 # theory default: assume the beam center is located at the center of sqr detector 321 xmax = qmax 322 xmin = -qmax 323 ymax = qmax 324 ymin = -qmax 325 326 x= numpy.linspace(start= -1*qmax, 327 stop= qmax, 328 num= qstep, 329 endpoint=True ) 330 y = numpy.linspace(start= -1*qmax, 331 stop= qmax, 332 num= qstep, 333 endpoint=True ) 334 335 ## use data info instead 336 new_x = numpy.tile(x, (len(y),1)) 337 new_y = numpy.tile(y, (len(x),1)) 338 new_y = new_y.swapaxes(0,1) 339 340 # all data reuire now in 1d array 341 qx_data = new_x.flatten() 342 qy_data = new_y.flatten() 343 344 q_data = numpy.sqrt(qx_data*qx_data+qy_data*qy_data) 345 # set all True (standing for unmasked) as default 346 mask = numpy.ones(len(qx_data), dtype = bool) 347 348 # calculate the range of qx and qy: this way, it is a little more independent 349 x_size = xmax- xmin 350 y_size = ymax -ymin 351 352 # store x and y bin centers in q space 353 x_bins = x 354 y_bins = y 355 # bin size: x- & y-directions 356 xstep = x_size/len(x_bins-1) 357 ystep = y_size/len(y_bins-1) 358 359 #theory.data = numpy.zeros(len(mask)) 360 theory.err_data = numpy.zeros(len(mask)) 361 theory.qx_data = qx_data 362 theory.qy_data = qy_data 363 theory.q_data = q_data 364 theory.mask = mask 365 theory.x_bins = x_bins 366 theory.y_bins = y_bins 367 368 # max and min taking account of the bin sizes 369 theory.xmin= xmin - xstep/2 370 theory.xmax= xmax + xstep/2 371 theory.ymin= ymin - ystep/2 372 theory.ymax= ymax + ystep/2 335 373 theory.group_id ="Model" 336 374 theory.id ="Model" 337 ## determine plot boundaries338 theory.xmin= -qmax339 theory.xmax= qmax340 theory.ymin= -qmax341 theory.ymax= qmax342 375 343 376 … … 421 454 that can be plot. 422 455 """ 423 424 425 456 err_image = numpy.zeros(numpy.shape(image)) 426 457 427 458 theory= Data2D(image= image , err_image= err_image) 428 459 theory.name= model.name 429 460 430 461 if data ==None: 431 462 self._fill_default_model2D(theory= theory, qmax=qmax,qstep=qstep, qmin= qmin) … … 439 470 theory.source= data.source 440 471 theory.is_data =False 472 theory.qx_data = data.qx_data 473 theory.qy_data = data.qy_data 474 theory.q_data = data.q_data 475 theory.err_data = data.err_data 476 theory.mask = data.mask 441 477 ## plot boundaries 442 478 theory.ymin= data.ymin … … 444 480 theory.xmin= data.xmin 445 481 theory.xmax= data.xmax 446 447 482 448 483 ## plot
Note: See TracChangeset
for help on using the changeset viewer.