source: inundation/damage/inundation_damage.py @ 3315

Last change on this file since 3315 was 3310, checked in by sexton, 19 years ago

handling INF's

File size: 4.0 KB
Line 
1"""Classes for implementing damage curves and economic damage
2
3   Duncan Gray, Ole Nielsen, Jane Sexton, Nick Bartzis
4   Geoscience Australia, 2006
5"""
6
7from math import sqrt
8
9from pyvolution.data_manager import Exposure_csv
10from pyvolution.util import file_function
11from geospatial_data.geospatial_data import ensure_absolute
12from utilities.numerical_tools import INF
13try: 
14    import kinds 
15except 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
30def 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   
48def 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, overwrite=overwrite)
62    csv.set_column("MOMENTUM (m^2/s) ",max_momentum, overwrite=overwrite)
63    csv.save(exposure_file_out)
64   
65def 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            #print "quantities", quantities
87           
88            w = quantities[0]
89            z = quantities[1]
90            uh = quantities[2]
91            vh = quantities[3]
92            depth = w - z - ground_floor_height
93             
94            if depth > max_depth[point_i]:
95                max_depth[point_i] = depth
96            if w == INF or z == INF or uh == INF or vh == INF:
97                continue
98            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       
102       
Note: See TracBrowser for help on using the repository browser.