예제 #1
0
def plot_cartesian(traj,
                   xaxis=None,
                   yaxis=None,
                   zaxis=None,
                   color='b',
                   label='_nolegend_',
                   linewidth=2,
                   scatter_size=20):
    ''' xaxis - x axis for the graph (0,1 or 2)
        zaxis - for a 3d plot. not implemented.
    '''

    import arm_trajectories as at
    #if traj.__class__ == at.JointTrajectory:
    if isinstance(traj, at.JointTrajectory):
        traj = joint_to_cartesian(traj)

    pts = np.matrix(traj.p_list).T
    label_list = ['X coord (m)', 'Y coord (m)', 'Z coord (m)']
    x = pts[xaxis, :].A1.tolist()
    y = pts[yaxis, :].A1.tolist()

    if zaxis == None:
        pl.plot(x, y, c=color, linewidth=linewidth, label=label)
        pl.scatter(
            x, y, c=color, s=scatter_size, label='_nolegend_', linewidths=0)
        pl.xlabel(label_list[xaxis])
        pl.ylabel(label_list[yaxis])
        pl.legend(loc='best')
        pl.axis('equal')
    else:
        from numpy import array
        from enthought.mayavi.api import Engine
        engine = Engine()
        engine.start()
        if len(engine.scenes) == 0:
            engine.new_scene()

        z = pts[zaxis, :].A1.tolist()
        time_list = [t - traj.time_list[0] for t in traj.time_list]
        mlab.plot3d(x, y, z, time_list, tube_radius=None, line_width=4)
        mlab.axes()
        mlab.xlabel(label_list[xaxis])
        mlab.ylabel(label_list[yaxis])
        mlab.zlabel(label_list[zaxis])
        mlab.colorbar(title='Time')

        # -------------------------------------------
        axes = engine.scenes[0].children[0].children[0].children[1]
        axes.axes.position = array([0., 0.])
        axes.axes.label_format = '%-#6.2g'
        axes.title_text_property.font_size = 4
예제 #2
0
def plot_cartesian(traj, xaxis=None, yaxis=None, zaxis=None, color='b',label='_nolegend_',
                   linewidth=2, scatter_size=10, plot_velocity=False):
    import matplotlib_util.util as mpu
    import arm_trajectories as at
    #if traj.__class__ == at.JointTrajectory:
    if isinstance(traj,at.JointTrajectory):
        traj = joint_to_cartesian(traj)

    pts = np.matrix(traj.p_list).T
    label_list = ['X coord (m)', 'Y coord (m)', 'Z coord (m)']
    x = pts[xaxis,:].A1.tolist()
    y = pts[yaxis,:].A1.tolist()

    if plot_velocity:
        vels = np.matrix(traj.v_list).T
        xvel = vels[xaxis,:].A1.tolist()
        yvel = vels[yaxis,:].A1.tolist()

    if zaxis == None:
        mpu.plot_yx(y, x, color, linewidth, '-', scatter_size, label,
                    axis = 'equal', xlabel = label_list[xaxis],
                    ylabel = label_list[yaxis],)
        if plot_velocity:
            mpu.plot_quiver_yxv(y, x, np.matrix([xvel,yvel]),
                                width = 0.001, scale = 1.)
        mpu.legend()
    else:
        from numpy import array
        from enthought.mayavi.api import Engine
        engine = Engine()
        engine.start()
        if len(engine.scenes) == 0:
            engine.new_scene()

        z = pts[zaxis,:].A1.tolist()
        time_list = [t-traj.time_list[0] for t in traj.time_list]
        mlab.plot3d(x,y,z,time_list,tube_radius=None,line_width=4)
        mlab.axes()
        mlab.xlabel(label_list[xaxis])
        mlab.ylabel(label_list[yaxis])
        mlab.zlabel(label_list[zaxis])
        mlab.colorbar(title='Time')

        # ------------------------------------------- 
        axes = engine.scenes[0].children[0].children[0].children[1]
        axes.axes.position = array([ 0.,  0.])
        axes.axes.label_format = '%-#6.2g'
        axes.title_text_property.font_size=4
