Changeset 3303
- Timestamp:
- Jul 11, 2006, 3:05:46 PM (18 years ago)
- Location:
- inundation/damage
- Files:
-
- 1 added
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
inundation/damage/inundation_damage.py
r3231 r3303 5 5 """ 6 6 7 print "not done yet.." 7 from math import sqrt 8 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 13 try: 14 import kinds 15 except ImportError: 16 # Hand-built mockup of the things we need from the kinds package, 17 #since it 18 # was recently removed from the standard Numeric distro. Some users may 19 # not have it by default. 20 class _bunch: 21 pass 22 23 class _kinds(_bunch): 24 default_float_kind = _bunch() 25 default_float_kind.MIN = 2.2250738585072014e-308 #smallest +ve number 26 default_float_kind.MAX = 1.7976931348623157e+308 27 28 kinds = _kinds() 29 30 def inundation_damage(sww_file, exposure_file_in, 31 exposure_file_out=None, 32 overwrite=False, verbose=True, 33 use_cache = True): 34 """ 35 """ 36 37 csv = Exposure_csv(exposure_file_in) 38 geospatial = csv.get_location() 39 max_depth, max_momentum = calc_max_depth_and_momentum(sww_file, 40 geospatial, 41 verbose=verbose, 42 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) 46 47 48 def add_depth_and_momentum2csv(sww_file, exposure_file_in, 49 exposure_file_out=None, 50 overwrite=False, verbose=True, 51 use_cache = True): 52 """ 53 """ 54 55 csv = Exposure_csv(exposure_file_in) 56 geospatial = csv.get_location() 57 max_depth, max_momentum = calc_max_depth_and_momentum(sww_file, 58 geospatial, 59 verbose=verbose, 60 use_cache=use_cache) 61 csv.set_column("MAX INUNDATION DEPTH (m)",max_depth) 62 csv.set_column("MOMENTUM (m^2/s) ",max_momentum) 63 csv.save(exposure_file_out) 64 65 def calc_max_depth_and_momentum(sww_file, points, 66 ground_floor_height=0.0, 67 verbose=True, 68 use_cache = True): 69 """ 70 Calculate the maximum depth above ground height 71 """ 72 quantities = ['stage', 'elevation', 'xmomentum', 'ymomentum'] 73 points = ensure_absolute(points) 74 point_count = len(points) 75 callable_sww = file_function(sww_file, 76 quantities=quantities, 77 interpolation_points=points, 78 verbose=verbose, 79 use_cache=use_cache) 80 # initialise the max lists 81 max_depth = [kinds.default_float_kind.MIN]*point_count 82 max_momentum = [kinds.default_float_kind.MIN]*point_count 83 for point_i, point in enumerate(points): 84 for time in callable_sww.get_time(): 85 quantities = callable_sww(time,point_i) 86 w = quantities[0] 87 z = quantities[1] 88 uh = quantities[2] 89 vh = quantities[3] 90 depth = w - z - ground_floor_height 91 momentum = sqrt(uh*uh + vh*vh) 92 if depth > max_depth[point_i]: 93 max_depth[point_i] = depth 94 if momentum > max_momentum[point_i]: 95 max_momentum[point_i] = momentum 96 return max_depth, max_momentum 97
Note: See TracChangeset
for help on using the changeset viewer.