Changeset 3318
- Timestamp:
- Jul 12, 2006, 5:40:30 PM (18 years ago)
- Location:
- inundation/damage
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
inundation/damage/inundation_damage.py
r3310 r3318 6 6 7 7 from math import sqrt 8 from Scientific.Functions.Interpolation import InterpolatingFunction 9 from Numeric import array 8 10 9 from pyvolution.data_manager import Exposure_csv 10 from pyvolution.util import file_function 11 from geospatial_data.geospatial_data import ensure_absolute 12 from utilities.numerical_tools import INF 11 13 12 try: 14 13 import kinds 15 14 except ImportError: 16 # Hand-built mockup of the things we need from the kinds package, 17 #since it 15 # Hand-built mockup of the things we need from the kinds package, since it 18 16 # was recently removed from the standard Numeric distro. Some users may 19 17 # not have it by default. … … 27 25 28 26 kinds = _kinds() 27 28 29 from pyvolution.data_manager import Exposure_csv 30 from pyvolution.util import file_function 31 from geospatial_data.geospatial_data import ensure_absolute 32 from utilities.numerical_tools import INF 33 from anuga_config import epsilon 29 34 30 35 def inundation_damage(sww_file, exposure_file_in, … … 37 42 csv = Exposure_csv(exposure_file_in) 38 43 geospatial = csv.get_location() 39 max_depth , max_momentum= calc_max_depth_and_momentum(sww_file,44 max_depths, max_momentums = calc_max_depth_and_momentum(sww_file, 40 45 geospatial, 41 46 verbose=verbose, 42 47 use_cache=use_cache) 43 csv.set_column("MAX INUNDATION DEPTH (m)",max_depth) 44 csv.set_column("MOMENTUM (m^2/s) ",max_momentum) 45 csv.save(exposure_file_out) 48 #Do the two damage curves 49 # Ole probably knows if ther is good code for this lying around 50 #Do the prob of struct collapse 51 #Do economics 52 # Save info back to csv file 46 53 47 54 … … 55 62 csv = Exposure_csv(exposure_file_in) 56 63 geospatial = csv.get_location() 57 max_depth , max_momentum= calc_max_depth_and_momentum(sww_file,64 max_depths, max_momentums = calc_max_depth_and_momentum(sww_file, 58 65 geospatial, 59 66 verbose=verbose, 60 67 use_cache=use_cache) 61 csv.set_column("MAX INUNDATION DEPTH (m)",max_depth , overwrite=overwrite)62 csv.set_column("MOMENTUM (m^2/s) ",max_momentum , overwrite=overwrite)68 csv.set_column("MAX INUNDATION DEPTH (m)",max_depths, overwrite=overwrite) 69 csv.set_column("MOMENTUM (m^2/s) ",max_momentums, overwrite=overwrite) 63 70 csv.save(exposure_file_out) 64 71 … … 68 75 use_cache = True): 69 76 """ 70 Calculate the maximum depth above ground height 77 Calculate the maximum inundation height above ground floor (mihagf) for a list 78 of locations. 79 80 The mihagf value is in the range -ground_floor_height to overflow errors. 71 81 """ 72 82 quantities = ['stage', 'elevation', 'xmomentum', 'ymomentum'] … … 79 89 use_cache=use_cache) 80 90 # initialise the max lists 81 max_depth = [kinds.default_float_kind.MIN]*point_count82 max_momentum = [kinds.default_float_kind.MIN]*point_count91 max_depths = [ground_floor_height]*point_count 92 max_momentums = [ground_floor_height]*point_count 83 93 for point_i, point in enumerate(points): 84 94 for time in callable_sww.get_time(): … … 90 100 uh = quantities[2] 91 101 vh = quantities[3] 102 103 # This can easily give -ve values, 104 # but the array is initialised to 0.0, 105 # so 0.0 will be the minimum value. 92 106 depth = w - z - ground_floor_height 93 107 94 if depth > max_depth [point_i]:95 max_depth [point_i] = depth108 if depth > max_depths[point_i]: 109 max_depths[point_i] = depth 96 110 if w == INF or z == INF or uh == INF or vh == INF: 97 111 continue 98 112 momentum = sqrt(uh*uh + vh*vh) 99 if momentum > max_momentum[point_i]: 100 max_momentum[point_i] = momentum 101 return max_depth, max_momentum 113 if momentum > max_momentums[point_i]: 114 max_momentums[point_i] = momentum 115 return max_depths, max_momentums 116 117 class EventDamageModel: 118 """ 119 Initially I'm doing this as a class to group all of these functions/methods. 120 121 122 """ 123 double_brick_damage_curve = array([[-kinds.default_float_kind.MAX, 0.0], 124 [0.0-epsilon, 0.0], 125 [0.0,1.6], 126 [2.5,70.0], 127 [kinds.default_float_kind.MAX,70]]) 128 129 def __init__(self,max_depths, shore_distances, walls): 130 self.max_depths = max_depths 131 self.shore_distances = shore_distances 132 self.walls = walls 133 assert len(self.max_depths) == len(self.shore_distances) 134 self.structure_count = len(self.max_depths) 135 structure_damage_curve = InterpolatingFunction((array([0,1]),),array([0,10])) 136 137 def calc_damage_percentages(self): 138 139 # the data being created 140 percent_struct_damage = [0.0]*self.structure_count 141 percent_contents_damage = [0.0]*self.structure_count 142 #for i_building, 143 144 for i,max_height,shore_distance,wall in map(None, 145 range(self.structure_count), 146 self.max_depths, 147 self.shore_distances, 148 self.walls): 149 print "i",i 150 print "max_height",max_height 151 print "shore_distance",shore_distance 152 102 153 154 ############################################################################# 155 if __name__ == "__main__": 156 from Scientific.Functions.Interpolation import InterpolatingFunction 157 from Numeric import array, ravel 158 a = array([[0,0],[1,10]]) 159 c = array([0,1]) 160 161 axis = ravel(a[:,0:1]) 162 values = ravel(a[:,1:]) 163 164 #axis = array([0,1]) 165 #values = array([0,10]) 166 print "axis",axis 167 print "values",values 168 i = InterpolatingFunction((axis,), values) 169 print "value",i(0.5) 170 171 172 i = InterpolatingFunction((array([0,1]),),array([0,10])) 173 print "value",i(0.5) 174 175 -
inundation/damage/test_inundation_damage.py
r3312 r3318 128 128 fd = open(self.csv_file,'wb') 129 129 writer = csv.writer(fd) 130 writer.writerow(['LONGITUDE','LATITUDE','STR_VALUE','C_VALUE','ROOF_TYPE','WALLS' ])131 writer.writerow(['151.5','-34','199770','130000','Metal','Timber' ])132 writer.writerow(['151','-34.5','150000','76000','Metal','Double Brick' ])130 writer.writerow(['LONGITUDE','LATITUDE','STR_VALUE','C_VALUE','ROOF_TYPE','WALLS', 'SHORE_DIST']) 131 writer.writerow(['151.5','-34','199770','130000','Metal','Timber',20]) 132 writer.writerow(['151','-34.5','150000','76000','Metal','Double Brick',200]) 133 133 134 134 … … 153 153 out_csv, verbose=False) 154 154 155 def test_calc_damage_percentages(self): 156 max_depths = [-0.3, 0.0, 1.0] 157 shore_distances = [100, 200, 300] 158 walls = ['Double Brick','Timber','Brick Veneer'] 159 160 edm = EventDamageModel(max_depths, shore_distances, walls) 161 edm.calc_damage_percentages() 162 155 163 #------------------------------------------------------------- 156 164 if __name__ == "__main__":
Note: See TracChangeset
for help on using the changeset viewer.