예제 #3
0
def plot_cartesian(traj, xaxis=None, yaxis=None, zaxis=None, color='b',label='_nolegend_',
                   linewidth=2, scatter_size=10, plot_velocity=False):

    import arm_trajectories as at
    #if traj.__class__ == at.JointTrajectory:
    if isinstance(traj,at.JointTrajectory):
        traj = joint_to_cartesian(traj)

    pts = np.matrix(traj.p_list).T
    label_list = ['X coord (m)', 'Y coord (m)', 'Z coord (m)']
    x = pts[xaxis,:].A1.tolist()
    y = pts[yaxis,:].A1.tolist()

    if plot_velocity:
        vels = np.matrix(traj.v_list).T
        xvel = vels[xaxis,:].A1.tolist()
        yvel = vels[yaxis,:].A1.tolist()

    if zaxis == None:
        mpu.plot_yx(y, x, color, linewidth, '-', scatter_size, label,
                    axis = 'equal', xlabel = label_list[xaxis],
                    ylabel = label_list[yaxis],)
        if plot_velocity:
            mpu.plot_quiver_yxv(y, x, np.matrix([xvel,yvel]),
                                width = 0.001, scale = 1.)
        mpu.legend()
    else:
        from numpy import array
        from enthought.mayavi.api import Engine
        engine = Engine()
        engine.start()
        if len(engine.scenes) == 0:
            engine.new_scene()

        z = pts[zaxis,:].A1.tolist()
        time_list = [t-traj.time_list[0] for t in traj.time_list]
        mlab.plot3d(x,y,z,time_list,tube_radius=None,line_width=4)
        mlab.axes()
        mlab.xlabel(label_list[xaxis])
        mlab.ylabel(label_list[yaxis])
        mlab.zlabel(label_list[zaxis])
        mlab.colorbar(title='Time')

        # ------------------------------------------- 
        axes = engine.scenes[0].children[0].children[0].children[1]
        axes.axes.position = array([ 0.,  0.])
        axes.axes.label_format = '%-#6.2g'
        axes.title_text_property.font_size=4
예제 #4
0
 def __init__(self, data, scene, minv, maxv, warp=1, scalarbar=False,
              points=True, surf=True):
     self.data, self.min, self.max, self.warp = data, minv, maxv, warp
     self.scalarbar = scalarbar
     global engine
     if engine is None: # If Mayavi is not running already
         from enthought.mayavi.api import Engine
         engine = Engine()
         engine.start() # start Mayavi (only works in ipython)
     self.scene = engine.new_scene() if scene is None else scene
     self.source = sapi.VTKDataSource()
     engine.add_source(self.source, scene=self.scene)
     self.update_data()
     if points: self.plot_points()
     if surf: self.plot_surf()
     self.scene.scene.isometric_view()
예제 #5
0
#sudo easy_install appscript

# Recorded script from Mayavi2
from numpy import array

import os
import fnmatch
from enthought.mayavi.modules.orientation_axes import OrientationAxes
import enthought.mayavi.mlab
from enthought.mayavi.api import OffScreenEngine

try:
    engine = mayavi.engine
except NameError:
    from enthought.mayavi.api import Engine
    engine = Engine()
    engine.start()
if len(engine.scenes) == 0:
    engine.new_scene()
# -------------------------------------------
dir = os.getcwd()
os.chdir(dir)

thresh = 0.15  #threshold for isosurface
mag = 1.3
zoom = 3.0
ph_max = 3.14 / 2
ph_min = -3.14 / 2

show_cbar = False  #True or False to show the legend
예제 #6
0
# Recorded script from Mayavi2
from numpy import array
try:
    engine = mayavi.engine
except NameError:
    from enthought.mayavi.api import Engine
    engine = Engine()
    engine.start()
if len(engine.scenes) == 0:
    engine.new_scene()
