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_dir1 = '20081002_111053_run_final_0_27283_250m_none_kvanputt' |
---|
23 | time_dir2 = '20081002_111207_run_final_0_27283_250m_all_kvanputt' |
---|
24 | #time_dir3 = '20081007_081134_run_final_0_27283_alpha0.1_kvanputt' |
---|
25 | time_dir3 = '20081028_151417_run_final_0.0_27283_alpha0.1_lfountai' |
---|
26 | |
---|
27 | time_dirs = [time_dir1, time_dir2, time_dir3] |
---|
28 | |
---|
29 | #cellsize = 20 |
---|
30 | cellsize = 250 |
---|
31 | |
---|
32 | timestep = None # None means no timestep! |
---|
33 | #timestep = 0 |
---|
34 | |
---|
35 | ###### |
---|
36 | # Set the special areas of interest. If none, do: area='All' |
---|
37 | ###### |
---|
38 | #area = ['Geordie', 'Sorrento', 'Fremantle', 'Rockingham'] # strings must match keys in var_equations below |
---|
39 | area = ['All'] # 'All' means no special areas - the whole thing |
---|
40 | |
---|
41 | ###### |
---|
42 | # Define allowed variable names and associated equations to generate values. |
---|
43 | # This would not normally change. |
---|
44 | ###### |
---|
45 | var_equations = {'stage': 'stage', |
---|
46 | 'momentum': '(xmomentum**2 + ymomentum**2)**0.5', |
---|
47 | 'depth': 'stage-elevation', |
---|
48 | 'speed': '(xmomentum**2 + ymomentum**2)**0.5/(stage-elevation+1.e-6)', |
---|
49 | 'elevation': 'elevation' } |
---|
50 | |
---|
51 | # one or more key strings from var_equations above |
---|
52 | var = ['stage', 'elevation'] |
---|
53 | |
---|
54 | ###### |
---|
55 | # Start running the various conversions we require. |
---|
56 | ###### |
---|
57 | for time_dir in time_dirs: |
---|
58 | name1 = directory+time_dir+sep+project.scenario_name |
---|
59 | # name2 = directory+time_dir+sep+'sww2'+sep+project.scenario_name+'_time_39900_0' #need to get assistance on how to make this into anything |
---|
60 | names = [name1] |
---|
61 | |
---|
62 | for name in names: |
---|
63 | for which_area in area: |
---|
64 | if which_area == 'All': |
---|
65 | easting_min = None |
---|
66 | easting_max = None |
---|
67 | northing_min = None |
---|
68 | northing_max = None |
---|
69 | else: |
---|
70 | try: |
---|
71 | easting_min = eval('project.xmin%s' % which_area) |
---|
72 | easting_max = eval('project.xmax%s' % which_area) |
---|
73 | northing_min = eval('project.ymin%s' % which_area) |
---|
74 | northing_max = eval('project.ymax%s' % which_area) |
---|
75 | except AttributeError: |
---|
76 | print 'Unrecognized area name: %s' % which_area |
---|
77 | break |
---|
78 | |
---|
79 | for which_var in var: |
---|
80 | if which_var not in var_equations: |
---|
81 | print 'Unrecognized variable name: %s' % which_var |
---|
82 | break |
---|
83 | |
---|
84 | outname = name + which_area + '_' + which_var |
---|
85 | quantityname = var_equations[which_var] |
---|
86 | |
---|
87 | print 'start sww2dem: time_dir=%s' % time_dir |
---|
88 | |
---|
89 | sww2dem(name, basename_out = outname, |
---|
90 | quantity = quantityname, |
---|
91 | timestep = timestep, |
---|
92 | cellsize = cellsize, |
---|
93 | easting_min = easting_min, |
---|
94 | easting_max = easting_max, |
---|
95 | northing_min = northing_min, |
---|
96 | northing_max = northing_max, |
---|
97 | reduction = max, |
---|
98 | verbose = True, |
---|
99 | format = 'asc') |
---|