Changeset 3399


Ignore:
Timestamp:
Jul 21, 2006, 2:26:48 PM (18 years ago)
Author:
duncan
Message:

adding comments

Location:
inundation/damage
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • inundation/damage/inundation_damage.py

    r3382 r3399  
    1 """Classes for implementing damage curves and economic damage
     1"""Classes for implementing damage curves and calculating financial damage
    22
    33   Duncan Gray, Ole Nielsen, Jane Sexton, Nick Bartzis
     
    1313    import kinds 
    1414except 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
    1616    # was recently removed from the standard Numeric distro.  Some users may 
    1717    # not have it by default. 
     
    4646    sww file.
    4747
    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).
    4952    """
    5053
     
    7780                                 use_cache = True):
    7881    """
     82    Calculate the maximum depth and momemtum in an sww file, for locations
     83    specified in an csv exposure file.
    7984    """
    8085
     
    9499                                 use_cache = True):
    95100    """
    96     Calculate the maximum inundation height above ground floor (mihagf) for a list
     101    Calculate the maximum inundation height above ground floor for a list
    97102    of locations.
    98103
    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.
    100106    """
    101107    quantities =  ['stage', 'elevation', 'xmomentum', 'ymomentum']
     
    135141class EventDamageModel:
    136142    """
    137 
     143    Object for working out the damage and cost
    138144
    139145    """
     
    195201    #building collapse probability
    196202    # 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]
    198205    # shore mistance, m
    199206    shore_upper_limits = [125,200,250, kinds.default_float_kind.MAX]
     
    227234       
    228235    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        """
    229240        self.calc_damage_percentages()
    230241        collapse_probability = self.calc_collapse_probability()
     
    245256           
    246257    def calc_damage_percentages(self):
     258        """
     259        Using stage curves calc the damage to structures and contents
     260        """
    247261
    248262        # the data being created
     
    278292       
    279293    def calc_cost(self):
     294        """
     295        Once the damage has been calculated, determine the $ cost.
     296        """
    280297        # ensure_numeric does not cut it.
    281298        self.struct_loss = self.struct_damage * \
     
    361378            # Warning, the collapse_probability list now lists
    362379            # houses that did not collapse, (though not all of them)
    363             #print "",self.collapse_csv_info
     380            #print "",self.collapse_csv_info
     381           
    364382#############################################################################
    365383if __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  
    158158
    159159        # create mesh
    160         mesh_file = tempfile.mktemp(".tsh")       
     160        mesh_file = tempfile.mktemp(".tsh")   
    161161        points = [[0.0,0.0],[6.0,0.0],[6.0,6.0],[0.0,6.0]]
    162162        m = Mesh()
     
    174174
    175175        #Set some field values
    176         domain.set_quantity('stage', 0.3)
    177176        domain.set_quantity('elevation', elevation_function)
    178177        domain.set_quantity('friction', 0.03)
     
    184183        B = Transmissive_boundary(domain)
    185184        domain.set_boundary( {'exterior': B})
     185
     186        # This call mangles the stage values.
    186187        domain.distribute_to_vertices_and_edges()
     188        domain.set_quantity('stage', 0.3)
    187189
    188190        #sww_file = tempfile.mktemp("")
     
    197199        sww.store_connectivity()
    198200        sww.store_timestep(['stage', 'xmomentum', 'ymomentum'])
     201        domain.set_quantity('stage', -0.3)
    199202        domain.time = 2.
    200203        sww.store_timestep(['stage', 'xmomentum', 'ymomentum'])
     
    206209        writer = csv.writer(fd)
    207210        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])
    211215        fd.close()
    212216
     
    215219        inundation_damage(sww_file, csv_file, verbose=False)
    216220
    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       
    218233    def ztest_add_depth_and_momentum2csv(self):
    219234        sww_file = self.domain.filename + "." + self.domain.format
     
    299314                         edm.contents_damage[3] + edm.contents_damage[4] ==1.0,
    300315                        '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!')
    303331       
    304332    def test_calc_collapse_probability(self):
     
    358386#-------------------------------------------------------------
    359387if __name__ == "__main__":
    360     #suite = unittest.makeSuite(Test_inundation_damage,'test_inundation_damage2')
     388    #suite = unittest.makeSuite(Test_inundation_damage,'test_in_damage2')
    361389    suite = unittest.makeSuite(Test_inundation_damage,'test')
    362390    runner = unittest.TextTestRunner()
Note: See TracChangeset for help on using the changeset viewer.