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

  ViewVC Help
Powered by ViewVC 1.1.26