/[escript]/trunk/pyvisi/test/python/run_movie_with_lazy_evaluation.py
ViewVC logotype

Contents of /trunk/pyvisi/test/python/run_movie_with_lazy_evaluation.py

Parent Directory Parent Directory | Revision Log Revision Log


Revision 2367 - (show annotations)
Mon Apr 6 04:51:49 2009 UTC (13 years, 3 months ago) by jfenwick
File MIME type: text/x-python
File size: 4820 byte(s)
Added version number to deb files.
Fixed tests to check for ppmtompeg before running
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 from esys.pyvisi import Scene, DataCollector, Map, Camera, Velocity, Legend
23 from esys.pyvisi import Movie, LocalPosition
24 from esys.pyvisi.constant import *
25 import unittest, os, sys
26 from stat import ST_SIZE
27 from esys.escript import getMPISizeWorld
28
29 try:
30 PYVISI_WORKDIR=os.environ['PYVISI_WORKDIR']
31 except KeyError:
32 PYVISI_WORKDIR='.'
33 try:
34 PYVISI_TEST_DATA_ROOT=os.environ['PYVISI_TEST_DATA_ROOT']
35 except KeyError:
36 PYVISI_TEST_DATA_ROOT='.'
37
38 PYVISI_TEST_MESHES_PATH = os.path.join(PYVISI_TEST_DATA_ROOT, "data_meshes")
39 PYVISI_TEST_MOVIE_IMAGES_PATH = os.path.join(PYVISI_WORKDIR, \
40 "data_sample_images", "movie")
41
42 MIN_IMAGE_SIZE = 100
43 X_SIZE = 400
44 Y_SIZE = 400
45
46 SCALAR_FIELD_POINT_DATA = "temp"
47 FILE_2D = "tempvel-"
48 IMAGE_NAME = "TestMovie"
49 JPG_RENDERER = Renderer.OFFLINE_JPG
50
51 class TestMovie:
52 def render(self, file):
53 self.scene.render(image_name = \
54 os.path.join(PYVISI_TEST_MOVIE_IMAGES_PATH, file))
55
56 self.failUnless(os.stat(os.path.join(PYVISI_TEST_MOVIE_IMAGES_PATH,\
57 file))[ST_SIZE] > MIN_IMAGE_SIZE)
58
59 class TestGenerateMovie(unittest.TestCase, TestMovie):
60 def setUp(self):
61 self.scene = \
62 Scene(renderer = JPG_RENDERER, num_viewport = 1,
63 x_size = X_SIZE, y_size = Y_SIZE)
64
65 self.data_collector = DataCollector(source = Source.XML)
66 self.data_collector.setActiveScalar(scalar = SCALAR_FIELD_POINT_DATA)
67
68
69 # Create a Contour.
70 self.map = Map(scene = self.scene,
71 data_collector = self.data_collector,
72 viewport = Viewport.SOUTH_WEST, lut = Lut.COLOR,
73 cell_to_point = False, outline = True)
74
75 self.velocity = Velocity(scene = self.scene,
76 data_collector = self.data_collector,
77 viewport = Viewport.SOUTH_WEST, arrow = Arrow.TWO_D,
78 color_mode = ColorMode.VECTOR, lut = Lut.COLOR,
79 cell_to_point = False, outline = True)
80
81 self.velocity.setScaleFactor(scale_factor = 0.07)
82 self.velocity.setRatio(ratio = 8)
83 self.velocity.setColor(color = Color.BLACK)
84
85 self.mov = Movie()
86 self.lst = []
87 self.cam = Camera(scene = self.scene, viewport = Viewport.SOUTH_WEST)
88
89 def tearDown(self):
90 del self.scene
91 del self.data_collector
92 del self.velocity
93 del self.map
94 del self.cam
95 del self.mov
96 del self.lst
97
98 def testMovieRange(self):
99
100 for i in range(938, 949):
101 self.data_collector.setFileName(file_name = \
102 os.path.join(PYVISI_TEST_MESHES_PATH, FILE_2D + "%06d.vtu")
103 % i)
104
105 self.render(IMAGE_NAME + "%06d.jpg" % i)
106
107 self.mov.imageRange(input_directory = PYVISI_TEST_MOVIE_IMAGES_PATH,
108 first_image = IMAGE_NAME + "000938.jpg",
109 last_image = IMAGE_NAME + "000948.jpg")
110
111 self.mov.makeMovie(os.path.join(PYVISI_TEST_MOVIE_IMAGES_PATH, \
112 "movie_testMovieRange.mpg"))
113
114 self.failUnless(os.stat(os.path.join(PYVISI_TEST_MOVIE_IMAGES_PATH,\
115 "movie_testMovieRange.mpg"))[ST_SIZE] > MIN_IMAGE_SIZE)
116
117
118 def testMovieList(self):
119
120 for i in range(938, 949):
121 self.data_collector.setFileName(file_name = \
122 os.path.join(PYVISI_TEST_MESHES_PATH, FILE_2D + "%06d.vtu")
123 % i)
124
125 self.render(IMAGE_NAME + "%06d.jpg" % i)
126 self.lst.append(IMAGE_NAME + "%06d.jpg" % i)
127
128 self.mov.imageList(input_directory = PYVISI_TEST_MOVIE_IMAGES_PATH,
129 image_list = self.lst)
130
131 self.mov.makeMovie(os.path.join(PYVISI_TEST_MOVIE_IMAGES_PATH, \
132 "movie_testMovieList.mpg"))
133
134 self.failUnless(os.stat(os.path.join(PYVISI_TEST_MOVIE_IMAGES_PATH,\
135 "movie_testMovieList.mpg"))[ST_SIZE] > MIN_IMAGE_SIZE)
136
137
138 ###############################################################################
139
140
141 if __name__ == '__main__':
142 if getMPISizeWorld() == 1:
143 if os.system('ppmtompeg')/256==127: #Command not found
144 print "run_movie_with_lazy_evaluation.py was not executed because more than one processor is in use."
145 else:
146 suite = unittest.TestSuite()
147 suite.addTest(unittest.TestLoader().loadTestsFromTestCase(TestGenerateMovie))
148 s=unittest.TextTestRunner(verbosity=2).run(suite)
149 if not s.wasSuccessful(): sys.exit(1)
150 else:
151 print "run_movie_with_lazy_evaluation.py was not executed because more than one processor is in use."
152

  ViewVC Help
Powered by ViewVC 1.1.26