Changeset b3703f5 in sasmodels for sasmodels/jitter.py
- Timestamp:
- Mar 26, 2018 5:50:35 PM (6 years ago)
- Branches:
- master, core_shell_microgels, magnetic_model, ticket-1257-vesicle-product, ticket_1156, ticket_1265_superball, ticket_822_more_unit_tests
- Children:
- c11d09f, c462169
- Parents:
- 802c412
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
sasmodels/jitter.py
r802c412 rb3703f5 99 99 _draw_crystal(axes, size, view, jitter, atoms=atoms) 100 100 101 def _draw_crystal(axes, size, view, jitter, steps=None, alpha=1,atoms=None):101 def _draw_crystal(axes, size, view, jitter, atoms=None): 102 102 atoms, size = np.asarray(atoms, 'd').T, np.asarray(size, 'd') 103 103 x, y, z = atoms*size[:, None] … … 298 298 # TODO: try Kent distribution instead of a gaussian warped by projection 299 299 300 t= np.linspace(-1, 1, n)301 weights = np.ones_like( t)300 dist_x = np.linspace(-1, 1, n) 301 weights = np.ones_like(dist_x) 302 302 if dist == 'gaussian': 303 t*= 3304 weights = exp(-0.5* t**2)303 dist_x *= 3 304 weights = exp(-0.5*dist_x**2) 305 305 elif dist == 'rectangle': 306 306 # Note: uses sasmodels ridiculous definition of rectangle width 307 t*= sqrt(3)307 dist_x *= sqrt(3) 308 308 elif dist == 'uniform': 309 309 pass … … 392 392 z = np.matrix([[0], [0], [radius]]) 393 393 points = np.hstack([_rotate(theta_i, phi_j)*z 394 for theta_i in dtheta* t395 for phi_j in dphi* t])396 w = np.array([_weight(theta_i, phi_j, w_i, w_j)397 for w_i, theta_i in zip(weights, dtheta*t)398 for w_j, phi_j in zip(weights, dphi*t)])399 #print(max( w), min(w), min(w[w>0]))400 points = points[:, w > 0]401 w = w[w > 0]402 w /= max(w)394 for theta_i in dtheta*dist_x 395 for phi_j in dphi*dist_x]) 396 dist_w = np.array([_weight(theta_i, phi_j, w_i, w_j) 397 for w_i, theta_i in zip(weights, dtheta*dist_x) 398 for w_j, phi_j in zip(weights, dphi*dist_x)]) 399 #print(max(dist_w), min(dist_w), min(dist_w[dist_w > 0])) 400 points = points[:, dist_w > 0] 401 dist_w = dist_w[dist_w > 0] 402 dist_w /= max(dist_w) 403 403 404 404 # rotate relative to beam … … 407 407 x, y, z = [np.array(v).flatten() for v in points] 408 408 #plt.figure(2); plt.clf(); plt.hist(z, bins=np.linspace(-1, 1, 51)) 409 axes.scatter(x, y, z, c= w, marker='o', vmin=0., vmax=1.)409 axes.scatter(x, y, z, c=dist_w, marker='o', vmin=0., vmax=1.) 410 410 411 411 def draw_labels(axes, view, jitter, text): … … 430 430 """Construct a matrix to rotate points about *x* by *angle* degrees.""" 431 431 angle = radians(angle) 432 R= [[1, 0, 0],433 [0, +cos(angle), -sin(angle)],434 [0, +sin(angle), +cos(angle)]]435 return np.matrix( R)432 rot = [[1, 0, 0], 433 [0, +cos(angle), -sin(angle)], 434 [0, +sin(angle), +cos(angle)]] 435 return np.matrix(rot) 436 436 437 437 def Ry(angle): 438 438 """Construct a matrix to rotate points about *y* by *angle* degrees.""" 439 439 angle = radians(angle) 440 R= [[+cos(angle), 0, +sin(angle)],441 [0, 1, 0],442 [-sin(angle), 0, +cos(angle)]]443 return np.matrix( R)440 rot = [[+cos(angle), 0, +sin(angle)], 441 [0, 1, 0], 442 [-sin(angle), 0, +cos(angle)]] 443 return np.matrix(rot) 444 444 445 445 def Rz(angle): 446 446 """Construct a matrix to rotate points about *z* by *angle* degrees.""" 447 447 angle = radians(angle) 448 R= [[+cos(angle), -sin(angle), 0],449 [+sin(angle), +cos(angle), 0],450 [0, 0, 1]]451 return np.matrix( R)448 rot = [[+cos(angle), -sin(angle), 0], 449 [+sin(angle), +cos(angle), 0], 450 [0, 0, 1]] 451 return np.matrix(rot) 452 452 453 453 def transform_xyz(view, jitter, x, y, z): … … 564 564 elif 1: 565 565 axes.contourf(qx/qx.max(), qy/qy.max(), Iqxy, zdir='z', offset=-1.1, 566 levels=np.linspace(vmin, vmax, 24))566 levels=np.linspace(vmin, vmax, 24)) 567 567 else: 568 568 axes.pcolormesh(qx, qy, Iqxy) … … 583 583 for details. 584 584 """ 585 from sasmodels.core import load_model_info, build_model 585 from sasmodels.core import load_model_info, build_model as build_sasmodel 586 586 from sasmodels.data import empty_data2D 587 587 from sasmodels.direct_model import DirectModel 588 588 589 589 model_info = load_model_info(model_name) 590 model = build_ model(model_info) #, dtype='double!')590 model = build_sasmodel(model_info) #, dtype='double!') 591 591 q = np.linspace(-qmax, qmax, n) 592 592 data = empty_data2D(q, q)
Note: See TracChangeset
for help on using the changeset viewer.