""" Generates ascii grids of nominated areas - Input: sww file from run_model.py boundaries for grids from project.py Outputs: ascii grids of specified variables Stored in the 'outputs_folder' 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 os.path import join 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_folder #Specify output directories time_dir1 = '20090601_172248_run_final_0.0_58284__250m_jgriffin' ##time_dir2 = '20090529_143458_run_final_0.0_58346_jgriffin' time_dirs = [time_dir1]#, time_dir2] # sww filename extensions ie. if batemans_bay_time_37860_0.sww, input into list 37860 # make sure numbers are in sequential order times = [] #Modify the cellsize value to set the size of the raster you require #Take into account mesh size when aplying this paramater cellsize = 250 #dependent on data resolution in area of interest. #Now set the timestep at which you want the raster generated. #Either set the actual timestep required or use 'None' to indicate that #you want the maximum values in the raster over all timesteps timestep = None # None means no timestep! ##timestep = 0 ###### # Set the special areas of interest. If none, do: area='All' ###### #area = ['', ''] # 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 = ['depth', 'speed','stage'] var = ['stage','speed','elevation'] ###### # Start script, running through variables, area, folder, sww file (determine by times) # Then creates a maximum asci if there is more than one sww file ###### 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: names = [join(directory, time_dir, project.scenario_name)] for time in times: names.append(join(directory, time_dir, project.scenario_name)+ '_time_' + str(time) + '_0') 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') if len(names) >1: maxasc_outname = join(directory, time_dir, 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) else: print 'only one sww input'