[906] | 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 pmesh2domain import pmesh_to_domain_instance |
---|
| 14 | import time, os |
---|
| 15 | from data_manager import get_dataobject |
---|
| 16 | from util import mean |
---|
| 17 | |
---|
| 18 | def tsh2sww(infilename, sww_file_name = None, verbose = False): |
---|
| 19 | """ |
---|
| 20 | Note: This currently just writes the output file in the input file dir. |
---|
| 21 | """ |
---|
| 22 | if verbose == True:print 'Creating domain from', infilename |
---|
| 23 | domain = pmesh_to_domain_instance(infilename, Domain) |
---|
| 24 | if verbose == True:print "Number of triangles = ", len(domain) |
---|
| 25 | |
---|
| 26 | domain.smooth = True |
---|
| 27 | domain.format = 'sww' #Native netcdf visualisation format |
---|
| 28 | |
---|
| 29 | file_path, filename = path.split(infilename) |
---|
| 30 | filename, ext = path.splitext(filename) |
---|
| 31 | |
---|
| 32 | if not (sww_file_name == None): |
---|
| 33 | file_path, filename = path.split(sww_file_name) |
---|
| 34 | filename, ext = path.splitext(filename) |
---|
| 35 | domain.filename = filename |
---|
| 36 | |
---|
| 37 | domain.reduction = mean |
---|
| 38 | if verbose == True:print "file_path",file_path |
---|
| 39 | if file_path == "":file_path = "." |
---|
| 40 | domain.set_datadir(file_path) |
---|
| 41 | |
---|
| 42 | if verbose == True: |
---|
| 43 | print "Output written to " + domain.get_datadir() + sep + \ |
---|
| 44 | domain.filename + "." + domain.format |
---|
| 45 | sww = get_dataobject(domain) |
---|
| 46 | sww.store_connectivity() |
---|
| 47 | sww.store_timestep('stage') |
---|
| 48 | |
---|
| 49 | if __name__ == "__main__": |
---|
| 50 | usage = "usage: %s pmesh_file_name [verbose|non_verbose]" % path.basename(sys.argv[0]) |
---|
| 51 | if len(sys.argv) < 2: |
---|
| 52 | print usage |
---|
| 53 | else: |
---|
| 54 | filename = sys.argv[1] |
---|
| 55 | verbose = False |
---|
| 56 | if len(sys.argv) > 2: |
---|
| 57 | if sys.argv[2][0] == "v" or sys.argv[2][0] == "V": |
---|
| 58 | verbose = True |
---|
| 59 | tsh2sww(filename, verbose = verbose) |
---|
| 60 | |
---|