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 = '20090505_150430_run_final_0.8_58292_None_kvanputt' |
---|
21 | time_dir2 = '20090505_150517_run_final_0_58292_None_kvanputt' |
---|
22 | time_dir3 = '20090505_150711_run_final_0_58280_None_kvanputt' |
---|
23 | time_dir4 = '20090505_150805_run_final_0.8_58280_None_kvanputt' |
---|
24 | time_dir5 = '20090505_151322_run_final_0.8_64477_None_kvanputt' |
---|
25 | time_dir6 = '20090505_151447_run_final_0_64477_None_kvanputt' |
---|
26 | |
---|
27 | time_dirs = [time_dir1, time_dir2, time_dir3, time_dir4, time_dir5, time_dir6] |
---|
28 | |
---|
29 | |
---|
30 | # polygons is a dictionary of polygon data indexed by 'id' |
---|
31 | # values is a dictionary of polygon names indexed by 'id' |
---|
32 | polygons, values = csv2polygons(project.images) |
---|
33 | print 'Creating %d highest runup' % len(polygons) |
---|
34 | |
---|
35 | # create a dictionary {<polygon_name>: <polygon_data>, ...} |
---|
36 | area_dictionary = {} |
---|
37 | for id in polygons: |
---|
38 | area_dictionary[values[id]] = polygons[id] |
---|
39 | |
---|
40 | # for each time directory ... |
---|
41 | for time_dir in time_dirs: |
---|
42 | print 'time_dir ',time_dir |
---|
43 | basename = join(directory, time_dir, project.scenario_name) |
---|
44 | |
---|
45 | out_file = basename+'_runup.csv' |
---|
46 | output_file = open(out_file, 'w') |
---|
47 | s = 'area,q,x,y\n' |
---|
48 | output_file.write(s) |
---|
49 | |
---|
50 | # iterate over polygon names |
---|
51 | for which_area in values.itervalues(): |
---|
52 | print 'which_area = %s' % which_area |
---|
53 | polygon = area_dictionary[which_area] |
---|
54 | |
---|
55 | q, loc = get_maximum_inundation_data(basename+'.sww', |
---|
56 | polygon=polygon, verbose=True) |
---|
57 | |
---|
58 | print '%s, %.6f, %.6f, %.6f\n' %(str(which_area), q, loc[0],loc[1]) |
---|
59 | s = '%s, %.6f, %.6f, %.6f\n' %(str(which_area), q, loc[0],loc[1]) |
---|
60 | |
---|
61 | output_file.write(s) |
---|
62 | |
---|
63 | print 'output file printed to: %s' %out_file |
---|
64 | output_file.close() |
---|