1 | """ |
---|
2 | Generates ascii grids of nominated areas - |
---|
3 | Input: sww file from run_perth.py |
---|
4 | boundaries for grids from project.py |
---|
5 | Outputs: ascii grids of specified variables |
---|
6 | Stored in the 'outputs_dir' folder for respective .sww file |
---|
7 | |
---|
8 | Note: |
---|
9 | If producing a grid for the enitre extent cellsize should be greater than 30m |
---|
10 | If producing grids for inundation area resolution should be greater than mesh (ie ~22m) |
---|
11 | """ |
---|
12 | |
---|
13 | import project, os |
---|
14 | import sys |
---|
15 | from os.path import join |
---|
16 | from anuga.lib.maxasc.maxasc import MaxAsc |
---|
17 | from anuga.shallow_water.data_manager import convert_dem_from_ascii2netcdf, dem2pts |
---|
18 | from anuga.shallow_water.data_manager import sww2dem |
---|
19 | from os import sep |
---|
20 | |
---|
21 | |
---|
22 | directory = project.output_folder |
---|
23 | |
---|
24 | time_dir1 = '20090414_121216_run_final_0_27279_711_Tb__kvanputt' |
---|
25 | time_dir2 = '20090415_001215_run_final_0_70371_711_Tb__kvanputt' |
---|
26 | time_dir3 = '20090415_114548_run_final_0_27168_711_Tb__kvanputt' |
---|
27 | |
---|
28 | time_dirs = [time_dir1, time_dir2, time_dir3] |
---|
29 | |
---|
30 | cellsize = 250 |
---|
31 | ##cellsize = 5 |
---|
32 | |
---|
33 | timestep = None # None means no timestep! |
---|
34 | #timestep = 0 |
---|
35 | |
---|
36 | ###### |
---|
37 | # Set the special areas of interest. If none, do: area='All' |
---|
38 | ###### |
---|
39 | |
---|
40 | #area = ['Bunbury', 'Busselton'] # strings must match keys in var_equations below |
---|
41 | area = ['All'] # 'All' means no special areas - the whole thing |
---|
42 | |
---|
43 | ###### |
---|
44 | # Define allowed variable names and associated equations to generate values. |
---|
45 | # This would not normally change. |
---|
46 | ###### |
---|
47 | var_equations = {'stage': 'stage', |
---|
48 | 'momentum': '(xmomentum**2 + ymomentum**2)**0.5', |
---|
49 | 'depth': 'stage-elevation', |
---|
50 | 'speed': '(xmomentum**2 + ymomentum**2)**0.5/(stage-elevation+1.e-6)', |
---|
51 | 'elevation': 'elevation' } |
---|
52 | |
---|
53 | # one or more key strings from var_equations above |
---|
54 | var = ['stage'] |
---|
55 | |
---|
56 | ###### |
---|
57 | # Start running the various conversions we require. |
---|
58 | ###### |
---|
59 | |
---|
60 | for which_var in var: |
---|
61 | if which_var not in var_equations: |
---|
62 | print 'Unrecognized variable name: %s' % which_var |
---|
63 | break |
---|
64 | |
---|
65 | for which_area in area: |
---|
66 | if which_area == 'All': |
---|
67 | easting_min = None |
---|
68 | easting_max = None |
---|
69 | northing_min = None |
---|
70 | northing_max = None |
---|
71 | else: |
---|
72 | try: |
---|
73 | easting_min = eval('project.xmin%s' % which_area) |
---|
74 | easting_max = eval('project.xmax%s' % which_area) |
---|
75 | northing_min = eval('project.ymin%s' % which_area) |
---|
76 | northing_max = eval('project.ymax%s' % which_area) |
---|
77 | except AttributeError: |
---|
78 | print 'Unrecognized area name: %s' % which_area |
---|
79 | break |
---|
80 | |
---|
81 | for time_dir in time_dirs: |
---|
82 | |
---|
83 | name1 = join(directory, time_dir, project.scenario_name) |
---|
84 | name2 = join(directory, time_dir, project.scenario_name)+'_time_44400_0' |
---|
85 | |
---|
86 | names = [name1, name2] |
---|
87 | |
---|
88 | for name in names: |
---|
89 | |
---|
90 | outname = name + '_' + which_area + '_' + which_var |
---|
91 | quantityname = var_equations[which_var] |
---|
92 | |
---|
93 | print 'start sww2dem: time_dir=%s' % time_dir |
---|
94 | |
---|
95 | sww2dem(name, basename_out = outname, |
---|
96 | quantity = quantityname, |
---|
97 | timestep = timestep, |
---|
98 | cellsize = cellsize, |
---|
99 | easting_min = easting_min, |
---|
100 | easting_max = easting_max, |
---|
101 | northing_min = northing_min, |
---|
102 | northing_max = northing_max, |
---|
103 | reduction = max, |
---|
104 | verbose = True, |
---|
105 | format = 'asc') |
---|
106 | |
---|
107 | |
---|