Exemple #1
0
def spin(fcm, idx0, idx1, idx2):
    """Plots 3D data as points in space."""
    x = fcm[:, idx0]
    y = fcm[:, idx1]
    z = fcm[:, idx2]

    s = trilinear_interpolate(x, y, z)

#     bins = int(len(x)**(1/3.0))

#     xfrac, xint = numpy.modf((x - numpy.min(x))/
#                              (numpy.max(x)-numpy.min(x))*(bins-1))
#     yfrac, yint = numpy.modf((y - numpy.min(y))/
#                              (numpy.max(y)-numpy.min(y))*(bins-1))
#     zfrac, zint = numpy.modf((z - numpy.min(z))/
#                              (numpy.max(z)-numpy.min(z))*(bins-1))

#     xint = xint.astype('i')
#     yint = yint.astype('i')
#     zint = zint.astype('i')

#     # not interpolated - kiv write trilinear_interpolate function
#     h, edges = numpy.histogramdd(fcm[:,[idx0, idx1, idx2]], bins=bins)
#     v = h[xint, yint, zint]

    mlab.figure()
    mlab.points3d(x, y, z, s, mode='point')
    mlab.xlabel(fcm.channels[idx0])
    mlab.ylabel(fcm.channels[idx1])
    mlab.zlabel(fcm.channels[idx2])
Exemple #2
0
    def newSurface(self):
        processes = self.plotter.getProcesses()

        if not self._cv_dlg:
            self._cv_dlg = daeChooseVariable(daeChooseVariable.plot3D)
        self._cv_dlg.updateProcessesList(processes)
        self._cv_dlg.setWindowTitle('Choose variable for 3D plot')
        if self._cv_dlg.exec_() != QtWidgets.QDialog.Accepted:
            return False

        variable, domainIndexes, domainPoints, xAxisLabel, yAxisLabel, zAxisLabel, xPoints, yPoints, zPoints, currentTime = self._cv_dlg.getPlot3DData(
        )
        xPoints = numpy.array(xPoints)
        yPoints = numpy.array(yPoints)

        xmax = numpy.max(xPoints)
        ymax = numpy.max(yPoints)
        zmax = numpy.max(zPoints)

        xmin = numpy.min(xPoints)
        ymin = numpy.min(yPoints)
        zmin = numpy.min(zPoints)

        warp = 'auto'
        #if((xmax == xmin) or (ymax == ymin) or (zmax == zmin)):
        #    warp = 'auto'
        #else:
        #    warp = math.sqrt( (xmax-xmin)*(ymax-ymin) ) / (zmax-zmin)

        # colormap='gist_earth', 'RdBu'
        stype = 'surface'
        mlab.figure()
        if (stype == 'surface'):
            #print "warp=", warp
            #print "[xmin, xmax, ymin, ymax, zmin, zmax]=", [xmin, xmax, ymin, ymax, zmin, zmax]
            mlab.surf(xPoints,
                      yPoints,
                      zPoints,
                      warp_scale=warp,
                      representation='surface')
            mlab.colorbar(orientation='vertical')
            #mlab.title('polar mesh')
            #mlab.outline()
            mlab.axes(ranges=[xmin, xmax, ymin, ymax, zmin, zmax], nb_labels=3)

            mlab.xlabel(xAxisLabel)
            mlab.ylabel(yAxisLabel)
            mlab.zlabel(zAxisLabel)
        elif (stype == 'map'):
            mlab.imshow(zPoints)
            mlab.colorbar(orientation='vertical')
            #mlab.title('polar mesh')
            #mlab.outline()
            mlab.axes(ranges=[xmin, xmax, ymin, ymax], nb_labels=3)

            mlab.xlabel(xAxisLabel)
            mlab.ylabel(yAxisLabel)
            mlab.zlabel(zAxisLabel)

        mlab.show()
