source: trunk/anuga_core/source/anuga/visualiser_new/sww_visualiser.py @ 8050

Last change on this file since 8050 was 4621, checked in by jack, 17 years ago

New visualiser layout. Functionally equivalent to the old one, but much cleaner. Slightly different interface.

File size: 2.5 KB
Line 
1from Numeric import array, Float
2from Scientific.IO.NetCDF import NetCDFFile
3from visualiser import Visualiser
4from vtk import vtkCellArray
5
6class SWWVisualiser(Visualiser):
7    '''
8    A Visualiser that views SWW files. The source for this
9    visualiser is a string containing the sww file name.
10    '''
11
12    def __init__(self, *args, **kwargs):
13        Visualiser.__init__(self, *args, **kwargs)
14        fin = NetCDFFile(self.vis_source, 'r')
15        self.xPoints = array(fin.variables['x'], Float)
16        self.yPoints = array(fin.variables['y'], Float)
17        self.quantityCache = {}
18        fin.close()
19
20    def setupGrid(self):
21        fin = NetCDFFile(self.vis_source, 'r')
22        nTri = fin.variables['volumes'].shape[0]
23        insertNextCell = vtkCellArray.InsertNextCell
24        insertCellPoint = vtkCellArray.InsertCellPoint
25       
26        for v in range(nTri):
27            insertNextCell(self.vtk_cells, 3)
28            for i in range(3):
29                insertCellPoint(self.vtk_cells, fin.variables['volumes'][v][i])
30
31        fin.close()
32
33    def getMaxFrameNumber(self):
34        fin = NetCDFFile(self.vis_source, 'r')
35        rv = fin.variables['time'].shape[0] - 1
36        fin.close()
37        return rv
38
39    def getQuantityPoints(self, quantityName, dynamic=False):
40        try:
41            if dynamic:
42                q = self.quantityCache[quantityName][self.vis_frame]
43            else:
44                q = self.quantityCache[quantityName]
45        except KeyError:
46            fin = NetCDFFile(self.vis_source, 'r')
47            if dynamic:
48                if not self.quantityCache.has_key(quantityName):
49                    self.quantityCache[quantityName] = {}
50                q = array(fin.variables[quantityName][self.vis_frame], Float)
51                self.quantityCache[quantityName][self.vis_frame] = q
52            else:
53                q = array(fin.variables[quantityName], Float)
54                self.quantityCache[quantityName] = q
55            fin.close()
56        return q
57
58    def getQuantityDict(self):
59        quantities = {}
60        fin = NetCDFFile(self.vis_source, 'r')
61        names = [ k for k in fin.variables.keys()
62                  if k != 'x'
63                  and k != 'y'
64                  and k != 'z'
65                  and k != 'time'
66                  and k != 'volumes' ]
67        argss = [ (name, len(fin.variables[name].shape) != 1) for name in names ]
68        fin.close()
69        for args in argss:
70            quantities[name] = self.getQuantityPoints(*args)
71        return quantities
Note: See TracBrowser for help on using the repository browser.