Changeset 3318


Ignore:
Timestamp:
Jul 12, 2006, 5:40:30 PM (18 years ago)
Author:
duncan
Message:

more damage stuff. still working on it

Location:
inundation/damage
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • inundation/damage/inundation_damage.py

    r3310 r3318  
    66
    77from math import sqrt
     8from Scientific.Functions.Interpolation import InterpolatingFunction
     9from Numeric import array
    810
    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
    1312try: 
    1413    import kinds 
    1514except 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 
    1816    # was recently removed from the standard Numeric distro.  Some users may 
    1917    # not have it by default. 
     
    2725     
    2826    kinds = _kinds()
     27   
     28
     29from pyvolution.data_manager import Exposure_csv
     30from pyvolution.util import file_function
     31from geospatial_data.geospatial_data import ensure_absolute
     32from utilities.numerical_tools import INF
     33from anuga_config import epsilon
    2934
    3035def inundation_damage(sww_file, exposure_file_in,
     
    3742    csv = Exposure_csv(exposure_file_in)
    3843    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,
    4045                                                          geospatial,
    4146                                                          verbose=verbose,
    4247                                                          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
    4653
    4754   
     
    5562    csv = Exposure_csv(exposure_file_in)
    5663    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,
    5865                                                          geospatial,
    5966                                                          verbose=verbose,
    6067                                                          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)
    6370    csv.save(exposure_file_out)
    6471   
     
    6875                                 use_cache = True):
    6976    """
    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.
    7181    """
    7282    quantities =  ['stage', 'elevation', 'xmomentum', 'ymomentum']
     
    7989                                 use_cache=use_cache)
    8090    # initialise the max lists
    81     max_depth = [kinds.default_float_kind.MIN]*point_count
    82     max_momentum = [kinds.default_float_kind.MIN]*point_count
     91    max_depths = [ground_floor_height]*point_count
     92    max_momentums = [ground_floor_height]*point_count
    8393    for point_i, point in enumerate(points):
    8494        for time in callable_sww.get_time():
     
    90100            uh = quantities[2]
    91101            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.
    92106            depth = w - z - ground_floor_height
    93107             
    94             if depth > max_depth[point_i]:
    95                 max_depth[point_i] = depth
     108            if depth > max_depths[point_i]:
     109                max_depths[point_i] = depth
    96110            if w == INF or z == INF or uh == INF or vh == INF:
    97111                continue
    98112            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
     117class 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           
    102153       
     154#############################################################################
     155if __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  
    128128        fd = open(self.csv_file,'wb')
    129129        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])
    133133
    134134       
     
    153153                                   out_csv, verbose=False)
    154154       
     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       
    155163#-------------------------------------------------------------
    156164if __name__ == "__main__":
Note: See TracChangeset for help on using the changeset viewer.