[6295] | 1 | """ |
---|
| 2 | Generates ascii grids of nominated areas - |
---|
| 3 | Input: sww file from run_pt_hedland.py |
---|
| 4 | boundaries for grids from project_250m.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_250m, 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 | directory = project_250m.output_dir |
---|
| 21 | |
---|
[6498] | 22 | time_dir1 = '20090210_162935_run_final_0_250m_vlarge_jgriffin' |
---|
[6295] | 23 | #time_dir2 = '20090123_155045_run_final_0_7875_250m_large_jgriffin' |
---|
| 24 | #time_dir3 = '20090123_154945_run_final_0_7875_250m_small_jgriffin' |
---|
| 25 | time_dirs = [time_dir1]#,time_dir2,time_dir3]#, time_dir2, time_dir3, time_dir4, time_dir5, time_dir6] |
---|
| 26 | |
---|
| 27 | #cellsize = 20 |
---|
| 28 | cellsize = 250 |
---|
| 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 | |
---|
| 37 | #area = [''] # strings must match keys in var_equations below |
---|
| 38 | area = ['All'] # 'All' means no special areas - the whole thing |
---|
| 39 | |
---|
| 40 | ###### |
---|
| 41 | # Define allowed variable names and associated equations to generate values. |
---|
| 42 | # This would not normally change. |
---|
| 43 | ###### |
---|
| 44 | var_equations = {'stage': 'stage', |
---|
| 45 | 'momentum': '(xmomentum**2 + ymomentum**2)**0.5', |
---|
| 46 | 'depth': 'stage-elevation', |
---|
| 47 | 'speed': '(xmomentum**2 + ymomentum**2)**0.5/(stage-elevation+1.e-6)', |
---|
| 48 | 'elevation': 'elevation' } |
---|
| 49 | |
---|
| 50 | # one or more key strings from var_equations above |
---|
| 51 | #var = ['stage', 'speed','depth'] |
---|
| 52 | var = ['stage','elevation'] |
---|
| 53 | |
---|
| 54 | ###### |
---|
| 55 | # Start running the various conversions we require. |
---|
| 56 | ###### |
---|
| 57 | |
---|
| 58 | for which_var in var: |
---|
| 59 | if which_var not in var_equations: |
---|
| 60 | print 'Unrecognized variable name: %s' % which_var |
---|
| 61 | break |
---|
| 62 | |
---|
| 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_250m.xmin%s' % which_area) |
---|
| 72 | easting_max = eval('project_250m.xmax%s' % which_area) |
---|
| 73 | northing_min = eval('project_250m.ymin%s' % which_area) |
---|
| 74 | northing_max = eval('project_250m.ymax%s' % which_area) |
---|
| 75 | except AttributeError: |
---|
| 76 | print 'Unrecognized area name: %s' % which_area |
---|
| 77 | break |
---|
| 78 | |
---|
| 79 | for time_dir in time_dirs: |
---|
| 80 | |
---|
| 81 | name1 = directory+time_dir+sep+project_250m.scenario_name |
---|
[6498] | 82 | name2 = directory+time_dir+sep+project_250m.scenario_name+'_time_16680_0' |
---|
| 83 | name3 = directory+time_dir+sep+project_250m.scenario_name+'_time_33360_0' |
---|
| 84 | name4 = directory+time_dir+sep+project_250m.scenario_name+'_time_50040_0' |
---|
| 85 | name5 = directory+time_dir+sep+project_250m.scenario_name+'_time_66720_0' |
---|
| 86 | |
---|
| 87 | names = [name1, name2 , name3, name4, name5] |
---|
[6295] | 88 | |
---|
| 89 | asc_name = [] |
---|
| 90 | |
---|
| 91 | for name in names: |
---|
| 92 | |
---|
| 93 | outname = name + '_' + which_area + '_' + which_var |
---|
| 94 | quantityname = var_equations[which_var] |
---|
| 95 | |
---|
| 96 | print 'start sww2dem: time_dir=%s' % time_dir |
---|
| 97 | |
---|
| 98 | sww2dem(name, basename_out = outname, |
---|
| 99 | quantity = quantityname, |
---|
| 100 | timestep = timestep, |
---|
| 101 | cellsize = cellsize, |
---|
| 102 | easting_min = easting_min, |
---|
| 103 | easting_max = easting_max, |
---|
| 104 | northing_min = northing_min, |
---|
| 105 | northing_max = northing_max, |
---|
| 106 | reduction = max, |
---|
| 107 | verbose = True, |
---|
| 108 | format = 'asc') |
---|
| 109 | |
---|
| 110 | asc_name.append(outname + '.asc') |
---|
| 111 | |
---|
| 112 | maxasc_outname = directory+time_dir+sep+project_250m.scenario_name+'_'+which_area+'_'+which_var+'_max.asc' |
---|
| 113 | |
---|
| 114 | print 'max asc outname ', maxasc_outname |
---|
| 115 | print 'asc_name ', str(asc_name) |
---|
| 116 | |
---|
| 117 | MaxAsc(maxasc_outname, asc_name) |
---|