[7628] | 1 | # Standard modules |
---|
| 2 | from os import sep |
---|
| 3 | import os |
---|
| 4 | from os.path import dirname, basename |
---|
| 5 | from os import mkdir, access, F_OK |
---|
| 6 | from os.path import join |
---|
| 7 | from anuga.utilities.polygon import read_polygon |
---|
| 8 | from shutil import copy |
---|
| 9 | import time |
---|
| 10 | import sys |
---|
| 11 | # Related major packages |
---|
| 12 | from anuga.shallow_water.data_manager import get_maximum_inundation_data |
---|
| 13 | from anuga.shallow_water.data_manager import csv2polygons |
---|
| 14 | |
---|
| 15 | # Application specific imports |
---|
| 16 | from setup_model import project # Definition of file names and polygons |
---|
| 17 | import csv |
---|
| 18 | directory = project.output_folder |
---|
| 19 | |
---|
| 20 | time_dir1 = '20090508_150215_run_final_0_51469_lfountai' |
---|
| 21 | time_dir2 = '20090511_161526_run_final_1.1_51469_kvanputt' |
---|
| 22 | time_dir3 = '20090511_165539_run_final_0_50863_lfountai' |
---|
| 23 | time_dir4 = '20090521_220101_run_final_1.1_50863_kvanputt' |
---|
| 24 | time_dir5 = '20090518_154710_run_final_0_50994_lfountai' |
---|
| 25 | time_dir6 = '20090519_160510_run_final_1.1_50994_lfountai' |
---|
| 26 | time_dir7 = '20090522_164526_run_final_0_51392_lfountai' |
---|
| 27 | time_dir8 = '20090522_164640_run_final_1.1_51392_lfountai' |
---|
| 28 | time_dir9 = '20090522_164948_run_final_0_51423_lfountai' |
---|
| 29 | time_dir10 = '20090522_165600_run_final_1.1_51423_lfountai' |
---|
| 30 | |
---|
| 31 | time_dirs = [time_dir1, time_dir2, time_dir3, time_dir4, time_dir5, |
---|
| 32 | time_dir6, time_dir7, time_dir8, time_dir9, time_dir10] |
---|
| 33 | |
---|
| 34 | |
---|
| 35 | # polygons is a dictionary of polygon data indexed by 'id' |
---|
| 36 | # values is a dictionary of polygon names indexed by 'id' |
---|
| 37 | polygons, values = csv2polygons(project.images) |
---|
| 38 | print 'Creating %d highest runup' % len(polygons) |
---|
| 39 | |
---|
| 40 | # create a dictionary {<polygon_name>: <polygon_data>, ...} |
---|
| 41 | area_dictionary = {} |
---|
| 42 | for id in polygons: |
---|
| 43 | area_dictionary[values[id]] = polygons[id] |
---|
| 44 | |
---|
| 45 | # for each time directory ... |
---|
| 46 | for time_dir in time_dirs: |
---|
| 47 | print 'time_dir ',time_dir |
---|
| 48 | basename = join(directory, time_dir, project.scenario_name) |
---|
| 49 | |
---|
| 50 | out_file = basename+'_runup.csv' |
---|
| 51 | output_file = open(out_file, 'w') |
---|
| 52 | s = 'area,q,x,y\n' |
---|
| 53 | output_file.write(s) |
---|
| 54 | |
---|
| 55 | # iterate over polygon names |
---|
| 56 | for which_area in values.itervalues(): |
---|
| 57 | print 'which_area = %s' % which_area |
---|
| 58 | polygon = area_dictionary[which_area] |
---|
| 59 | |
---|
| 60 | q, loc = get_maximum_inundation_data(basename+'.sww', |
---|
| 61 | polygon=polygon, verbose=True) |
---|
| 62 | |
---|
| 63 | print '%s, %.6f, %.6f, %.6f\n' %(str(which_area), q, loc[0],loc[1]) |
---|
| 64 | s = '%s, %.6f, %.6f, %.6f\n' %(str(which_area), q, loc[0],loc[1]) |
---|
| 65 | |
---|
| 66 | output_file.write(s) |
---|
| 67 | |
---|
| 68 | print 'output file printed to: %s' %out_file |
---|
| 69 | output_file.close() |
---|