Exemple #3
0
def spin(fcm, idx0, idx1, idx2):
    """Plots 3D data as points in space."""
    x = fcm[:, idx0]
    y = fcm[:, idx1]
    z = fcm[:, idx2]

    s = trilinear_interpolate(x, y, z)

    #     bins = int(len(x)**(1/3.0))

    #     xfrac, xint = numpy.modf((x - numpy.min(x))/
    #                              (numpy.max(x)-numpy.min(x))*(bins-1))
    #     yfrac, yint = numpy.modf((y - numpy.min(y))/
    #                              (numpy.max(y)-numpy.min(y))*(bins-1))
    #     zfrac, zint = numpy.modf((z - numpy.min(z))/
    #                              (numpy.max(z)-numpy.min(z))*(bins-1))

    #     xint = xint.astype('i')
    #     yint = yint.astype('i')
    #     zint = zint.astype('i')

    # not interpolated - kiv write trilinear_interpolate function
    #     h, edges = numpy.histogramdd(fcm[:,[idx0, idx1, idx2]], bins=bins)
    #     v = h[xint, yint, zint]

    mlab.figure()
    mlab.points3d(x, y, z, s, mode='point')
    mlab.xlabel(fcm.channels[idx0])
    mlab.ylabel(fcm.channels[idx1])
    mlab.zlabel(fcm.channels[idx2])
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
	def _plotbutton1_fired(self):
		mlab.clf()
		self.loaddata()
		field=mlab.pipeline.scalar_field(self.sregion)     # Generate a scalar field
		mlab.pipeline.volume(field,vmax=self.datamax,vmin=self.datamin) # Render the field with dots

		mlab.outline()
		mlab.xlabel('RA(J2000)')
		mlab.ylabel('DEC(J2000)')
		mlab.zlabel('Velocity')
		mlab.view(azimuth=0, elevation=0)
		mlab.show()
		
		self.field   = field
Exemple #6
0
def surface(fcm, idx0, idx1):
    """Plots a surface plot for 2D data."""
    x = fcm[:, idx0]
    y = fcm[:, idx1]
    bins = int(numpy.sqrt(len(x)))
    z, xedge, yedge = numpy.histogram2d(y, x, bins=[bins, bins],
                                        range=[(numpy.min(y), numpy.max(y)),
                                               (numpy.min(x), numpy.max(x))]
                                        )

    mlab.figure()
    mlab.surf(xedge, yedge, z, warp_scale='auto')
    mlab.xlabel(fcm.channels[idx0])
    mlab.ylabel(fcm.channels[idx1])
    mlab.zlabel('Density')
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
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
Exemple #9
0
def surface(fcm, idx0, idx1):
    """Plots a surface plot for 2D data."""
    x = fcm[:, idx0]
    y = fcm[:, idx1]
    bins = int(numpy.sqrt(len(x)))
    z, xedge, yedge = numpy.histogram2d(y,
                                        x,
                                        bins=[bins, bins],
                                        range=[(numpy.min(y), numpy.max(y)),
                                               (numpy.min(x), numpy.max(x))])

    mlab.figure()
    mlab.surf(xedge, yedge, z, warp_scale='auto')
    mlab.xlabel(fcm.channels[idx0])
    mlab.ylabel(fcm.channels[idx1])
    mlab.zlabel('Density')
	def _plotbutton2_fired(self):
		mlab.clf()
		self.loaddata()
		field=mlab.contour3d(self.sregion,colormap='gist_ncar')     # Generate a scalar field
		field.contour.maximum_contour = self.datamax
		field.contour.minimum_contour = self.datamin
		field.actor.property.opacity = self.opacity

		mlab.outline()
		mlab.xlabel('RA(J2000)')
		mlab.ylabel('DEC(J2000)')
		mlab.zlabel('Velocity')
		mlab.view(azimuth=0, elevation=0)
		mlab.show()

		self.field   = field
