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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 2344 - (show annotations)
Mon Mar 30 02:13:58 2009 UTC (10 years, 7 months ago) by jfenwick
Original Path: trunk/finley/test/python/convection_viz.py
File MIME type: text/x-python
File size: 4127 byte(s)
Change __url__ to launchpad site

1
2 ########################################################
3 #
4 # Copyright (c) 2003-2008 by University of Queensland
5 # Earth Systems Science Computational Center (ESSCC)
6 # http://www.uq.edu.au/esscc
7 #
8 # Primary Business: Queensland, Australia
9 # Licensed under the Open Software License version 3.0
10 # http://www.opensource.org/licenses/osl-3.0.php
11 #
12 ########################################################
13
14 __copyright__="""Copyright (c) 2003-2008 by University of Queensland
15 Earth Systems Science Computational Center (ESSCC)
16 http://www.uq.edu.au/esscc
17 Primary Business: Queensland, Australia"""
18 __license__="""Licensed under the Open Software License version 3.0
19 http://www.opensource.org/licenses/osl-3.0.php"""
20 __url__="https://launchpad.net/escript-finley"
21
22
23 # Create an MPEG movie called movie.mpg from the output of convection.py using pyvisi
24 # Usage: python convection_viz.py
25
26 # View movie with: mplayer movie.mpg
27 # Create an animated GIF "out.gif" with: mplayer -vo gif89a movie.mpg
28
29 # The output of convection.py consists of VTK files state.i1.vtu ... state.i2.vtu
30 # Specify range of file names: state.i1.vtu ... state.i2.vtu
31 i1 = 0
32 i2 = 499
33
34
35 ################################################################################
36 # You shouldn't have to change anything below here
37 ################################################################################
38
39
40 from esys.pyvisi import Camera, Contour, DataCollector, Legend, LocalPosition, Map, Movie, Scene, Velocity, VelocityOnPlaneCut
41 from esys.pyvisi.constant import *
42 import os, sys
43
44 # List the input files (which are in .vtu format)
45 filList = []
46 for i in range(i1, i2+1):
47 filList.append("state.%d.vtu" % (i))
48
49 print "Making a movie using files: ", filList[0], "...", filList[len(filList)-1], "\n"
50
51 # Make sure all input files exist before starting
52 for filName in filList:
53 # Check that the name is a valid file
54 if not os.path.isfile(filName):
55 print "%s: Invalid input file '%s'\n" % (sys.argv[0], filName)
56 sys.exit(1)
57
58 # Now create the .jpg images for each input VTK file
59 imgList = []
60 for filName in filList:
61 imgName = filName + ".jpg"
62
63 # Check that the name is a valid file
64 if not os.path.isfile(filName):
65 print "%s: Input file '%s' has disappeared\n" % (sys.argv[0], filName)
66 sys.exit(1)
67
68 print "Reading %s and writing %s" % (filName, imgName)
69 imgList.append(imgName)
70
71 # Create a pyvisi Scene
72 s = Scene(renderer = Renderer.OFFLINE_JPG, num_viewport = 1, x_size = 400, y_size = 400)
73
74 # Create a DataCollector reading a XML file
75 dc1 = DataCollector(source = Source.XML)
76 dc1.setFileName(file_name = filName)
77 dc1.setActiveScalar(scalar = "T")
78 dc1.setActiveVector(vector = "v")
79
80 # Create a Contour
81 ctr1 = Contour(scene = s, data_collector = dc1, viewport = Viewport.SOUTH_WEST, lut = Lut.COLOR, cell_to_point = False, outline = True)
82 # ctr1.generateContours(contours = 1, lower_range=0.5, upper_range=0.5) # lower_range controls top isosurface in the case of convection.py
83 ctr1.generateContours(contours = 2, lower_range=0.3, upper_range=0.9) # lower_range controls top isosurface in the case of convection.py
84
85 # Create VelocityOnPlaneCut at 0.9 to show the direction of movement where the continents would be
86 if False:
87 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)
88 vopc1.setScaleFactor(scale_factor = 70.0) # Set the scale factor for the length of the arrows
89 vopc1.setPlaneToXY(offset = 0.9) # Set the height of the plane orthogonal to the z-axis
90 vopc1.setRatio(2) # Mask every Nth point
91 vopc1.randomOn()
92
93 # Create a Camera
94 cam1 = Camera(scene = s, viewport = Viewport.SOUTH_WEST)
95 cam1.elevation(angle = 0)
96 cam1.roll(angle = 45)
97 cam1.elevation(angle = -65)
98
99 # Render the jpg image for this input file
100 s.render(image_name = imgName)
101
102
103 # Finally, create the movie from the .jpg files
104 mov = Movie()
105 mov.imageList(input_directory = ".", image_list = imgList)
106 mov.makeMovie("movie.mpg")
107
108 print "\nCreated movie.mpg\n"
109

  ViewVC Help
Powered by ViewVC 1.1.26