コード例 #1
0
    def test_close(self):
        """ Various tests for mlab.close().
        """
        f = mlab.figure()
        self.assert_(f.running)
        mlab.close(f)
        self.assertFalse(f.running)

        f = mlab.figure(314)
        self.assert_(f.running)
        mlab.close(314)
        self.assertFalse(f.running)

        f = mlab.figure('test_figure')
        self.assert_(f.running)
        mlab.close('test_figure')
        self.assertFalse(f.running)

        f = mlab.figure()
        self.assert_(f.running)
        mlab.close()
        self.assertFalse(f.running)

        figs = [mlab.figure() for i in range(5)]
        for f in figs:
            self.assert_(f.running)
        mlab.close(all=True)
        for f in figs:
            self.assertFalse(f.running)
コード例 #2
0
ファイル: gen_rst.py プロジェクト: giterdone/mne-python
def generate_file_rst(fname, target_dir, src_dir, plot_gallery):
    """ Generate the rst file for a given example.
    """
    image_name = fname[:-2] + 'png'
    global rst_template, plot_rst_template
    this_template = rst_template
    last_dir = os.path.split(src_dir)[-1]
    # to avoid leading . in file names
    if last_dir == '.': last_dir = ''
    else: last_dir += '_'
    short_fname =  last_dir + fname
    src_file = os.path.join(src_dir, fname)
    example_file = os.path.join(target_dir, fname)
    shutil.copyfile(src_file, example_file)
    if plot_gallery and fname.startswith('plot'):
        # generate the plot as png image if file name
        # starts with plot and if it is more recent than an
        # existing image.
        if not os.path.exists(os.path.join(target_dir, 'images')):
            os.makedirs(os.path.join(target_dir, 'images'))
        image_file = os.path.join(target_dir, 'images', image_name)
        if (not os.path.exists(image_file) or
                os.stat(image_file).st_mtime <= os.stat(src_file).st_mtime):
            print 'plotting %s' % fname
            import matplotlib.pyplot as plt
            plt.close('all')
            try:
                from enthought.mayavi import mlab
                mlab.close(all=True)
            except:
                pass

            try:
                execfile(example_file, {'pl' : plt})
                facecolor = plt.gcf().get_facecolor() # hack to keep black bg
                if facecolor == (0.0, 0.0, 0.0, 1.0):
                    plt.savefig(image_file, facecolor='black')
                else:
                    plt.savefig(image_file)

                try:
                    from enthought.mayavi import mlab
                    e = mlab.get_engine()
                    if len(e.scenes) > 0:
                        mlab.savefig(image_file)
                except:
                    pass

            except:
                print 80*'_'
                print '%s is not compiling:' % fname
                traceback.print_exc()
                print 80*'_'
        this_template = plot_rst_template

    docstring, short_desc, end_row = extract_docstring(example_file)

    f = open(os.path.join(target_dir, fname[:-2] + 'rst'), 'w')
    f.write(this_template % locals())
    f.flush()
コード例 #3
0
    def test_close(self):
        """ Various tests for mlab.close().
        """
        f = mlab.figure()
        self.assert_(f.running)
        mlab.close(f)
        self.assertFalse(f.running)

        f = mlab.figure(314)
        self.assert_(f.running)
        mlab.close(314)
        self.assertFalse(f.running)

        f = mlab.figure('test_figure')
        self.assert_(f.running)
        mlab.close('test_figure')
        self.assertFalse(f.running)

        f = mlab.figure()
        self.assert_(f.running)
        mlab.close()
        self.assertFalse(f.running)

        figs = [mlab.figure() for i in range(5)]
        for f in figs:
            self.assert_(f.running)
        mlab.close(all=True)
        for f in figs:
            self.assertFalse(f.running)
コード例 #4
0
ファイル: HCG91.py プロジェクト: fpavogt/x3d-pathway
                                    (decmax-decmean)*3600.:
                                    (limy[1]-limy[0]+1)*1j,
                                    vmin:vmax+0.1:dv]