# ------------------------------------------- 
scene = engine.scenes[0]
vtkxml_file_reader = engine.open(u'/Users/prabhu/work/MEDIA/m2/data/solution.vtp', scene)
from enthought.mayavi.modules.surface import Surface
surface = Surface()
engine.add_filter(surface, vtkxml_file_reader)
scene.scene.camera.position = [-5.0805380472988206, -22.772737120755238, 27.951999647518075]
scene.scene.camera.focal_point = [-0.30313491821289062, 0.0, 1.4027749300003052]
scene.scene.camera.view_angle = 30.0
scene.scene.camera.view_up = [-0.1142423672711194, 0.76412329986979977, 0.63487342369670707]
scene.scene.camera.clipping_range = [22.838642391722981, 51.077591804257452]
scene.scene.camera.compute_view_plane_normal()
scene.scene.render()
scene.scene.camera.position = [-26.79814746753679, -17.616423028517339, 16.698474306673273]
scene.scene.camera.focal_point = [-0.30313491821289062, 0.0, 1.4027749300003052]
scene.scene.camera.view_angle = 30.0
scene.scene.camera.view_up = [0.117668827287714, 0.54423876670086724, 0.83063723243342136]
scene.scene.camera.clipping_range = [16.95271984178639, 58.486755617116714]
scene.scene.camera.compute_view_plane_normal()
scene.scene.render()
surface.actor.property.edge_visibility = True
예제 #7
0
파일: test.py 프로젝트: FOSSEE/workshops
# Recorded script from Mayavi2
from numpy import array
try:
    engine = mayavi.engine
except NameError:
    from enthought.mayavi.api import Engine
    engine = Engine()
    engine.start()
if len(engine.scenes) == 0:
    engine.new_scene()
# -------------------------------------------
scene = engine.scenes[0]
vtkxml_file_reader = engine.open(
    u'/Users/prabhu/work/MEDIA/m2/data/solution.vtp', scene)
