Changeset 1511a60c in sasmodels


Ignore:
Timestamp:
Jan 31, 2019 8:06:17 AM (5 years ago)
Author:
Paul Kienzle <pkienzle@…>
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
Message:

more jitter plot tweaks to help with euler angle figures

File:
1 edited

Legend:

Unmodified
Added
Removed
  • sasmodels/jitter.py

    r5f12750 r1511a60c  
    5252from numpy import pi, cos, sin, sqrt, exp, degrees, radians 
    5353 
    54 def draw_beam(axes, view=(0, 0), alpha=0.5): 
     54def draw_beam(axes, view=(0, 0), alpha=0.5, steps=6): 
    5555    """ 
    5656    Draw the beam going from source at (0, 0, 1) to detector at (0, 0, -1) 
     
    5959    #axes.scatter([0]*100,[0]*100,np.linspace(1, -1, 100), alpha=alpha) 
    6060 
    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) 
    6463 
    6564    r = 0.02 
     
    7372    points = Rz(phi)*Ry(theta)*points 
    7473    x, y, z = [v.reshape(shape) for v in points] 
    75  
    7674    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 
    7787 
    7888def draw_ellipsoid(axes, size, view, jitter, steps=25, alpha=1): 
     
    155165    return atoms 
    156166 
    157 def draw_parallelepiped(axes, size, view, jitter, steps=None, alpha=1): 
     167def 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 
     182def draw_parallelepiped(axes, size, view, jitter, steps=None,  
     183                        color=(0.6, 1.0, 0.6), alpha=1): 
    158184    """Draw a parallelepiped.""" 
    159185    a, b, c = size 
     
    173199 
    174200    x, y, z = transform_xyz(view, jitter, x, y, z) 
    175     color = [0.6, 1, 0.6]  # pale green 
    176201    axes.plot_trisurf(x, y, triangles=tri, Z=z, color=color, alpha=alpha) 
    177202 
     
    181206    # rotate that face. 
    182207    if 0: 
    183         #color = [1, 0.6, 0.6]  # pink 
     208        color = (1, 0.6, 0.6)  # pink 
    184209        x = a*np.array([+1, -1, +1, -1, +1, -1, +1, -1]) 
    185210        y = b*np.array([+1, +1, -1, -1, +1, +1, -1, -1]) 
     
    197222    ]) 
    198223 
    199 def draw_sphere(axes, radius=0.5, steps=25): 
     224def draw_sphere(axes, radius=0.5, steps=25, center=(0,0,0), color='w'): 
    200225    """Draw a sphere""" 
    201226    u = np.linspace(0, 2 * np.pi, steps) 
    202227    v = np.linspace(0, np.pi, steps) 
    203228 
    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) 
    208233    #axes.plot_wireframe(x, y, z) 
     234 
     235def 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') 
    209241 
    210242def draw_person_on_sphere(axes, view, height=0.5, radius=0.5): 
     
    273305        limit = base*delta 
    274306        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))) 
    276308        else: 
    277309            n = views 
     
    752784    #qx, qy = np.meshgrid(qx, qy) 
    753785    if 0: 
     786        from matplotlib import cm 
    754787        level = np.asarray(255*(Iqxy - vmin)/(vmax - vmin), 'i') 
    755788        level[level < 0] = 0 
    756789        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) 
    758794    elif 1: 
    759795        axes.contourf(qx/qx.max(), qy/qy.max(), Iqxy, zdir='z', offset=-1.1, 
     
    10811117        kw['color'] = color 
    10821118 
    1083  
    1084 def ipv_plot(calculator, draw_shape, size, view, jitter, dist, mesh, projection): 
    1085     import ipywidgets as widgets 
     1119def ipv_axes(): 
    10861120    import ipyvolume as ipv 
    10871121 
     
    10921126            ipv.plot(x, y, z, **kw) 
    10931127        def plot_surface(self, x, y, z, **kw): 
     1128            facecolors = kw.pop('facecolors', None) 
     1129            if facecolors is not None: 
     1130                kw['color'] = facecolors  
    10941131            ipv_fix_color(kw) 
    10951132            x, y, z = make_vec(x, y, z) 
     
    11331170        def set_axis_off(self): 
    11341171            ipv.style.axes_off() 
    1135     axes = Plotter() 
    1136  
     1172    return Plotter() 
     1173 
     1174def 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() 
    11371179 
    11381180    def draw(view, jitter): 
     
    11601202        draw_jitter(axes, view, jitter, dist=dist, size=size,  
    11611203                    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) 
    11641206     
     1207        draw_axes(axes, origin=(-1, -1, -1.1)) 
    11651208        ipv.style.box_off() 
    1166         #ipv.style.axes_off() 
     1209        ipv.style.axes_off() 
    11671210        ipv.xyzlabel(" ", " ", " ") 
    11681211 
Note: See TracChangeset for help on using the changeset viewer.