""" Generates ascii grids of nominated areas - Input: sww file from run_broome.py boundaries for grids from project.py Outputs: ascii grids of specified variables Stored in the 'outputs_dir' folder for respective .sww file Note: If producing a grid for the enitre extent cellsize should be greater than 30m If producing grids for inundation area resolution should be greater than mesh (ie ~22m) """ import project, os import sys from anuga.lib.maxasc.maxasc import MaxAsc from anuga.shallow_water.data_manager import convert_dem_from_ascii2netcdf, dem2pts from anuga.shallow_water.data_manager import sww2dem from os import sep directory = project.output_dir time_dir = '20090106_151505_run_final_0.6_27283_alpha0.1_jgriffin' time_dirs = [time_dir]# , time_dir3, time_dir4, time_dir5, time_dir6] #cellsize = 20 cellsize = 250 timestep = None # None means no timestep! #timestep = 0 ###### # Set the special areas of interest. If none, do: area='All' ###### #area = ['Bunbury', 'Busselton'] # strings must match keys in var_equations below area = ['All'] # 'All' means no special areas - the whole thing ###### # Define allowed variable names and associated equations to generate values. # This would not normally change. ###### var_equations = {'stage': 'stage', 'momentum': '(xmomentum**2 + ymomentum**2)**0.5', 'depth': 'stage-elevation', 'speed': '(xmomentum**2 + ymomentum**2)**0.5/(stage-elevation+1.e-6)', 'elevation': 'elevation' } # one or more key strings from var_equations above var = ['stage','depth','speed'] ###### # Start running the various conversions we require. ###### for which_var in var: if which_var not in var_equations: print 'Unrecognized variable name: %s' % which_var break for which_area in area: if which_area == 'All': easting_min = None easting_max = None northing_min = None northing_max = None else: try: easting_min = eval('project.xmin%s' % which_area) easting_max = eval('project.xmax%s' % which_area) northing_min = eval('project.ymin%s' % which_area) northing_max = eval('project.ymax%s' % which_area) except AttributeError: print 'Unrecognized area name: %s' % which_area break for time_dir in time_dirs: name1 = directory+time_dir+sep+project.scenario_name name2 = directory+time_dir+sep+project.scenario_name+'_time_63900_0' names = [name1, name2] asc_name = [] for name in names: outname = name + '_' + which_area + '_' + which_var quantityname = var_equations[which_var] print 'start sww2dem: time_dir=%s' % time_dir sww2dem(name, basename_out = outname, quantity = quantityname, timestep = timestep, cellsize = cellsize, easting_min = easting_min, easting_max = easting_max, northing_min = northing_min, northing_max = northing_max, reduction = max, verbose = True, format = 'asc') asc_name.append(outname + '.asc') maxasc_outname = directory+time_dir+sep+project.scenario_name+'_'+which_area+'_'+which_var+'_max.asc' print 'max asc outname ', maxasc_outname print 'asc_name ', str(asc_name) MaxAsc(maxasc_outname, asc_name)