from enthought.mayavi.modules.surface import Surface
surface = Surface()
engine.add_filter(surface, vtkxml_file_reader)
scene.scene.camera.position = [
    -7.8710042803035831, -23.270734468965951, 26.848457084803901
]
scene.scene.camera.focal_point = [
    -0.30313491821289062, 0.0, 1.4027749300003052
]
scene.scene.camera.view_angle = 30.0
scene.scene.camera.view_up = [
    -0.18791276028283388, 0.75198808427818908, 0.63182490899497246
]
scene.scene.camera.clipping_range = [21.722908882245918, 52.482070417945934]
scene.scene.camera.compute_view_plane_normal()
scene.scene.render()
scene.scene.camera.position = [
예제 #8
0
# Recorded script from Mayavi2
from numpy import array

import numpy
import os
import fnmatch
from enthought.mayavi.modules.orientation_axes import OrientationAxes
import enthought.mayavi.mlab
from enthought.mayavi.api import OffScreenEngine

try:
    engine = mayavi.engine
except NameError:
    from enthought.mayavi.api import Engine
    engine = Engine()
    engine.start()
if len(engine.scenes) == 0:
    engine.new_scene()
# -------------------------------------------
dir = os.getcwd()

thresh = 0.5  #threshold for isosurface
mag = 1.3
zoom = 3.0
ph_max = 1.5
ph_min = -1.5

step_size = 3  #rotation step size, degrees
images = int(round(360 / step_size))  #total number of images
예제 #9
0
# Recorded script from Mayavi2
from numpy import array

import os
import fnmatch
from enthought.mayavi.modules.orientation_axes import OrientationAxes
import enthought.mayavi.mlab
from enthought.mayavi.api import OffScreenEngine

try:
    engine = mayavi.engine
except NameError:
    from enthought.mayavi.api import Engine
    engine = Engine()
    engine.start()
if len(engine.scenes) == 0:
    engine.new_scene()
# -------------------------------------------
dir = os.getcwd()

thresh = 0.4
mag = 1.
zoom = 3.0
ph_max = 3.14
ph_min = -3.14

rib = 1

for file0 in os.listdir('.'):
    if fnmatch.fnmatch(file0, 'Amp-Phase.vtk'):
        filename = file0
예제 #10
0
파일: mayavi_test.py 프로젝트: spyke/spyke
If you're using the mlab API:

from enthought.mayavi import mlab
f = mlab.figure() # returns the current scene
engine = mlab.get_engine() # returns the running mayavi engine

"""

from enthought.mayavi.api import Engine
from enthought.mayavi.sources.api import ParametricSurface
from enthought.mayavi.modules.api import Surface
from enthought.mayavi import mlab

import numpy as np

engine = Engine()
engine.start()
scene = engine.new_scene()
scene.scene.disable_render = True # for speed

surfaces = []
for i in range(10):

    source = ParametricSurface()
    source.function = 'ellipsoid'
    engine.add_source(source)

    surface = Surface()
    source.add_module(surface)

    actor = surface.actor # mayavi actor, actor.actor is tvtk actor
예제 #11
0
'''
Created on Apr 28, 2009

@author: jakub
'''
import numpy as np
a = np.random.random((4, 4))
from enthought.mayavi.api import Engine
e = Engine()
e.start()
s = e.new_scene()
from enthought.mayavi.sources.api import ArraySource
src = ArraySource(scalar_data=a)
e.add_source(src)
from enthought.mayavi.filters.api import WarpScalar, PolyDataNormals
warp = WarpScalar()
e.add_filter(warp, obj=src)
normals = PolyDataNormals()
e.add_filter(normals, obj=warp)
from enthought.mayavi.modules.api import Surface
surf = Surface()
e.add_module(surf, obj=normals)
import sys

print "len(sys.argv) is ", len(sys.argv)

if len(sys.argv)<3 :
	print "Usage: ", sys.argv[0], " input, output [, activate_scale_bar]"
	exit(1)

# Recorded script from Mayavi2
from numpy import array
try:
    engine = mayavi.engine
except NameError:
    from enthought.mayavi.api import Engine
    engine = Engine()
    engine.start()
if len(engine.scenes) == 0:
    engine.new_scene(size=(512,512))
    #engine.new_scene(size=(1000,1000))
# ------------------------------------------- 
#vtkxml_file_reader = engine.open(u'/home/mike/vilnius/prog/computenode/src/test/test.vtp')
vtkxml_file_reader = engine.open(sys.argv[1])

from enthought.mayavi.modules.surface import Surface
surface = Surface()
engine.add_module(surface, obj=None)
scene = engine.scenes[0]
scene.scene.parallel_projection = True
scene.scene.background = (0.49803921568627452, 0.49803921568627452, 0.49803921568627452)
camera_light = engine.scenes[0].scene.light_manager.lights[0]
예제 #13
0
from enthought.mayavi import mlab
from enthought.mayavi.sources.array_source import ArraySource
from enthought.mayavi.modules.surface import Surface
from enthought.mayavi.modules.iso_surface import IsoSurface
from enthought.mayavi.modules.outline import Outline
#from enthought.mayavi.modules.labels.Labels import Labels
#from enthought.mayavi.modules.orientation_axes.OrientationAxes import Axes
#from enthought.mayavi.modules.grid_plane.GridPlane import Grid

from numpy import array
try:
    engine = mayavi.engine
except NameError:
    from enthought.mayavi.api import Engine
    engine = Engine()
    engine.start()
if len(engine.scenes) == 0:
    engine.new_scene()

picno = 75600
inname = "DensProf" + "%09d" % picno + ".dat"
#inname = "data.dat"

command = "ElPoly " + inname + " --rzd"
os.system(command)

inname = "data.dat"

#field = open("out.dat.0")
field = open(inname)
예제 #14
0
#sudo easy_install appscript

# Recorded script from Mayavi2
from numpy import array

import os
import fnmatch
from enthought.mayavi.modules.orientation_axes import OrientationAxes
import enthought.mayavi.mlab
from enthought.mayavi.api import OffScreenEngine

try:
    engine = mayavi.engine
except NameError:
    from enthought.mayavi.api import Engine
    engine = Engine()
    engine.start()
if len(engine.scenes) == 0:
    engine.new_scene()
# -------------------------------------------
dir = os.getcwd()
os.chdir(dir)

thresh = 0.25  #threshold for isosurface
mag = 1.3
zoom = 3.0
ph_max = 1.5
ph_min = -1.5

step_size = 3  #rotation step size, degrees
images = int(round(360 / step_size))  #total number of images
# Recorded script from Mayavi2
from numpy import array
try:
    engine = mayavi.engine
except NameError:
    from enthought.mayavi.api import Engine
    engine = Engine()
    engine.start()
if len(engine.scenes) == 0:
    engine.new_scene()
# ------------------------------------------- 
scene = engine.scenes[0]
scene.scene.background = (0.49803921568627452, 0.49803921568627452, 0.49803921568627452)
scene.scene.background = (0.97254901960784312, 0.97254901960784312, 0.97254901960784312)
module_manager = engine.scenes[0].children[0].children[0]
module_manager.scalar_lut_manager.title_text_property.shadow_offset = array([ 1, -1])
module_manager.scalar_lut_manager.title_text_property.color = (0.039215686274509803, 0.039215686274509803, 0.039215686274509803)
module_manager.scalar_lut_manager.label_text_property.shadow_offset = array([ 1, -1])
module_manager.scalar_lut_manager.label_text_property.color = (0.039215686274509803, 0.039215686274509803, 0.039215686274509803)
module_manager.vector_lut_manager.title_text_property.shadow_offset = array([ 1, -1])
module_manager.vector_lut_manager.title_text_property.color = (0.039215686274509803, 0.039215686274509803, 0.039215686274509803)
module_manager.vector_lut_manager.label_text_property.shadow_offset = array([ 1, -1])
module_manager.vector_lut_manager.label_text_property.color = (0.039215686274509803, 0.039215686274509803, 0.039215686274509803)
vectors = engine.scenes[0].children[0].children[0].children[0]
vectors.actor.property.specular_color = (0.039215686274509803, 0.039215686274509803, 0.039215686274509803)
vectors.actor.property.diffuse_color = (0.039215686274509803, 0.039215686274509803, 0.039215686274509803)
vectors.actor.property.ambient_color = (0.039215686274509803, 0.039215686274509803, 0.039215686274509803)
vectors.actor.property.color = (0.039215686274509803, 0.039215686274509803, 0.039215686274509803)
text = engine.scenes[0].children[0].children[0].children[1]
text.property.shadow_offset = array([ 1, -1])
text.property.color = (0.039215686274509803, 0.039215686274509803, 0.039215686274509803)
# Recorded script from Mayavi2
from numpy import array

import os
import fnmatch
from enthought.mayavi.modules.orientation_axes import OrientationAxes
import enthought.mayavi.mlab
from enthought.mayavi.api import OffScreenEngine

try:
    engine = mayavi.engine
except NameError:
    from enthought.mayavi.api import Engine
    engine = Engine()
    engine.start()
if len(engine.scenes) == 0:
    engine.new_scene()
# -------------------------------------------
dir = os.getcwd()

for file0 in os.listdir('.'):
    if fnmatch.fnmatch(file0, '*AMP.rec'):
        filename = file0
        print filename
        savename = filename

        ##
        scene1 = engine.new_scene()
        scene1.scene.off_screen_rendering = True

        jesse_mat_lab_coord_source1 = engine.open(filename, scene1)
import sys

print "len(sys.argv) is ", len(sys.argv)

if len(sys.argv) < 3:
    print "Usage: ", sys.argv[0], " input, output [, activate_scale_bar]"
    exit(1)

# Recorded script from Mayavi2
from numpy import array
try:
    engine = mayavi.engine
except NameError:
    from enthought.mayavi.api import Engine
    engine = Engine()
    engine.start()
if len(engine.scenes) == 0:
    engine.new_scene(size=(512, 512))
    #engine.new_scene(size=(1000,1000))
# -------------------------------------------
#vtkxml_file_reader = engine.open(u'/home/mike/vilnius/prog/computenode/src/test/test.vtp')
vtkxml_file_reader = engine.open(sys.argv[1])

from enthought.mayavi.modules.surface import Surface
surface = Surface()
engine.add_module(surface, obj=None)
scene = engine.scenes[0]
scene.scene.parallel_projection = True
scene.scene.background = (0.49803921568627452, 0.49803921568627452,
                          0.49803921568627452)