Changeset 3399
- Timestamp:
- Jul 21, 2006, 2:26:48 PM (18 years ago)
- Location:
- inundation/damage
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
inundation/damage/inundation_damage.py
r3382 r3399 1 """Classes for implementing damage curves and economicdamage1 """Classes for implementing damage curves and calculating financial damage 2 2 3 3 Duncan Gray, Ole Nielsen, Jane Sexton, Nick Bartzis … … 13 13 import kinds 14 14 except ImportError: 15 # Hand-built mockup of the things we need from the kinds package, since it 15 # Hand-built mockup of the things we need from the kinds package, since it 16 16 # was recently removed from the standard Numeric distro. Some users may 17 17 # not have it by default. … … 46 46 sww file. 47 47 48 It then calculates the damage loss. 48 It then calculates the damage loss. 49 50 Note, structures outside of the sww file get the minimum inundation 51 (-ground_floor_height). 49 52 """ 50 53 … … 77 80 use_cache = True): 78 81 """ 82 Calculate the maximum depth and momemtum in an sww file, for locations 83 specified in an csv exposure file. 79 84 """ 80 85 … … 94 99 use_cache = True): 95 100 """ 96 Calculate the maximum inundation height above ground floor (mihagf)for a list101 Calculate the maximum inundation height above ground floor for a list 97 102 of locations. 98 103 99 The mihagf value is in the range -ground_floor_height to overflow errors. 104 The inundation value is in the range -ground_floor_height to 105 overflow errors. 100 106 """ 101 107 quantities = ['stage', 'elevation', 'xmomentum', 'ymomentum'] … … 135 141 class EventDamageModel: 136 142 """ 137 143 Object for working out the damage and cost 138 144 139 145 """ … … 195 201 #building collapse probability 196 202 # inundation depth above ground floor, m 197 depth_upper_limits = [depth_epsilon, 1.0, 2.0, 3.0, 5.0, kinds.default_float_kind.MAX] 203 depth_upper_limits = [depth_epsilon, 1.0, 2.0, 3.0, 5.0, 204 kinds.default_float_kind.MAX] 198 205 # shore mistance, m 199 206 shore_upper_limits = [125,200,250, kinds.default_float_kind.MAX] … … 227 234 228 235 def calc_damage_and_costs(self, verbose_csv=False, verbose=False): 236 """ 237 This is an overall method to calculate the % damage and collapsed 238 structures and then the $ loss. 239 """ 229 240 self.calc_damage_percentages() 230 241 collapse_probability = self.calc_collapse_probability() … … 245 256 246 257 def calc_damage_percentages(self): 258 """ 259 Using stage curves calc the damage to structures and contents 260 """ 247 261 248 262 # the data being created … … 278 292 279 293 def calc_cost(self): 294 """ 295 Once the damage has been calculated, determine the $ cost. 296 """ 280 297 # ensure_numeric does not cut it. 281 298 self.struct_loss = self.struct_damage * \ … … 361 378 # Warning, the collapse_probability list now lists 362 379 # houses that did not collapse, (though not all of them) 363 #print "",self.collapse_csv_info 380 #print "",self.collapse_csv_info 381 364 382 ############################################################################# 365 383 if __name__ == "__main__": 366 from Scientific.Functions.Interpolation import InterpolatingFunction 367 from Numeric import array, ravel 368 a = array([[0,0],[1,10]]) 369 c = array([0,1]) 370 371 axis = ravel(a[:,0:1]) 372 values = ravel(a[:,1:]) 373 374 #axis = array([0,1]) 375 #values = array([0,10]) 376 print "axis",axis 377 print "values",values 378 i = InterpolatingFunction((axis,), values) 379 print "value",i(0.5) 380 381 382 i = InterpolatingFunction((array([0,1]),),array([0,10])) 383 print "value",i(0.5) 384 385 dict = {1:10, 2:20} 386 print dict.get(100,dict[2]) 387 388 inundation_damage('source.sww', 'augmented_buildings_high.csv', 389 'augmented_buildings_high_dsg.csv') 384 pass -
inundation/damage/test_inundation_damage.py
r3382 r3399 158 158 159 159 # create mesh 160 mesh_file = tempfile.mktemp(".tsh") 160 mesh_file = tempfile.mktemp(".tsh") 161 161 points = [[0.0,0.0],[6.0,0.0],[6.0,6.0],[0.0,6.0]] 162 162 m = Mesh() … … 174 174 175 175 #Set some field values 176 domain.set_quantity('stage', 0.3)177 176 domain.set_quantity('elevation', elevation_function) 178 177 domain.set_quantity('friction', 0.03) … … 184 183 B = Transmissive_boundary(domain) 185 184 domain.set_boundary( {'exterior': B}) 185 186 # This call mangles the stage values. 186 187 domain.distribute_to_vertices_and_edges() 188 domain.set_quantity('stage', 0.3) 187 189 188 190 #sww_file = tempfile.mktemp("") … … 197 199 sww.store_connectivity() 198 200 sww.store_timestep(['stage', 'xmomentum', 'ymomentum']) 201 domain.set_quantity('stage', -0.3) 199 202 domain.time = 2. 200 203 sww.store_timestep(['stage', 'xmomentum', 'ymomentum']) … … 206 209 writer = csv.writer(fd) 207 210 writer.writerow(['x','y','STR_VALUE','C_VALUE','ROOF_TYPE','WALLS', 'SHORE_DIST']) 208 writer.writerow([5.5,0.5,'199770','130000','Metal','Timber',20]) 209 writer.writerow([4.5,1.0,'150000','76000','Metal','Double Brick',20]) 210 writer.writerow([4.5,1.5,'150000','76000','Metal','Brick Veneer',20]) 211 writer.writerow([5.5,0.5,'10','130000','Metal','Timber',20]) 212 writer.writerow([4.5,1.0,'150','76000','Metal','Double Brick',20]) 213 writer.writerow([0.1,1.5,'100','76000','Metal','Brick Veneer',300]) 214 writer.writerow([6.1,1.5,'100','76000','Metal','Brick Veneer',300]) 211 215 fd.close() 212 216 … … 215 219 inundation_damage(sww_file, csv_file, verbose=False) 216 220 217 221 csv_handle = Exposure_csv(csv_file) 222 struct_loss = csv_handle.get_column(EventDamageModel.STRUCT_LOSS_TITLE) 223 #print "struct_loss",struct_loss 224 struct_loss = [float(x) for x in struct_loss] 225 assert allclose(struct_loss,[10,150,16.9,0]) 226 depth = csv_handle.get_column(EventDamageModel.MAX_DEPTH_TITLE) 227 #print "depth",depth 228 depth = [float(x) for x in depth] 229 assert allclose(depth,[5.5,4.5,0.1,-0.3]) 230 os.remove(sww.filename) 231 os.remove(csv_file) 232 218 233 def ztest_add_depth_and_momentum2csv(self): 219 234 sww_file = self.domain.filename + "." + self.domain.format … … 299 314 edm.contents_damage[3] + edm.contents_damage[4] ==1.0, 300 315 'Error!') 301 # FIXME use list comprehension to do the next two tests 302 316 sum_struct = 0.0 317 sum_contents = 0.0 318 for i in [5,6,7,8]: 319 sum_struct += edm.struct_damage[i] 320 sum_contents += edm.contents_damage[i] 321 print "", 322 self.failUnless( sum_struct == 0.0 and sum_contents == 0.0, 323 'Error!') 324 sum_struct = 0.0 325 sum_contents = 0.0 326 for i in [9,10,11,12,13,14,15,16]: 327 sum_struct += edm.struct_damage[i] 328 sum_contents += edm.contents_damage[i] 329 self.failUnless( sum_struct == 2.0 and sum_contents == 2.0, 330 'Error!') 303 331 304 332 def test_calc_collapse_probability(self): … … 358 386 #------------------------------------------------------------- 359 387 if __name__ == "__main__": 360 #suite = unittest.makeSuite(Test_inundation_damage,'test_in undation_damage2')388 #suite = unittest.makeSuite(Test_inundation_damage,'test_in_damage2') 361 389 suite = unittest.makeSuite(Test_inundation_damage,'test') 362 390 runner = unittest.TextTestRunner()
Note: See TracChangeset
for help on using the changeset viewer.