Index: /inundation/damage/inundation_damage.py
===================================================================
--- /inundation/damage/inundation_damage.py	(revision 3398)
+++ /inundation/damage/inundation_damage.py	(revision 3399)
@@ -1,3 +1,3 @@
-"""Classes for implementing damage curves and economic damage
+"""Classes for implementing damage curves and calculating financial damage
 
    Duncan Gray, Ole Nielsen, Jane Sexton, Nick Bartzis
@@ -13,5 +13,5 @@
     import kinds  
 except ImportError:  
-    # Hand-built mockup of the things we need from the kinds package, since it  
+    # Hand-built mockup of the things we need from the kinds package, since it
     # was recently removed from the standard Numeric distro.  Some users may  
     # not have it by default.  
@@ -46,5 +46,8 @@
     sww file.
 
-    It then calculates the damage loss. 
+    It then calculates the damage loss.
+
+    Note, structures outside of the sww file get the minimum inundation
+    (-ground_floor_height).
     """
 
@@ -77,4 +80,6 @@
                                  use_cache = True):
     """
+    Calculate the maximum depth and momemtum in an sww file, for locations
+    specified in an csv exposure file.
     """
 
@@ -94,8 +99,9 @@
                                  use_cache = True):
     """
-    Calculate the maximum inundation height above ground floor (mihagf) for a list
+    Calculate the maximum inundation height above ground floor for a list
     of locations.
 
-    The mihagf value is in the range -ground_floor_height to overflow errors.
+    The inundation value is in the range -ground_floor_height to
+    overflow errors.
     """
     quantities =  ['stage', 'elevation', 'xmomentum', 'ymomentum']
@@ -135,5 +141,5 @@
 class EventDamageModel:
     """