Exemple #11
0
def make_3d_graph(scalarfield, filename):
    mlab.figure(bgcolor=(1,1,1),fgcolor=(0,0,0))
    #mlab.options.offscreen = True
    #win = e.new_scene()
    #src = mlab.pipeline.scalar_scatter(Phi_graph)
    #e.add_source(src)
    #e.add_module(IsoSurface())
    #e.add_module(
    #win.scene.isometric_view()
    #win.scene.save(filename,size=(800,600))
    mlab.clf()
    mlab.contour3d(scalarfield,opacity=.5,transparent=True)#,contours=[1.0])
#    mlab.outline()
    mlab.zlabel('Z')
    mlab.xlabel('X')
    mlab.ylabel('Y')
    print 'saving %s' % filename
    mlab.savefig(filename)
Exemple #12
0
def mcrtmv(frames, dt, Lx, Ly, Nx, Ny, savemovie=False, mvname='test'):
    x = np.linspace(0, Lx, Nx)
    y = np.linspace(0, Lx, Nx)
    X, Y = np.meshgrid(x, y)
    size = 500, 500

    fig = ml.figure(size=size, bgcolor=(1., 1., 1.))

    #fig.scene.anti_aliasing_frames=07

    #extent = [0,Nx-1,0,Ny-1,-30,30]

    ml.clf(figure=fig)
    u = np.loadtxt('data/solution_%06d.txt' % 1)

    fname = 'data/_tmp%07d.png' % 1
    s = ml.surf(x, y, u, figure=fig, vmin=-1, vmax=1)
    ml.axes(extent=[0, Lx, 0, Ly, -2, 2])
    ml.colorbar()
    ml.xlabel('x position')
    ml.ylabel('y position')
    ml.zlabel('wave amplitude')
    if savemovie == True:
        pl.ion()
        arr = ml.screenshot()
        img = pl.imshow(arr)
        pl.axis('off')

    for i in range(2, frames):

        u = np.loadtxt('data/solution_%06d.txt' % i)
        s.mlab_source.scalars = u
        fname = 'data/_tmp%07d.png' % i
        if savemovie == True:
            arr = ml.screenshot()
            img.set_array(arr)
            pl.savefig(filename=fname)  #,figure=fig)
            print 'Saving frame', fname
            pl.draw()

    fig.scene.disable_render = False
    os.system(
        "mencoder 'mf://data/_tmp*.png' -mf type=png:fps=20 -ovc lavc -lavcopts vcodec=wmv2 -oac copy -o %s.mpg"
        % mvname)
Exemple #13
0
def mcrtmv(frames, dt,Lx,Ly,Nx,Ny,savemovie=False, mvname='test'):
	x = np.linspace(0,Lx,Nx);
	y = np.linspace(0,Lx,Nx);
	X,Y = np.meshgrid(x,y);
	size = 500,500
	
	fig = ml.figure(size= size, bgcolor=(1.,1.,1.));

	#fig.scene.anti_aliasing_frames=07

	#extent = [0,Nx-1,0,Ny-1,-30,30]
	
	ml.clf(figure=fig)
	u = np.loadtxt('data/solution_%06d.txt'%1);
	
	fname = 'data/_tmp%07d.png' % 1
	s = ml.surf(x,y,u,figure=fig,vmin=-1,vmax=1)
	ml.axes(extent=[0,Lx,0,Ly,-2,2])
	ml.colorbar()
	ml.xlabel('x position')
	ml.ylabel('y position')
	ml.zlabel('wave amplitude')
	if savemovie == True:
		pl.ion()
		arr = ml.screenshot()
		img = pl.imshow(arr)
		pl.axis('off')
	
	for i in range(2,frames):

		u = np.loadtxt('data/solution_%06d.txt'%i);
		s.mlab_source.scalars = u
		fname = 'data/_tmp%07d.png' % i
		if savemovie == True:
			arr = ml.screenshot()
			img.set_array(arr)
			pl.savefig(filename=fname)#,figure=fig)
			print 'Saving frame', fname
			pl.draw()

	fig.scene.disable_render = False
	os.system("mencoder 'mf://data/_tmp*.png' -mf type=png:fps=20 -ovc lavc -lavcopts vcodec=wmv2 -oac copy -o %s.mpg" % mvname);
