1 | """ |
---|
2 | Generates ascii grids of nominated areas - |
---|
3 | Input: sww file from run_model.py |
---|
4 | area 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 ~20m) |
---|
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 | directory = project.output_folder |
---|
22 | #Folders that contain the sww files of interest found in anuga/outputs |
---|
23 | time_dir1 = '20090714_162136_run_final_0_58260_None_kvanputt' |
---|
24 | time_dir2 = '20090714_162041_run_final_0.8_58292_None_kvanputt' |
---|
25 | time_dir3 = '20090714_161944_run_final_0.8_58280_None_kvanputt' |
---|
26 | time_dir4 = '20090714_161740_run_final_0.8_58260_None_kvanputt' |
---|
27 | |
---|
28 | time_dirs = [time_dir1, time_dir2, time_dir3, time_dir4] |
---|
29 | |
---|
30 | # sww filename extensions ie. hobart_time_17640_0.sww, input into list 17640 |
---|
31 | # make sure numbers are in sequential order |
---|
32 | times = [17640, 35280, 52920] |
---|
33 | |
---|
34 | #Modify the cellsize value to set the size of the raster you require |
---|
35 | #Take into account mesh size when aplying this paramater |
---|
36 | cellsize = 20 #250 |
---|
37 | |
---|
38 | #Now set the timestep at which you want the raster generated. |
---|
39 | #Either set the actual timestep required or use 'None' to indicate that |
---|
40 | #you want the maximum values in the raster over all timesteps |
---|
41 | timestep = None #0 |
---|
42 | |
---|
43 | # Set the special areas of interest. If none, do: area=['All'] |
---|
44 | # Areas identified below are specified by cooridinates in project.py |
---|
45 | |
---|
46 | area = ['Hobart', 'NW', 'South'] |
---|
47 | #area = ['All'] |
---|
48 | |
---|
49 | # one or more key strings from var_equations below |
---|
50 | var = ['depth', 'speed'] |
---|
51 | |
---|
52 | ###### |
---|
53 | # Define allowed variable names and associated equations to generate values. |
---|
54 | # This would not normally change. |
---|
55 | ###### |
---|
56 | var_equations = {'stage': 'stage', |
---|
57 | 'momentum': '(xmomentum**2 + ymomentum**2)**0.5', |
---|
58 | 'depth': 'stage-elevation', |
---|
59 | 'speed': '(xmomentum**2 + ymomentum**2)**0.5/(stage-elevation+1.e-6)', |
---|
60 | 'elevation': 'elevation' } |
---|
61 | |
---|
62 | |
---|
63 | ###### |
---|
64 | # Start script, running through variables, area, folder, sww file (determine by times) |
---|
65 | # Then creates a maximum asci if there is more than one sww file |
---|
66 | ###### |
---|
67 | |
---|
68 | for which_var in var: |
---|
69 | if which_var not in var_equations: |
---|
70 | print 'Unrecognized variable name: %s' % which_var |
---|
71 | break |
---|
72 | |
---|
73 | for which_area in area: |
---|
74 | if which_area == 'All': |
---|
75 | easting_min = None |
---|
76 | easting_max = None |
---|
77 | northing_min = None |
---|
78 | northing_max = None |
---|
79 | else: |
---|
80 | try: |
---|
81 | easting_min = eval('project.xmin%s' % which_area) |
---|
82 | easting_max = eval('project.xmax%s' % which_area) |
---|
83 | northing_min = eval('project.ymin%s' % which_area) |
---|
84 | northing_max = eval('project.ymax%s' % which_area) |
---|
85 | except AttributeError: |
---|
86 | print 'Unrecognized area name: %s' % which_area |
---|
87 | break |
---|
88 | |
---|
89 | for time_dir in time_dirs: |
---|
90 | names = [join(directory, time_dir, project.scenario_name)] |
---|
91 | for time in times: |
---|
92 | names.append(join(directory, time_dir, project.scenario_name)+ '_time_' + str(time) + '_0') |
---|
93 | |
---|
94 | asc_name = [] |
---|
95 | |
---|
96 | for name in names: |
---|
97 | outname = name + '_' + which_area + '_' + which_var |
---|
98 | quantityname = var_equations[which_var] |
---|
99 | |
---|
100 | print 'start sww2dem: time_dir=%s' % time_dir |
---|
101 | print 'name=%s' % name |
---|
102 | sww2dem(name, basename_out = outname, |
---|
103 | quantity = quantityname, |
---|
104 | timestep = timestep, |
---|
105 | cellsize = cellsize, |
---|
106 | easting_min = easting_min, |
---|
107 | easting_max = easting_max, |
---|
108 | northing_min = northing_min, |
---|
109 | northing_max = northing_max, |
---|
110 | reduction = max, |
---|
111 | verbose = True, |
---|
112 | format = 'asc') |
---|
113 | |
---|
114 | asc_name.append(outname + '.asc') |
---|
115 | |
---|
116 | if len(names) >1: |
---|
117 | maxasc_outname = join(directory, time_dir, project.scenario_name)+'_'+which_area+'_'+which_var+'_max.asc' |
---|
118 | |
---|
119 | print 'max asc outname ', maxasc_outname |
---|
120 | print 'asc_name ', str(asc_name) |
---|
121 | |
---|
122 | MaxAsc(maxasc_outname, asc_name) |
---|
123 | else: |
---|
124 | print 'Only one sww file, no Max file required' |
---|