# Standard modules from os import sep import os from os.path import dirname, basename from os import mkdir, access, F_OK from os.path import join from anuga.utilities.polygon import read_polygon from shutil import copy import time import sys # Related major packages from anuga.shallow_water.data_manager import get_maximum_inundation_data from anuga.shallow_water.data_manager import csv2polygons # Application specific imports from setup_model import project # Definition of file names and polygons import csv directory = project.output_folder time_dir1 = '20090508_150215_run_final_0_51469_lfountai' time_dir2 = '20090511_161526_run_final_1.1_51469_kvanputt' time_dir3 = '20090511_165539_run_final_0_50863_lfountai' time_dir4 = '20090521_220101_run_final_1.1_50863_kvanputt' time_dir5 = '20090518_154710_run_final_0_50994_lfountai' time_dir6 = '20090519_160510_run_final_1.1_50994_lfountai' time_dir7 = '20090522_164526_run_final_0_51392_lfountai' time_dir8 = '20090522_164640_run_final_1.1_51392_lfountai' time_dir9 = '20090522_164948_run_final_0_51423_lfountai' time_dir10 = '20090522_165600_run_final_1.1_51423_lfountai' time_dirs = [time_dir1, time_dir2, time_dir3, time_dir4, time_dir5, time_dir6, time_dir7, time_dir8, time_dir9, time_dir10] # polygons is a dictionary of polygon data indexed by 'id' # values is a dictionary of polygon names indexed by 'id' polygons, values = csv2polygons(project.images) print 'Creating %d highest runup' % len(polygons) # create a dictionary {: , ...} area_dictionary = {} for id in polygons: area_dictionary[values[id]] = polygons[id] # for each time directory ... for time_dir in time_dirs: print 'time_dir ',time_dir basename = join(directory, time_dir, project.scenario_name) out_file = basename+'_runup.csv' output_file = open(out_file, 'w') s = 'area,q,x,y\n' output_file.write(s) # iterate over polygon names for which_area in values.itervalues(): print 'which_area = %s' % which_area polygon = area_dictionary[which_area] q, loc = get_maximum_inundation_data(basename+'.sww', polygon=polygon, verbose=True) print '%s, %.6f, %.6f, %.6f\n' %(str(which_area), q, loc[0],loc[1]) s = '%s, %.6f, %.6f, %.6f\n' %(str(which_area), q, loc[0],loc[1]) output_file.write(s) print 'output file printed to: %s' %out_file output_file.close()