from enthought.mayavi import mlab

## For volume rendering (problems in saving as a obj file)
#field=mlab.pipeline.scalar_field(sregion)     # Generate a scalar field
#mlab.pipeline.volume(field,vmin=2000,vmax=10000) # Render the field with dots

## For surface rendering
field=mlab.contour3d(sregion,colormap='gist_ncar')     # Generate a scalar field
#field.contour.maximum_contour = 13000
field.contour.minimum_contour = 2000
field.actor.property.opacity = 0.3

mlab.outline()
mlab.xlabel('RA(J2000)')
mlab.ylabel('DEC(J2000)')
mlab.zlabel('Velocity')
#mlab.axes()
#mlab.colorbar()

## Add 3-d text in the cube
mlab.text3d(30,80,23,'Outflows in L1551 IRS5',scale=2.)
#mlab.text(45,45,"outflows!",width=0.2,z=20)

## Draw arrows to show outflows etc.
vector1=mlab.quiver3d(55,55,30,1,1,0.2,mode='arrow',scale_factor=10.0,color=(0.0,0.0,1.0))
vector2=mlab.quiver3d(55,40,30,1,-1.2,0.2,mode='arrow',scale_factor=10.0,color=(0.0,0.0,1.0))
vector3=mlab.quiver3d(45,50,30,-0.8,1,0.2,mode='2dthick_arrow',scale_factor=10.0,color=(0.0,0.0,1.0))
vector4=mlab.quiver3d(49,48,30,0.2,0,1,mode='2darrow',scale_factor=8.0,color=(0.0,0.0,1.0))

vector5=mlab.quiver3d(47,58,20,-1,1.8,-0.2,mode='arrow',scale_factor=10.0,color=(1.0,0.0,0.0))
vector6=mlab.quiver3d(45,45,20,-1.2,-1,-0.2,mode='arrow',scale_factor=10.0,color=(1.0,0.0,0.0))
Exemple #15
0
		#elif v >= 0.5:
		#	r_a.append(i)
		#	th_a.append(j)
		#	ph_a.append(k)
		#	s_a.append(v)
	
	if False:
		from enthought.mayavi import mlab
		fig1 = mlab.figure(bgcolor=(1,1,1),fgcolor=(0,0,0),size=(800,800))
		#mlab.points3d(ph_a, th_a, r_a, s_a,opacity=0.1,scale_factor=3)#, color=(0,0,1))
		mlab.points3d(ph_r, th_r, r_r, s_r,opacity=0.3,scale_factor=2)#, color=(1,0,0))
		mlab.axes(ranges=[0.0, 90.0, 0.0, 90.0, 3.0, 9.0])
		#mlab.orientation_axes()
		mlab.xlabel("phi")
		mlab.ylabel("theta")
		mlab.zlabel("centroid\ndistance")
		#mlab.colorbar(nb_labels=2,nb_colors=2,label_fmt='')
		mlab.colorbar()
		#mlab.text(0.1,0.1,"attraction",color=(0,0,1),width=0.1)
		#mlab.text(0.8,0.1,"repulsion",color=(1,0,0),width=0.1)
		mlab.text(0.1,0.8,"%s-%s (n=%i; x=%i); (%s)"%(res1,res2,ndata,countNone,pdblistfile),width=0.8)
		mlab.title("Free Energy (%s,%s)"%(res1,res2),size=0.3,height=0.7,figure=fig1)
		viewdist = 120
		elevation = 60  # angle or 'rotate'
		azimuth = 180+45 # angle or 'rotate'
		mlab.view(distance=viewdist,elevation=elevation, azimuth=azimuth)
	
		mlab.savefig(pdblistfile+"_%s_%s_r_theta_phi.png"%(res1,res2))
	
		mlab.show()