""" Generates ascii grids of nominated areas - Input: sww file from run_perth.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_dir1 = '20081209_155431_run_final_0_27255_250m_none_lfountai' ##time_dir2 = '20081210_100528_run_final_0_68693_250m_none_kvanputt' ###time_dir1 = '20080924_123626_run_final_0_27283_250m_all_kvanputt' # This uses the 250m bathymetry with all interior polygons ###time_dir2 = '20080912_154716_run_final_0_27283_alpha0.1_kvanputt' # This uses original bathyemetry data ###time_dir3 = '20080924_123601_run_final_0_27283_250m_none_kvanputt' # This uses the 250m bathymetry without any interior polygons ##time_dirs = [time_dir1, time_dir2]#, time_dir3] ##time_dir1 = '20081031_133353_run_final_0.6_68693_alpha0.1_kvanputt' time_dir2 = '20081031_133511_run_final_0_68693_alpha0.1_kvanputt' time_dir3 = '20081031_133624_run_final_0_27255_alpha0.1_kvanputt' ##time_dir4 = '20081031_133735_run_final_0.6_27255_alpha0.1_kvanputt' ##time_dir5 = '20081031_133841_run_final_0_27283_alpha0.1_kvanputt' ##time_dir6 = '20081031_133925_run_final_0.6_27283_alpha0.1_kvanputt' ## time_dirs = [time_dir2, time_dir3] #, time_dir3, time_dir4, time_dir5, time_dir6] #cellsize = 5 cellsize = 250 timestep = None # None means no timestep! #timestep = 0 ###### # Set the special areas of interest. If none, do: area='All' ###### #area = ['Sorrento', 'Geordie' ] # 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'] ###### # 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_39900_0' name3 = directory+time_dir+sep+project.scenario_name+'_time_79800_0' names = [name1, name2, name3] 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)