예제 #1
0
def run_test(_fld, _seeds, plot2d=True, plot3d=True, title="", show=False, **kwargs):
    lines, topo = viscid.calc_streamlines(_fld, _seeds, **kwargs)
    topo_color = viscid.topology2color(topo)

    # downsample lines for plotting
    lines = [line[:, ::8] for line in lines]

    try:
        if not plot2d:
            raise ImportError
        from viscid.plot import mpl

        mpl.plt.clf()

        mpl.plot2d_lines(lines, scalars=topo_color, symdir="y", marker="^")
        if title:
            mpl.plt.title(title)

        mpl.plt.savefig(next_plot_fname(__file__, series="2d"))
        if show:
            mpl.plt.show()
    except ImportError:
        pass

    try:
        if not plot3d:
            raise ImportError
        from viscid.plot import mvi

        try:
            fig = _global_ns["figure"]
            mvi.clf()
        except KeyError:
            fig = mvi.figure(size=[1200, 800], offscreen=not show)
            _global_ns["figure"] = fig

        fld_mag = np.log(viscid.magnitude(_fld))
        try:
            # note: mayavi.mlab.mesh can't take color tuples as scalars
            #       so one can't use topo_color on a mesh surface. This
            #       is a limitation of mayavi. To actually plot a specific
            #       set of colors on a mesh, one must use a texture
            mesh = mvi.mesh_from_seeds(_seeds, scalars=topo, opacity=0.6)
            mesh.actor.property.backface_culling = True
        except RuntimeError:
            pass
        mvi.plot_lines(lines, scalars=fld_mag, tube_radius=0.01, cmap="viridis")
        if title:
            mvi.title(title)

        mvi.savefig(next_plot_fname(__file__, series="3d"))
        if show:
            mvi.show()

    except ImportError:
        pass
예제 #2
0
def run_test(_fld, _seeds, plot2d=True, plot3d=True, show=False, **kwargs):
    lines, topo = viscid.calc_streamlines(_fld, _seeds, **kwargs)
    topo_fld = _seeds.wrap_field(topo)
    topo_color = viscid.topology2color(topo)

    # downsample lines for plotting
    lines = [line[:, ::8] for line in lines]

    try:
        if not plot2d:
            raise ImportError
        from viscid.plot import mpl

        mpl.plt.clf()

        mpl.plot2d_lines(lines, scalars=topo_color, symdir="y", marker="^")
        if show:
            mpl.plt.show()
    except ImportError:
        pass

    try:
        if not plot3d:
            raise ImportError
        from viscid.plot import mvi

        mvi.clf()

        fld_mag = np.log(viscid.magnitude(_fld))
        try:
            # note: mayavi.mlab.mesh can't take color tuples as scalars
            #       so one can't use topo_color on a mesh surface. This
            #       is a limitation of mayavi. To actually plot a specific
            #       set of colors on a mesh, one must use a texture
            vertices, scalars = _seeds.wrap_mesh(topo_fld.data)
            mesh = mvi.mlab.mesh(vertices[0], vertices[1], vertices[2], scalars=scalars, opacity=0.5)
            mesh.actor.property.backface_culling = True
        except RuntimeError:
            pass
        mvi.plot_lines(lines, scalars=fld_mag, tube_radius=0.005)
        if show:
            mvi.show()

    except ImportError:
        pass