1 | """Given a .tsh, print an sww |
---|
2 | """ |
---|
3 | |
---|
4 | ###################### |
---|
5 | # Module imports |
---|
6 | # |
---|
7 | |
---|
8 | import sys |
---|
9 | from os import sep, path |
---|
10 | sys.path.append('..'+sep+'pyvolution') |
---|
11 | |
---|
12 | from shallow_water import Domain |
---|
13 | from anuga.pyvolution.pmesh2domain import pmesh_to_domain_instance |
---|
14 | import time, os |
---|
15 | from anuga.pyvolution.sww_file import SWW_file |
---|
16 | from anuga.utilities.numerical_tools import mean |
---|
17 | import anuga.utilities.log as log |
---|
18 | |
---|
19 | |
---|
20 | def tsh2sww(infilename, sww_file_name = None, verbose = False): |
---|
21 | """ |
---|
22 | This converts a mesh file (.tsh/.msh) to an .sww file. |
---|
23 | This is usefull to visualise the mesh. |
---|
24 | |
---|
25 | Note: This currently just writes the output file in the input file dir. |
---|
26 | """ |
---|
27 | if verbose == True: log.critical('Creating domain from %s' % infilename) |
---|
28 | domain = pmesh_to_domain_instance(infilename, Domain) |
---|
29 | if verbose == True: log.critical("Number of triangles = %d" % len(domain)) |
---|
30 | |
---|
31 | domain.smooth = True |
---|
32 | domain.format = 'sww' #Native netcdf visualisation format |
---|
33 | |
---|
34 | file_path, filename = path.split(infilename) |
---|
35 | filename, ext = path.splitext(filename) |
---|
36 | |
---|
37 | if not (sww_file_name == None): |
---|
38 | file_path, filename = path.split(sww_file_name) |
---|
39 | filename, ext = path.splitext(filename) |
---|
40 | domain.set_name(filename) |
---|
41 | |
---|
42 | domain.reduction = mean |
---|
43 | if verbose == True: log.critical("file_path %s" % file_path) |
---|
44 | if file_path == "":file_path = "." |
---|
45 | domain.set_datadir(file_path) |
---|
46 | |
---|
47 | if verbose == True: |
---|
48 | log.critical("Output written to %s%s%s.%s" |
---|
49 | % (domain.get_datadir(), sep, domain.get_name(), |
---|
50 | domain.format) |
---|
51 | sww = SWW_file(domain) |
---|
52 | sww.store_connectivity() |
---|
53 | sww.store_timestep('stage') |
---|
54 | |
---|
55 | if __name__ == "__main__": |
---|
56 | usage = "usage:python %s pmesh_file_name [verbose|non_verbose]" % path.basename(sys.argv[0]) |
---|
57 | if len(sys.argv) < 2: |
---|
58 | print usage |
---|
59 | else: |
---|
60 | filename = sys.argv[1] |
---|
61 | verbose = False |
---|
62 | if len(sys.argv) > 2: |
---|
63 | if sys.argv[2][0] == "v" or sys.argv[2][0] == "V": |
---|
64 | verbose = True |
---|
65 | tsh2sww(filename, verbose = verbose) |
---|
66 | |
---|