Changeset 6151


Ignore:
Timestamp:
Jan 13, 2009, 1:50:07 PM (15 years ago)
Author:
rwilson
Message:

Change Numeric imports to general form - ready to change to NumPy?.

Location:
anuga_core/source/anuga/damage_modelling
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • anuga_core/source/anuga/damage_modelling/inundation_damage.py

    r6034 r6151  
    77from math import sqrt
    88from Scientific.Functions.Interpolation import InterpolatingFunction
    9 from Numeric import array, ravel, Float, zeros
    109from random import choice
    1110from types import StringType
     11
     12import Numeric as num
     13
    1214
    1315try: 
     
    203205    STRUCT_COLLAPSED_TITLE = "STRUCT_COLLAPSED"#"collapsed structure if 1"
    204206    STRUCT_INUNDATED_TITLE = "STRUCT_INUNDATED"#"inundated structure if 1"
    205     double_brick_damage_array = array([[-kinds.default_float_kind.MAX, 0.0],
    206                                        [0.0-depth_epsilon, 0.0],
    207                                        [0.0,0.016],
    208                                        [0.1,0.150],
    209                                        [0.3,0.425],
    210                                        [0.5,0.449],
    211                                        [1.0,0.572],
    212                                        [1.5,0.582],
    213                                        [2.0,0.587],
    214                                        [2.5,0.647],
    215                                        [kinds.default_float_kind.MAX,64.7]])
     207    double_brick_damage_array = num.array([[-kinds.default_float_kind.MAX, 0.0],
     208                                           [0.0-depth_epsilon, 0.0],
     209                                           [0.0,0.016],
     210                                           [0.1,0.150],
     211                                           [0.3,0.425],
     212                                           [0.5,0.449],
     213                                           [1.0,0.572],
     214                                           [1.5,0.582],
     215                                           [2.0,0.587],
     216                                           [2.5,0.647],
     217                                           [kinds.default_float_kind.MAX,64.7]])
    216218    double_brick_damage_curve = InterpolatingFunction( \
    217         (ravel(double_brick_damage_array[:,0:1]),),
    218         ravel(double_brick_damage_array[:,1:]))
    219    
    220     brick_veeer_damage_array = array([[-kinds.default_float_kind.MAX, 0.0],
    221                                        [0.0-depth_epsilon, 0.0],
    222                                        [0.0,0.016],
    223                                        [0.1,0.169],
    224                                        [0.3,0.445],
    225                                        [0.5,0.472],
    226                                        [1.0,0.618],
    227                                        [1.5,0.629],
    228                                        [2.0,0.633],
    229                                        [2.5,0.694],
    230                                        [kinds.default_float_kind.MAX,69.4]])
     219        (num.ravel(double_brick_damage_array[:,0:1]),),
     220        num.ravel(double_brick_damage_array[:,1:]))
     221   
     222    brick_veeer_damage_array = num.array([[-kinds.default_float_kind.MAX, 0.0],
     223                                          [0.0-depth_epsilon, 0.0],
     224                                          [0.0,0.016],
     225                                          [0.1,0.169],
     226                                          [0.3,0.445],
     227                                          [0.5,0.472],
     228                                          [1.0,0.618],
     229                                          [1.5,0.629],
     230                                          [2.0,0.633],
     231                                          [2.5,0.694],
     232                                          [kinds.default_float_kind.MAX,69.4]])
    231233    brick_veeer_damage_curve = InterpolatingFunction( \
    232         (ravel(brick_veeer_damage_array[:,0:1]),),
    233         ravel(brick_veeer_damage_array[:,1:]))
     234        (num.ravel(brick_veeer_damage_array[:,0:1]),),
     235        num.ravel(brick_veeer_damage_array[:,1:]))
    234236    struct_damage_curve = {'Double Brick':double_brick_damage_curve,
    235237                           'Brick Veneer':brick_veeer_damage_curve}
    236238    default_struct_damage_curve = brick_veeer_damage_curve
    237239
    238     contents_damage_array = array([[-kinds.default_float_kind.MAX, 0.0],
     240    contents_damage_array = num.array([[-kinds.default_float_kind.MAX, 0.0],
    239241                                       [0.0-depth_epsilon, 0.0],
    240242                                       [0.0,0.013],
     
    247249                                       [kinds.default_float_kind.MAX,98.6]])
    248250    contents_damage_curve = InterpolatingFunction( \
    249         (ravel(contents_damage_array[:,0:1]),),
    250         ravel(contents_damage_array[:,1:]))
     251        (num.ravel(contents_damage_array[:,0:1]),),
     252        num.ravel(contents_damage_array[:,1:]))
    251253
    252254    #building collapse probability
     
    312314
    313315        # the data being created
    314         struct_damage = zeros(self.structure_count,Float)
    315         contents_damage = zeros(self.structure_count,Float)
     316        struct_damage = num.zeros(self.structure_count, num.Float)
     317        contents_damage = num.zeros(self.structure_count, num.Float)
    316318        self.struct_inundated = ['']* self.structure_count
    317319
  • anuga_core/source/anuga/damage_modelling/test_inundation_damage.py

    r5442 r6151  
    1717from anuga.shallow_water.data_manager import get_dataobject
    1818
    19 from Numeric import zeros, Float, allclose
     19import Numeric as num
    2020
    2121
     
    8383        #Initial condition - with jumps
    8484        bed = domain.quantities['elevation'].vertex_values
    85         stage = zeros(bed.shape, Float)
     85        stage = num.zeros(bed.shape, num.Float)
    8686
    8787        h = 0.3
     
    153153        #Initial condition - with jumps
    154154        bed = domain.quantities['elevation'].vertex_values
    155         stage = zeros(bed.shape, Float)
     155        stage = num.zeros(bed.shape, num.Float)
    156156
    157157        h = 30.
     
    308308        #print "struct_loss",struct_loss
    309309        struct_loss = [float(x) for x in struct_loss]
    310         assert allclose(struct_loss,[10,150,16.9,0])
     310        assert num.allclose(struct_loss,[10,150,16.9,0])
    311311        depth = csv_handle.get_column(EventDamageModel.MAX_DEPTH_TITLE)
    312312        #print "depth",depth
    313313        depth = [float(x) for x in depth]
    314         assert allclose(depth,[5.5,4.5,0.1,-0.3])
     314        assert num.allclose(depth,[5.5,4.5,0.1,-0.3])
    315315        os.remove(sww.filename)
    316316        os.remove(csv_file)
     
    395395        #print "struct_loss",struct_loss
    396396        struct_loss = [float(x) for x in struct_loss]
    397         assert allclose(struct_loss,[10,150,16.9,0])       
     397        assert num.allclose(struct_loss,[10,150,16.9,0])       
    398398        depth = csv_handle.get_column(EventDamageModel.MAX_DEPTH_TITLE)
    399399        #print "depth",depth
    400400        depth = [float(x) for x in depth]
    401         assert allclose(depth,[5.5,4.5,0.1,-0.3])
     401        assert num.allclose(depth,[5.5,4.5,0.1,-0.3])
    402402       
    403403        # Test another file
     
    406406        #print "struct_loss",struct_loss
    407407        struct_loss = [float(x) for x in struct_loss]
    408         assert allclose(struct_loss,[10,150,16.9,0])       
     408        assert num.allclose(struct_loss,[10,150,16.9,0])       
    409409        depth = csv_handle.get_column(EventDamageModel.MAX_DEPTH_TITLE)
    410410        #print "depth",depth
    411411        depth = [float(x) for x in depth]
    412         assert allclose(depth,[5.5,4.5,0.1,-0.3])
     412        assert num.allclose(depth,[5.5,4.5,0.1,-0.3])
    413413        os.remove(sww.filename)
    414414        os.remove(csv_file)
     
    458458                               struct_costs, content_costs)
    459459        edm.calc_damage_percentages()
    460         assert allclose(edm.struct_damage,[0.0,0.016,0.572,
    461                                             0.0,0.016,0.618,
    462                                             0.0,0.016,0.618])
    463         assert allclose(edm.contents_damage,[0.0,0.013,0.970,
    464                                              0.0,0.013,0.970,
    465                                              0.0,0.013,0.970])
     460        assert num.allclose(edm.struct_damage,[0.0,0.016,0.572,
     461                                               0.0,0.016,0.618,
     462                                               0.0,0.016,0.618])
     463        assert num.allclose(edm.contents_damage,[0.0,0.013,0.970,
     464                                                 0.0,0.013,0.970,
     465                                                 0.0,0.013,0.970])
    466466        edm.calc_cost()
    467         assert allclose(edm.struct_loss,[0.0,.16,5.72,
    468                                             0.0,.16,6.18,
    469                                             0.0,0.016,0.618])
    470         assert allclose(edm.contents_loss,[0.0,1.3,97,
    471                                              0.0,1.3,97,
    472                                              0.0,0.13,9.7])
     467        assert num.allclose(edm.struct_loss,[0.0,.16,5.72,
     468                                             0.0,.16,6.18,
     469                                             0.0,0.016,0.618])
     470        assert num.allclose(edm.contents_loss,[0.0,1.3,97,
     471                                               0.0,1.3,97,
     472                                               0.0,0.13,9.7])
    473473       
    474474       
     
    476476        edm = EventDamageModel([0.0]*17, [0.0]*17, [0.0]*17,
    477477                               [0.0]*17, [0.0]*17)
    478         edm.struct_damage = zeros(17,Float)
    479         edm.contents_damage = zeros(17,Float)
     478        edm.struct_damage = num.zeros(17,num.Float)
     479        edm.contents_damage = num.zeros(17,num.Float)
    480480        collapse_probability = {0.4:[0], #0
    481481                                0.6:[1], #1
     
    582582        # Test values based on returned results, so not an excellent test
    583583       
    584         assert allclose(deps[0],0.113204555211)
    585         assert allclose(deps[1],11.3215)
    586         assert allclose(deps[2],0.0) # this value is outside both sww files
     584        assert num.allclose(deps[0],0.113204555211)
     585        assert num.allclose(deps[1],11.3215)
     586        assert num.allclose(deps[2],0.0) # this value is outside both sww files
    587587       
    588588#-------------------------------------------------------------
Note: See TracChangeset for help on using the changeset viewer.