def PlotResultsFlow(results, onSurf = False): x, y = np.mgrid[0:512, 0:512] w = np.zeros((512, 512)) if onSurf: return mlab.flow(x, y, results['combineMap'], results['sU'], results['sV'], results['combineMap']) else: return mlab.flow(results['sU'], results['sV'], w, seed_resolution=100, seed_scale=1.0)
def do(self): ############################################################ # Imports. from enthought.mayavi import mlab ############################################################ # Create a new scene and set up the visualization. s = self.new_scene() ############################################################ # run all the "test_foobar" functions in the mlab module. for name, func in getmembers(mlab): if not callable(func) or not name[:4] in ('test', 'Test'): continue mlab.clf() func() # Mayavi has become too fast: the operator cannot see if the # Test function was succesful. sleep(0.1) ############################################################ # Test some specific corner-cases import numpy x, y, z = numpy.mgrid[1:10, 1:10, 1:10] u, v, w = numpy.mgrid[1:10, 1:10, 1:10] s = numpy.sqrt(u**2 + v**2) mlab.clf() # Test the extra argument "scalars" mlab.quiver3d(x, y, z, u, v, w, scalars=s) # Test surf with strange-shaped inputs X, Y = numpy.ogrid[-10:10, -10:10] Z = X**2 + Y**2 mlab.surf(X, Y, Z) mlab.surf(X.ravel(), Y.ravel(), Z) x, y, z = numpy.mgrid[-10:10, -10:10, -3:2] mlab.flow(x, y, z) # Test glyphs with number-only coordinnates mlab.points3d(0, 0, 0, resolution=50)
def show_lorenz(new_fig=True): x, y, z = np.mgrid[-50:50:100j,-50:50:100j,-10:60:70j] u, v, w = lorenz(x, y, z) if new_fig: fig = mlab.figure(size=(600,600), bgcolor=(0, 0, 0)) # Plot the flow of trajectories with suitable parameters. f = mlab.flow(x, y, z, u, v, w, line_width=3, colormap='Paired') f.module_manager.scalar_lut_manager.reverse_lut = True f.stream_tracer.integration_direction = 'both' f.stream_tracer.maximum_propagation = 200
def show_lorenz(new_fig=True): x, y, z = np.mgrid[-50:50:100j, -50:50:100j, -10:60:70j] u, v, w = lorenz(x, y, z) if new_fig: fig = mlab.figure(size=(600, 600), bgcolor=(0, 0, 0)) # Plot the flow of trajectories with suitable parameters. f = mlab.flow(x, y, z, u, v, w, line_width=3, colormap='Paired') f.module_manager.scalar_lut_manager.reverse_lut = True f.stream_tracer.integration_direction = 'both' f.stream_tracer.maximum_propagation = 200
def test_probe_data(self): """ Test probe_data """ x, y, z = np.mgrid[0:1:10j, 0:1:10j, 0:1:10j] r = np.sqrt(x**2 + y**2 + z**2) iso = mlab.contour3d(x, y, z, r) x_, y_, z_ = np.random.random((3, 10, 4, 2)) r_ = mlab.pipeline.probe_data(iso, x_, y_, z_) np.testing.assert_array_almost_equal(r_, np.sqrt(x_**2 + y_**2 + z_**2), decimal=2) flow = mlab.flow(x, y, z, x, y, z) u_, v_, w_ = mlab.pipeline.probe_data(flow, x_, y_, z_, type='vectors') np.testing.assert_array_almost_equal(u_, x_, decimal=2) np.testing.assert_array_almost_equal(v_, y_, decimal=2) np.testing.assert_array_almost_equal(w_, z_, decimal=3)
from enthought.mayavi import mlab def lorenz(x, y, z, s=10.,r=28., b=8./3.): """The Lorenz system.""" u = s*(y-x) v = r*x -y - x*z w = x*y - b*z return u, v, w # Sample the space in an interesting region. x, y, z = numpy.mgrid[-50:50:100j,-50:50:100j,-10:60:70j] u, v, w = lorenz(x, y, z) fig = mlab.figure(size=(400, 300), bgcolor=(0, 0, 0)) # Plot the flow of trajectories with suitable parameters. f = mlab.flow(x, y, z, u, v, w, line_width=3, colormap='Paired',seedtype="point") f.module_manager.scalar_lut_manager.reverse_lut = True f.stream_tracer.integration_direction = 'both' f.stream_tracer.integration_direction = 'forward' f.stream_tracer.maximum_propagation = 2000 # Uncomment the following line if you want to hide the seed: #f.seed.widget.enabled = False # Extract the z-velocity from the vectors and plot the 0 level set # hence producing the z-nullcline. src = f.mlab_source.m_data e = mlab.pipeline.extract_vector_components(src) e.component = 'z-component' zc = mlab.pipeline.iso_surface(e, opacity=0.5, contours=[0,], color=(0.6, 1, 0.2))
from enthought.mayavi import mlab def lorenz(x, y, z, s=10.,r=28., b=8./3.): """The Lorenz system.""" u = s*(y-x) v = r*x -y - x*z w = x*y - b*z return u, v, w # Sample the space in an interesting region. x, y, z = numpy.mgrid[-50:50:100j,-50:50:100j,-10:60:70j] u, v, w = lorenz(x, y, z) fig = mlab.figure(size=(400, 300), bgcolor=(0, 0, 0)) # Plot the flow of trajectories with suitable parameters. f = mlab.flow(x, y, z, u, v, w, line_width=3, colormap='Paired') f.module_manager.scalar_lut_manager.reverse_lut = True f.stream_tracer.integration_direction = 'both' f.stream_tracer.maximum_propagation = 200 # Uncomment the following line if you want to hide the seed: #f.seed.widget.enabled = False # Extract the z-velocity from the vectors and plot the 0 level set # hence producing the z-nullcline. src = f.mlab_source.m_data e = mlab.pipeline.extract_vector_components(src) e.component = 'z-component' zc = mlab.pipeline.iso_surface(e, opacity=0.5, contours=[0,], color=(0.6, 1, 0.2)) # When using transparency, hiding 'backface' triangles often gives better # results
import numpy as np from enthought.mayavi import mlab p, r, b = (10.0, 28.0, 3.0) x, y, z = np.mgrid[-17:20:20j, -21:28:20j, 0:48:20j] u, v, w = p*(y-x), x*(r-z)-y, x*y-b*z mlab.figure(size=(600, 600)) mlab.quiver3d(x, y, z, u, v, w) mlab.figure(size=(600, 600)) vectors = mlab.quiver3d(x, y, z, u, v, w) vectors.glyph.mask_input_points = True vectors.glyph.mask_points.on_ratio = 20 vectors.glyph.glyph.scale_factor = 5.0 mlab.figure(size=(600, 600)) src = mlab.pipeline.vector_field(x, y, z, u, v, w) mlab.pipeline.vector_cut_plane(src, mask_points=2, scale_factor=5) magnitude = mlab.pipeline.extract_vector_norm(src) surface = mlab.pipeline.iso_surface(magnitude) surface.actor.property.opacity = 0.3 mlab.gcf().scene.background = (0.8, 0.8, 0.8) mlab.figure(size=(600, 600)) mlab.flow(x, y, z, u, v, w) mlab.show()
import numpy as np from enthought.mayavi import mlab p, r, b = (10.0, 28.0, 3.0) x, y, z = np.mgrid[-17:20:20j, -21:28:20j, 0:48:20j] u, v, w = p * (y - x), x * (r - z) - y, x * y - b * z mlab.figure(size=(600, 600)) mlab.quiver3d(x, y, z, u, v, w) mlab.figure(size=(600, 600)) vectors = mlab.quiver3d(x, y, z, u, v, w) vectors.glyph.mask_input_points = True vectors.glyph.mask_points.on_ratio = 20 vectors.glyph.glyph.scale_factor = 5.0 mlab.figure(size=(600, 600)) src = mlab.pipeline.vector_field(x, y, z, u, v, w) mlab.pipeline.vector_cut_plane(src, mask_points=2, scale_factor=5) magnitude = mlab.pipeline.extract_vector_norm(src) surface = mlab.pipeline.iso_surface(magnitude) surface.actor.property.opacity = 0.3 mlab.gcf().scene.background = (0.8, 0.8, 0.8) mlab.figure(size=(600, 600)) mlab.flow(x, y, z, u, v, w) mlab.show()