[6386] | 1 | """ |
---|
| 2 | Generates ascii grids of nominated areas - |
---|
[7327] | 3 | Input: sww file from run_model.py |
---|
[6386] | 4 | boundaries for grids from project.py |
---|
| 5 | Outputs: ascii grids of specified variables |
---|
[7327] | 6 | Stored in the 'outputs_folder' folder for respective .sww file |
---|
[6386] | 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 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 | |
---|
| 22 | directory = project.output_folder |
---|
| 23 | |
---|
[7252] | 24 | #Specify output directories |
---|
[7606] | 25 | time_dir1 = '20090528_153025_run_final_0.0_58346_jgriffin' |
---|
[7577] | 26 | ##time_dir2 = '20090529_143458_run_final_0.0_58346_jgriffin' |
---|
[6386] | 27 | |
---|
[7577] | 28 | time_dirs = [time_dir1]#, time_dir2] |
---|
[6386] | 29 | |
---|
[7369] | 30 | # sww filename extensions ie. if batemans_bay_time_37860_0.sww, input into list 37860 |
---|
[7351] | 31 | # make sure numbers are in sequential order |
---|
[7606] | 32 | times = [37860] |
---|
[7351] | 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 |
---|
[7606] | 36 | cellsize = 20 #dependent on data resolution in area of interest. |
---|
[6386] | 37 | |
---|
[7351] | 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 |
---|
[6552] | 41 | timestep = None # None means no timestep! |
---|
| 42 | ##timestep = 0 |
---|
[6386] | 43 | |
---|
| 44 | ###### |
---|
| 45 | # Set the special areas of interest. If none, do: area='All' |
---|
| 46 | ###### |
---|
| 47 | |
---|
[7252] | 48 | #area = ['', ''] # strings must match keys in var_equations below |
---|
[6386] | 49 | area = ['All'] # 'All' means no special areas - the whole thing |
---|
| 50 | |
---|
| 51 | ###### |
---|
| 52 | # Define allowed variable names and associated equations to generate values. |
---|
| 53 | # This would not normally change. |
---|
| 54 | ###### |
---|
| 55 | var_equations = {'stage': 'stage', |
---|
| 56 | 'momentum': '(xmomentum**2 + ymomentum**2)**0.5', |
---|
| 57 | 'depth': 'stage-elevation', |
---|
| 58 | 'speed': '(xmomentum**2 + ymomentum**2)**0.5/(stage-elevation+1.e-6)', |
---|
[7606] | 59 | 'energy': '(((xmomentum/(stage-elevation+1.e-6))**2 + (ymomentum/(stage-elevation+1.e-6))**2)*0.5*1000*(stage-elevation+1.e-6))+(9.81*stage*1000)', |
---|
[6386] | 60 | 'elevation': 'elevation' } |
---|
| 61 | |
---|
| 62 | # one or more key strings from var_equations above |
---|
[7327] | 63 | #var = ['depth', 'speed','stage'] |
---|
[7606] | 64 | var = ['energy'] |
---|
[6386] | 65 | ###### |
---|
[7351] | 66 | # Start script, running through variables, area, folder, sww file (determine by times) |
---|
| 67 | # Then creates a maximum asci if there is more than one sww file |
---|
[6386] | 68 | ###### |
---|
| 69 | |
---|
| 70 | for which_var in var: |
---|
| 71 | if which_var not in var_equations: |
---|
| 72 | print 'Unrecognized variable name: %s' % which_var |
---|
| 73 | break |
---|
| 74 | |
---|
| 75 | for which_area in area: |
---|
| 76 | if which_area == 'All': |
---|
| 77 | easting_min = None |
---|
| 78 | easting_max = None |
---|
| 79 | northing_min = None |
---|
| 80 | northing_max = None |
---|
| 81 | else: |
---|
| 82 | try: |
---|
| 83 | easting_min = eval('project.xmin%s' % which_area) |
---|
| 84 | easting_max = eval('project.xmax%s' % which_area) |
---|
| 85 | northing_min = eval('project.ymin%s' % which_area) |
---|
| 86 | northing_max = eval('project.ymax%s' % which_area) |
---|
| 87 | except AttributeError: |
---|
| 88 | print 'Unrecognized area name: %s' % which_area |
---|
| 89 | break |
---|
| 90 | |
---|
| 91 | for time_dir in time_dirs: |
---|
[7351] | 92 | names = [join(directory, time_dir, project.scenario_name)] |
---|
| 93 | for time in times: |
---|
| 94 | names.append(join(directory, time_dir, project.scenario_name)+ '_time_' + str(time) + '_0') |
---|
[6386] | 95 | |
---|
[6552] | 96 | asc_name = [] |
---|
[6386] | 97 | |
---|
| 98 | for name in names: |
---|
| 99 | |
---|
| 100 | outname = name + '_' + which_area + '_' + which_var |
---|
| 101 | quantityname = var_equations[which_var] |
---|
| 102 | |
---|
| 103 | print 'start sww2dem: time_dir=%s' % time_dir |
---|
| 104 | |
---|
| 105 | sww2dem(name, basename_out = outname, |
---|
| 106 | quantity = quantityname, |
---|
| 107 | timestep = timestep, |
---|
| 108 | cellsize = cellsize, |
---|
| 109 | easting_min = easting_min, |
---|
| 110 | easting_max = easting_max, |
---|
| 111 | northing_min = northing_min, |
---|
| 112 | northing_max = northing_max, |
---|
| 113 | reduction = max, |
---|
| 114 | verbose = True, |
---|
| 115 | format = 'asc') |
---|
| 116 | |
---|
[6552] | 117 | asc_name.append(outname + '.asc') |
---|
| 118 | |
---|
[7351] | 119 | if len(names) >1: |
---|
| 120 | maxasc_outname = join(directory, time_dir, project.scenario_name)+'_'+which_area+'_'+which_var+'_max.asc' |
---|
[6552] | 121 | |
---|
[7351] | 122 | print 'max asc outname ', maxasc_outname |
---|
| 123 | print 'asc_name ', str(asc_name) |
---|
[6552] | 124 | |
---|
[7351] | 125 | MaxAsc(maxasc_outname, asc_name) |
---|
| 126 | else: |
---|
| 127 | print 'only one sww input' |
---|