'''

# ------------------------------------------------------------------------------

# Re-order the VLA array to have the dimensions in the good direction !
# (z = v, x= R.A.), etc ...
# Also flip the velocity axis to be in the good direction
HI_cube = scidata[slice_min:slice_max + 1, limy[0]:limy[1] + 1,
                  limx[0]:limx[1] + 1]
HI_cube = np.transpose(HI_cube, (2, 1, 0))[::-1, :, ::-1]

# Start the plotting
mlab.close(1)
fig = mlab.figure(1, size=(1100, 1100))

# What contours levels do I want ? Can be chosen by defaults, or scripted.
isolevels = [1.3, 2.5, 3.5, 6.0]

# --- !!! ---
# MAYAVI BUG & WORK-AROUND (#1)
# Currently, the x3d export function from Mayavi ignores the "vmin" and "vmax"
# parameters in the plotting function, and only uses the min and max of the
# datasets. Hence, to export the "exact same" color for the different plot
# elements shown in the interactive Mayavi window, the data itself MUST be
# modified; i.e. all values outside the [vmin->vmax] range must be replaced.
# This is NOT elegant, and will hopefully be fixed in future releases of Mayavi.

color_scale = [0.8, 6.1]
コード例 #5
0
                    mlab.clf()
                    mlab.points3d(center.T[0],
                                  center.T[1],
                                  center.T[2],
                                  colors_,
                                  scale_factor=0.05,
                                  scale_mode='none',
                                  colormap='RdBu',
                                  vmin=colors_.min(),
                                  vmax=colors_.max())
                    #mlab.quiver3d(center.T[0],center.T[1],center.T[2],normal.T[0],normal.T[1],normal.T[2],colormap='spectral',scale_mode='none')
                    mlab.colorbar()

                    if i >= 1:
                        vx,vy,vz = center.T[0]-old_center.T[0],\
                                   center.T[1]-old_center.T[1],\
                                   center.T[2]-old_center.T[2]
                        v = np.sqrt(vx**2 + vy**2 + vz**2)
                        mlab.quiver3d(center.T[0],center.T[1],center.T[2],\
                                      vx,vy,vz,scalars=v,colormap='spectral',scale_mode='scalar')
                        #mlab.show()
                    old_center = center.copy()
                    mlab.view(distance=5, azimuth=-90, elevation=90)
                    mlab.savefig('pulsation_lm%d%d_k%03d_%03d.png' %
                                 (l, m, k, i))
                mlab.close()
                multimedia.make_movie(
                    'pulsation_lm%d%d_k%03d_*.png' % (l, m, k),
                    output='pulsation_lm%d%d_k%03d.avi' % (l, m, k))
コード例 #6
0
span+=1
for j in range(skip,cnt-1):
    if j%span!=0 and j!=0:
        continue
    print "TimeStep: %d" % (times[j])
    xx=xs[j]
    yy=ys[j]
    zz=zs[j]
    tt=ts[j]
    mlab.clf(fig1)
    mlab.clf(fig2)
    mlab.points3d(xx,yy,zz,tt,colormap="gist_heat",scale_factor=0.2,figure=fig1)
    mlab.mesh(xdummy,ydummy,pairdistro[j],figure=fig2)
    mlab.show(stop=True)

mlab.close(all=True)


#Bond lengths
"""
print "Calculating histogram of bond lengths corresponding to the minimum energy."
n=pes.index(min(pes))
xs=xs[n][:N]
ys=ys[n][:N]
zs=zs[n][:N]
radii=list()
for i in range(N):
    for j in range(i+1,N):
        radii.append(((xs[i]-xs[j])**2+(ys[i]-ys[j])**2+(zs[i]-zs[j])**2)**0.5)
bins=pl.array(range(1000))/1000.0*rcut*1.5
pl.hist(radii,bins)
コード例 #7
0
ファイル: viz.py プロジェクト: satra/PySurfer
 def close(self):
     """Close the figure and cleanup data structure."""
     from enthought.mayavi import mlab
     mlab.close(self._f)
コード例 #8
0
ファイル: HCG91.py プロジェクト: fpavogt/x3d-pathway
                                    (limy[1]-limy[0]+1)*1j,
                                    vmin:vmax+0.1:dv]
'''

# ------------------------------------------------------------------------------


# Re-order the VLA array to have the dimensions in the good direction !
# (z = v, x= R.A.), etc ... 
# Also flip the velocity axis to be in the good direction
HI_cube = scidata[slice_min:slice_max+1,limy[0]:limy[1]+1,limx[0]:limx[1]+1 ]
HI_cube = np.transpose(HI_cube, (2,1,0))[::-1,:,::-1]


# Start the plotting
mlab.close(1)
fig = mlab.figure(1, size=(1100,1100)) 

# What contours levels do I want ? Can be chosen by defaults, or scripted.
isolevels = [1.3,2.5,3.5,6.0]

# --- !!! ---
# MAYAVI BUG & WORK-AROUND (#1)
# Currently, the x3d export function from Mayavi ignores the "vmin" and "vmax"
# parameters in the plotting function, and only uses the min and max of the 
# datasets. Hence, to export the "exact same" color for the different plot 
# elements shown in the interactive Mayavi window, the data itself MUST be
# modified; i.e. all values outside the [vmin->vmax] range must be replaced. 
# This is NOT elegant, and will hopefully be fixed in future releases of Mayavi.

color_scale = [0.8,6.1]
コード例 #9
0
ファイル: TestSurfCF.py プロジェクト: WaveBlocks/WaveBlocks
@author: R. Bourquin
@copyright: Copyright (C) 2010, 2011 R. Bourquin
@license: Modified BSD License
"""

import numpy as np
from enthought.mayavi import mlab

from WaveBlocks.Plot import surfcf


x, y = np.mgrid[0:5*np.pi:0.05, 0:5*np.pi:0.05]

# Plane waves:
k = 1
l = 0
z = np.exp(1.0j*k*x)*np.exp(1.0j*l*y)

surfcf(x, y, np.angle(z), np.real(z))
mlab.savefig("planewave_real_surfplot.png")
mlab.close()

surfcf(x, y, np.angle(z), np.imag(z))
mlab.savefig("planewave_imag_surfplot.png")
mlab.close()

surfcf(x, y, np.angle(z), np.conj(z)*z)
mlab.savefig("planewave_abs_surfplot.png")
mlab.close()
コード例 #10
0
figsize = (1200, 900)


# make a spatial_set object
a = 0.0  
b = 10.0
nz = 100
hz = .6
hv = .35

# function for testing 
fun = lambda z: sp.exp(-(z-a))

domain = Domain(a,b,hz, hv)

mlab.close(0)    
f = mlab.figure(0, 
                bgcolor=bgcolor, 
                fgcolor=fgcolor, size=figsize)

# plot the figure
# mlab.clf(0)    

# plot a funciton in space
domain.plot_function(fun, tube_radius=.1)


# plot quivers
names = ['incoming', 'outgoing', 'domain']
colors = [(0,0,1), (1,0,0), (0,1,0)]
scale_factors = [.3, .3, .2]
コード例 #11
0
 def cleanUp(self):
     from enthought.mayavi import mlab
     mlab.close()
コード例 #12
0
 def cleanUp(self):
     from enthought.mayavi import mlab
     mlab.close()