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 anuga.lib.maxasc.maxasc import MaxAsc |
---|
16 | from anuga.shallow_water.data_manager import convert_dem_from_ascii2netcdf, dem2pts |
---|
17 | from anuga.shallow_water.data_manager import sww2dem |
---|
18 | from os import sep |
---|
19 | |
---|
20 | |
---|
21 | directory = project.output_dir |
---|
22 | |
---|
23 | ##time_dir1 = '20081217_101310_run_final_0_27283_250m_none_dt_kvanputt' |
---|
24 | ##time_dir2 = '20081217_115336_run_final_0_27283_250m_none_dp_kvanputt' |
---|
25 | ###time_dir1 = '20080924_123626_run_final_0_27283_250m_all_kvanputt' # This uses the 250m bathymetry with all interior polygons |
---|
26 | ###time_dir2 = '20080912_154716_run_final_0_27283_alpha0.1_kvanputt' # This uses original bathyemetry data |
---|
27 | ###time_dir3 = '20080924_123601_run_final_0_27283_250m_none_kvanputt' # This uses the 250m bathymetry without any interior polygons |
---|
28 | ##time_dirs = [time_dir1, time_dir2]#, time_dir3] |
---|
29 | |
---|
30 | time_dir1 = '20081211_154006_run_final_0.6_27255_alpha0.1_kvanputt' |
---|
31 | ##time_dir2 = '20081211_162311_run_final_0_27255_alpha0.1_kvanputt' |
---|
32 | ##time_dir3 = '20081211_162346_run_final_0_68693_alpha0.1_kvanputt' |
---|
33 | ##time_dir4 = '20081211_162433_run_final_0.6_68693_alpha0.1_kvanputt' |
---|
34 | ##time_dir5 = '20081211_162656_run_final_0.6_27283_alpha0.1_kvanputt' |
---|
35 | ##time_dir6 = '20081211_162744_run_final_0_27283_alpha0.1_kvanputt' |
---|
36 | ## |
---|
37 | time_dirs = [time_dir1] #5, time_dir4]# , time_dir4, time_dir5, time_dir6] |
---|
38 | |
---|
39 | |
---|
40 | ##cellsize = 20 |
---|
41 | cellsize = 5 |
---|
42 | |
---|
43 | timestep = None # None means no timestep! |
---|
44 | #timestep = 0 |
---|
45 | |
---|
46 | ###### |
---|
47 | # Set the special areas of interest. If none, do: area='All' |
---|
48 | ###### |
---|
49 | |
---|
50 | area = ['Bunbury'] # strings must match keys in var_equations below |
---|
51 | ##area = ['All'] # 'All' means no special areas - the whole thing |
---|
52 | |
---|
53 | ###### |
---|
54 | # Define allowed variable names and associated equations to generate values. |
---|
55 | # This would not normally change. |
---|
56 | ###### |
---|
57 | var_equations = {'stage': 'stage', |
---|
58 | 'momentum': '(xmomentum**2 + ymomentum**2)**0.5', |
---|
59 | 'depth': 'stage-elevation', |
---|
60 | 'speed': '(xmomentum**2 + ymomentum**2)**0.5/(stage-elevation+1.e-6)', |
---|
61 | 'elevation': 'elevation' } |
---|
62 | |
---|
63 | # one or more key strings from var_equations above |
---|
64 | var = ['depth'] |
---|
65 | |
---|
66 | ###### |
---|
67 | # Start running the various conversions we require. |
---|
68 | ###### |
---|
69 | |
---|
70 | for which_var in var: |
---|
71 | if which_var not in var_equations: |
---|
72 | print 'Unrecognized variable name: %s' % which_var |
---|
73 | break |
---|
74 | |
---|
75 | for which_area in area: |
---|
76 | if which_area == 'All': |
---|
77 | easting_min = None |
---|
78 | easting_max = None |
---|
79 | northing_min = None |
---|
80 | northing_max = None |
---|
81 | else: |
---|
82 | try: |
---|
83 | easting_min = eval('project.xmin%s' % which_area) |
---|
84 | easting_max = eval('project.xmax%s' % which_area) |
---|
85 | northing_min = eval('project.ymin%s' % which_area) |
---|
86 | northing_max = eval('project.ymax%s' % which_area) |
---|
87 | except AttributeError: |
---|
88 | print 'Unrecognized area name: %s' % which_area |
---|
89 | break |
---|
90 | |
---|
91 | for time_dir in time_dirs: |
---|
92 | |
---|
93 | name1 = directory+time_dir+sep+project.scenario_name |
---|
94 | name2 = directory+time_dir+sep+project.scenario_name+'_time_39600_0' |
---|
95 | name3 = directory+time_dir+sep+project.scenario_name+'_time_79200_0' |
---|
96 | |
---|
97 | names = [name1, name2, name3] |
---|
98 | |
---|
99 | asc_name = [] |
---|
100 | |
---|
101 | for name in names: |
---|
102 | |
---|
103 | outname = name + '_' + which_area + '_' + which_var |
---|
104 | quantityname = var_equations[which_var] |
---|
105 | |
---|
106 | print 'start sww2dem: time_dir=%s' % time_dir |
---|
107 | |
---|
108 | sww2dem(name, basename_out = outname, |
---|
109 | quantity = quantityname, |
---|
110 | timestep = timestep, |
---|
111 | cellsize = cellsize, |
---|
112 | easting_min = easting_min, |
---|
113 | easting_max = easting_max, |
---|
114 | northing_min = northing_min, |
---|
115 | northing_max = northing_max, |
---|
116 | reduction = max, |
---|
117 | verbose = True, |
---|
118 | format = 'asc') |
---|
119 | |
---|
120 | asc_name.append(outname + '.asc') |
---|
121 | |
---|
122 | maxasc_outname = directory+time_dir+sep+project.scenario_name+'_'+which_area+'_'+which_var+'_max.asc' |
---|
123 | |
---|
124 | print 'max asc outname ', maxasc_outname |
---|
125 | print 'asc_name ', str(asc_name) |
---|
126 | |
---|
127 | MaxAsc(maxasc_outname, asc_name) |
---|