/[escript]/trunk/modellib/py_src/visualization.py
ViewVC logotype

Contents of /trunk/modellib/py_src/visualization.py

Parent Directory Parent Directory | Revision Log Revision Log


Revision 149 - (show annotations)
Thu Sep 1 03:31:39 2005 UTC (14 years, 1 month ago) by jgs
Original Path: trunk/esys2/modellib/py_src/visualization.py
File MIME type: text/x-python
File size: 5518 byte(s)
Merge of development branch dev-02 back to main trunk on 2005-09-01

1 # $Id$
2
3 from esys.escript.modelframe import Model
4 import os
5
6 class Visualization(Model):
7 """
8 Generic visualization of scalar, vector and tensorial data
9 (not implemeted yet)
10
11 @ivar t: current time
12 @ivar scalar: scalar data set
13 @ivar vector: vector data set
14 @ivar tensor: tensor data set
15 @ivar stride: visulaization is done every strides time step
16 @ivar filename: name of the movie file
17 """
18
19 def __init__(self, debug=False):
20 """
21 Initialisation of the visualisation model object
22
23 @param debug: Debugging flag
24 """
25 Model.__init__(self, debug=debug)
26 self.declareParameter(t=0.,
27 scalar=None, vector=None, tensor=None,
28 stride=1, movie="movie.mpg", counter=0)
29
30 def doInitialization(self):
31 """
32 Does some kind of initialisation
33 """
34 self.__n = 0
35 self.__scene = None
36
37 def doStepPostprocessing(self, dt):
38 """
39 Does any necessary postprocessing after each step
40
41 @param dt:
42 """
43 self.__n += 1
44 if self.__n % self.stride:
45 data = self.scalar
46 if data != None:
47 pass
48 data = self.vector
49 if data != None:
50 pass
51 data = self.tensor
52 if data != None:
53 pass
54
55 def doFinalization(self):
56 """
57 Finalises the visualisation. For instance, makes a movie of the
58 image files.
59 """
60 # make the movie into self.filename
61 pass
62
63 class ShadePlot(Visualization):
64 """
65 Shaded contour plots
66 """
67
68 def __init(self, debug=False):
69 """
70 Initialisation
71 """
72 Visualization.__init__(self, debug)
73 self.declareParameter(filename="shadePlot.%s.png")
74
75 def doStepPostprocessing(self, dt):
76 """
77 Do any necessary postprocessing operations after a timestep.
78
79 @param dt:
80 """
81 self.counter += 1
82 if self.counter % self.stride == 0:
83 n = self.counter/self.stride
84
85 # look for a vtk xml file of the right name and plot it
86 dataFname = "data.s.%d.xml" % n
87 if not os.path.exists(dataFname):
88 print "Data file doesn't exist! Skipping frame generation."
89
90 else:
91 import pyvisi
92 import pyvisi.renderers.vtk
93
94 scene = pyvisi.renderers.vtk.Scene()
95 plot = pyvisi.renderers.vtk.ContourPlot(scene)
96 plot.setData(fname=dataFname,
97 format='vtk-xml',
98 scalars='escript_scalar_data')
99 scene.save(fname="shadePlot.%05d.png" % n, format="png")
100
101
102 class ArrowPlot(Visualization):
103 """
104 Arrow/vector/quiver plots
105 """
106
107 def __init(self, debug=False):
108 """
109 Initialisation
110 """
111 Visualization.__init__(self, debug)
112 self.declareParameter(filename="arrowPlot.%s.png")
113
114 def doStepPostprocessing(self, dt):
115 """
116 Do any necessary postprocessing operations after a timestep.
117
118 @param dt:
119 """
120 self.counter += 1
121 if self.counter % self.stride == 0:
122 n = self.counter/self.stride
123
124 # look for a vtk xml file of the right name and plot it
125 dataFname = "data.v.%d.xml" % n
126 if not os.path.exists(dataFname):
127 print "Data file doesn't exist! Skipping frame generation."
128
129 else:
130 import pyvisi
131 import pyvisi.renderers.vtk
132
133 scene = pyvisi.renderers.vtk.Scene()
134 plot = pyvisi.renderers.vtk.ArrowPlot3D(scene)
135 plot.setData(fname=dataFname,
136 format='vtk-xml')
137 scene.save(fname="arrowPlot.%05d.png" % n, format="png")
138
139
140
141 class EllipsoidPlot(Visualization):
142 """
143 Ellipsoid plots
144 """
145
146 def __init(self, debug=False):
147 """
148 Initialisation
149 """
150 Visualization.__init__(self, debug)
151
152
153 class WriteVTK(Visualization):
154 """
155 Writes data into a VTK file for further processing. Currently data
156 are written in several files for each data type. This may change
157 in the future.
158
159 scalar: scalar data set
160 vector: vector data set
161 tensor: tensor data set
162 stride: file is written every stride-th time step
163 filename: name of the data files. use %s for indication of data type
164 (s,v,t) and time step id.
165 """
166
167 def __init__(self, debug=False):
168 """
169 Initialisation of the WriteVTK object
170
171 @param debug: Debugging flag
172 """
173 Visualization.__init__(self, debug=debug)
174 self.declareParameter(filename="data.%s.xml")
175
176 def doStepPostprocessing(self, dt):
177 """
178 Do any necessary postprocessing operations after a timestep.
179
180 @param dt:
181 """
182 self.counter += 1
183 if self.counter % self.stride == 0:
184 n = self.counter/self.stride
185 data = self.scalar
186 if hasattr(data, "saveVTK"):
187 data.saveVTK(self.filename % ("s.%d" % n))
188 data = self.vector
189 if hasattr(data, "saveVTK"):
190 data.saveVTK(self.filename % ("v.%d" % n))
191 data = self.tensor
192 if hasattr(data, "saveVTK"):
193 data.saveVTK(self.filename % ("t.%d" % n))
194
195 # vim: expandtab shiftwidth=4:

Properties

Name Value
svn:eol-style native
svn:keywords Author Date Id Revision

  ViewVC Help
Powered by ViewVC 1.1.26