Changeset 1511a60c in sasmodels
- Timestamp:
- Jan 31, 2019 10:06:17 AM (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:
- b1c49601
- Parents:
- 5f12750
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
sasmodels/jitter.py
r5f12750 r1511a60c 52 52 from numpy import pi, cos, sin, sqrt, exp, degrees, radians 53 53 54 def draw_beam(axes, view=(0, 0), alpha=0.5 ):54 def draw_beam(axes, view=(0, 0), alpha=0.5, steps=6): 55 55 """ 56 56 Draw the beam going from source at (0, 0, 1) to detector at (0, 0, -1) … … 59 59 #axes.scatter([0]*100,[0]*100,np.linspace(1, -1, 100), alpha=alpha) 60 60 61 steps = [6, 6] 62 u = np.linspace(0, 2 * np.pi, steps[0]) 63 v = np.linspace(-1, 1, steps[1]) 61 u = np.linspace(0, 2 * np.pi, steps) 62 v = np.linspace(-1, 1, 2) 64 63 65 64 r = 0.02 … … 73 72 points = Rz(phi)*Ry(theta)*points 74 73 x, y, z = [v.reshape(shape) for v in points] 75 76 74 axes.plot_surface(x, y, z, color='yellow', alpha=alpha) 75 76 # TODO: draw endcaps on beam 77 ## Draw tiny balls on the end will work 78 #draw_sphere(axes, radius=0.02, center=(0, 0, 1.3), color='yellow') 79 #draw_sphere(axes, radius=0.02, center=(0, 0, -1.3), color='yellow') 80 ## The following does not work 81 #triangles = [(0, i+1, i+2) for i in range(steps-2)] 82 #x_cap, y_cap = x[:, 0], y[:, 0] 83 #for z_cap in z[:, 0], z[:, -1]: 84 # axes.plot_trisurf(x_cap, y_cap, z_cap, triangles, 85 # color='yellow', alpha=alpha) 86 77 87 78 88 def draw_ellipsoid(axes, size, view, jitter, steps=25, alpha=1): … … 155 165 return atoms 156 166 157 def draw_parallelepiped(axes, size, view, jitter, steps=None, alpha=1): 167 def draw_box(axes, size, view): 168 a, b, c = size 169 x = a*np.array([+1, -1, +1, -1, +1, -1, +1, -1]) 170 y = b*np.array([+1, +1, -1, -1, +1, +1, -1, -1]) 171 z = c*np.array([+1, +1, +1, +1, -1, -1, -1, -1]) 172 x, y, z = transform_xyz(view, None, x, y, z) 173 def draw(i, j): 174 axes.plot([x[i],x[j]], [y[i], y[j]], [z[i], z[j]], color='black') 175 draw(0, 1) 176 draw(0, 2) 177 draw(0, 3) 178 draw(7, 4) 179 draw(7, 5) 180 draw(7, 6) 181 182 def draw_parallelepiped(axes, size, view, jitter, steps=None, 183 color=(0.6, 1.0, 0.6), alpha=1): 158 184 """Draw a parallelepiped.""" 159 185 a, b, c = size … … 173 199 174 200 x, y, z = transform_xyz(view, jitter, x, y, z) 175 color = [0.6, 1, 0.6] # pale green176 201 axes.plot_trisurf(x, y, triangles=tri, Z=z, color=color, alpha=alpha) 177 202 … … 181 206 # rotate that face. 182 207 if 0: 183 #color = [1, 0.6, 0.6]# pink208 color = (1, 0.6, 0.6) # pink 184 209 x = a*np.array([+1, -1, +1, -1, +1, -1, +1, -1]) 185 210 y = b*np.array([+1, +1, -1, -1, +1, +1, -1, -1]) … … 197 222 ]) 198 223 199 def draw_sphere(axes, radius=0.5, steps=25 ):224 def draw_sphere(axes, radius=0.5, steps=25, center=(0,0,0), color='w'): 200 225 """Draw a sphere""" 201 226 u = np.linspace(0, 2 * np.pi, steps) 202 227 v = np.linspace(0, np.pi, steps) 203 228 204 x = radius * np.outer(np.cos(u), np.sin(v)) 205 y = radius * np.outer(np.sin(u), np.sin(v)) 206 z = radius * np.outer(np.ones(np.size(u)), np.cos(v)) 207 axes.plot_surface(x, y, z, color= 'w')229 x = radius * np.outer(np.cos(u), np.sin(v)) + center[0] 230 y = radius * np.outer(np.sin(u), np.sin(v)) + center[1] 231 z = radius * np.outer(np.ones(np.size(u)), np.cos(v)) + center[2] 232 axes.plot_surface(x, y, z, color=color) 208 233 #axes.plot_wireframe(x, y, z) 234 235 def draw_axes(axes, origin=(-1, -1, -1), length=(2, 2, 2)): 236 x, y, z = origin 237 dx, dy, dz = length 238 axes.plot([x, x+dx], [y, y], [z, z], color='black') 239 axes.plot([x, x], [y, y+dy], [z, z], color='black') 240 axes.plot([x, x], [y, y], [z, z+dz], color='black') 209 241 210 242 def draw_person_on_sphere(axes, view, height=0.5, radius=0.5): … … 273 305 limit = base*delta 274 306 if views is None: 275 n = max(3, min(25, 2*int(base*delta/ 15)))307 n = max(3, min(25, 2*int(base*delta/5))) 276 308 else: 277 309 n = views … … 752 784 #qx, qy = np.meshgrid(qx, qy) 753 785 if 0: 786 from matplotlib import cm 754 787 level = np.asarray(255*(Iqxy - vmin)/(vmax - vmin), 'i') 755 788 level[level < 0] = 0 756 789 colors = plt.get_cmap()(level) 757 axes.plot_surface(qx, qy, -1.1, facecolors=colors) 790 #colors = cm.coolwarm(level) 791 #colors = cm.gist_yarg(level) 792 x, y = np.meshgrid(qx/qx.max(), qy/qy.max()) 793 axes.plot_surface(x, y, -1.1*np.ones_like(x), facecolors=colors) 758 794 elif 1: 759 795 axes.contourf(qx/qx.max(), qy/qy.max(), Iqxy, zdir='z', offset=-1.1, … … 1081 1117 kw['color'] = color 1082 1118 1083 1084 def ipv_plot(calculator, draw_shape, size, view, jitter, dist, mesh, projection): 1085 import ipywidgets as widgets 1119 def ipv_axes(): 1086 1120 import ipyvolume as ipv 1087 1121 … … 1092 1126 ipv.plot(x, y, z, **kw) 1093 1127 def plot_surface(self, x, y, z, **kw): 1128 facecolors = kw.pop('facecolors', None) 1129 if facecolors is not None: 1130 kw['color'] = facecolors 1094 1131 ipv_fix_color(kw) 1095 1132 x, y, z = make_vec(x, y, z) … … 1133 1170 def set_axis_off(self): 1134 1171 ipv.style.axes_off() 1135 axes = Plotter() 1136 1172 return Plotter() 1173 1174 def ipv_plot(calculator, draw_shape, size, view, jitter, dist, mesh, projection): 1175 import ipywidgets as widgets 1176 import ipyvolume as ipv 1177 1178 axes = ipv_axes() 1137 1179 1138 1180 def draw(view, jitter): … … 1160 1202 draw_jitter(axes, view, jitter, dist=dist, size=size, 1161 1203 draw_shape=draw_shape, projection=projection) 1162 #draw_mesh(axes, view, jitter, dist=dist, n=mesh, projection=projection)1163 #draw_scattering(calculator, axes, view, jitter, dist=dist)1204 draw_mesh(axes, view, jitter, dist=dist, n=mesh, radius=0.95, projection=projection) 1205 draw_scattering(calculator, axes, view, jitter, dist=dist) 1164 1206 1207 draw_axes(axes, origin=(-1, -1, -1.1)) 1165 1208 ipv.style.box_off() 1166 #ipv.style.axes_off()1209 ipv.style.axes_off() 1167 1210 ipv.xyzlabel(" ", " ", " ") 1168 1211
Note: See TracChangeset
for help on using the changeset viewer.