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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 990 - (hide annotations)
Wed Feb 21 04:27:52 2007 UTC (12 years, 5 months ago) by ksteube
File MIME type: text/x-python
File size: 19182 byte(s)
Cleaned up the python in-line doc to make epydoc work better

Configured for shake71 to find NetCDF libraries

1 jgs 127 # $Id$
2    
3 elspeth 628 __copyright__=""" Copyright (c) 2006 by ACcESS MNRF
4     http://www.access.edu.au
5     Primary Business: Queensland, Australia"""
6     __license__="""Licensed under the Open Software License version 3.0
7     http://www.opensource.org/licenses/osl-3.0.php"""
8    
9 gross 912 from esys.escript.modelframe import Model, Link
10 gross 911 from esys.escript import saveVTK, Data
11 jgs 148 import os
12 jgs 127
13     class Visualization(Model):
14 jgs 148 """
15 gross 912 Generic visualization Model
16 jgs 127
17 gross 814 @ivar t: current time (in)
18     @ivar n: frame counter (in)
19     @ivar dt: increment for output (in)
20     @ivar filename: name of the output file (in)
21 jgs 148 """
22 jgs 127
23 gross 918 def __init__(self, **kwargs):
24 jgs 148 """
25     Initialisation of the visualisation model object
26 jgs 127
27 jgs 148 @param debug: Debugging flag
28     """
29 gross 918 super(Visualization,self).__init__(**kwargs)
30 jgs 148 self.declareParameter(t=0.,
31 gross 423 n=0,
32     dt=1,
33     filename="movie.mpg")
34 jgs 127
35 jgs 148 def doInitialization(self):
36 gross 814 """
37     does some kind of initialisation
38     """
39     self.__last_t=self.t
40 gross 912 fnc=self.filename.split('.')
41     if len(fnc)==0:
42     self.__frame_filename="data.%s.xml"
43     else:
44     n=fnc[0]
45     for i in range(1,len(fnc)-1):
46     n+="."+fnc[i]
47     if len(fnc)==1:
48     self.__frame_filename=n+".%s"
49     else:
50     self.__frame_filename=n+".%s."+fnc[-1]
51     self.trace("output filename is %s."%self.__frame_filename)
52 jgs 127
53 gross 912 def getFrameFileName(self):
54     return self.__frame_filename%self.getFrameCounter()
55    
56 gross 423 def writeFrame(self):
57 gross 814 """
58     returns True if the time stamp for writing frame is reached.
59     """
60 gross 423 out=self.t>=self.__last_t+self.dt
61     if out:
62     self.__last_t+=self.dt
63     self.n+=1
64     return out
65    
66     def getFrameCounter(self):
67 gross 814 """
68     returns a frame counter
69     """
70 gross 908 return self.n
71 gross 423
72     def getSafeTimeStepSize(self,dt):
73 gross 814 """
74     returns new step size
75 gross 423
76 gross 814 @param dt: last time step size used
77     @type dt: C{float}
78     @return: time step size that can savely be used
79     @rtype: C{float}
80     """
81     return self.__last_t+self.dt-self.t
82    
83 gross 912 class Movie(Visualization):
84     """
85     Generic visualization of scalar, vector and/or tensorial data
86    
87     @ivar scalar: scalar data set (in)
88     @ivar vector: vector data set (in)
89     @ivar tensor: tensor data set (in)
90     """
91    
92 gross 918 def __init__(self, **kwargs):
93 gross 912 """
94     Initialisation of the visualisation model object
95    
96     @param debug: Debugging flag
97     """
98 gross 918 super(Movie,self).__init__(**kwargs)
99 gross 912 self.declareParameter(scalar=None,
100     vector=None,
101     tensor=None)
102    
103 jgs 148 def doStepPostprocessing(self, dt):
104     """
105 gross 423 renders the scene
106 jgs 148 """
107 gross 912 super(Movie, self).doStepPostprocessing(dt)
108 gross 423 if self.writeFrame():
109 gross 814 if self.debug():
110     self.trace("%s-th frame at time %s"%(self.getFrameCounter(),self.t))
111 gross 911 if isinstance(self.scalar,Data):
112 gross 814 self.trace("scalar data: (min,max) =(%s,%s)"%(inf(self.scalar),sup(self.scalar)))
113 gross 911 if isinstance(self.vector,Data):
114 gross 814 self.trace("vector data: (min,max) =(%s,%s)"%(inf(self.vector),sup(self.vector)))
115 gross 911 if isinstance(self.tensor,Data):
116 gross 814 self.trace("tensor data: (min,max) =(%s,%s)"%(inf(self.tensor),sup(self.tensor)))
117 gross 423
118 gross 912 class ShadePlot(Movie):
119 gross 423 """
120 jgs 148 Shaded contour plots
121     """
122    
123 gross 918 def __init(self, **kwargs):
124 jgs 148 """
125     Initialisation
126     """
127 gross 918 Movie.__init__(self, **kwargs)
128 jgs 148 self.declareParameter(filename="shadePlot.%s.png")
129    
130     def doStepPostprocessing(self, dt):
131     """
132     Do any necessary postprocessing operations after a timestep.
133    
134     @param dt:
135     """
136     self.counter += 1
137     if self.counter % self.stride == 0:
138     n = self.counter/self.stride
139    
140     # look for a vtk xml file of the right name and plot it
141     dataFname = "data.s.%d.xml" % n
142     if not os.path.exists(dataFname):
143     print "Data file doesn't exist! Skipping frame generation."
144    
145     else:
146     import pyvisi
147     import pyvisi.renderers.vtk
148    
149     scene = pyvisi.renderers.vtk.Scene()
150     plot = pyvisi.renderers.vtk.ContourPlot(scene)
151     plot.setData(fname=dataFname,
152     format='vtk-xml',
153     scalars='escript_scalar_data')
154     scene.save(fname="shadePlot.%05d.png" % n, format="png")
155    
156    
157 gross 912 class ArrowPlot(Movie):
158 jgs 148 """
159     Arrow/vector/quiver plots
160     """
161    
162 gross 918 def __init(self, **kwargs):
163 jgs 148 """
164     Initialisation
165     """
166 gross 918 Movie.__init__(self, **kwargs)
167 jgs 148 self.declareParameter(filename="arrowPlot.%s.png")
168    
169     def doStepPostprocessing(self, dt):
170     """
171     Do any necessary postprocessing operations after a timestep.
172    
173     @param dt:
174     """
175     self.counter += 1
176     if self.counter % self.stride == 0:
177     n = self.counter/self.stride
178    
179     # look for a vtk xml file of the right name and plot it
180     dataFname = "data.v.%d.xml" % n
181     if not os.path.exists(dataFname):
182     print "Data file doesn't exist! Skipping frame generation."
183    
184     else:
185     import pyvisi
186     import pyvisi.renderers.vtk
187    
188     scene = pyvisi.renderers.vtk.Scene()
189     plot = pyvisi.renderers.vtk.ArrowPlot3D(scene)
190     plot.setData(fname=dataFname,
191     format='vtk-xml')
192     scene.save(fname="arrowPlot.%05d.png" % n, format="png")
193    
194    
195    
196 gross 912 class EllipsoidPlot(Movie):
197 jgs 148 """
198     Ellipsoid plots
199     """
200    
201 gross 918 def __init(self, **kwargs):
202 jgs 148 """
203     Initialisation
204     """
205 gross 918 Movie.__init__(self, **kwargs)
206 jgs 148
207    
208 gross 912 class WriteVTK(Visualization):
209     """
210     Writes data into a VTK file.
211    
212     The Model can handel up to 20 data sets that are written into a single file tagged with the given name. If no name is given and
213     the data are defined by a L{Link} the name of the target attribute is used as a tag.
214    
215     @ivar data0: data set 0 to be written
216     @type data0: L{escript.Data}
217     @ivar name0: name tag for data set 0
218     @type name0: C{str} or C{None}
219     @ivar data1: data set 1 to be written
220     @type data1: L{escript.Data}
221     @ivar name1: name tag for data set 1
222     @type name1: C{str} or C{None}
223     @ivar data2: data set 2 to be written
224     @type data2: L{escript.Data}
225     @ivar name2: name tag for data set 2
226     @type name2: C{str} or C{None}
227     @ivar data3: data set 3 to be written
228     @type data3: L{escript.Data}
229     @ivar name3: name tag for data set 3
230     @type name3: C{str} or C{None}
231     @ivar data4: data set 4 to be written
232     @type data4: L{escript.Data}
233     @ivar name4: name tag for data set 4
234     @type name4: C{str} or C{None}
235     @ivar data5: data set 5 to be written
236     @type data5: L{escript.Data}
237     @ivar name5: name tag for data set 5
238     @type name5: C{str} or C{None}
239     @ivar data6: data set 6 to be written
240     @type data6: L{escript.Data}
241     @ivar name6: name tag for data set 6
242     @type name6: C{str} or C{None}
243 ksteube 990 @ivar data7: data set 7 to be written
244 gross 912 @type data7: L{escript.Data}
245     @ivar name7: name tag for data set 7
246     @type name7: C{str} or C{None}
247     @ivar data8: data set 8 to be written
248     @type data8: L{escript.Data}
249     @ivar name8: name tag for data set 8
250     @type name8: C{str} or C{None}
251     @ivar data9: data set 9 to be written
252     @type data9: L{escript.Data}
253     @ivar name9: name tag for data set 9
254     @type name9: C{str} or C{None}
255     @ivar data10: data set 10 to be written
256     @type data10: L{escript.Data}
257     @ivar name10: name tag for data set 10
258     @type name10: C{str} or C{None}
259     @ivar data11: data set 11 to be written
260     @type data11: L{escript.Data}
261     @ivar name11: name tag for data set 11
262     @type name11: C{str} or C{None}
263     @ivar data12: data set 12 to be written
264     @type data12: L{escript.Data}
265     @ivar name12: name tag for data set 12
266     @type name12: C{str} or C{None}
267     @ivar data13: data set 13 to be written
268     @type data13: L{escript.Data}
269     @ivar name13: name tag for data set 13
270     @type name13: C{str} or C{None}
271     @ivar data14: data set 14 to be written
272     @type data14: L{escript.Data}
273     @ivar name14: name tag for data set 14
274     @type name14: C{str} or C{None}
275     @ivar data15: data set 15 to be written
276     @type data15: L{escript.Data}
277     @ivar name15: name tag for data set 15
278     @type name15: C{str} or C{None}
279     @ivar data16: data set 16 to be written
280     @type data16: L{escript.Data}
281     @ivar name16: name tag for data set 16
282     @type name16: C{str} or C{None}
283     @ivar data17: data set 17 to be written
284     @type data17: L{escript.Data}
285     @ivar name17: name tag for data set 17
286     @type name17: C{str} or C{None}
287     @ivar data18: data set 18 to be written
288     @type data18: L{escript.Data}
289     @ivar name18: name tag for data set 18
290     @type name18: C{str} or C{None}
291     @ivar data19: data set 19 to be written
292     @type data19: L{escript.Data}
293     @ivar name19: name tag for data set 19
294     @type name19: C{str} or C{None}
295     """
296 gross 918 def __init__(self, **kwargs):
297 gross 912 """
298     Initialisation of the WriteVTK object
299    
300     @param debug: debugging flag
301     @type debug: C{bool}
302     """
303 gross 918 super(WriteVTK,self).__init__(**kwargs)
304 gross 912 self.declareParameter(data0=None,name0=None,
305     data1=None,name1=None,
306     data2=None,name2=None,
307     data3=None,name3=None,
308     data4=None,name4=None,
309     data5=None,name5=None,
310     data6=None,name6=None,
311     data7=None,name7=None,
312     data8=None,name8=None,
313     data9=None,name9=None,
314     data10=None,name10=None,
315     data11=None,name11=None,
316     data12=None,name12=None,
317     data13=None,name13=None,
318     data14=None,name14=None,
319     data15=None,name15=None,
320     data16=None,name16=None,
321     data17=None,name17=None,
322     data18=None,name18=None,
323     data19=None,name19=None)
324     def collectData(self):
325     kwargs={}
326 gross 917 if isinstance(self.data0, Data):
327 gross 912 if self.name0 == None:
328     if isinstance(self.getAttributeObject("data0"),Link):
329     kwargs[self.getAttributeObject("data0").getAttributeName()]=self.data0
330     else:
331     kwargs["data0"]=self.data0
332     else:
333     kwargs[str(self.name0)]=self.data0
334    
335    
336 gross 917 if isinstance(self.data1, Data):
337 gross 912 if self.name1 == None:
338     if isinstance(self.getAttributeObject("data1"),Link):
339     kwargs[self.getAttributeObject("data1").getAttributeName()]=self.data1
340     else:
341     kwargs["data1"]=self.data1
342     else:
343     kwargs[str(self.name1)]=self.data1
344    
345    
346 gross 917 if isinstance(self.data2, Data):
347 gross 912 if self.name2 == None:
348     if isinstance(self.getAttributeObject("data2"),Link):
349     kwargs[self.getAttributeObject("data2").getAttributeName()]=self.data2
350     else:
351     kwargs["data2"]=self.data2
352     else:
353     kwargs[str(self.name2)]=self.data2
354    
355    
356 gross 917 if isinstance(self.data3, Data):
357 gross 912 if self.name3 == None:
358     if isinstance(self.getAttributeObject("data3"),Link):
359     kwargs[self.getAttributeObject("data3").getAttributeName()]=self.data3
360     else:
361     kwargs["data3"]=self.data3
362     else:
363     kwargs[str(self.name3)]=self.data3
364    
365    
366 gross 917 if isinstance(self.data4, Data):
367 gross 912 if self.name4 == None:
368     if isinstance(self.getAttributeObject("data4"),Link):
369     kwargs[self.getAttributeObject("data4").getAttributeName()]=self.data4
370     else:
371     kwargs["data4"]=self.data4
372     else:
373     kwargs[str(self.name4)]=self.data4
374    
375    
376 gross 917 if isinstance(self.data5, Data):
377 gross 912 if self.name5 == None:
378     if isinstance(self.getAttributeObject("data5"),Link):
379     kwargs[self.getAttributeObject("data5").getAttributeName()]=self.data5
380     else:
381     kwargs["data5"]=self.data5
382     else:
383     kwargs[str(self.name5)]=self.data5
384    
385    
386 gross 917 if isinstance(self.data6, Data):
387 gross 912 if self.name6 == None:
388     if isinstance(self.getAttributeObject("data6"),Link):
389     kwargs[self.getAttributeObject("data6").getAttributeName()]=self.data6
390     else:
391     kwargs["data6"]=self.data6
392     else:
393     kwargs[str(self.name6)]=self.data6
394    
395    
396 gross 917 if isinstance(self.data7, Data):
397 gross 912 if self.name7 == None:
398     if isinstance(self.getAttributeObject("data7"),Link):
399     kwargs[self.getAttributeObject("data7").getAttributeName()]=self.data7
400     else:
401     kwargs["data7"]=self.data7
402     else:
403     kwargs[str(self.name7)]=self.data7
404    
405    
406 gross 917 if isinstance(self.data8, Data):
407 gross 912 if self.name8 == None:
408     if isinstance(self.getAttributeObject("data8"),Link):
409     kwargs[self.getAttributeObject("data8").getAttributeName()]=self.data8
410     else:
411     kwargs["data8"]=self.data8
412     else:
413     kwargs[str(self.name8)]=self.data8
414    
415    
416 gross 917 if isinstance(self.data9, Data):
417 gross 912 if self.name9 == None:
418     if isinstance(self.getAttributeObject("data9"),Link):
419     kwargs[self.getAttributeObject("data9").getAttributeName()]=self.data9
420     else:
421     kwargs["data9"]=self.data9
422     else:
423     kwargs[str(self.name9)]=self.data9
424    
425    
426 gross 917 if isinstance(self.data10, Data):
427 gross 912 if self.name10 == None:
428     if isinstance(self.getAttributeObject("data10"),Link):
429     kwargs[self.getAttributeObject("data10").getAttributeName()]=self.data10
430     else:
431     kwargs["data10"]=self.data10
432     else:
433     kwargs[str(self.name10)]=self.data10
434    
435    
436 gross 917 if isinstance(self.data11, Data):
437 gross 912 if self.name11 == None:
438     if isinstance(self.getAttributeObject("data11"),Link):
439     kwargs[self.getAttributeObject("data11").getAttributeName()]=self.data11
440     else:
441     kwargs["data11"]=self.data11
442     else:
443     kwargs[str(self.name11)]=self.data11
444    
445    
446 gross 917 if isinstance(self.data12, Data):
447 gross 912 if self.name12 == None:
448     if isinstance(self.getAttributeObject("data12"),Link):
449     kwargs[self.getAttributeObject("data12").getAttributeName()]=self.data12
450     else:
451     kwargs["data12"]=self.data12
452     else:
453     kwargs[str(self.name12)]=self.data12
454    
455    
456 gross 917 if isinstance(self.data13, Data):
457 gross 912 if self.name13 == None:
458     if isinstance(self.getAttributeObject("data13"),Link):
459     kwargs[self.getAttributeObject("data13").getAttributeName()]=self.data13
460     else:
461     kwargs["data13"]=self.data13
462     else:
463     kwargs[str(self.name13)]=self.data13
464    
465    
466 gross 917 if isinstance(self.data14, Data):
467 gross 912 if self.name14 == None:
468     if isinstance(self.getAttributeObject("data14"),Link):
469     kwargs[self.getAttributeObject("data14").getAttributeName()]=self.data14
470     else:
471     kwargs["data14"]=self.data14
472     else:
473     kwargs[str(self.name14)]=self.data14
474    
475    
476 gross 917 if isinstance(self.data15, Data):
477 gross 912 if self.name15 == None:
478     if isinstance(self.getAttributeObject("data15"),Link):
479     kwargs[self.getAttributeObject("data15").getAttributeName()]=self.data15
480     else:
481     kwargs["data15"]=self.data15
482     else:
483     kwargs[str(self.name15)]=self.data15
484    
485    
486 gross 917 if isinstance(self.data16, Data):
487 gross 912 if self.name16 == None:
488     if isinstance(self.getAttributeObject("data16"),Link):
489     kwargs[self.getAttributeObject("data16").getAttributeName()]=self.data16
490     else:
491     kwargs["data16"]=self.data16
492     else:
493     kwargs[str(self.name16)]=self.data16
494    
495    
496 gross 917 if isinstance(self.data17, Data):
497 gross 912 if self.name17 == None:
498     if isinstance(self.getAttributeObject("data17"),Link):
499     kwargs[self.getAttributeObject("data17").getAttributeName()]=self.data17
500     else:
501     kwargs["data17"]=self.data17
502     else:
503     kwargs[str(self.name17)]=self.data17
504    
505    
506 gross 917 if isinstance(self.data18, Data):
507 gross 912 if self.name18 == None:
508     if isinstance(self.getAttributeObject("data18"),Link):
509     kwargs[self.getAttributeObject("data18").getAttributeName()]=self.data18
510     else:
511     kwargs["data18"]=self.data18
512     else:
513     kwargs[str(self.name18)]=self.data18
514    
515    
516 gross 917 if isinstance(self.data19, Data):
517 gross 912 if self.name19 == None:
518     if isinstance(self.getAttributeObject("data19"),Link):
519     kwargs[self.getAttributeObject("data19").getAttributeName()]=self.data19
520     else:
521     kwargs["data19"]=self.data19
522     else:
523     kwargs[str(self.name19)]=self.data19
524     return kwargs
525    
526     def doInitialPostprocessing(self):
527     """
528     writes vtk file at the end of initial iteration
529     """
530     super(WriteVTK,self).doInitialPostprocessing()
531     kwargs=self.collectData()
532     if len(kwargs)>0:
533     saveVTK(self.getFrameFileName(),**kwargs)
534     self.trace("%s-th frame at time %s is writen to %s"%(self.getFrameCounter(),self.t,self.getFrameFileName()))
535    
536     def doStepPostprocessing(self, dt):
537     """
538     writes vtk file at the end of time iteration
539     """
540     super(WriteVTK,self).doStepPostprocessing(dt)
541     if self.writeFrame():
542     kwargs=self.collectData()
543     if len(kwargs)>0:
544     saveVTK(self.getFrameFileName(),**kwargs)
545     self.trace("%s-th frame at time %s is writen to %s"%(self.getFrameCounter(),self.t,self.getFrameFileName()))
546    
547 jgs 148 # 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