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 = '20090504_114635_run_final_0_68754_84_Tb__mhingee' |
---|
25 | time_dir2 = '20090504_114715_run_final_0_70881_84_Tb__mhingee' |
---|
26 | time_dir3 = '20090505_100250_run_final_0_27285_84_Tb__mhingee' |
---|
27 | time_dir4 = '20090505_173023_run_final_0_27285_84_Tb_internal_mhingee' |
---|
28 | ##time_dir5 = '' |
---|
29 | ##time_dir6 = '' |
---|
30 | ## |
---|
31 | time_dirs = [time_dir1, time_dir2, time_dir3, time_dir4] |
---|
32 | |
---|
33 | |
---|
34 | cellsize = 250 |
---|
35 | ##cellsize = 5 |
---|
36 | |
---|
37 | timestep = None # None means no timestep! |
---|
38 | ##timestep = 0 |
---|
39 | |
---|
40 | ###### |
---|
41 | # Set the special areas of interest. If none, do: area='All' |
---|
42 | ###### |
---|
43 | |
---|
44 | #area = ['Bunbury', 'Busselton'] # strings must match keys in var_equations below |
---|
45 | area = ['All'] # 'All' means no special areas - the whole thing |
---|
46 | |
---|
47 | ###### |
---|
48 | # Define allowed variable names and associated equations to generate values. |
---|
49 | # This would not normally change. |
---|
50 | ###### |
---|
51 | var_equations = {'stage': 'stage', |
---|
52 | 'momentum': '(xmomentum**2 + ymomentum**2)**0.5', |
---|
53 | 'depth': 'stage-elevation', |
---|
54 | 'speed': '(xmomentum**2 + ymomentum**2)**0.5/(stage-elevation+1.e-6)', |
---|
55 | 'elevation': 'elevation' } |
---|
56 | |
---|
57 | # one or more key strings from var_equations above |
---|
58 | var = ['stage'] |
---|
59 | |
---|
60 | ###### |
---|
61 | # Start running the various conversions we require. |
---|
62 | ###### |
---|
63 | |
---|
64 | for which_var in var: |
---|
65 | if which_var not in var_equations: |
---|
66 | print 'Unrecognized variable name: %s' % which_var |
---|
67 | break |
---|
68 | |
---|
69 | for which_area in area: |
---|
70 | if which_area == 'All': |
---|
71 | easting_min = None |
---|
72 | easting_max = None |
---|
73 | northing_min = None |
---|
74 | northing_max = None |
---|
75 | else: |
---|
76 | try: |
---|
77 | easting_min = eval('project.xmin%s' % which_area) |
---|
78 | easting_max = eval('project.xmax%s' % which_area) |
---|
79 | northing_min = eval('project.ymin%s' % which_area) |
---|
80 | northing_max = eval('project.ymax%s' % which_area) |
---|
81 | except AttributeError: |
---|
82 | print 'Unrecognized area name: %s' % which_area |
---|
83 | break |
---|
84 | |
---|
85 | for time_dir in time_dirs: |
---|
86 | |
---|
87 | name1 = join(directory, time_dir, project.scenario_name) |
---|
88 | name2 = join(directory, time_dir, project.scenario_name)+'_time_31980_0' |
---|
89 | |
---|
90 | names = [name1, name2] |
---|
91 | |
---|
92 | asc_name = [] |
---|
93 | |
---|
94 | for name in names: |
---|
95 | |
---|
96 | outname = name + '_' + which_area + '_' + which_var |
---|
97 | quantityname = var_equations[which_var] |
---|
98 | |
---|
99 | print 'start sww2dem: time_dir=%s' % time_dir |
---|
100 | |
---|
101 | sww2dem(name, basename_out = outname, |
---|
102 | quantity = quantityname, |
---|
103 | timestep = timestep, |
---|
104 | cellsize = cellsize, |
---|
105 | easting_min = easting_min, |
---|
106 | easting_max = easting_max, |
---|
107 | northing_min = northing_min, |
---|
108 | northing_max = northing_max, |
---|
109 | reduction = max, |
---|
110 | verbose = True, |
---|
111 | format = 'asc') |
---|
112 | |
---|
113 | asc_name.append(outname + '.asc') |
---|
114 | |
---|
115 | maxasc_outname = join(directory, time_dir, project.scenario_name)+'_'+which_area+'_'+which_var+'_max.asc' |
---|
116 | |
---|
117 | print 'max asc outname ', maxasc_outname |
---|
118 | print 'asc_name ', str(asc_name) |
---|
119 | |
---|
120 | MaxAsc(maxasc_outname, asc_name) |
---|