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.shallow_water.data_manager import convert_dem_from_ascii2netcdf, dem2pts |
---|
16 | from anuga.shallow_water.data_manager import sww2dem |
---|
17 | from os import sep |
---|
18 | |
---|
19 | |
---|
20 | directory = project.output_dir |
---|
21 | |
---|
22 | #time_dir = '20080526_104946_run_final_0.6_test_kvanputt' |
---|
23 | #time_dir = '20080530_170833_run_final_0.6_exmouth_kvanputt' |
---|
24 | time_dir1 = '20081002_171412_run_final_0.6_27255_alpha0.1_rwilson' |
---|
25 | time_dirs = [time_dir1] |
---|
26 | |
---|
27 | #cellsize = 20 |
---|
28 | cellsize = 30 |
---|
29 | |
---|
30 | #timestep = None # None means no timestep! |
---|
31 | timestep = 0 |
---|
32 | |
---|
33 | ###### |
---|
34 | # Set the special areas of interest. If none, do: area='All' |
---|
35 | ###### |
---|
36 | #area = ['Geordie', 'Sorrento', 'Fremantle', 'Rockingham'] # strings must match keys in var_equations below |
---|
37 | area = ['All'] # 'All' means no special areas - the whole thing |
---|
38 | |
---|
39 | ###### |
---|
40 | # Define allowed variable names and associated equations to generate values. |
---|
41 | # This would not normally change. |
---|
42 | ###### |
---|
43 | var_equations = {'stage': 'stage', |
---|
44 | 'momentum': '(xmomentum**2 + ymomentum**2)**0.5', |
---|
45 | 'depth': 'stage-elevation', |
---|
46 | 'speed': '(xmomentum**2 + ymomentum**2)**0.5/(stage-elevation+1.e-6)', |
---|
47 | 'elevation': 'elevation' } |
---|
48 | |
---|
49 | # one or more key strings from var_equations above |
---|
50 | var = ['stage', 'elevation'] |
---|
51 | |
---|
52 | ###### |
---|
53 | # Start running the various conversions we require. |
---|
54 | ###### |
---|
55 | for time_dir in time_dirs: |
---|
56 | name1 = directory+time_dir+sep+project.scenario_name |
---|
57 | # name2 = directory+time_dir+sep+'sww2'+sep+project.scenario_name+'_time_39900_0' #need to get assistance on how to make this into anything |
---|
58 | names = [name1] |
---|
59 | |
---|
60 | for name in names: |
---|
61 | for which_area in area: |
---|
62 | if which_area == 'All': |
---|
63 | easting_min = None |
---|
64 | easting_max = None |
---|
65 | northing_min = None |
---|
66 | northing_max = None |
---|
67 | else: |
---|
68 | try: |
---|
69 | easting_min = eval('project.xmin%s' % which_area) |
---|
70 | easting_max = eval('project.xmax%s' % which_area) |
---|
71 | northing_min = eval('project.ymin%s' % which_area) |
---|
72 | northing_max = eval('project.ymax%s' % which_area) |
---|
73 | except AttributeError: |
---|
74 | print 'Unrecognized area name: %s' % which_area |
---|
75 | break |
---|
76 | ### This is replaced by the single 'else' case above |
---|
77 | ## elif which_area == 'Geordie': |
---|
78 | ## easting_min = project.xminGeordie |
---|
79 | ## easting_max = project.xmaxGeordie |
---|
80 | ## northing_min = project.yminGeordie |
---|
81 | ## northing_max = project.ymaxGeordie |
---|
82 | ## elif which_area == 'Sorrento': |
---|
83 | ## easting_min = project.xminSorrento |
---|
84 | ## easting_max = project.xmaxSorrento |
---|
85 | ## northing_min = project.yminSorrento |
---|
86 | ## northing_max = project.ymaxSorrento |
---|
87 | ## elif which_area == 'Fremantle': |
---|
88 | ## easting_min = project.xminFremantle |
---|
89 | ## easting_max = project.xmaxFremantle |
---|
90 | ## northing_min = project.yminFremantle |
---|
91 | ## northing_max = project.ymaxFremantle |
---|
92 | ## elif which_area == 'Rockingham': |
---|
93 | ## easting_min = project.xminRockingham |
---|
94 | ## easting_max = project.xmaxRockingham |
---|
95 | ## northing_min = project.yminRockingham |
---|
96 | ## northing_max = project.ymaxRockingham |
---|
97 | ## else: |
---|
98 | ## print 'Unrecognized area name: %s' % which_area |
---|
99 | ## break |
---|
100 | |
---|
101 | for which_var in var: |
---|
102 | if which_var not in var_equations: |
---|
103 | print 'Unrecognized variable name: %s' % which_var |
---|
104 | break |
---|
105 | |
---|
106 | outname = name + which_area + '_' + which_var |
---|
107 | quantityname = var_equations[which_var] |
---|
108 | |
---|
109 | print 'start sww2dem: time_dir=%s' % time_dir |
---|
110 | |
---|
111 | sww2dem(name, basename_out = outname, |
---|
112 | quantity = quantityname, |
---|
113 | timestep = timestep, |
---|
114 | cellsize = cellsize, |
---|
115 | easting_min = easting_min, |
---|
116 | easting_max = easting_max, |
---|
117 | northing_min = northing_min, |
---|
118 | northing_max = northing_max, |
---|
119 | reduction = max, |
---|
120 | verbose = True, |
---|
121 | format = 'asc') |
---|