-
+    Object for working out the damage and cost
 
     """
@@ -195,5 +201,6 @@
     #building collapse probability
     # inundation depth above ground floor, m
-    depth_upper_limits = [depth_epsilon, 1.0, 2.0, 3.0, 5.0, kinds.default_float_kind.MAX]
+    depth_upper_limits = [depth_epsilon, 1.0, 2.0, 3.0, 5.0,
+                          kinds.default_float_kind.MAX]
     # shore mistance, m
     shore_upper_limits = [125,200,250, kinds.default_float_kind.MAX]
@@ -227,4 +234,8 @@
         
     def calc_damage_and_costs(self, verbose_csv=False, verbose=False):
+        """
+        This is an overall method to calculate the % damage and collapsed
+        structures and then the $ loss.
+        """
         self.calc_damage_percentages()
         collapse_probability = self.calc_collapse_probability()
@@ -245,4 +256,7 @@
             
     def calc_damage_percentages(self):
+        """
+        Using stage curves calc the damage to structures and contents
+        """
 
         # the data being created
@@ -278,4 +292,7 @@
         
     def calc_cost(self):
+        """
+        Once the damage has been calculated, determine the $ cost.
+        """
         # ensure_numeric does not cut it.
         self.struct_loss = self.struct_damage * \
@@ -361,29 +378,7 @@
             # Warning, the collapse_probability list now lists 
             # houses that did not collapse, (though not all of them)
-            #print "",self.collapse_csv_info 
+            #print "",self.collapse_csv_info
+            
 #############################################################################
 if __name__ == "__main__":
-    from Scientific.Functions.Interpolation import InterpolatingFunction
-    from Numeric import array, ravel
-    a = array([[0,0],[1,10]])
-    c = array([0,1])
-
-    axis = ravel(a[:,0:1])
-    values = ravel(a[:,1:])
-    
-    #axis = array([0,1])
-    #values = array([0,10])
-    print "axis",axis
-    print "values",values 
-    i = InterpolatingFunction((axis,), values)
-    print "value",i(0.5)
-
-    
-    i = InterpolatingFunction((array([0,1]),),array([0,10]))
-    print "value",i(0.5)
-
-    dict = {1:10, 2:20}
-    print dict.get(100,dict[2])
-
-    inundation_damage('source.sww', 'augmented_buildings_high.csv',
-                      'augmented_buildings_high_dsg.csv')        
+    pass 
Index: /inundation/damage/test_inundation_damage.py
===================================================================
--- /inundation/damage/test_inundation_damage.py	(revision 3398)
+++ /inundation/damage/test_inundation_damage.py	(revision 3399)
@@ -158,5 +158,5 @@
 
         # create mesh
-        mesh_file = tempfile.mktemp(".tsh")        
+        mesh_file = tempfile.mktemp(".tsh")    
         points = [[0.0,0.0],[6.0,0.0],[6.0,6.0],[0.0,6.0]]
         m = Mesh()
@@ -174,5 +174,4 @@
 
         #Set some field values
-        domain.set_quantity('stage', 0.3)
         domain.set_quantity('elevation', elevation_function)
         domain.set_quantity('friction', 0.03)
@@ -184,5 +183,8 @@
         B = Transmissive_boundary(domain)
         domain.set_boundary( {'exterior': B})
+
+        # This call mangles the stage values.
         domain.distribute_to_vertices_and_edges()
+        domain.set_quantity('stage', 0.3)
 
         #sww_file = tempfile.mktemp("")
@@ -197,4 +199,5 @@
         sww.store_connectivity()
         sww.store_timestep(['stage', 'xmomentum', 'ymomentum'])
+        domain.set_quantity('stage', -0.3)
         domain.time = 2.
         sww.store_timestep(['stage', 'xmomentum', 'ymomentum'])
@@ -206,7 +209,8 @@
         writer = csv.writer(fd)
         writer.writerow(['x','y','STR_VALUE','C_VALUE','ROOF_TYPE','WALLS', 'SHORE_DIST'])
-        writer.writerow([5.5,0.5,'199770','130000','Metal','Timber',20])
-        writer.writerow([4.5,1.0,'150000','76000','Metal','Double Brick',20])
-        writer.writerow([4.5,1.5,'150000','76000','Metal','Brick Veneer',20])
+        writer.writerow([5.5,0.5,'10','130000','Metal','Timber',20])
+        writer.writerow([4.5,1.0,'150','76000','Metal','Double Brick',20])
+        writer.writerow([0.1,1.5,'100','76000','Metal','Brick Veneer',300])
+        writer.writerow([6.1,1.5,'100','76000','Metal','Brick Veneer',300])
         fd.close()
 
@@ -215,5 +219,16 @@
         inundation_damage(sww_file, csv_file, verbose=False)
 
-
+        csv_handle = Exposure_csv(csv_file)
+        struct_loss = csv_handle.get_column(EventDamageModel.STRUCT_LOSS_TITLE)
+        #print "struct_loss",struct_loss
+        struct_loss = [float(x) for x in struct_loss]
+        assert allclose(struct_loss,[10,150,16.9,0])
+        depth = csv_handle.get_column(EventDamageModel.MAX_DEPTH_TITLE)
+        #print "depth",depth
+        depth = [float(x) for x in depth]
+        assert allclose(depth,[5.5,4.5,0.1,-0.3])
+        os.remove(sww.filename)
+        os.remove(csv_file)
+        
     def ztest_add_depth_and_momentum2csv(self):
         sww_file = self.domain.filename + "." + self.domain.format
@@ -299,6 +314,19 @@
                          edm.contents_damage[3] + edm.contents_damage[4] ==1.0,
                         'Error!')
-        # FIXME use list comprehension to do the next two tests
-
+        sum_struct = 0.0
+        sum_contents = 0.0
+        for i in [5,6,7,8]:
+            sum_struct += edm.struct_damage[i]
+            sum_contents += edm.contents_damage[i]
+        print "", 
+        self.failUnless( sum_struct == 0.0 and sum_contents  == 0.0,
+                        'Error!')
+        sum_struct = 0.0
+        sum_contents = 0.0
+        for i in [9,10,11,12,13,14,15,16]:
+            sum_struct += edm.struct_damage[i]
+            sum_contents += edm.contents_damage[i]
+        self.failUnless( sum_struct == 2.0 and sum_contents  == 2.0,
+                        'Error!')
         
     def test_calc_collapse_probability(self):
@@ -358,5 +386,5 @@
 #-------------------------------------------------------------
 if __name__ == "__main__":
-    #suite = unittest.makeSuite(Test_inundation_damage,'test_inundation_damage2')
+    #suite = unittest.makeSuite(Test_inundation_damage,'test_in_damage2')
     suite = unittest.makeSuite(Test_inundation_damage,'test')
     runner = unittest.TextTestRunner()
