1 | """Read in sww file, interpolate at specified locations and |
---|
2 | Cross section at specified T. Cross sections are spatial drawing |
---|
3 | at the specified time. |
---|
4 | |
---|
5 | '2nd normal' test is employed to find the best fit friction value |
---|
6 | for the given building scenario => 'B_file' |
---|
7 | |
---|
8 | """ |
---|
9 | from os import sep |
---|
10 | import Numeric |
---|
11 | import project |
---|
12 | from pyvolution.util import file_function |
---|
13 | from create_buildings import WidtH |
---|
14 | from pylab import * |
---|
15 | from numerical_tools import norm, corr, err |
---|
16 | |
---|
17 | B_list=['buildings_Str_D=3_1714.sww', |
---|
18 | 'buildings_Str_D=5_1578.sww', |
---|
19 | 'buildings_Str_D=7_1067.sww', |
---|
20 | 'buildings_Str_D=9_1052.sww', |
---|
21 | 'buildings_Str_D=11_694.sww', |
---|
22 | 'buildings_Str_D=13_693.sww', |
---|
23 | 'buildings_Str_D=15_717.sww', |
---|
24 | 'buildings_Str_D=17_749.sww', |
---|
25 | 'buildings_Str_D=19_1008.sww', |
---|
26 | 'buildings_Str_D=21_1581.sww', |
---|
27 | 'buildings_Str_D=23_1798.sww'] |
---|
28 | |
---|
29 | |
---|
30 | fd = open("Straight_log_report.csv", 'w') |
---|
31 | fd.write( 'Straight_log_report. Summary at bottom.' + '\n' ) |
---|
32 | |
---|
33 | |
---|
34 | # Building scenario file to be compared to |
---|
35 | #--------------------------------------------- |
---|
36 | #B_list = ['buildings_S0_D=23_1784.sww'] |
---|
37 | #--------------------------------------------- |
---|
38 | |
---|
39 | best_fric=[] |
---|
40 | B_Density=[] |
---|
41 | best_norm=[] |
---|
42 | Breadth=[] |
---|
43 | |
---|
44 | |
---|
45 | for B_file in B_list: |
---|
46 | swwfile_B = project.outputdir + sep + B_file |
---|
47 | a=B_file.split('_') |
---|
48 | b=a[2].split('=') |
---|
49 | bre=int(b[1]) |
---|
50 | |
---|
51 | gauge_depth = Numeric.arrayrange((52.5-bre/2), 1.5*WidtH, 25) |
---|
52 | gauge_breadth = 100 |
---|
53 | gauge_locations = [] |
---|
54 | |
---|
55 | for GD in gauge_depth: |
---|
56 | gauge_location = [GD,gauge_breadth] |
---|
57 | gauge_locations.append(gauge_location) |
---|
58 | |
---|
59 | |
---|
60 | #Read model output |
---|
61 | quantities = ['stage', 'elevation', 'xmomentum', 'ymomentum'] |
---|
62 | |
---|
63 | f_B = file_function(swwfile_B, |
---|
64 | quantities = quantities, |
---|
65 | interpolation_points = gauge_locations, |
---|
66 | verbose = True, |
---|
67 | use_cache = True) |
---|
68 | |
---|
69 | fric_OK=[] |
---|
70 | least_norm=[100] |
---|
71 | Normal=[] |
---|
72 | #Friction = Numeric.arrayrange(1,120,1) |
---|
73 | Friction = [0.025, 0.1, 0.2, 0.5, 1, 2, 5, 10, 20, 50, 100, 200, 500, 1000, 2000, 5000, 10000] |
---|
74 | for fric in Friction: |
---|
75 | swwfile_F = project.outputdir + sep + 'friction_n=' + str(fric) + '_3135.sww' |
---|
76 | f_F = file_function(swwfile_F, |
---|
77 | quantities = quantities, |
---|
78 | interpolation_points = gauge_locations, |
---|
79 | verbose = True, |
---|
80 | use_cache = True) |
---|
81 | |
---|
82 | t=990 # specifies times to look at cross sections |
---|
83 | |
---|
84 | stages_B = [] |
---|
85 | stages_F = [] |
---|
86 | for i, GL in enumerate(gauge_depth): |
---|
87 | |
---|
88 | # mines data from specified time values in sww file |
---|
89 | # Building file |
---|
90 | wB = f_B(t, point_id = i)[0] |
---|
91 | zB = f_B(t, point_id = i)[1] |
---|
92 | uhB = f_B(t, point_id = i)[2] |
---|
93 | vhB = f_B(t, point_id = i)[3] |
---|
94 | # Friction file |
---|
95 | wF = f_F(t, point_id = i)[0] |
---|
96 | uhF = f_B(t, point_id = i)[2] |
---|
97 | vhF = f_B(t, point_id = i)[3] |
---|
98 | |
---|
99 | #m = sqrt(uh*uh + vh*vh) #Absolute momentum |
---|
100 | velB = sqrt(uhB*uhB + vhB*vhB) / (wB + 1.e-30) #Absolute velocity |
---|
101 | velF = sqrt(uhF*uhF + vhF*vhF) / (wF + 1.e-30) #Absolute velocity |
---|
102 | stages_B.append(wB) |
---|
103 | stages_F.append(wF) |
---|
104 | |
---|
105 | |
---|
106 | Ar_B = Numeric.array(stages_B) |
---|
107 | Ar_F = Numeric.array(stages_F) |
---|
108 | diff = abs(Ar_B - Ar_F) |
---|
109 | norm_F = err(Ar_F, Ar_B, 2, relative = True) # 2nd norm (rel. RMS) test |
---|
110 | Normal.append(norm_F) |
---|
111 | #print " " |
---|
112 | #print norm_F, "2nd norm test result (N_F)" |
---|
113 | #print " " |
---|
114 | if norm_F < least_norm: |
---|
115 | least_norm = norm_F |
---|
116 | fric_OK = fric |
---|
117 | else: |
---|
118 | print fric, " NOT OK" |
---|
119 | |
---|
120 | print fric_OK, " <- This Manning's n is best fit from 2nd norm test" |
---|
121 | print least_norm, "2nd normal of Friction vs Buildings " |
---|
122 | best_fric.append(fric_OK) |
---|
123 | B_Density.append((float(bre)**2)/625) |
---|
124 | best_norm.append(least_norm) |
---|
125 | Breadth.append(bre) |
---|
126 | |
---|
127 | print len(Friction), "friction" |
---|
128 | print len(Normal), "normal" |
---|
129 | fd.write('_______________________________________________________' + '\n' ) |
---|
130 | fd.write( '<<<< Mannings n for [' + B_file + '] >>>>' + '\n' ) |
---|
131 | fd.write( '(n), 2nd norm ' + '\n') |
---|
132 | for j,drt in enumerate(Friction): |
---|
133 | fd.write(str(Friction[j]) + ', ' + str(Normal[j]) + '\n') |
---|
134 | |
---|
135 | print best_fric, " << Best fit friction" |
---|
136 | print B_Density, " << Building footprint density" |
---|
137 | print best_norm, " << Matching normal densities" |
---|
138 | |
---|
139 | |
---|
140 | len_file=Numeric.arrayrange(0,len(B_list),1) |
---|
141 | fd.write('_______________________________________________________' + '\n' ) |
---|
142 | fd.write( '<<<<< Straight_log_report Summary >>>>>' + '\n' ) |
---|
143 | fd.write( 'width, footprint ratio, mannings n, 2nd norm ' + '\n') |
---|
144 | for i in len_file: |
---|
145 | fd.write( str(Breadth[i]) + ', ' + str(B_Density[i]) + ', ' + str(best_fric[i]) + ', ' + str(best_norm[i]) + '\n') |
---|
146 | fd.close |
---|
147 | |
---|