Changeset 226473d in sasmodels
- Timestamp:
- Jan 9, 2018 6:12:14 PM (7 years ago)
- Branches:
- master, core_shell_microgels, magnetic_model, ticket-1257-vesicle-product, ticket_1156, ticket_1265_superball, ticket_822_more_unit_tests
- Children:
- 2ab331f
- Parents:
- 5fb0634
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
explore/realspace.py
ra1c32c2 r226473d 44 44 """ 45 45 return Rx(phi)*Ry(theta)*Rz(psi) 46 47 def apply_view(points, view): 48 """ 49 Apply the view transform (theta, phi, psi) to a set of points. 50 51 Points are stored in a 3 x n numpy array. 52 53 View angles are in degrees. 54 """ 55 theta, phi, psi = view 56 return np.asarray((Rz(phi)*Ry(theta)*Rz(psi))*np.matrix(points.T)).T 57 58 59 def invert_view(qx, qy, view): 60 """ 61 Return (qa, qb, qc) for the (theta, phi, psi) view angle at detector 62 pixel (qx, qy). 63 64 View angles are in degrees. 65 """ 66 theta, phi, psi = view 67 q = np.vstack((qx.flatten(), qy.flatten(), 0*qx.flatten())) 68 return np.asarray((Rz(-psi)*Ry(-theta)*Rz(-phi))*np.matrix(q)) 69 46 70 47 71 class Shape: … … 219 243 values = self.value.repeat(points.shape[0]) 220 244 return values, self._adjust(points) 245 246 def calc_Iqxy(qx, qy, rho, points, volume=1, view=(0, 0, 0)): 247 x, y, z = points.T 248 qx, qy = np.broadcast_arrays(qx, qy) 249 qa, qb, qc = invert_view(qx, qy, view) 250 rho, volume = np.broadcast_arrays(rho, volume) 251 values = rho*volume 252 253 # I(q) = |sum V(r) rho(r) e^(1j q.r)|^2 / sum V(r) 254 Iq = [abs(np.sum(values*np.exp(1j*(qa_k*x + qb_k*y + qc_k*z))))**2 255 for qa_k, qb_k, qc_k in zip(qa.flat, qb.flat, qc.flat)] 256 return np.array(Iq).reshape(qx.shape) / np.sum(volume) 221 257 222 258 def _calc_Pr_nonuniform(r, rho, points): … … 333 369 plt.legend() 334 370 371 def plot_calc_2d(qx, qy, Iqxy, theory=None): 372 import matplotlib.pyplot as plt 373 qx, qy = bin_edges(qx), bin_edges(qy) 374 #qx, qy = np.meshgrid(qx, qy) 375 if theory is not None: 376 plt.subplot(121) 377 plt.pcolormesh(qx, qy, np.log10(Iqxy)) 378 plt.xlabel('qx (1/A)') 379 plt.ylabel('qy (1/A)') 380 if theory is not None: 381 plt.subplot(122) 382 plt.pcolormesh(qx, qy, np.log10(theory)) 383 plt.xlabel('qx (1/A)') 384 335 385 def plot_points(rho, points): 336 386 import mpl_toolkits.mplot3d … … 373 423 Iq = Iq/Iq[0] 374 424 return Iq 425 426 def cylinder_Iqxy(qx, qy, radius, length, view=(0, 0, 0)): 427 qa, qb, qc = invert_view(qx, qy, view) 428 qab = np.sqrt(qa**2 + qb**2) 429 Fq = sas_2J1x_x(qab*radius) * j0(qc*length/2) 430 Iq = Fq**2 431 return Iq.reshape(qx.shape) 375 432 376 433 def sphere_Iq(q, radius): … … 430 487 pylab.show() 431 488 489 def check_shape_2d(shape, fn=None, view=(0, 0, 0)): 490 rho_solvent = 0 491 qx = qy = np.linspace(-1, 1, 100) 492 Qx, Qy = np.meshgrid(qx, qy) 493 sampling_density = 50000 / shape.volume() 494 rho, points = shape.sample(sampling_density) 495 Iqxy = calc_Iqxy(Qx, Qy, rho, points, view=view) 496 Iqxy += 0.001 * Iqxy.max() 497 theory = fn(Qx, Qy)+0.001 if fn is not None else None 498 499 import pylab 500 plot_calc_2d(qx, qy, Iqxy, theory=theory) 501 pylab.show() 502 432 503 def check_cylinder(radius=25, length=125, rho=2.): 433 504 shape = EllipticalCylinder(radius, radius, length, rho) 434 505 fn = lambda q: cylinder_Iq(q, radius, length) 435 506 check_shape(shape, fn) 507 508 def check_cylinder_2d(radius=25, length=125, rho=2., view=(0, 0, 0)): 509 shape = EllipticalCylinder(radius, radius, length, rho) 510 fn = lambda qx, qy, view=view: cylinder_Iqxy(qx, qy, radius, length, view=view) 511 check_shape_2d(shape, fn, view=view) 436 512 437 513 def check_sphere(radius=125, rho=2): … … 454 530 if __name__ == "__main__": 455 531 check_cylinder(radius=10, length=40) 532 #check_cylinder_2d(radius=10, length=40, view=(90,30,0)) 456 533 #check_sphere() 457 534 #check_csbox()
Note: See TracChangeset
for help on using the changeset viewer.