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