source: trunk/anuga_core/source/anuga/visualiser/commandline_viewer.py @ 8879

Last change on this file since 8879 was 8649, checked in by steve, 12 years ago

Testing visualising height quantity

File size: 2.4 KB
Line 
1""" VTK sww Visualiser for ANUGA
2
3python vtk_viewer swwfile.sww
4"""
5
6import sys, os
7from anuga.visualiser import OfflineVisualiser
8
9def get_filename():
10    if len(sys.argv) > 1:
11        filename = sys.argv[1]
12
13        root, ext = os.path.splitext(filename)
14           
15        if ext <> '.sww':
16            print 'WARNING: I only view sww files.' %filename
17     
18        return filename
19
20
21
22if __name__ == '__main__':
23
24   
25    filename = get_filename()
26    if filename is not None:
27        # The argument to OfflineVisualiser is the path to a sww file
28        o = OfflineVisualiser(filename)
29
30        # Specify the height-based-quantities to render.
31        # Remember to set dynamic=True for time-varying quantities
32        o.render_quantity_height("elevation", dynamic=False)
33        o.render_quantity_height("stage", dynamic=True)
34
35        # Colour the stage:
36        # Either with an RGB value as a 3-tuple of Floats,
37        # o.colour_height_quantity('stage', (0.0, 0.0, 0.8))
38        # Or with a function of the quantities at that point, such as
39        # the stage height:
40        # 0 and 10 are the minimum and maximum values of the stage.
41        o.colour_height_quantity('stage', (lambda q: q['stage'], 1.0, 5.0))
42        # Or with the magnitude of the momentum at that point:
43        # Needs the sqrt function from numeric. Again, 0 and 10
44        # define the colour range.
45        from numpy import sqrt
46        #o.colour_height_quantity('stage',
47        #                          (lambda q:sqrt((q['xmomentum'] ** 2) +
48        #                                         (q['ymomentum'] ** 2)),
49        #                                          0, 10))
50        o.colour_height_quantity('stage',
51                                  (lambda q: q['xmomentum']/
52                                             (q['stage'] - q['elevation']),
53                                              0, 5))
54
55
56        # Draw some axes on the visualiser so we can see how big the wave is
57
58
59        # Draw some axes on the visualiser so we can see how big the wave is
60        o.render_axes()
61
62        # Precaching the height-based quantities reduces the time taken
63        # to draw each frame, but increases the time taken when the
64        # visualiser starts.
65        o.precache_height_quantities()
66
67        # Start the visualiser (in its own thread).
68        o.start()
69        # Wait for the visualiser to terminate before shutdown
70        o.join()
71       
Note: See TracBrowser for help on using the repository browser.