/[escript]/trunk/dudley/test/python/convection_viz.py
ViewVC logotype

Annotation of /trunk/dudley/test/python/convection_viz.py

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1543 - (hide annotations)
Wed Apr 30 23:21:27 2008 UTC (11 years, 6 months ago) by ksteube
Original Path: trunk/finley/test/python/convection_viz.py
File MIME type: text/x-python
File size: 3315 byte(s)
Create an MPEG movie from the state.N.vtu files of convection.py using pyvisi

1 ksteube 1543
2     # Create an MPEG movie called movie.mpg from the output of convection.py using pyvisi
3     # Usage: python convection_viz.py
4    
5     # View movie with: mplayer movie.mpg
6     # Create an animated GIF "out.gif" with: mplayer -vo gif89a movie.mpg
7    
8     # The output of convection.py consists of VTK files state.i1.vtu ... state.i2.vtu
9     # Specify range of file names: state.i1.vtu ... state.i2.vtu
10     i1 = 0
11     i2 = 271
12    
13    
14     ################################################################################
15     # You shouldn't have to change anything below here
16     ################################################################################
17    
18    
19     from esys.pyvisi import Camera, Contour, DataCollector, Legend, LocalPosition, Map, Movie, Scene, Velocity, VelocityOnPlaneCut
20     from esys.pyvisi.constant import *
21     import os, sys
22    
23     # List the input files (which are in .vtu format)
24     filList = []
25     for i in range(i1, i2+1):
26     filList.append("state.%d.vtu" % (i))
27    
28     print "Making a movie using files: ", filList[0], "...", filList[len(filList)-1], "\n"
29    
30     # Make sure all input files exist before starting
31     for filName in filList:
32     # Check that the name is a valid file
33     if not os.path.isfile(filName):
34     print "%s: Invalid input file '%s'\n" % (sys.argv[0], filName)
35     sys.exit(1)
36    
37     # Now create the .jpg images for each input VTK file
38     imgList = []
39     for filName in filList:
40     imgName = filName + ".jpg"
41    
42     # Check that the name is a valid file
43     if not os.path.isfile(filName):
44     print "%s: Input file '%s' has disappeared\n" % (sys.argv[0], filName)
45     sys.exit(1)
46    
47     print "Reading %s and writing %s" % (filName, imgName)
48     imgList.append(imgName)
49    
50     # Create a pyvisi Scene
51     s = Scene(renderer = Renderer.OFFLINE_JPG, num_viewport = 1, x_size = 400, y_size = 400)
52    
53     # Create a DataCollector reading a XML file
54     dc1 = DataCollector(source = Source.XML)
55     dc1.setFileName(file_name = filName)
56     dc1.setActiveScalar(scalar = "T")
57     dc1.setActiveVector(vector = "v")
58    
59     # Create a Contour
60     ctr1 = Contour(scene = s, data_collector = dc1, viewport = Viewport.SOUTH_WEST, lut = Lut.COLOR, cell_to_point = False, outline = True)
61     # ctr1.generateContours(contours = 1, lower_range=0.5, upper_range=0.5) # lower_range controls top isosurface in the case of convection.py
62     ctr1.generateContours(contours = 2, lower_range=0.3, upper_range=0.9) # lower_range controls top isosurface in the case of convection.py
63    
64     # Create VelocityOnPlaneCut at 0.9 to show the direction of movement where the continents would be
65     if False:
66     vopc1 = VelocityOnPlaneCut(scene = s, data_collector = dc1, viewport = Viewport.SOUTH_WEST, color_mode = ColorMode.VECTOR, arrow = Arrow.THREE_D, lut = Lut.COLOR, cell_to_point = False, outline = True)
67     vopc1.setScaleFactor(scale_factor = 70.0) # Set the scale factor for the length of the arrows
68     vopc1.setPlaneToXY(offset = 0.9) # Set the height of the plane orthogonal to the z-axis
69     vopc1.setRatio(2) # Mask every Nth point
70     vopc1.randomOn()
71    
72     # Create a Camera
73     cam1 = Camera(scene = s, viewport = Viewport.SOUTH_WEST)
74     cam1.elevation(angle = -60)
75    
76     # Render the jpg image for this input file
77     s.render(image_name = imgName)
78    
79    
80     # Finally, create the movie from the .jpg files
81     mov = Movie()
82     mov.imageList(input_directory = ".", image_list = imgList)
83     mov.makeMovie("movie.mpg")
84    
85     print "\nCreated movie.mpg\n"
86    

  ViewVC Help
Powered by ViewVC 1.1.26