本文整理汇总了Python中mayavi.mlab.animate方法的典型用法代码示例。如果您正苦于以下问题:Python mlab.animate方法的具体用法?Python mlab.animate怎么用?Python mlab.animate使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类mayavi.mlab
的用法示例。
在下文中一共展示了mlab.animate方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: animate_plots
# 需要导入模块: from mayavi import mlab [as 别名]
# 或者: from mayavi.mlab import animate [as 别名]
def animate_plots(base_directory, fname_prefix):
"""
This function creates a movie of the plots using ffmpeg
Args:
base_directory (str): the directory with the plots.
fname_prefix (str): the filename for the model run
Returns:
none but creates mp4 from pngs in base directory
Author: FJC
"""
import subprocess
# animate the pngs using ffmpeg
system_call = "ffmpeg -framerate 5 -pattern_type glob -i '"+base_directory+"*.png' -vcodec libx264 -s 1000x1000 -pix_fmt yuv420p "+base_directory+fname_prefix+"_movie.mp4"
print(system_call)
subprocess.call(system_call, shell=True)
#=============================================================================
# This is just a welcome screen that is displayed if no arguments are provided.
#=============================================================================
示例2: run_plots
# 需要导入模块: from mayavi import mlab [as 别名]
# 或者: from mayavi.mlab import animate [as 别名]
def run_plots(DataDirectory,Base_file):
root = DataDirectory+Base_file
filenames = get_filenames(root)
counter = 0
# create the plot for the initial raster
initial_file = filenames[0]
# read in the raster
raster = IO.ReadRasterArrayBlocks(initial_file)
f = mlab.figure(size=(1000,1000), bgcolor=(0.5,0.5,0.5))
s = mlab.surf(raster, warp_scale=0.4, colormap='gist_earth', vmax=100)
#mlab.outline(color=(0,0,0))
#mlab.axes(s, color=(1,1,1), z_axis_visibility=True, y_axis_visibility=False, xlabel='', ylabel='', zlabel='', ranges=[0,500,0,1000,0,0])
#@mlab.animate(delay=10)
#def anim():
# now loop through each file and update the z values
for fname in filenames:
this_rast = IO.ReadRasterArrayBlocks(fname)
s.mlab_source.scalars = this_rast
#f.scene.render()
#
mlab.savefig(fname[:-4]+'_3d.png')
#mlab.clf()
# for (x, y, z) in zip(xs, ys, zs):
# print('Updating scene...')
# plt.mlab_source.set(x=x, y=y, z=z)
# yield
示例3: main
# 需要导入模块: from mayavi import mlab [as 别名]
# 或者: from mayavi.mlab import animate [as 别名]
def main(argv):
"""
This is just a few lines for keeping track of how long the program is taking.
You can ignore it.
"""
import time
tic = time.clock()
# If there are no arguments, send to the welcome screen
if not len(sys.argv) > 1:
full_paramfile = print_welcome()
sys.exit()
# Get the arguments
import argparse
parser = argparse.ArgumentParser()
# The location of the data files
parser.add_argument("-dir", "--base_directory", type=str, help="The base directory with the hillshades. If this isn't defined I'll assume it's the same as the current directory.")
parser.add_argument("-fname", "--fname_prefix", type=str, help="The base file name of the hillshades.")
parser.add_argument("-animate", "--animate", type=bool, default=False, help="If this is true I'll create a movie of the model run.")
parser.add_argument("-zmax", "--maximum_elevation_for_plotting", type=float, default = 400, help="This is the maximum elevation in the colourbar of the landscape plot.")
args = parser.parse_args()
run_plots(args.base_directory,args.fname_prefix)
if (args.animate):
animate_plots(args.base_directory, args.fname_prefix)
toc = time.clock()
print("This took: "+str(toc - tic)+" units of time")
#=============================================================================
示例4: evolve_visual3d
# 需要导入模块: from mayavi import mlab [as 别名]
# 或者: from mayavi.mlab import animate [as 别名]
def evolve_visual3d(msnake, levelset=None, num_iters=20):
"""
Visual evolution of a three-dimensional morphological snake.
Parameters
----------
msnake : MorphGAC or MorphACWE instance
The morphological snake solver.
levelset : array-like, optional
If given, the levelset of the solver is initialized to this. If not
given, the evolution will use the levelset already set in msnake.
num_iters : int, optional
The number of iterations.
"""
from mayavi import mlab
# import matplotlib.pyplot as ppl
if levelset is not None:
msnake.levelset = levelset
fig = mlab.gcf()
mlab.clf()
src = mlab.pipeline.scalar_field(msnake.data)
mlab.pipeline.image_plane_widget(
src, plane_orientation='x_axes', colormap='gray')
cnt = mlab.contour3d(msnake.levelset, contours=[0.5])
@mlab.animate(ui=True)
def anim():
for i in range(num_iters):
msnake.step()
cnt.mlab_source.scalars = msnake.levelset
yield
anim()
mlab.show()
# Return the last levelset.
return msnake.levelset
示例5: fill_render
# 需要导入模块: from mayavi import mlab [as 别名]
# 或者: from mayavi.mlab import animate [as 别名]
def fill_render(self, model, save_movie=True, **kwargs):
from mayavi import mlab
body = self.to_body()
mask = body.mask
fig = mlab.figure(size=(1280, 720))
if self.target is not None:
target_grid = mlab.pipeline.scalar_field(np.transpose(self.target))
target_grid.spacing = np.flipud(CONFIG.volume.resolution)
target_grid = mlab.pipeline.iso_surface(target_grid, contours=[0.5], color=(1, 0, 0), opacity=0.1)
grid = mlab.pipeline.scalar_field(np.transpose(mask.astype(np.int32)))
grid.spacing = np.flipud(CONFIG.volume.resolution)
contour = mlab.pipeline.iso_surface(grid, color=(0, 1, 0), contours=[0.5], opacity=0.6)
contour.actor.property.backface_culling = True
grid = contour.mlab_source
mlab.orientation_axes(figure=fig)
mlab.view(azimuth=45, elevation=60, focalpoint='auto', figure=fig)
fill_generator = self.fill(model, generator=True, **kwargs)
FRAMES_PER_MOVE = 2
FPS = 60.0
ORBIT_RATE = 0.125
@mlab.animate(delay=int(1000.0/FPS), ui=True)
def animate():
try:
for _, _ in fill_generator:
body = self.to_body()
mask = body.mask
grid.set(scalars=np.transpose(mask.astype(np.int32)))
for _ in range(FRAMES_PER_MOVE):
view = list(mlab.view(figure=fig))
view[0] = (view[0] + ORBIT_RATE * 360.0 / FPS) % 360.0
mlab.view(azimuth=view[0], elevation=view[1], focalpoint='auto')
fig.scene.render()
# fig.scene.movie_maker.animation_step()
yield
except Region.EarlyFillTermination:
pass
fig.scene.movie_maker.record = False
fig.scene.movie_maker.animation_stop()
if save_movie:
fig.scene.movie_maker.record = True
a = animate() # noqa
mlab.show()