Changeset 5897


Ignore:
Timestamp:
Nov 6, 2008, 12:17:15 PM (15 years ago)
Author:
ole
Message:

Reverted numpy changes to the trunk that should have been made to the branch.
The command was svn merge -r 5895:5890 .

Location:
anuga_core
Files:
44 edited

Legend:

Unmodified
Added
Removed
  • anuga_core/compile_all.py

    r4978 r5897  
    33buildroot = os.getcwd()
    44
    5 os.chdir('source')
     5os.chdir('source_numpy_conversion')
    66
    77os.chdir('anuga')
  • anuga_core/source/anuga/abstract_2d_finite_volumes/domain.py

    r5892 r5897  
    88"""
    99
    10 ##from numpy.oldnumeric import allclose, argmax, zeros, Float
    11 import numpy
    12 
     10from Numeric import allclose, argmax, zeros, Float
    1311from anuga.config import epsilon
    1412from anuga.config import beta_euler, beta_rk2
     
    107105
    108106        if verbose: print 'Initialising Domain'
     107        from Numeric import zeros, Float, Int, ones
    109108        from quantity import Quantity
    110109
     
    156155        for key in self.full_send_dict:
    157156            buffer_shape = self.full_send_dict[key][0].shape[0]
    158             self.full_send_dict[key].append(numpy.zeros( (buffer_shape,self.nsys), numpy.float))
     157            self.full_send_dict[key].append(zeros( (buffer_shape,self.nsys) ,Float))
    159158
    160159
    161160        for key in self.ghost_recv_dict:
    162161            buffer_shape = self.ghost_recv_dict[key][0].shape[0]
    163             self.ghost_recv_dict[key].append(numpy.zeros( (buffer_shape,self.nsys), numpy.float))
     162            self.ghost_recv_dict[key].append(zeros( (buffer_shape,self.nsys) ,Float))
    164163
    165164
     
    169168        N = len(self) #number_of_elements
    170169        self.number_of_elements = N
    171         self.tri_full_flag = numpy.ones(N, numpy.int)
     170        self.tri_full_flag = ones(N, Int)
    172171        for i in self.ghost_recv_dict.keys():
    173172            for id in self.ghost_recv_dict[i][0]:
     
    176175        # Test the assumption that all full triangles are store before
    177176        # the ghost triangles.
    178         if not numpy.allclose(self.tri_full_flag[:self.number_of_full_nodes],1):
     177        if not allclose(self.tri_full_flag[:self.number_of_full_nodes],1):
    179178            print 'WARNING:  Not all full triangles are store before ghost triangles'
    180179                       
     
    231230        # calculation
    232231        N = len(self) # Number_of_triangles
    233         self.already_computed_flux = numpy.zeros((N, 3), numpy.int)
     232        self.already_computed_flux = zeros((N, 3), Int)
    234233
    235234        # Storage for maximal speeds computed for each triangle by
    236235        # compute_fluxes
    237236        # This is used for diagnostics only (reset at every yieldstep)
    238         self.max_speed = numpy.zeros(N, numpy.float)
     237        self.max_speed = zeros(N, Float)
    239238
    240239        if mesh_filename is not None:
     
    267266        """
    268267
     268        from Numeric import zeros, Float
     269
    269270        if not (vertex is None or edge is None):
    270271            msg = 'Values for both vertex and edge was specified.'
     
    272273            raise msg
    273274
    274         q = numpy.zeros( len(self.conserved_quantities), numpy.float)
     275        q = zeros( len(self.conserved_quantities), Float)
    275276
    276277        for i, name in enumerate(self.conserved_quantities):
     
    768769            # Find index of largest computed flux speed
    769770            if triangle_id is None:
    770                 k = self.k = numpy.argmax(self.max_speed)
     771                k = self.k = argmax(self.max_speed)
    771772            else:
    772773                errmsg = 'Triangle_id %d does not exist in mesh: %s' %(triangle_id,
     
    10851086
    10861087        """
    1087         print '.evolve: 0'
    10881088
    10891089        from anuga.config import min_timestep, max_timestep, epsilon
     
    10961096               %self.get_boundary_tags()
    10971097        assert hasattr(self, 'boundary_objects'), msg
    1098         print '.evolve: 1'
    10991098
    11001099
     
    11051104
    11061105        self._order_ = self.default_order
    1107         print '.evolve: 2'
    11081106
    11091107
     
    11291127        self.number_of_first_order_steps = 0
    11301128
    1131         print '.evolve: 3'
     1129
    11321130        # Update ghosts
    11331131        self.update_ghosts()
    11341132
    1135         print '.evolve: 4'
    11361133        # Initial update of vertex and edge values
    11371134        self.distribute_to_vertices_and_edges()
    11381135
    1139         print '.evolve: 5'
    11401136        # Update extrema if necessary (for reporting)
    11411137        self.update_extrema()
    11421138       
    1143         print '.evolve: 6'
    11441139        # Initial update boundary values
    11451140        self.update_boundary()
    11461141
    1147         print '.evolve: 7'
    11481142        # Or maybe restore from latest checkpoint
    11491143        if self.checkpoint is True:
    11501144            self.goto_latest_checkpoint()
    1151         print '.evolve: 8'
    11521145
    11531146        if skip_initial_step is False:
     
    12091202                self.number_of_steps = 0
    12101203                self.number_of_first_order_steps = 0
    1211                 self.max_speed = numpy.zeros(N, numpy.float)
     1204                self.max_speed = zeros(N, Float)
    12121205
    12131206    def evolve_one_euler_step(self, yieldstep, finaltime):
     
    15751568        """
    15761569
     1570        from Numeric import ones, sum, equal, Float
     1571
    15771572        N = len(self) # Number_of_triangles
    15781573        d = len(self.conserved_quantities)
  • anuga_core/source/anuga/abstract_2d_finite_volumes/ermapper_grids.py

    r5892 r5897  
    22
    33# from os import open, write, read
    4 ##import numpy.oldnumeric as Numeric
    5 import numpy
    6 
    7 celltype_map = {'IEEE4ByteReal': numpy.float32, 'IEEE8ByteReal': numpy.float64}
     4import Numeric
     5
     6celltype_map = {'IEEE4ByteReal': Numeric.Float32, 'IEEE8ByteReal': Numeric.Float64}
    87
    98
     
    1211    write_ermapper_grid(ofile, data, header = {}):
    1312   
    14     Function to write a 2D NumPy array to an ERMapper grid.  There are a series of conventions adopted within
     13    Function to write a 2D Numeric array to an ERMapper grid.  There are a series of conventions adopted within
    1514    this code, specifically:
    1615    1)  The registration coordinate for the data is the SW (or lower-left) corner of the data
    1716    2)  The registration coordinates refer to cell centres
    18     3)  The data is a 2D NumPy array with the NW-most data in element (0,0) and the SE-most data in element (N,M)
     17    3)  The data is a 2D Numeric array with the NW-most data in element (0,0) and the SE-most data in element (N,M)
    1918        where N is the last line and M is the last column
    2019    4)  There has been no testng of the use of a rotated grid.  Best to keep data in an NS orientation
     
    2322    ofile:      string - filename for output (note the output will consist of two files
    2423                ofile and ofile.ers.  Either of these can be entered into this function
    25     data:       NumPy.array - 2D array containing the data to be output to the grid
     24    data:       Numeric.array - 2D array containing the data to be output to the grid
    2625    header:     dictionary - contains spatial information about the grid, in particular:
    2726                    header['datum'] datum for the data ('"GDA94"')
     
    5857
    5958    # Check that the data is a 2 dimensional array
    60     data_size = numpy.shape(data)
     59    data_size = Numeric.shape(data)
    6160    assert len(data_size) == 2
    6261   
     
    8483    nrofcellsperlines = int(header['nrofcellsperline'])
    8584    data = read_ermapper_data(data_file)
    86     data = numpy.reshape(data,(nroflines,nrofcellsperlines))
     85    data = Numeric.reshape(data,(nroflines,nrofcellsperlines))
    8786    return data
    8887   
     
    164163    return header                     
    165164
    166 def write_ermapper_data(grid, ofile, data_format = numpy.float32):
     165def write_ermapper_data(grid, ofile, data_format = Numeric.Float32):
    167166
    168167
     
    182181       
    183182   
    184     # Convert the array to data_format (default format is float32)
     183    # Convert the array to data_format (default format is Float32)
    185184    grid_as_float = grid.astype(data_format)
    186185
     
    194193
    195194
    196 def read_ermapper_data(ifile, data_format = numpy.float32):
     195def read_ermapper_data(ifile, data_format = Numeric.Float32):
    197196    # open input file in a binary format and read the input string
    198197    fid = open(ifile,'rb')
     
    200199    fid.close()
    201200
    202     # convert input string to required format (Note default format is numpy.float32)
    203     grid_as_float = numpy.fromstring(input_string,data_format)
     201    # convert input string to required format (Note default format is Numeric.Float32)
     202    grid_as_float = Numeric.fromstring(input_string,data_format)
    204203    return grid_as_float
    205204
  • anuga_core/source/anuga/abstract_2d_finite_volumes/general_mesh.py

    r5894 r5897  
    1 import numpy
     1
     2from Numeric import concatenate, reshape, take, allclose
     3from Numeric import array, zeros, Int, Float, sqrt, sum, arange
    24
    35from anuga.coordinate_transforms.geo_reference import Geo_reference
     
    8890        if verbose: print 'General_mesh: Building basic mesh structure in ANUGA domain'
    8991
    90 ##        self.triangles = array(triangles, Int)
    91 ##        self.nodes = array(nodes, Float)
    92         self.triangles = numpy.array(triangles, numpy.int)
    93         self.nodes = numpy.array(nodes, numpy.float)
     92        self.triangles = array(triangles, Int)
     93        self.nodes = array(nodes, Float)
    9494
    9595
     
    138138
    139139        msg = 'Vertex indices reference non-existing coordinate sets'
    140         assert max(self.triangles.ravel()) < self.nodes.shape[0], msg
     140        assert max(self.triangles.flat) < self.nodes.shape[0], msg
    141141
    142142
     
    146146                      max(self.nodes[:,0]), max(self.nodes[:,1]) ]
    147147
    148 ##        self.xy_extent = array(xy_extent, Float)
    149         self.xy_extent = numpy.array(xy_extent, numpy.float)
     148        self.xy_extent = array(xy_extent, Float)
    150149
    151150
    152151        # Allocate space for geometric quantities
    153 ##        self.normals = zeros((N, 6), Float)
    154 ##        self.areas = zeros(N, Float)
    155 ##        self.edgelengths = zeros((N, 3), Float)
    156         self.normals = numpy.zeros((N, 6), numpy.float)
    157         self.areas = numpy.zeros(N, numpy.float)
    158         self.edgelengths = numpy.zeros((N, 3), numpy.float)
     152        self.normals = zeros((N, 6), Float)
     153        self.areas = zeros(N, Float)
     154        self.edgelengths = zeros((N, 3), Float)
    159155
    160156        # Get x,y coordinates for all triangles and store
     
    191187            #   - Stored as six floats n0x,n0y,n1x,n1y,n2x,n2y per triangle
    192188
    193             n0 = numpy.array([x2 - x1, y2 - y1])
    194             l0 = numpy.sqrt(numpy.sum(n0**2))
    195 
    196             n1 = numpy.array([x0 - x2, y0 - y2])
    197             l1 = numpy.sqrt(numpy.sum(n1**2))
    198 
    199             n2 = numpy.array([x1 - x0, y1 - y0])
    200             l2 = numpy.sqrt(numpy.sum(n2**2))
     189            n0 = array([x2 - x1, y2 - y1])
     190            l0 = sqrt(sum(n0**2))
     191
     192            n1 = array([x0 - x2, y0 - y2])
     193            l1 = sqrt(sum(n1**2))
     194
     195            n2 = array([x1 - x0, y1 - y0])
     196            l2 = sqrt(sum(n2**2))
    201197
    202198            # Normalise
     
    278274        if absolute is True:
    279275            if not self.geo_reference.is_absolute():
    280                 return V + numpy.array([self.geo_reference.get_xllcorner(),
    281                                         self.geo_reference.get_yllcorner()])
     276                return V + array([self.geo_reference.get_xllcorner(),
     277                                  self.geo_reference.get_yllcorner()])
    282278            else:
    283279                return V
     
    320316            i3 = 3*i 
    321317            if absolute is True and not self.geo_reference.is_absolute():
    322                 offset = numpy.array([self.geo_reference.get_xllcorner(),
    323                                       self.geo_reference.get_yllcorner()])
    324                 return numpy.array([V[i3,:]+offset,
    325                                     V[i3+1,:]+offset,
    326                                     V[i3+2,:]+offset])
     318                offset=array([self.geo_reference.get_xllcorner(),
     319                                  self.geo_reference.get_yllcorner()])
     320                return array([V[i3,:]+offset,
     321                              V[i3+1,:]+offset,
     322                              V[i3+2,:]+offset])
    327323            else:
    328                 return numpy.array([V[i3,:], V[i3+1,:], V[i3+2,:]])
     324                return array([V[i3,:], V[i3+1,:], V[i3+2,:]])
    329325               
    330326
     
    353349
    354350        M = self.number_of_triangles
    355 ##        vertex_coordinates = zeros((3*M, 2), Float)
    356         vertex_coordinates = numpy.zeros((3*M, 2), numpy.float)
     351        vertex_coordinates = zeros((3*M, 2), Float)
    357352
    358353        for i in range(M):
     
    381376            indices = range(M)
    382377
    383         return numpy.take(self.triangles, indices, axis=0)
     378        return take(self.triangles, indices)
    384379   
    385380
     
    414409       
    415410        #T = reshape(array(range(K)).astype(Int), (M,3))
    416 ##        T = reshape(arange(K).astype(Int), (M,3))  # Faster
    417         T = numpy.reshape(numpy.arange(K).astype(numpy.int), (M,3))  # Faster
     411        T = reshape(arange(K).astype(Int), (M,3))  # Faster
    418412       
    419413        return T     
     
    445439        if node is not None:
    446440            # Get index for this node
    447             first = numpy.sum(self.number_of_triangles_per_node[:node])
     441            first = sum(self.number_of_triangles_per_node[:node])
    448442           
    449443            # Get number of triangles for this node
    450             count = int(self.number_of_triangles_per_node[node])
     444            count = self.number_of_triangles_per_node[node]
    451445
    452446            for i in range(count):
     
    458452                triangle_list.append( (volume_id, vertex_id) )
    459453
    460             triangle_list = numpy.array(triangle_list)   
     454            triangle_list = array(triangle_list)   
    461455        else:
    462456            # Get info for all nodes recursively.
     
    535529
    536530        # Count number of triangles per node
    537         number_of_triangles_per_node = numpy.zeros(self.number_of_full_nodes)
     531        number_of_triangles_per_node = zeros(self.number_of_full_nodes)
    538532        for volume_id, triangle in enumerate(self.get_triangles()):
    539533            for vertex_id in triangle:
     
    541535
    542536        # Allocate space for inverted structure
    543         number_of_entries = numpy.sum(number_of_triangles_per_node)
    544         vertex_value_indices = numpy.zeros(number_of_entries, numpy.int)
     537        number_of_entries = sum(number_of_triangles_per_node)
     538        vertex_value_indices = zeros(number_of_entries)
    545539
    546540        # Register (triangle, vertex) indices for each node
     
    588582        Y = C[:,1:6:2].copy()
    589583
    590         xmin = min(X.ravel())
    591         xmax = max(X.ravel())
    592         ymin = min(Y.ravel())
    593         ymax = max(Y.ravel())
     584        xmin = min(X.flat)
     585        xmax = max(X.flat)
     586        ymin = min(Y.flat)
     587        ymax = max(Y.flat)
    594588        #print "C",C
    595589        return xmin, xmax, ymin, ymax
     
    604598        """
    605599
    606         return numpy.sum(self.areas)
     600        return sum(self.areas)
     601
     602       
     603       
  • anuga_core/source/anuga/abstract_2d_finite_volumes/generic_boundary_conditions.py

    r5892 r5897  
    77from anuga.fit_interpolate.interpolate import Modeltime_too_late
    88from anuga.fit_interpolate.interpolate import Modeltime_too_early
    9 
    10 import numpy
    119
    1210
     
    6967            raise Exception, msg
    7068
    71         self.conserved_quantities=numpy.array(conserved_quantities).astype(numpy.float)
     69        from Numeric import array, Float
     70        self.conserved_quantities=array(conserved_quantities).astype(Float)
    7271
    7372    def __repr__(self):
     
    9796            raise msg
    9897
     98
     99        from Numeric import array, Float
    99100        try:
    100             q = numpy.array(q).astype(numpy.float)
     101            q = array(q).astype(Float)
    101102        except:
    102103            msg = 'Return value from time boundary function could '
     
    135136    def __init__(self, filename, domain):
    136137        import time
     138        from Numeric import array
    137139        from anuga.config import time_format
    138140        from anuga.abstract_2d_finite_volumes.util import File_function
     
    204206
    205207        import time
     208        from Numeric import array, zeros, Float
    206209        from anuga.config import time_format
    207210        from anuga.abstract_2d_finite_volumes.util import file_function
     
    219222
    220223        if verbose: print 'Find midpoint coordinates of entire boundary'
    221         self.midpoint_coordinates = numpy.zeros( (len(domain.boundary), 2), numpy.float)
     224        self.midpoint_coordinates = zeros( (len(domain.boundary), 2), Float)
    222225        boundary_keys = domain.boundary.keys()
    223226
     
    239242           
    240243            # Compute midpoints
    241             if edge_id == 0: m = numpy.array([(x1 + x2)/2, (y1 + y2)/2])
    242             if edge_id == 1: m = numpy.array([(x0 + x2)/2, (y0 + y2)/2])
    243             if edge_id == 2: m = numpy.array([(x1 + x0)/2, (y1 + y0)/2])
     244            if edge_id == 0: m = array([(x1 + x2)/2, (y1 + y2)/2])
     245            if edge_id == 1: m = array([(x0 + x2)/2, (y0 + y2)/2])
     246            if edge_id == 2: m = array([(x1 + x0)/2, (y1 + y0)/2])
    244247
    245248            # Convert to absolute UTM coordinates
  • anuga_core/source/anuga/abstract_2d_finite_volumes/mesh_factory.py

    r5892 r5897  
    22mesh file formats
    33"""
    4 
    5 import numpy
    64
    75
     
    7573
    7674    from anuga.config import epsilon
     75    from Numeric import zeros, Float, Int
    7776
    7877    delta1 = float(len1)/m
     
    9493    index = Index(n,m)
    9594
    96     points = numpy.zeros( (Np,2), numpy.float)
     95    points = zeros( (Np,2), Float)
    9796
    9897    for i in range(m+1):
     
    106105
    107106
    108     elements = numpy.zeros( (Nt,3), numpy.int)
     107    elements = zeros( (Nt,3), Int)
    109108    boundary = {}
    110109    nt = -1
     
    150149
    151150    from anuga.config import epsilon
     151    from Numeric import zeros, Float, Int
    152152
    153153    delta1 = float(len1)/m
     
    208208    """
    209209
     210    from Numeric import array
    210211    import math
    211212
     
    509510    """
    510511
    511 #    from numpy.oldnumeric import array
     512    from Numeric import array
    512513    import math
    513514
     
    591592    """
    592593
     594    from Numeric import array
    593595    import math
    594596
     
    684686    """
    685687
     688    from Numeric import array
    686689    import math
     690
    687691    from anuga.config import epsilon
     692
    688693
    689694    deltax = lenx/float(m)
  • anuga_core/source/anuga/abstract_2d_finite_volumes/neighbour_mesh.py

    r5892 r5897  
    1111from anuga.caching import cache
    1212from math import pi, sqrt
    13 import numpy       
     13from Numeric import array, allclose
     14       
    1415
    1516class Mesh(General_mesh):
     
    7879        """
    7980
     81
     82
     83        from Numeric import array, zeros, Int, Float, maximum, sqrt, sum
     84
    8085        General_mesh.__init__(self, coordinates, triangles,
    8186                              number_of_full_nodes=\
     
    9398
    9499        #Allocate space for geometric quantities
    95         self.centroid_coordinates = numpy.zeros((N, 2), numpy.float)
    96 
    97         self.radii = numpy.zeros(N, numpy.float)
    98 
    99         self.neighbours = numpy.zeros((N, 3), numpy.int)
    100         self.neighbour_edges = numpy.zeros((N, 3), numpy.int)
    101         self.number_of_boundaries = numpy.zeros(N, numpy.int)
    102         self.surrogate_neighbours = numpy.zeros((N, 3), numpy.int)
     100        self.centroid_coordinates = zeros((N, 2), Float)
     101
     102        self.radii = zeros(N, Float)
     103
     104        self.neighbours = zeros((N, 3), Int)
     105        self.neighbour_edges = zeros((N, 3), Int)
     106        self.number_of_boundaries = zeros(N, Int)
     107        self.surrogate_neighbours = zeros((N, 3), Int)
    103108
    104109        #Get x,y coordinates for all triangles and store
     
    119124
    120125            #Compute centroid
    121             centroid = numpy.array([(x0 + x1 + x2)/3, (y0 + y1 + y2)/3])
     126            centroid = array([(x0 + x1 + x2)/3, (y0 + y1 + y2)/3])
    122127            self.centroid_coordinates[i] = centroid
    123128
     
    128133
    129134                #Midpoints
    130                 m0 = numpy.array([(x1 + x2)/2, (y1 + y2)/2])
    131                 m1 = numpy.array([(x0 + x2)/2, (y0 + y2)/2])
    132                 m2 = numpy.array([(x1 + x0)/2, (y1 + y0)/2])
     135                m0 = array([(x1 + x2)/2, (y1 + y2)/2])
     136                m1 = array([(x0 + x2)/2, (y0 + y2)/2])
     137                m2 = array([(x1 + x0)/2, (y1 + y0)/2])
    133138
    134139                #The radius is the distance from the centroid of
    135140                #a triangle to the midpoint of the side of the triangle
    136141                #closest to the centroid
    137                 d0 = numpy.sqrt(numpy.sum( (centroid-m0)**2 ))
    138                 d1 = numpy.sqrt(numpy.sum( (centroid-m1)**2 ))
    139                 d2 = numpy.sqrt(numpy.sum( (centroid-m2)**2 ))
     142                d0 = sqrt(sum( (centroid-m0)**2 ))
     143                d1 = sqrt(sum( (centroid-m1)**2 ))
     144                d2 = sqrt(sum( (centroid-m2)**2 ))
    140145
    141146                self.radii[i] = min(d0, d1, d2)
     
    145150                #of inscribed circle is computed
    146151
    147                 a = numpy.sqrt((x0-x1)**2+(y0-y1)**2)
    148                 b = numpy.sqrt((x1-x2)**2+(y1-y2)**2)
    149                 c = numpy.sqrt((x2-x0)**2+(y2-y0)**2)
     152                a = sqrt((x0-x1)**2+(y0-y1)**2)
     153                b = sqrt((x1-x2)**2+(y1-y2)**2)
     154                c = sqrt((x2-x0)**2+(y2-y0)**2)
    150155
    151156                self.radii[i]=2.0*self.areas[i]/(a+b+c)
     
    383388            self.element_tag is defined
    384389        """
     390        from Numeric import array, Int
    385391
    386392        if tagged_elements is None:
     
    389395            #Check that all keys in given boundary exist
    390396            for tag in tagged_elements.keys():
    391                 tagged_elements[tag] = numpy.array(tagged_elements[tag]).astype(numpy.int)
     397                tagged_elements[tag] = array(tagged_elements[tag]).astype(Int)
    392398
    393399                msg = 'Not all elements exist. '
     
    457463        """
    458464       
     465        from Numeric import allclose, sqrt, array, minimum, maximum
    459466        from anuga.utilities.numerical_tools import angle, ensure_numeric     
    460467
     
    470477        inverse_segments = {}
    471478        p0 = None
    472         mindist = numpy.sqrt(numpy.sum((pmax-pmin)**2)) # Start value across entire mesh
     479        mindist = sqrt(sum((pmax-pmin)**2)) # Start value across entire mesh
    473480        for i, edge_id in self.boundary.keys():
    474481            # Find vertex ids for boundary segment
     
    480487            B = self.get_vertex_coordinate(i, b, absolute=True) # End
    481488
     489
    482490            # Take the point closest to pmin as starting point
    483491            # Note: Could be arbitrary, but nice to have
    484492            # a unique way of selecting
    485             dist_A = numpy.sqrt(numpy.sum((A-pmin)**2))
    486             dist_B = numpy.sqrt(numpy.sum((B-pmin)**2))
     493            dist_A = sqrt(sum((A-pmin)**2))
     494            dist_B = sqrt(sum((B-pmin)**2))
    487495
    488496            # Find lower leftmost point
     
    585593                # We have reached a point already visited.
    586594               
    587                 if numpy.allclose(p1, polygon[0]):
     595                if allclose(p1, polygon[0]):
    588596                    # If it is the initial point, the polygon is complete.
    589597                   
     
    621629        from anuga.utilities.numerical_tools import anglediff
    622630
     631        from Numeric import sort, allclose
     632
    623633        N = len(self)
    624634
     
    662672
    663673                # Normalise
    664                 l_u = numpy.sqrt(u[0]*u[0] + u[1]*u[1])
    665                 l_v = numpy.sqrt(v[0]*v[0] + v[1]*v[1])
     674                l_u = sqrt(u[0]*u[0] + u[1]*u[1])
     675                l_v = sqrt(v[0]*v[0] + v[1]*v[1])
    666676
    667677                msg = 'Normal vector in triangle %d does not have unit length' %i
    668                 assert numpy.allclose(l_v, 1), msg
     678                assert allclose(l_v, 1), msg
    669679
    670680                x = (u[0]*v[0] + u[1]*v[1])/l_u # Inner product
     
    720730
    721731        V = self.vertex_value_indices[:] #Take a copy
    722         V = numpy.sort(V)
    723         assert numpy.allclose(V, range(3*N))
     732        V = sort(V)
     733        assert allclose(V, range(3*N))
    724734
    725735        assert sum(self.number_of_triangles_per_node) ==\
     
    732742                count[i] += 1
    733743
    734         assert numpy.allclose(count, self.number_of_triangles_per_node)
     744        assert allclose(count, self.number_of_triangles_per_node)
    735745
    736746
     
    795805        """
    796806
     807        from Numeric import arange
    797808        from anuga.utilities.numerical_tools import histogram, create_bins
    798809
     
    11301141
    11311142            # Distances from line origin to the two intersections
    1132             z0 = numpy.array([x0 - xi0, y0 - eta0])
    1133             z1 = numpy.array([x1 - xi0, y1 - eta0])             
    1134             d0 = numpy.sqrt(numpy.sum(z0**2))
    1135             d1 = numpy.sqrt(numpy.sum(z1**2))
     1143            z0 = array([x0 - xi0, y0 - eta0])
     1144            z1 = array([x1 - xi0, y1 - eta0])             
     1145            d0 = sqrt(sum(z0**2))
     1146            d1 = sqrt(sum(z1**2))
    11361147               
    11371148            if d1 < d0:
     
    11461157            # Normal direction:
    11471158            # Right hand side relative to line direction
    1148             vector = numpy.array([x1 - x0, y1 - y0]) # Segment vector
    1149             length = numpy.sqrt(numpy.sum(vector**2))      # Segment length
    1150             normal = numpy.array([vector[1], -vector[0]])/length
     1159            vector = array([x1 - x0, y1 - y0]) # Segment vector
     1160            length = sqrt(sum(vector**2))      # Segment length
     1161            normal = array([vector[1], -vector[0]])/length
    11511162
    11521163
     
    12281239        assert isinstance(segment, Triangle_intersection), msg
    12291240       
    1230         midpoint = numpy.sum(numpy.array(segment.segment))/2
     1241        midpoint = sum(array(segment.segment))/2
    12311242        midpoints.append(midpoint)
    12321243
  • anuga_core/source/anuga/abstract_2d_finite_volumes/pmesh2domain.py

    r5892 r5897  
    99import sys
    1010
    11 import numpy
    1211
    1312
     
    162161    """
    163162
     163    from Numeric import transpose
    164164    from load_mesh.loadASCII import import_mesh_file
    165165
     
    172172    volumes = mesh_dict['triangles']
    173173    vertex_quantity_dict = {}
    174     point_atts = numpy.transpose(mesh_dict['vertex_attributes'])
     174    point_atts = transpose(mesh_dict['vertex_attributes'])
    175175    point_titles  = mesh_dict['vertex_attribute_titles']
    176176    geo_reference  = mesh_dict['geo_reference']
    177177    if point_atts != None:
    178         print 'type(point_atts)=%s' % type(point_atts)
    179         for quantity, value_vector in map(None, point_titles, point_atts):
     178        for quantity, value_vector in map (None, point_titles, point_atts):
    180179            vertex_quantity_dict[quantity] = value_vector
    181180    tag_dict = pmesh_dict_to_tag_dict(mesh_dict)
  • anuga_core/source/anuga/abstract_2d_finite_volumes/quantity.py

    r5892 r5897  
    1515"""
    1616
    17 import numpy
     17from Numeric import array, zeros, Float, less, concatenate, NewAxis,\
     18     argmax, argmin, allclose, take, reshape, alltrue
    1819
    1920from anuga.utilities.numerical_tools import ensure_numeric, is_scalar
     
    3738        if vertex_values is None:
    3839            N = len(domain) # number_of_elements
    39             self.vertex_values = numpy.zeros((N, 3), numpy.float)
     40            self.vertex_values = zeros((N, 3), Float)
    4041        else:
    41             self.vertex_values = numpy.array(vertex_values).astype(numpy.float)
     42            self.vertex_values = array(vertex_values).astype(Float)
    4243
    4344            N, V = self.vertex_values.shape
     
    5657
    5758        # Allocate space for other quantities
    58         self.centroid_values = numpy.zeros(N, numpy.float)
    59         self.edge_values = numpy.zeros((N, 3), numpy.float)
     59        self.centroid_values = zeros(N, Float)
     60        self.edge_values = zeros((N, 3), Float)
    6061
    6162        # Allocate space for Gradient
    62         self.x_gradient = numpy.zeros(N, numpy.float)
    63         self.y_gradient = numpy.zeros(N, numpy.float)
     63        self.x_gradient = zeros(N, Float)
     64        self.y_gradient = zeros(N, Float)
    6465
    6566        # Allocate space for Limiter Phi
    66         self.phi = numpy.zeros(N, numpy.float)       
     67        self.phi = zeros(N, Float)       
    6768
    6869        # Intialise centroid and edge_values
     
    7172        # Allocate space for boundary values
    7273        L = len(domain.boundary)
    73         self.boundary_values = numpy.zeros(L, numpy.float)
     74        self.boundary_values = zeros(L, Float)
    7475
    7576        # Allocate space for updates of conserved quantities by
     
    7778
    7879        # Allocate space for update fields
    79         self.explicit_update = numpy.zeros(N, numpy.float )
    80         self.semi_implicit_update = numpy.zeros(N, numpy.float )
    81         self.centroid_backup_values = numpy.zeros(N, numpy.float)
     80        self.explicit_update = zeros(N, Float )
     81        self.semi_implicit_update = zeros(N, Float )
     82        self.centroid_backup_values = zeros(N, Float)
    8283
    8384        self.set_beta(1.0)
     
    381382        from anuga.geospatial_data.geospatial_data import Geospatial_data
    382383        from types import FloatType, IntType, LongType, ListType, NoneType
     384        from Numeric import ArrayType
    383385
    384386        # Treat special case: Polygon situation
     
    446448
    447449        msg = 'Indices must be a list or None'
    448         assert type(indices) in [ListType, NoneType, numpy.ndarray], msg
     450        assert type(indices) in [ListType, NoneType, ArrayType], msg
    449451
    450452
     
    456458                self.set_values_from_constant(numeric,
    457459                                              location, indices, verbose)
    458             elif type(numeric) in [numpy.ndarray, ListType]:
     460            elif type(numeric) in [ArrayType, ListType]:
    459461                self.set_values_from_array(numeric,
    460462                                           location, indices, verbose)
     
    472474                                                     use_cache=use_cache)
    473475            else:
    474                 msg = 'Illegal type for argument numeric: %s' % str(numeric)
    475                 raise TypeError, msg
     476                msg = 'Illegal type for argument numeric: %s' %str(numeric)
     477                raise msg
    476478
    477479        elif quantity is not None:
     
    608610        """
    609611
    610         values = numpy.array(values).astype(numpy.float)
     612        from Numeric import array, Float, Int, allclose
     613
     614        values = array(values).astype(Float)
    611615
    612616        if indices is not None:
    613             indices = numpy.array(indices).astype(numpy.int)
     617            indices = array(indices).astype(Int)
    614618            msg = 'Number of values must match number of indices:'
    615619            msg += ' You specified %d values and %d indices'\
     
    636640
    637641        elif location == 'unique vertices':
    638             assert len(values.shape) == 1 or numpy.allclose(values.shape[1:], 1),\
     642            assert len(values.shape) == 1 or allclose(values.shape[1:], 1),\
    639643                   'Values array must be 1d'
    640644
    641             self.set_vertex_values(values.ravel(), indices=indices)
     645            self.set_vertex_values(values.flat, indices=indices)
    642646           
    643647        else:
     
    672676        A = q.vertex_values
    673677
     678        from Numeric import allclose
    674679        msg = 'Quantities are defined on different meshes. '+\
    675680              'This might be a case for implementing interpolation '+\
    676681              'between different meshes.'
    677         assert numpy.allclose(A.shape, self.vertex_values.shape), msg
     682        assert allclose(A.shape, self.vertex_values.shape), msg
    678683
    679684        self.set_values(A, location='vertices',
     
    711716                indices = range(len(self))
    712717               
    713             V = numpy.take(self.domain.get_centroid_coordinates(), indices, axis=0)
    714             print 'V=%s' % str(V)
     718            V = take(self.domain.get_centroid_coordinates(), indices)
    715719            self.set_values(f(V[:,0], V[:,1]),
    716720                            location=location,
     
    776780
    777781
    778         points = ensure_numeric(points, numpy.float)
    779         values = ensure_numeric(values, numpy.float)
     782        points = ensure_numeric(points, Float)
     783        values = ensure_numeric(values, Float)
    780784
    781785        if location != 'vertices':
     
    909913        # Always return absolute indices
    910914        if mode is None or mode == 'max':
    911             i = numpy.argmax(V)
     915            i = argmax(V)
    912916        elif mode == 'min':   
    913             i = numpy.argmin(V)
     917            i = argmin(V)
    914918
    915919           
     
    11141118        """
    11151119       
     1120        from Numeric import take
     1121
    11161122        # FIXME (Ole): I reckon we should have the option of passing a
    11171123        #              polygon into get_values. The question becomes how
     
    11371143            raise msg
    11381144
    1139         import types
    1140        
    1141         assert type(indices) in [types.ListType, types.NoneType, numpy.ndarray], \
     1145        import types, Numeric
     1146        assert type(indices) in [types.ListType, types.NoneType,
     1147                                 Numeric.ArrayType],\
    11421148                                 'Indices must be a list or None'
    11431149
     
    11451151            if (indices ==  None):
    11461152                indices = range(len(self))
    1147             return numpy.take(self.centroid_values, indices, axis=0)
     1153            return take(self.centroid_values,indices)
    11481154        elif location == 'edges':
    11491155            if (indices ==  None):
    11501156                indices = range(len(self))
    1151             return numpy.take(self.edge_values, indices, axis=0)
     1157            return take(self.edge_values,indices)
    11521158        elif location == 'unique vertices':
    11531159            if (indices ==  None):
     
    11721178                    sum += self.vertex_values[triangle_id, vertex_id]
    11731179                vert_values.append(sum/len(triangles))
    1174             return numpy.array(vert_values)
     1180            return Numeric.array(vert_values)
    11751181        else:
    11761182            if (indices is None):
    11771183                indices = range(len(self))
    1178             return numpy.take(self.vertex_values, indices, axis=0)
     1184            return take(self.vertex_values, indices)
    11791185
    11801186
     
    11901196        """
    11911197
     1198        from Numeric import array, Float
     1199
    11921200        # Assert that A can be converted to a Numeric array of appropriate dim
    1193         A = ensure_numeric(A, numpy.float)
     1201        A = ensure_numeric(A, Float)
    11941202
    11951203        # print 'SHAPE A', A.shape
     
    12651273        """
    12661274
     1275        from Numeric import concatenate, zeros, Float, Int, array, reshape
     1276
     1277
    12671278        if smooth is None:
    12681279            # Take default from domain
     
    12731284
    12741285        if precision is None:
    1275             precision = numpy.float
     1286            precision = Float
    12761287           
    12771288
     
    12821293            V = self.domain.get_triangles()
    12831294            N = self.domain.number_of_full_nodes # Ignore ghost nodes if any
    1284             A = numpy.zeros(N, numpy.float)
     1295            A = zeros(N, Float)
    12851296            points = self.domain.get_nodes()           
    12861297           
     
    13321343            V = self.domain.get_disconnected_triangles()
    13331344            points = self.domain.get_vertex_coordinates()
    1334             A = self.vertex_values.ravel().astype(precision)
     1345            A = self.vertex_values.flat.astype(precision)
    13351346
    13361347
  • anuga_core/source/anuga/abstract_2d_finite_volumes/quantity_ext.c

    r5892 r5897  
    1111
    1212#include "Python.h"
    13 #include "numpy/arrayobject.h"
     13#include "Numeric/arrayobject.h"
    1414#include "math.h"
    1515
  • anuga_core/source/anuga/abstract_2d_finite_volumes/region.py

    r5892 r5897  
    88# FIXME (DSG-DSG) add better comments
    99
    10 import numpy
    11 
    12 
     10from Numeric import average
    1311class Region:
    1412    """Base class for modifying quantities based on a region.
     
    103101                values = Q.get_values(indices=self.build_indices(elements, domain),
    104102                                      location=self.location)
    105                 av = numpy.average(values)
     103                av = average(values)
    106104                if self.location == "vertices":
    107                     av = numpy.average(av)
     105                    av = average(av)
    108106                new_values = av + self.X   
    109107            else:
  • anuga_core/source/anuga/abstract_2d_finite_volumes/show_balanced_limiters.py

    r5892 r5897  
    1818
    1919from mesh_factory import rectangular
    20 
     20from Numeric import array
     21   
    2122
    2223######################
     
    7778domain.set_quantity('stage', Z)
    7879
     80from Numeric import allclose
     81
    7982#Evolve
    8083for t in domain.evolve(yieldstep = 0.1, finaltime = 30):
  • anuga_core/source/anuga/abstract_2d_finite_volumes/test_domain.py

    r5892 r5897  
    66from domain import *
    77from anuga.config import epsilon
    8 import numpy
     8from Numeric import allclose, array, ones, Float
    99
    1010
     
    6464
    6565
    66         assert numpy.alltrue(domain.get_conserved_quantities(0, edge=1) == 0.)
     66        assert domain.get_conserved_quantities(0, edge=1) == 0.
    6767
    6868
     
    9595        #Centroids
    9696        q = domain.get_conserved_quantities(0)
    97         assert numpy.allclose(q, [2., 2., 0.])
     97        assert allclose(q, [2., 2., 0.])
    9898
    9999        q = domain.get_conserved_quantities(1)
    100         assert numpy.allclose(q, [5., 5., 0.])
     100        assert allclose(q, [5., 5., 0.])
    101101
    102102        q = domain.get_conserved_quantities(2)
    103         assert numpy.allclose(q, [3., 3., 0.])
     103        assert allclose(q, [3., 3., 0.])
    104104
    105105        q = domain.get_conserved_quantities(3)
    106         assert numpy.allclose(q, [0., 0., 0.])
     106        assert allclose(q, [0., 0., 0.])
    107107
    108108
    109109        #Edges
    110110        q = domain.get_conserved_quantities(0, edge=0)
    111         assert numpy.allclose(q, [2.5, 2.5, 0.])
     111        assert allclose(q, [2.5, 2.5, 0.])
    112112        q = domain.get_conserved_quantities(0, edge=1)
    113         assert numpy.allclose(q, [2., 2., 0.])
     113        assert allclose(q, [2., 2., 0.])
    114114        q = domain.get_conserved_quantities(0, edge=2)
    115         assert numpy.allclose(q, [1.5, 1.5, 0.])
     115        assert allclose(q, [1.5, 1.5, 0.])
    116116
    117117        for i in range(3):
    118118            q = domain.get_conserved_quantities(1, edge=i)
    119             assert numpy.allclose(q, [5, 5, 0.])
     119            assert allclose(q, [5, 5, 0.])
    120120
    121121
    122122        q = domain.get_conserved_quantities(2, edge=0)
    123         assert numpy.allclose(q, [4.5, 4.5, 0.])
     123        assert allclose(q, [4.5, 4.5, 0.])
    124124        q = domain.get_conserved_quantities(2, edge=1)
    125         assert numpy.allclose(q, [4.5, 4.5, 0.])
     125        assert allclose(q, [4.5, 4.5, 0.])
    126126        q = domain.get_conserved_quantities(2, edge=2)
    127         assert numpy.allclose(q, [0., 0., 0.])
     127        assert allclose(q, [0., 0., 0.])
    128128
    129129
    130130        q = domain.get_conserved_quantities(3, edge=0)
    131         assert numpy.allclose(q, [3., 3., 0.])
     131        assert allclose(q, [3., 3., 0.])
    132132        q = domain.get_conserved_quantities(3, edge=1)
    133         assert numpy.allclose(q, [-1.5, -1.5, 0.])
     133        assert allclose(q, [-1.5, -1.5, 0.])
    134134        q = domain.get_conserved_quantities(3, edge=2)
    135         assert numpy.allclose(q, [-1.5, -1.5, 0.])
     135        assert allclose(q, [-1.5, -1.5, 0.])
    136136
    137137
     
    179179        Q = domain.create_quantity_from_expression(expression)
    180180
    181         assert numpy.allclose(Q.vertex_values, [[2,3,4], [6,6,6],
    182                                                 [1,1,10], [-5, 4, 4]])
     181        assert allclose(Q.vertex_values, [[2,3,4], [6,6,6],
     182                                      [1,1,10], [-5, 4, 4]])
    183183
    184184        expression = '(xmomentum*xmomentum + ymomentum*ymomentum)**0.5'
     
    188188        Y = domain.quantities['ymomentum'].vertex_values
    189189
    190         assert numpy.allclose(Q.vertex_values, (X**2 + Y**2)**0.5)
     190        assert allclose(Q.vertex_values, (X**2 + Y**2)**0.5)
    191191
    192192
     
    314314        Q = domain.quantities['depth']
    315315
    316         assert numpy.allclose(Q.vertex_values, [[2,3,4], [6,6,6],
    317                                                 [1,1,10], [-5, 4, 4]])
     316        assert allclose(Q.vertex_values, [[2,3,4], [6,6,6],
     317                                      [1,1,10], [-5, 4, 4]])
    318318
    319319
     
    382382        domain.check_integrity()
    383383
    384         assert numpy.allclose(domain.neighbours, [[-1,-2,-3]])
     384        assert allclose(domain.neighbours, [[-1,-2,-3]])
    385385
    386386
     
    471471                                      [0,0,9], [-6, 3, 3]])
    472472
    473         assert numpy.allclose( domain.quantities['stage'].centroid_values,
    474                                [2,5,3,0] )
     473        assert allclose( domain.quantities['stage'].centroid_values,
     474                         [2,5,3,0] )
    475475
    476476        domain.set_quantity('xmomentum', [[1,1,1], [2,2,2],
     
    484484
    485485        #First order extrapolation
    486         assert numpy.allclose( domain.quantities['stage'].vertex_values,
    487                                [[ 2.,  2.,  2.],
    488                                 [ 5.,  5.,  5.],
    489                                 [ 3.,  3.,  3.],
    490                                 [ 0.,  0.,  0.]])
     486        assert allclose( domain.quantities['stage'].vertex_values,
     487                         [[ 2.,  2.,  2.],
     488                          [ 5.,  5.,  5.],
     489                          [ 3.,  3.,  3.],
     490                          [ 0.,  0.,  0.]])
    491491
    492492
     
    527527
    528528        for name in domain.conserved_quantities:
    529             domain.quantities[name].explicit_update = numpy.array([4.,3.,2.,1.])
    530             domain.quantities[name].semi_implicit_update = numpy.array([1.,1.,1.,1.])
     529            domain.quantities[name].explicit_update = array([4.,3.,2.,1.])
     530            domain.quantities[name].semi_implicit_update = array([1.,1.,1.,1.])
    531531
    532532
     
    535535        domain.update_conserved_quantities()
    536536
    537         sem = numpy.array([1.,1.,1.,1.])/numpy.array([1, 2, 3, 4])
    538         denom = numpy.ones(4, numpy.float)-domain.timestep*sem
     537        sem = array([1.,1.,1.,1.])/array([1, 2, 3, 4])
     538        denom = ones(4, Float)-domain.timestep*sem
    539539
    540540#        x = array([1, 2, 3, 4]) + array( [.4,.3,.2,.1] )
    541541#        x /= denom
    542542
    543         x = numpy.array([1., 2., 3., 4.])
     543        x = array([1., 2., 3., 4.])
    544544        x /= denom
    545         x += domain.timestep*numpy.array( [4,3,2,1] )
     545        x += domain.timestep*array( [4,3,2,1] )
    546546
    547547        for name in domain.conserved_quantities:
    548             assert numpy.allclose(domain.quantities[name].centroid_values, x)
     548            assert allclose(domain.quantities[name].centroid_values, x)
    549549
    550550
     
    578578                                      [0,0,9], [-6, 3, 3]])
    579579
    580         assert numpy.allclose( domain.quantities['stage'].centroid_values,
    581                                [2,5,3,0] )
     580        assert allclose( domain.quantities['stage'].centroid_values,
     581                         [2,5,3,0] )
    582582
    583583        domain.set_quantity('xmomentum', [[1,1,1], [2,2,2],
     
    591591
    592592        #First order extrapolation
    593         assert numpy.allclose( domain.quantities['stage'].vertex_values,
    594                                [[ 2.,  2.,  2.],
    595                                 [ 5.,  5.,  5.],
    596                                 [ 3.,  3.,  3.],
    597                                 [ 0.,  0.,  0.]])
     593        assert allclose( domain.quantities['stage'].vertex_values,
     594                         [[ 2.,  2.,  2.],
     595                          [ 5.,  5.,  5.],
     596                          [ 3.,  3.,  3.],
     597                          [ 0.,  0.,  0.]])
    598598
    599599        domain.build_tagged_elements_dictionary({'mound':[0,1]})
     
    610610        from mesh_factory import rectangular
    611611        from shallow_water import Domain
     612        from Numeric import zeros, Float
    612613
    613614        #Create basic mesh
     
    626627        from mesh_factory import rectangular
    627628        from shallow_water import Domain
     629        from Numeric import zeros, Float
    628630
    629631        #Create basic mesh
     
    643645        domain.set_region([set_bottom_friction, set_top_friction])
    644646        #print domain.quantities['friction'].get_values()
    645         assert numpy.allclose(domain.quantities['friction'].get_values(),\
    646                               [[ 0.09,  0.09,  0.09],
    647                                [ 0.09,  0.09,  0.09],
    648                                [ 0.07,  0.07,  0.07],
    649                                [ 0.07,  0.07,  0.07],
    650                                [ 1.0,  1.0,  1.0],
    651                                [ 1.0,  1.0,  1.0]])
     647        assert allclose(domain.quantities['friction'].get_values(),\
     648                        [[ 0.09,  0.09,  0.09],
     649                         [ 0.09,  0.09,  0.09],
     650                         [ 0.07,  0.07,  0.07],
     651                         [ 0.07,  0.07,  0.07],
     652                         [ 1.0,  1.0,  1.0],
     653                         [ 1.0,  1.0,  1.0]])
    652654
    653655        domain.set_region([set_all_friction])
    654656        #print domain.quantities['friction'].get_values()
    655         assert numpy.allclose(domain.quantities['friction'].get_values(),
    656                               [[ 10.09, 10.09, 10.09],
    657                                [ 10.09, 10.09, 10.09],
    658                                [ 10.07, 10.07, 10.07],
    659                                [ 10.07, 10.07, 10.07],
    660                                [ 11.0,  11.0,  11.0],
    661                                [ 11.0,  11.0,  11.0]])
     657        assert allclose(domain.quantities['friction'].get_values(),
     658                        [[ 10.09, 10.09, 10.09],
     659                         [ 10.09, 10.09, 10.09],
     660                         [ 10.07, 10.07, 10.07],
     661                         [ 10.07, 10.07, 10.07],
     662                         [ 11.0,  11.0,  11.0],
     663                         [ 11.0,  11.0,  11.0]])
    662664
    663665
     
    668670        from mesh_factory import rectangular
    669671        from shallow_water import Domain
     672        from Numeric import zeros, Float
    670673
    671674        #Create basic mesh
     
    687690       
    688691        #print domain.quantities['friction'].get_values()
    689         assert numpy.allclose(domain.quantities['friction'].get_values(),
    690                               [[ 0.09,  0.09,  0.09],
    691                                [ 0.09,  0.09,  0.09],
    692                                [ 0.07,  0.07,  0.07],
    693                                [ 0.07,  0.07,  0.07],
    694                                [ 1.0,  1.0,  1.0],
    695                                [ 1.0,  1.0,  1.0]])
     692        assert allclose(domain.quantities['friction'].get_values(),\
     693                        [[ 0.09,  0.09,  0.09],
     694                         [ 0.09,  0.09,  0.09],
     695                         [ 0.07,  0.07,  0.07],
     696                         [ 0.07,  0.07,  0.07],
     697                         [ 1.0,  1.0,  1.0],
     698                         [ 1.0,  1.0,  1.0]])
    696699       
    697700        domain.set_region([set_bottom_friction, set_top_friction])
    698701        #print domain.quantities['friction'].get_values()
    699         assert numpy.allclose(domain.quantities['friction'].get_values(),
    700                               [[ 0.09,  0.09,  0.09],
    701                                [ 0.09,  0.09,  0.09],
    702                                [ 0.07,  0.07,  0.07],
    703                                [ 0.07,  0.07,  0.07],
    704                                [ 1.0,  1.0,  1.0],
    705                                [ 1.0,  1.0,  1.0]])
     702        assert allclose(domain.quantities['friction'].get_values(),\
     703                        [[ 0.09,  0.09,  0.09],
     704                         [ 0.09,  0.09,  0.09],
     705                         [ 0.07,  0.07,  0.07],
     706                         [ 0.07,  0.07,  0.07],
     707                         [ 1.0,  1.0,  1.0],
     708                         [ 1.0,  1.0,  1.0]])
    706709
    707710        domain.set_region([set_all_friction])
    708711        #print domain.quantities['friction'].get_values()
    709         assert numpy.allclose(domain.quantities['friction'].get_values(),
    710                               [[ 10.09, 10.09, 10.09],
    711                                [ 10.09, 10.09, 10.09],
    712                                [ 10.07, 10.07, 10.07],
    713                                [ 10.07, 10.07, 10.07],
    714                                [ 11.0,  11.0,  11.0],
    715                                [ 11.0,  11.0,  11.0]])
     712        assert allclose(domain.quantities['friction'].get_values(),
     713                        [[ 10.09, 10.09, 10.09],
     714                         [ 10.09, 10.09, 10.09],
     715                         [ 10.07, 10.07, 10.07],
     716                         [ 10.07, 10.07, 10.07],
     717                         [ 11.0,  11.0,  11.0],
     718                         [ 11.0,  11.0,  11.0]])
    716719
    717720#-------------------------------------------------------------
  • anuga_core/source/anuga/abstract_2d_finite_volumes/test_ermapper.py

    r5892 r5897  
    55
    66import ermapper_grids
    7 import numpy
     7import Numeric
    88from os import remove
    99
     
    1919        data_filename = 'test_write_ermapper_grid'
    2020       
    21         original_grid = numpy.array([[0.0, 0.1, 1.0], [2.0, 3.0, 4.0]])
     21        original_grid = Numeric.array([[0.0, 0.1, 1.0], [2.0, 3.0, 4.0]])
    2222
    2323        # Check that the function works when passing the filename without
     
    2525        ermapper_grids.write_ermapper_grid(data_filename, original_grid)
    2626        new_grid = ermapper_grids.read_ermapper_grid(data_filename)
    27         assert numpy.allclose(original_grid, new_grid)
     27        assert Numeric.allclose(original_grid, new_grid)
    2828
    2929        # Check that the function works when passing the filename with
     
    3131        ermapper_grids.write_ermapper_grid(header_filename, original_grid)
    3232        new_grid = ermapper_grids.read_ermapper_grid(header_filename)
    33         assert numpy.allclose(original_grid, new_grid)
     33        assert Numeric.allclose(original_grid, new_grid)
    3434
    3535        # Clean up created files
     
    4040        # Setup test data
    4141        filename = 'test_write_ermapper_grid'
    42         original_grid = numpy.array([0.0, 0.1, 1.0, 2.0, 3.0, 4.0])
     42        original_grid = Numeric.array([0.0, 0.1, 1.0, 2.0, 3.0, 4.0])
    4343
    4444        # Write test data
    45         ermapper_grids.write_ermapper_data(original_grid, filename, numpy.float64)
     45        ermapper_grids.write_ermapper_data(original_grid, filename, Numeric.Float64)
    4646
    4747        # Read in the test data
    48         new_grid = ermapper_grids.read_ermapper_data(filename, numpy.float64)
     48        new_grid = ermapper_grids.read_ermapper_data(filename, Numeric.Float64)
    4949
    5050        # Check that the test data that has been read in matches the original data
    51         assert numpy.allclose(original_grid, new_grid)
     51        assert Numeric.allclose(original_grid, new_grid)
    5252
    5353        # Clean up created files
     
    5757        # Setup test data
    5858        filename = 'test_write_ermapper_grid'
    59         original_grid = numpy.array([0.0, 0.1, 1.0, 2.0, 3.0, 4.0])
     59        original_grid = Numeric.array([0.0, 0.1, 1.0, 2.0, 3.0, 4.0])
    6060
    6161        # Write test data
     
    6666
    6767        # Check that the test data that has been read in matches the original data
    68         assert numpy.allclose(original_grid, new_grid)
     68        assert Numeric.allclose(original_grid, new_grid)
    6969
    7070        # Clean up created files
     
    7575
    7676        # setup test data
    77         original_grid = numpy.array([[0, 1, 2, 3], [4, 5, 6, 7], [8, 9, 10, 11]])
     77        original_grid = Numeric.array([[0, 1, 2, 3], [4, 5, 6, 7], [8, 9, 10, 11]])
    7878        # Write test data
    7979        ermapper_grids.write_ermapper_data(original_grid, data_filename)
  • anuga_core/source/anuga/abstract_2d_finite_volumes/test_general_mesh.py

    r5892 r5897  
    77
    88from anuga.config import epsilon
    9 import numpy
     9from Numeric import allclose, array, ones, Float
    1010from general_mesh import General_mesh
    1111from anuga.coordinate_transforms.geo_reference import Geo_reference
     
    2323    def test_get_vertex_coordinates(self):
    2424        from mesh_factory import rectangular
     25        from Numeric import zeros, Float
    2526
    2627        #Create basic mesh
     
    2930
    3031
    31         assert numpy.allclose(domain.get_nodes(), nodes)
     32        assert allclose(domain.get_nodes(), nodes)
    3233
    3334
     
    4041            for j in range(3):
    4142                k = triangles[i,j]  #Index of vertex j in triangle i
    42                 assert numpy.allclose(V[3*i+j,:], nodes[k])
     43                assert allclose(V[3*i+j,:], nodes[k])
    4344
    4445    def test_get_vertex_coordinates_with_geo_ref(self):
     
    5455        f = [4.0, 0.0]
    5556
    56         nodes = numpy.array([a, b, c, d, e, f])
     57        nodes = array([a, b, c, d, e, f])
    5758
    5859        nodes_absolute = geo.get_absolute(nodes)
    5960       
    6061        #bac, bce, ecf, dbe, daf, dae
    61         triangles = numpy.array([[1,0,2], [1,2,4], [4,2,5], [3,1,4]])
     62        triangles = array([[1,0,2], [1,2,4], [4,2,5], [3,1,4]])
    6263
    6364        domain = General_mesh(nodes, triangles,
    6465                       geo_reference = geo)
    6566        verts = domain.get_vertex_coordinates(triangle_id=0)       
    66         self.assert_(numpy.allclose(numpy.array([b,a,c]), verts))
     67        self.assert_(allclose(array([b,a,c]), verts))
    6768        verts = domain.get_vertex_coordinates(triangle_id=0)       
    68         self.assert_(numpy.allclose(numpy.array([b,a,c]), verts))
     69        self.assert_(allclose(array([b,a,c]), verts))
    6970        verts = domain.get_vertex_coordinates(triangle_id=0,
    7071                                              absolute=True)       
    71         self.assert_(numpy.allclose(numpy.array([nodes_absolute[1],
    72                                                  nodes_absolute[0],
    73                                                  nodes_absolute[2]]), verts))
     72        self.assert_(allclose(array([nodes_absolute[1],
     73                                     nodes_absolute[0],
     74                                     nodes_absolute[2]]), verts))
    7475        verts = domain.get_vertex_coordinates(triangle_id=0,
    7576                                              absolute=True)       
    76         self.assert_(numpy.allclose(numpy.array([nodes_absolute[1],
    77                                                  nodes_absolute[0],
    78                                                  nodes_absolute[2]]), verts))
     77        self.assert_(allclose(array([nodes_absolute[1],
     78                                     nodes_absolute[0],
     79                                     nodes_absolute[2]]), verts))
    7980       
    8081       
     
    8586        """
    8687        from mesh_factory import rectangular
     88        from Numeric import zeros, Float
    8789
    8890        #Create basic mesh
     
    9193
    9294
    93         assert numpy.allclose(domain.get_nodes(), nodes)
     95        assert allclose(domain.get_nodes(), nodes)
    9496
    9597
     
    102104            for j in range(3):
    103105                k = triangles[i,j]  #Index of vertex j in triangle i
    104                 assert numpy.allclose(V[j,:], nodes[k])
     106                assert allclose(V[j,:], nodes[k])
    105107
    106108
     
    112114        """
    113115        from mesh_factory import rectangular
     116        from Numeric import zeros, Float
    114117
    115118        #Create basic mesh
     
    118121
    119122        value = [7]
    120         assert numpy.allclose(domain.get_triangles(), triangles)
    121         assert numpy.allclose(domain.get_triangles([0,4]),
    122                               [triangles[0], triangles[4]])
     123        assert allclose(domain.get_triangles(), triangles)
     124        assert allclose(domain.get_triangles([0,4]),
     125                        [triangles[0], triangles[4]])
    123126       
    124127
     
    127130        """
    128131        from mesh_factory import rectangular
    129 
    130         a = [0.0, 0.0]
    131         b = [0.0, 2.0]
    132         c = [2.0, 0.0]
    133         d = [0.0, 4.0]
    134         e = [2.0, 2.0]
    135         f = [4.0, 0.0]
    136 
    137         nodes = numpy.array([a, b, c, d, e, f])
     132        from Numeric import zeros, Float, array
     133
     134        a = [0.0, 0.0]
     135        b = [0.0, 2.0]
     136        c = [2.0, 0.0]
     137        d = [0.0, 4.0]
     138        e = [2.0, 2.0]
     139        f = [4.0, 0.0]
     140
     141        nodes = array([a, b, c, d, e, f])
    138142        #bac, bce, ecf, dbe, daf, dae
    139         triangles = numpy.array([[1,0,2], [1,2,4], [4,2,5], [3,1,4]])
     143        triangles = array([[1,0,2], [1,2,4], [4,2,5], [3,1,4]])
    140144
    141145        domain1 = General_mesh(nodes, triangles)
     
    158162            #print count
    159163            #
    160             assert numpy.allclose(count, domain.number_of_triangles_per_node)
     164            assert allclose(count, domain.number_of_triangles_per_node)
    161165           
    162166            # Check indices
     
    192196        f = [4.0, 0.0]
    193197
    194         nodes = numpy.array([a, b, c, d, e, f])
     198        nodes = array([a, b, c, d, e, f])
    195199        #bac, bce, ecf, dbe, daf, dae
    196         triangles = numpy.array([[1,0,2], [1,2,4], [4,2,5], [3,1,4]])
     200        triangles = array([[1,0,2], [1,2,4], [4,2,5], [3,1,4]])
    197201
    198202        domain = General_mesh(nodes, triangles)
     
    200204        # One node
    201205        L = domain.get_triangles_and_vertices_per_node(node=2)
    202         print 'L=%s' % str(L)
    203         assert numpy.allclose(L[0], [0, 2])
    204         assert numpy.allclose(L[1], [1, 1])
    205         assert numpy.allclose(L[2], [2, 1])
     206        assert allclose(L[0], [0, 2])
     207        assert allclose(L[1], [1, 1])
     208        assert allclose(L[2], [2, 1])
    206209
    207210        # All nodes
     
    210213        for i, Lref in enumerate(ALL):
    211214            L = domain.get_triangles_and_vertices_per_node(node=i)
    212             assert numpy.allclose(L, Lref)
     215            assert allclose(L, Lref)
    213216           
    214217
     
    221224        from mesh_factory import rectangular
    222225        from shallow_water import Domain
     226        from Numeric import zeros, Float
    223227
    224228        #Create basic mesh
     
    235239        from mesh_factory import rectangular
    236240        from shallow_water import Domain
     241        from Numeric import zeros, Float
    237242
    238243        #Create basic mesh
     
    268273        f = [4.0, 0.0]
    269274
    270         nodes = numpy.array([a, b, c, d, e, f])
     275        nodes = array([a, b, c, d, e, f])
    271276
    272277        nodes_absolute = geo.get_absolute(nodes)
    273278       
    274279        #bac, bce, ecf, dbe, daf, dae
    275         triangles = numpy.array([[1,0,2], [1,2,4], [4,2,5], [3,1,4]])
     280        triangles = array([[1,0,2], [1,2,4], [4,2,5], [3,1,4]])
    276281
    277282        domain = General_mesh(nodes, triangles,
    278283                       geo_reference = geo)
    279284        node = domain.get_node(2)       
    280         self.assertTrue(numpy.alltrue(c == node))
     285        self.assertEqual(c, node)
    281286       
    282287        node = domain.get_node(2, absolute=True)     
    283         self.assertTrue(numpy.alltrue(nodes_absolute[2] == node))
     288        self.assertEqual(nodes_absolute[2], node)
    284289       
    285290        node = domain.get_node(2, absolute=True)     
    286         self.assertTrue(numpy.alltrue(nodes_absolute[2] == node))
     291        self.assertEqual(nodes_absolute[2], node)
    287292       
    288293
     
    305310        f = [4.0, 0.0]
    306311
    307         nodes = numpy.array([a, b, c, d, e, f])
     312        nodes = array([a, b, c, d, e, f])
    308313
    309314        nodes_absolute = geo.get_absolute(nodes)
    310315       
    311316        # max index is 5, use 5, expect success
    312         triangles = numpy.array([[1,5,2], [1,2,4], [4,2,5], [3,1,4]])
     317        triangles = array([[1,5,2], [1,2,4], [4,2,5], [3,1,4]])
    313318        General_mesh(nodes, triangles, geo_reference=geo)
    314319       
    315320        # max index is 5, use 6, expect assert failure
    316         triangles = numpy.array([[1,6,2], [1,2,4], [4,2,5], [3,1,4]])
     321        triangles = array([[1,6,2], [1,2,4], [4,2,5], [3,1,4]])
    317322        self.failUnlessRaises(AssertionError, General_mesh,
    318323                              nodes, triangles, geo_reference=geo)
    319324       
    320325        # max index is 5, use 10, expect assert failure
    321         triangles = numpy.array([[1,10,2], [1,2,4], [4,2,5], [3,1,4]])
     326        triangles = array([[1,10,2], [1,2,4], [4,2,5], [3,1,4]])
    322327        self.failUnlessRaises(AssertionError, General_mesh,
    323328                              nodes, triangles, geo_reference=geo)
     
    328333if __name__ == "__main__":
    329334    suite = unittest.makeSuite(Test_General_Mesh,'test')
     335    #suite = unittest.makeSuite(Test_General_Mesh,'test_get_node')   
    330336    runner = unittest.TextTestRunner()
    331337    runner.run(suite)
  • anuga_core/source/anuga/abstract_2d_finite_volumes/test_generic_boundary_conditions.py

    r5892 r5897  
    66from generic_boundary_conditions import *
    77from anuga.config import epsilon
    8 import numpy
     8from Numeric import allclose, array
    99
    1010
     
    4444
    4545        q = Bd.evaluate()
    46         assert numpy.allclose(q, x)
     46        assert allclose(q, x)
    4747
    4848
     
    9898        q = T.evaluate(0, 2)  #Vol=0, edge=2
    9999
    100         assert numpy.allclose(q, [1.5, 2.5])
     100        assert allclose(q, [1.5, 2.5])
    101101
    102102
     
    175175
    176176        #Check that midpoint coordinates at boundary are correctly computed
    177         assert numpy.allclose( F.midpoint_coordinates,
    178                                [[1.0, 0.0], [0.0, 1.0], [3.0, 0.0],
    179                                 [3.0, 1.0], [1.0, 3.0], [0.0, 3.0]])
    180 
    181         #assert numpy.allclose(F.midpoint_coordinates[(3,2)], [0.0, 3.0])
    182         #assert numpy.allclose(F.midpoint_coordinates[(3,1)], [1.0, 3.0])
    183         #assert numpy.allclose(F.midpoint_coordinates[(0,2)], [0.0, 1.0])
    184         #assert numpy.allclose(F.midpoint_coordinates[(0,0)], [1.0, 0.0])
    185         #assert numpy.allclose(F.midpoint_coordinates[(2,0)], [3.0, 0.0])
    186         #assert numpy.allclose(F.midpoint_coordinates[(2,1)], [3.0, 1.0])
     177        assert allclose( F.midpoint_coordinates,
     178                         [[1.0, 0.0], [0.0, 1.0], [3.0, 0.0],
     179                          [3.0, 1.0], [1.0, 3.0], [0.0, 3.0]])
     180
     181        #assert allclose(F.midpoint_coordinates[(3,2)], [0.0, 3.0])
     182        #assert allclose(F.midpoint_coordinates[(3,1)], [1.0, 3.0])
     183        #assert allclose(F.midpoint_coordinates[(0,2)], [0.0, 1.0])
     184        #assert allclose(F.midpoint_coordinates[(0,0)], [1.0, 0.0])
     185        #assert allclose(F.midpoint_coordinates[(2,0)], [3.0, 0.0])
     186        #assert allclose(F.midpoint_coordinates[(2,1)], [3.0, 1.0])
    187187
    188188
     
    193193        domain.time = 5*30/2  #A quarter way through first step
    194194        q = F.evaluate()
    195         assert numpy.allclose(q, [1.0/4, sin(2*pi/10)/4])
     195        assert allclose(q, [1.0/4, sin(2*pi/10)/4])
    196196
    197197
    198198        domain.time = 2.5*5*60  #Half way between steps 2 and 3
    199199        q = F.evaluate()
    200         assert numpy.allclose(q, [2.5, (sin(2*2*pi/10) + sin(3*2*pi/10))/2])
     200        assert allclose(q, [2.5, (sin(2*2*pi/10) + sin(3*2*pi/10))/2])
    201201
    202202
  • anuga_core/source/anuga/abstract_2d_finite_volumes/test_ghost.py

    r5892 r5897  
    66from domain import *
    77from anuga.config import epsilon
    8 import numpy
     8from Numeric import allclose, array, ones, Float
     9
     10
    911
    1012
     
    4143
    4244
    43         assert numpy.alltrue(domain.get_conserved_quantities(0, edge=1) == 0.)
     45        assert domain.get_conserved_quantities(0, edge=1) == 0.
    4446
    4547
  • anuga_core/source/anuga/abstract_2d_finite_volumes/test_neighbour_mesh.py

    r5892 r5897  
    11#!/usr/bin/env python
     2
     3
    24
    35#FIXME: Seperate the tests for mesh and general_mesh
     
    1113from mesh_factory import rectangular
    1214from anuga.config import epsilon
    13 import numpy
     15from Numeric import allclose, array, Int
    1416
    1517from anuga.coordinate_transforms.geo_reference import Geo_reference
     
    1820
    1921def distance(x, y):
    20     return sqrt( sum( (numpy.array(x)-numpy.array(y))**2 ))
     22    return sqrt( sum( (array(x)-array(y))**2 ))
    2123
    2224class Test_Mesh(unittest.TestCase):
     
    6163        #Normals
    6264        normals = mesh.get_normals()
    63         assert numpy.allclose(normals[0, 0:2], [3.0/5, 4.0/5])
    64         assert numpy.allclose(normals[0, 2:4], [-1.0, 0.0])
    65         assert numpy.allclose(normals[0, 4:6], [0.0, -1.0])
    66 
    67         assert numpy.allclose(mesh.get_normal(0,0), [3.0/5, 4.0/5])
    68         assert numpy.allclose(mesh.get_normal(0,1), [-1.0, 0.0])
    69         assert numpy.allclose(mesh.get_normal(0,2), [0.0, -1.0])
     65        assert allclose(normals[0, 0:2], [3.0/5, 4.0/5])
     66        assert allclose(normals[0, 2:4], [-1.0, 0.0])
     67        assert allclose(normals[0, 4:6], [0.0, -1.0])
     68
     69        assert allclose(mesh.get_normal(0,0), [3.0/5, 4.0/5])
     70        assert allclose(mesh.get_normal(0,1), [-1.0, 0.0])
     71        assert allclose(mesh.get_normal(0,2), [0.0, -1.0])
    7072
    7173        #Edge lengths
    72         assert numpy.allclose(mesh.edgelengths[0], [5.0, 3.0, 4.0])
     74        assert allclose(mesh.edgelengths[0], [5.0, 3.0, 4.0])
    7375
    7476
     
    7981
    8082        V = mesh.get_vertex_coordinates()
    81         assert numpy.allclose(V, [ [0.0, 0.0],
    82                                    [4.0, 0.0],
    83                                    [0.0, 3.0] ])
     83        assert allclose(V, [ [0.0, 0.0],
     84                             [4.0, 0.0],
     85                             [0.0, 3.0] ])
    8486
    8587        V0 = mesh.get_vertex_coordinate(0, 0)
    86         assert numpy.allclose(V0, [0.0, 0.0])
     88        assert allclose(V0, [0.0, 0.0])
    8789
    8890        V1 = mesh.get_vertex_coordinate(0, 1)
    89         assert numpy.allclose(V1, [4.0, 0.0])
     91        assert allclose(V1, [4.0, 0.0])
    9092
    9193        V2 = mesh.get_vertex_coordinate(0, 2)
    92         assert numpy.allclose(V2, [0.0, 3.0])
     94        assert allclose(V2, [0.0, 3.0])
    9395
    9496
     
    235237
    236238        mesh = Mesh(points, vertices,use_inscribed_circle=False)
    237         assert numpy.allclose(mesh.radii[0],sqrt(3.0)/3),'Steve''s doesn''t work'
     239        assert allclose(mesh.radii[0],sqrt(3.0)/3),'Steve''s doesn''t work'
    238240
    239241        mesh = Mesh(points, vertices,use_inscribed_circle=True)
    240         assert numpy.allclose(mesh.radii[0],sqrt(3.0)/3),'inscribed circle doesn''t work'
     242        assert allclose(mesh.radii[0],sqrt(3.0)/3),'inscribed circle doesn''t work'
    241243
    242244    def test_inscribed_circle_rightangle_triangle(self):
     
    250252
    251253        mesh = Mesh(points, vertices,use_inscribed_circle=False)
    252         assert numpy.allclose(mesh.radii[0],5.0/6),'Steve''s doesn''t work'
     254        assert allclose(mesh.radii[0],5.0/6),'Steve''s doesn''t work'
    253255
    254256        mesh = Mesh(points, vertices,use_inscribed_circle=True)
    255         assert numpy.allclose(mesh.radii[0],1.0),'inscribed circle doesn''t work'
     257        assert allclose(mesh.radii[0],1.0),'inscribed circle doesn''t work'
    256258
    257259
     
    267269        assert mesh.areas[0] == 2.0
    268270
    269         assert numpy.allclose(mesh.centroid_coordinates[0], [2.0/3, 2.0/3])
     271        assert allclose(mesh.centroid_coordinates[0], [2.0/3, 2.0/3])
    270272
    271273
     
    301303        assert mesh.edgelengths[1,2] == sqrt(8.0)
    302304
    303         assert numpy.allclose(mesh.centroid_coordinates[0], [2.0/3, 2.0/3])
    304         assert numpy.allclose(mesh.centroid_coordinates[1], [4.0/3, 4.0/3])
    305         assert numpy.allclose(mesh.centroid_coordinates[2], [8.0/3, 2.0/3])
    306         assert numpy.allclose(mesh.centroid_coordinates[3], [2.0/3, 8.0/3])
     305        assert allclose(mesh.centroid_coordinates[0], [2.0/3, 2.0/3])
     306        assert allclose(mesh.centroid_coordinates[1], [4.0/3, 4.0/3])
     307        assert allclose(mesh.centroid_coordinates[2], [8.0/3, 2.0/3])
     308        assert allclose(mesh.centroid_coordinates[3], [2.0/3, 8.0/3])
    307309
    308310    def test_mesh_and_neighbours(self):
     
    695697        get values based on triangle lists.
    696698        """
    697 
    698699        from mesh_factory import rectangular
     700        from Numeric import zeros, Float
    699701
    700702        #Create basic mesh
     
    714716    def test_boundary_polygon(self):
    715717        from mesh_factory import rectangular
     718        #from mesh import Mesh
     719        from Numeric import zeros, Float
    716720
    717721        #Create basic mesh
     
    723727
    724728        assert len(P) == 8
    725         assert numpy.allclose(P, [[0.0, 0.0], [0.5, 0.0], [1.0, 0.0],
    726                                   [1.0, 0.5], [1.0, 1.0], [0.5, 1.0],
    727                                   [0.0, 1.0], [0.0, 0.5]])
     729        assert allclose(P, [[0.0, 0.0], [0.5, 0.0], [1.0, 0.0],
     730                            [1.0, 0.5], [1.0, 1.0], [0.5, 1.0],
     731                            [0.0, 1.0], [0.0, 0.5]])
    728732        for p in points:
    729733            #print p, P
     
    732736
    733737    def test_boundary_polygon_II(self):
     738        from Numeric import zeros, Float
     739       
     740
    734741        #Points
    735742        a = [0.0, 0.0] #0
     
    757764
    758765        assert len(P) == 8
    759         assert numpy.allclose(P, [a, d, f, i, h, e, c, b])
     766        assert allclose(P, [a, d, f, i, h, e, c, b])
    760767
    761768        for p in points:
     
    767774        """Same as II but vertices ordered differently
    768775        """
     776
     777        from Numeric import zeros, Float
     778
    769779
    770780        #Points
     
    794804
    795805        assert len(P) == 8
    796         assert numpy.allclose(P, [a, d, f, i, h, e, c, b])
     806        assert allclose(P, [a, d, f, i, h, e, c, b])
    797807
    798808        for p in points:
     
    805815        is partitioned using pymetis.
    806816        """
     817
     818        from Numeric import zeros, Float
     819
    807820
    808821        #Points
     
    834847       
    835848        # Note that point e appears twice!
    836         assert numpy.allclose(P, [a, d, f, e, g, h, e, c, b])
     849        assert allclose(P, [a, d, f, e, g, h, e, c, b])
    837850
    838851        for p in points:
     
    851864        """
    852865
     866        from Numeric import zeros, Float
    853867        from mesh_factory import rectangular       
    854868
     
    893907       
    894908        """
     909        from Numeric import zeros, Float
     910       
    895911
    896912        #Points
     
    939955       
    940956        assert len(P) == 8
    941         assert numpy.allclose(P, [a, d, f, i, h, e, c, b])
    942         assert numpy.allclose(P, [(0.0, 0.0), (0.5, 0.0), (1.0, 0.0), (1.5, 0.5), (1.0, 1.0), (0.5, 0.5), (0.0, 1.0), (0.0, 0.5)])
     957        assert allclose(P, [a, d, f, i, h, e, c, b])
     958        assert allclose(P, [(0.0, 0.0), (0.5, 0.0), (1.0, 0.0), (1.5, 0.5), (1.0, 1.0), (0.5, 0.5), (0.0, 1.0), (0.0, 0.5)])
    943959       
    944960
     
    982998                  [  52341.70703125,  38563.39453125]]
    983999
    984         ##points = ensure_numeric(points, int)/1000  # Simplify for ease of interpretation       
     1000        ##points = ensure_numeric(points, Int)/1000  # Simplify for ease of interpretation       
    9851001
    9861002        triangles = [[19, 0,15],
     
    10851101                  [  35406.3359375 ,  79332.9140625 ]]
    10861102
    1087         scaled_points = ensure_numeric(points, int)/1000  # Simplify for ease of interpretation
     1103        scaled_points = ensure_numeric(points, Int)/1000  # Simplify for ease of interpretation
    10881104
    10891105        triangles = [[ 0, 1, 2],
     
    11261142            assert is_inside_polygon(p, P)           
    11271143
    1128         assert numpy.allclose(P, Pref)   
     1144        assert allclose(P, Pref)   
    11291145
    11301146    def test_lone_vertices(self):
     
    11781194        boundary_polygon = mesh.get_boundary_polygon()
    11791195
    1180         assert numpy.allclose(absolute_points, boundary_polygon)
     1196        assert allclose(absolute_points, boundary_polygon)
    11811197
    11821198    def test_get_triangle_containing_point(self):
     
    12251241
    12261242        neighbours = mesh.get_triangle_neighbours(0)
    1227         assert numpy.allclose(neighbours, [-1,1,-1])
     1243        assert allclose(neighbours, [-1,1,-1])
    12281244        neighbours = mesh.get_triangle_neighbours(-10)
    12291245        assert neighbours == []
     
    12741290            for x in L:
    12751291                if x.triangle_id % 2 == 0:
    1276                     assert numpy.allclose(x.length, ceiling-y_line)
     1292                    assert allclose(x.length, ceiling-y_line)
    12771293                else:
    1278                     assert numpy.allclose(x.length, y_line-floor)               
     1294                    assert allclose(x.length, y_line-floor)               
    12791295
    12801296               
    1281                 assert numpy.allclose(x.normal, [0,-1])
    1282 
    1283                 assert numpy.allclose(x.segment[1][0], x.segment[0][0] + x.length)
    1284                 assert numpy.allclose(x.segment[0][1], y_line)
    1285                 assert numpy.allclose(x.segment[1][1], y_line)               
     1297                assert allclose(x.normal, [0,-1])
     1298
     1299                assert allclose(x.segment[1][0], x.segment[0][0] + x.length)
     1300                assert allclose(x.segment[0][1], y_line)
     1301                assert allclose(x.segment[1][1], y_line)               
    12861302
    12871303                assert x.triangle_id in intersected_triangles
     
    12901306
    12911307            msg = 'Segments do not add up'
    1292             assert numpy.allclose(total_length, 2), msg
     1308            assert allclose(total_length, 2), msg
    12931309           
    12941310
     
    13251341        total_length = 0
    13261342        for x in L:
    1327             assert numpy.allclose(x.length, 1.0)
    1328             assert numpy.allclose(x.normal, [0,-1])
    1329 
    1330             assert numpy.allclose(x.segment[1][0], x.segment[0][0] + x.length)
    1331             assert numpy.allclose(x.segment[0][1], y_line)
    1332             assert numpy.allclose(x.segment[1][1], y_line)                           
     1343            assert allclose(x.length, 1.0)
     1344            assert allclose(x.normal, [0,-1])
     1345
     1346            assert allclose(x.segment[1][0], x.segment[0][0] + x.length)
     1347            assert allclose(x.segment[0][1], y_line)
     1348            assert allclose(x.segment[1][1], y_line)                           
    13331349
    13341350
     
    13391355
    13401356        msg = 'Segments do not add up'
    1341         assert numpy.allclose(total_length, 2), msg
     1357        assert allclose(total_length, 2), msg
    13421358       
    13431359
     
    13791395        for x in L:
    13801396            if x.triangle_id == 1:
    1381                 assert numpy.allclose(x.length, 1)       
    1382                 assert numpy.allclose(x.normal, [0, -1])
     1397                assert allclose(x.length, 1)       
     1398                assert allclose(x.normal, [0, -1])
    13831399               
    13841400            if x.triangle_id == 5:
    1385                 assert numpy.allclose(x.length, 0.5)
    1386                 assert numpy.allclose(x.normal, [0, -1])
     1401                assert allclose(x.length, 0.5)
     1402                assert allclose(x.normal, [0, -1])
    13871403
    13881404
     
    13921408
    13931409        msg = 'Segments do not add up'
    1394         assert numpy.allclose(total_length, 1.5), msg           
     1410        assert allclose(total_length, 1.5), msg           
    13951411
    13961412
     
    14261442        total_length = 0
    14271443        for i, x in enumerate(L):
    1428             assert numpy.allclose(x.length, s2)
    1429             assert numpy.allclose(x.normal, [-s2, -s2])
    1430             assert numpy.allclose(sum(x.normal**2), 1)
     1444            assert allclose(x.length, s2)
     1445            assert allclose(x.normal, [-s2, -s2])
     1446            assert allclose(sum(x.normal**2), 1)
    14311447           
    14321448            assert x.triangle_id in intersected_triangles
     
    14351451
    14361452        msg = 'Segments do not add up'
    1437         assert numpy.allclose(total_length, 4*s2), msg
     1453        assert allclose(total_length, 4*s2), msg
    14381454
    14391455
     
    14501466        total_length = 0
    14511467        for i, x in enumerate(L):
    1452             assert numpy.allclose(x.length, s2)
    1453             assert numpy.allclose(x.normal, [s2, s2])
    1454             assert numpy.allclose(sum(x.normal**2), 1)
     1468            assert allclose(x.length, s2)
     1469            assert allclose(x.normal, [s2, s2])
     1470            assert allclose(sum(x.normal**2), 1)
    14551471           
    14561472            assert x.triangle_id in intersected_triangles
     
    14591475
    14601476        msg = 'Segments do not add up'
    1461         assert numpy.allclose(total_length, 4*s2), msg                   
     1477        assert allclose(total_length, 4*s2), msg                   
    14621478
    14631479
     
    14751491        total_length = 0
    14761492        for i, x in enumerate(L):
    1477             assert numpy.allclose(x.length, 2*s2)
    1478             assert numpy.allclose(x.normal, [-s2, s2])
    1479             assert numpy.allclose(sum(x.normal**2), 1)
     1493            assert allclose(x.length, 2*s2)
     1494            assert allclose(x.normal, [-s2, s2])
     1495            assert allclose(sum(x.normal**2), 1)
    14801496           
    14811497            assert x.triangle_id in intersected_triangles
     
    14841500
    14851501        msg = 'Segments do not add up'
    1486         assert numpy.allclose(total_length, 4*s2), msg                       
     1502        assert allclose(total_length, 4*s2), msg                       
    14871503
    14881504
     
    14991515        total_length = 0
    15001516        for i, x in enumerate(L):
    1501             assert numpy.allclose(x.length, 2*s2)
    1502             assert numpy.allclose(x.normal, [s2, -s2])
    1503             assert numpy.allclose(sum(x.normal**2), 1)
     1517            assert allclose(x.length, 2*s2)
     1518            assert allclose(x.normal, [s2, -s2])
     1519            assert allclose(sum(x.normal**2), 1)
    15041520           
    15051521            assert x.triangle_id in intersected_triangles
     
    15081524
    15091525        msg = 'Segments do not add up'
    1510         assert numpy.allclose(total_length, 4*s2), msg                       
     1526        assert allclose(total_length, 4*s2), msg                       
    15111527
    15121528
     
    15241540        total_length = 0
    15251541        for i, x in enumerate(L):
    1526             assert numpy.allclose(x.length, s2)
    1527             assert numpy.allclose(x.normal, [-s2, -s2])
    1528             assert numpy.allclose(sum(x.normal**2), 1)
     1542            assert allclose(x.length, s2)
     1543            assert allclose(x.normal, [-s2, -s2])
     1544            assert allclose(sum(x.normal**2), 1)
    15291545           
    15301546            assert x.triangle_id in intersected_triangles
     
    15331549
    15341550        msg = 'Segments do not add up'
    1535         assert numpy.allclose(total_length, 2*s2), msg
     1551        assert allclose(total_length, 2*s2), msg
    15361552
    15371553
     
    15461562        total_length = 0
    15471563        for i, x in enumerate(L):
    1548             assert numpy.allclose(x.normal, [-s2, -s2])
    1549             assert numpy.allclose(sum(x.normal**2), 1)
     1564            assert allclose(x.normal, [-s2, -s2])
     1565            assert allclose(sum(x.normal**2), 1)
    15501566
    15511567            msg = 'Triangle %d' %x.triangle_id + ' is not in %s' %(intersected_triangles)
     
    15821598        assert len(L) == 1
    15831599        assert L[0].triangle_id == 3
    1584         assert numpy.allclose(L[0].length, 0.5)       
    1585         assert numpy.allclose(L[0].normal, [-1,0])               
     1600        assert allclose(L[0].length, 0.5)       
     1601        assert allclose(L[0].normal, [-1,0])               
    15861602
    15871603
     
    15941610        assert len(L) == 1
    15951611        assert L[0].triangle_id == 3
    1596         assert numpy.allclose(L[0].length, 0.4)
    1597         assert numpy.allclose(L[0].normal, [-1,0])
     1612        assert allclose(L[0].length, 0.4)
     1613        assert allclose(L[0].normal, [-1,0])
    15981614
    15991615        intersected_triangles = [3]
     
    16071623        assert len(L) == 1
    16081624        assert L[0].triangle_id == 3
    1609         assert numpy.allclose(L[0].length, 0.4)
    1610         assert numpy.allclose(L[0].normal, [1,0])               
     1625        assert allclose(L[0].length, 0.4)
     1626        assert allclose(L[0].normal, [1,0])               
    16111627       
    16121628
     
    16421658        for x in L:
    16431659            if x.triangle_id == 3:
    1644                 assert numpy.allclose(x.length, 0.5)       
    1645                 assert numpy.allclose(x.normal, [-1,0])
     1660                assert allclose(x.length, 0.5)       
     1661                assert allclose(x.normal, [-1,0])
    16461662               
    16471663            if x.triangle_id == 2:
    1648                 assert numpy.allclose(x.length, s2)
    1649                 assert numpy.allclose(x.normal, [-s2,-s2])
     1664                assert allclose(x.length, s2)
     1665                assert allclose(x.normal, [-s2,-s2])
    16501666
    16511667
     
    16801696        for x in L:
    16811697            if x.triangle_id == 3:
    1682                 assert numpy.allclose(x.length, 0.5)       
    1683                 assert numpy.allclose(x.normal, [-1,0])
     1698                assert allclose(x.length, 0.5)       
     1699                assert allclose(x.normal, [-1,0])
    16841700               
    16851701            if x.triangle_id == 2:
    16861702                msg = str(x.length)
    1687                 assert numpy.allclose(x.length, s2), msg
    1688                 assert numpy.allclose(x.normal, [-s2,-s2])
     1703                assert allclose(x.length, s2), msg
     1704                assert allclose(x.normal, [-s2,-s2])
    16891705
    16901706            if x.triangle_id == 5:
    1691                 segvec = numpy.array([line[2][0]-1,
    1692                                       line[2][1]-1])
     1707                segvec = array([line[2][0]-1,
     1708                                line[2][1]-1])
    16931709                msg = str(x.length)
    1694                 assert numpy.allclose(x.length, sqrt(sum(segvec**2))), msg
    1695                 assert numpy.allclose(x.normal, [-s2,-s2])                                               
     1710                assert allclose(x.length, sqrt(sum(segvec**2))), msg
     1711                assert allclose(x.normal, [-s2,-s2])                                               
    16961712
    16971713
     
    17311747        for x in L:
    17321748            if x.triangle_id == 3:
    1733                 assert numpy.allclose(x.length, 0.5)       
    1734                 assert numpy.allclose(x.normal, [-1,0])
     1749                assert allclose(x.length, 0.5)       
     1750                assert allclose(x.normal, [-1,0])
    17351751               
    17361752            if x.triangle_id == 2:
    17371753                msg = str(x.length)
    1738                 assert numpy.allclose(x.length, s2), msg
    1739                 assert numpy.allclose(x.normal, [-s2,-s2])
     1754                assert allclose(x.length, s2), msg
     1755                assert allclose(x.normal, [-s2,-s2])
    17401756
    17411757            if x.triangle_id == 5:
    17421758                if x.segment == ((1.0, 1.0), (1.25, 0.75)):                   
    1743                     segvec = numpy.array([line[2][0]-1,
    1744                                           line[2][1]-1])
     1759                    segvec = array([line[2][0]-1,
     1760                                    line[2][1]-1])
    17451761                    msg = str(x.length)
    1746                     assert numpy.allclose(x.length, sqrt(sum(segvec**2))), msg
    1747                     assert numpy.allclose(x.normal, [-s2,-s2])
     1762                    assert allclose(x.length, sqrt(sum(segvec**2))), msg
     1763                    assert allclose(x.normal, [-s2,-s2])
    17481764                elif x.segment == ((1.25, 0.75), (1.5, 1.0)):
    1749                     segvec = numpy.array([1.5-line[2][0],
    1750                                           1.0-line[2][1]])
     1765                    segvec = array([1.5-line[2][0],
     1766                                    1.0-line[2][1]])
    17511767                   
    1752                     assert numpy.allclose(x.length, sqrt(sum(segvec**2))), msg
    1753                     assert numpy.allclose(x.normal, [s2,-s2])
     1768                    assert allclose(x.length, sqrt(sum(segvec**2))), msg
     1769                    assert allclose(x.normal, [s2,-s2])
    17541770                else:
    17551771                    msg = 'Unknow segment: %s' %x.segment
     
    17591775                   
    17601776            if x.triangle_id == 6:
    1761                 assert numpy.allclose(x.normal, [s2,-s2])
    1762                 assert numpy.allclose(x.segment, ((1.5, 1.0), (2, 1.5)))
     1777                assert allclose(x.normal, [s2,-s2])
     1778                assert allclose(x.segment, ((1.5, 1.0), (2, 1.5)))
    17631779
    17641780
     
    18261842            ref_length = line[1][1] - line[0][1]
    18271843            #print ref_length, total_length
    1828             assert numpy.allclose(total_length, ref_length)
     1844            assert allclose(total_length, ref_length)
    18291845
    18301846
  • anuga_core/source/anuga/abstract_2d_finite_volumes/test_pmesh2domain.py

    r5892 r5897  
    33
    44import unittest
    5 import numpy
     5
     6from Numeric import allclose, array
     7
    68
    79#from anuga.pyvolution.pmesh2domain import *
     
    6466
    6567         tags = {}
    66          b1 =  Dirichlet_boundary(conserved_quantities = numpy.array([0.0]))
    67          b2 =  Dirichlet_boundary(conserved_quantities = numpy.array([1.0]))
    68          b3 =  Dirichlet_boundary(conserved_quantities = numpy.array([2.0]))
     68         b1 =  Dirichlet_boundary(conserved_quantities = array([0.0]))
     69         b2 =  Dirichlet_boundary(conserved_quantities = array([1.0]))
     70         b3 =  Dirichlet_boundary(conserved_quantities = array([2.0]))
    6971         tags["1"] = b1
    7072         tags["2"] = b2
     
    7880         answer = [[0., 8., 0.],
    7981                   [0., 10., 8.]]
    80          assert numpy.allclose(domain.quantities['elevation'].vertex_values,
    81                                answer)
     82         assert allclose(domain.quantities['elevation'].vertex_values,
     83                        answer)
    8284
    8385         #print domain.quantities['stage'].vertex_values
    8486         answer = [[0., 12., 10.],
    8587                   [0., 10., 12.]]
    86          assert numpy.allclose(domain.quantities['stage'].vertex_values,
    87                                answer)
     88         assert allclose(domain.quantities['stage'].vertex_values,
     89                        answer)
    8890
    8991         #print domain.quantities['friction'].vertex_values
    9092         answer = [[0.01, 0.04, 0.03],
    9193                   [0.01, 0.02, 0.04]]
    92          assert numpy.allclose(domain.quantities['friction'].vertex_values,
    93                                answer)
    94 
    95          #print domain.quantities['friction'].vertex_values
    96          assert numpy.allclose(domain.tagged_elements['dsg'][0],0)
    97          assert numpy.allclose(domain.tagged_elements['ole nielsen'][0],1)
     94         assert allclose(domain.quantities['friction'].vertex_values,
     95                        answer)
     96
     97         #print domain.quantities['friction'].vertex_values
     98         assert allclose(domain.tagged_elements['dsg'][0],0)
     99         assert allclose(domain.tagged_elements['ole nielsen'][0],1)
    98100
    99101         self.failUnless( domain.boundary[(1, 0)]  == '1',
     
    157159       
    158160         tags = {}
    159          b1 =  Dirichlet_boundary(conserved_quantities = numpy.array([0.0]))
    160          b2 =  Dirichlet_boundary(conserved_quantities = numpy.array([1.0]))
    161          b3 =  Dirichlet_boundary(conserved_quantities = numpy.array([2.0]))
     161         b1 =  Dirichlet_boundary(conserved_quantities = array([0.0]))
     162         b2 =  Dirichlet_boundary(conserved_quantities = array([1.0]))
     163         b3 =  Dirichlet_boundary(conserved_quantities = array([2.0]))
    162164         tags["1"] = b1
    163165         tags["2"] = b2
     
    172174         answer = [[0., 8., 0.],
    173175                   [0., 10., 8.]]
    174          assert numpy.allclose(domain.quantities['elevation'].vertex_values,
    175                                answer)
     176         assert allclose(domain.quantities['elevation'].vertex_values,
     177                        answer)
    176178
    177179         #print domain.quantities['stage'].vertex_values
    178180         answer = [[0., 12., 10.],
    179181                   [0., 10., 12.]]
    180          assert numpy.allclose(domain.quantities['stage'].vertex_values,
    181                                answer)
     182         assert allclose(domain.quantities['stage'].vertex_values,
     183                        answer)
    182184
    183185         #print domain.quantities['friction'].vertex_values
    184186         answer = [[0.01, 0.04, 0.03],
    185187                   [0.01, 0.02, 0.04]]
    186          assert numpy.allclose(domain.quantities['friction'].vertex_values,
    187                                answer)
    188 
    189          #print domain.quantities['friction'].vertex_values
    190          assert numpy.allclose(domain.tagged_elements['dsg'][0],0)
    191          assert numpy.allclose(domain.tagged_elements['ole nielsen'][0],1)
     188         assert allclose(domain.quantities['friction'].vertex_values,
     189                        answer)
     190
     191         #print domain.quantities['friction'].vertex_values
     192         assert allclose(domain.tagged_elements['dsg'][0],0)
     193         assert allclose(domain.tagged_elements['ole nielsen'][0],1)
    192194
    193195         self.failUnless( domain.boundary[(1, 0)]  == '1',
     
    226228         #domain.set_tag_dict(tag_dict)
    227229         #Boundary tests
    228          b1 =  Dirichlet_boundary(conserved_quantities = numpy.array([0.0]))
    229          b2 =  Dirichlet_boundary(conserved_quantities = numpy.array([1.0]))
    230          b3 =  Dirichlet_boundary(conserved_quantities = numpy.array([1.0]))
     230         b1 =  Dirichlet_boundary(conserved_quantities = array([0.0]))
     231         b2 =  Dirichlet_boundary(conserved_quantities = array([1.0]))
     232         b3 =  Dirichlet_boundary(conserved_quantities = array([1.0]))
    231233         #test adding a boundary
    232234         tags = {}
  • anuga_core/source/anuga/abstract_2d_finite_volumes/test_quantity.py

    r5894 r5897  
    77from quantity import *
    88from anuga.config import epsilon
    9 import numpy
     9from Numeric import allclose, array, ones, Float
    1010
    1111from anuga.fit_interpolate.fit import fit_to_mesh
     
    1818#Aux for fit_interpolate.fit example
    1919def linear_function(point):
    20     point = numpy.array(point)
     20    point = array(point)
    2121    return point[:,0]+point[:,1]
    2222
     
    6363
    6464        quantity = Quantity(self.mesh1, [[1,2,3]])
    65         assert numpy.allclose(quantity.vertex_values, [[1.,2.,3.]])
     65        assert allclose(quantity.vertex_values, [[1.,2.,3.]])
    6666
    6767        try:
     
    8484
    8585        quantity = Quantity(self.mesh1)
    86         assert numpy.allclose(quantity.vertex_values, [[0.,0.,0.]])
    87 
    88 
    89         quantity = Quantity(self.mesh4)
    90         assert numpy.allclose(quantity.vertex_values, [[0.,0.,0.], [0.,0.,0.],
     86        assert allclose(quantity.vertex_values, [[0.,0.,0.]])
     87
     88
     89        quantity = Quantity(self.mesh4)
     90        assert allclose(quantity.vertex_values, [[0.,0.,0.], [0.,0.,0.],
    9191                                                 [0.,0.,0.], [0.,0.,0.]])
    9292
     
    9494    def test_interpolation(self):
    9595        quantity = Quantity(self.mesh1, [[1,2,3]])
    96         assert numpy.allclose(quantity.centroid_values, [2.0]) #Centroid
    97 
    98         assert numpy.allclose(quantity.edge_values, [[2.5, 2.0, 1.5]])
     96        assert allclose(quantity.centroid_values, [2.0]) #Centroid
     97
     98        assert allclose(quantity.edge_values, [[2.5, 2.0, 1.5]])
    9999
    100100
     
    102102        quantity = Quantity(self.mesh4,
    103103                            [[1,2,3], [5,5,5], [0,0,9], [-6, 3, 3]])
    104         assert numpy.allclose(quantity.centroid_values, [2., 5., 3., 0.]) #Centroid
     104        assert allclose(quantity.centroid_values, [2., 5., 3., 0.]) #Centroid
    105105
    106106
     
    108108
    109109        #print quantity.vertex_values
    110         assert numpy.allclose(quantity.vertex_values, [[3.5, -1.0, 3.5],
    111                                                        [3.+2./3, 6.+2./3, 4.+2./3],
    112                                                        [4.6, 3.4, 1.],
    113                                                        [-5.0, 1.0, 4.0]])
     110        assert allclose(quantity.vertex_values, [[3.5, -1.0, 3.5],
     111                                                 [3.+2./3, 6.+2./3, 4.+2./3],
     112                                                 [4.6, 3.4, 1.],
     113                                                 [-5.0, 1.0, 4.0]])
    114114
    115115        #print quantity.edge_values
    116         assert numpy.allclose(quantity.edge_values, [[1.25, 3.5, 1.25],
    117                                                      [5. + 2/3.0, 4.0 + 1.0/6, 5.0 + 1.0/6],
    118                                                      [2.2, 2.8, 4.0],
    119                                                      [2.5, -0.5, -2.0]])
    120 
    121 
    122         #assert numpy.allclose(quantity.edge_values, [[2.5, 2.0, 1.5],
    123         #                                             [5., 5., 5.],
    124         #                                             [4.5, 4.5, 0.],
    125         #                                             [3.0, -1.5, -1.5]])
     116        assert allclose(quantity.edge_values, [[1.25, 3.5, 1.25],
     117                                               [5. + 2/3.0, 4.0 + 1.0/6, 5.0 + 1.0/6],
     118                                               [2.2, 2.8, 4.0],
     119                                               [2.5, -0.5, -2.0]])
     120
     121
     122        #assert allclose(quantity.edge_values, [[2.5, 2.0, 1.5],
     123        #                                       [5., 5., 5.],
     124        #                                       [4.5, 4.5, 0.],
     125        #                                       [3.0, -1.5, -1.5]])
    126126
    127127    def test_get_extrema_1(self):
    128128        quantity = Quantity(self.mesh4,
    129129                                      [[1,2,3], [5,5,5], [0,0,9], [-6, 3, 3]])
    130         assert numpy.allclose(quantity.centroid_values, [2., 5., 3., 0.]) #Centroids
     130        assert allclose(quantity.centroid_values, [2., 5., 3., 0.]) #Centroids
    131131
    132132        v = quantity.get_maximum_value()
     
    148148
    149149        v = quantity.get_values(interpolation_points = [[x,y]])
    150         assert numpy.allclose(v, 5)
     150        assert allclose(v, 5)
    151151
    152152
    153153        x,y = quantity.get_minimum_location()
    154154        v = quantity.get_values(interpolation_points = [[x,y]])
    155         assert numpy.allclose(v, 0)
     155        assert allclose(v, 0)
    156156
    157157
     
    192192
    193193        v = quantity.get_values(interpolation_points = [[x,y]])
    194         assert numpy.allclose(v, 6)
     194        assert allclose(v, 6)
    195195
    196196        x,y = quantity.get_minimum_location()       
    197197        v = quantity.get_values(interpolation_points = [[x,y]])
    198         assert numpy.allclose(v, 2)
     198        assert allclose(v, 2)
    199199
    200200        #Multiple locations for maximum -
    201201        #Test that the algorithm picks the first occurrence       
    202202        v = quantity.get_maximum_value(indices=[0,1,2])
    203         assert numpy.allclose(v, 4)
     203        assert allclose(v, 4)
    204204
    205205        i = quantity.get_maximum_index(indices=[0,1,2])
     
    212212
    213213        v = quantity.get_values(interpolation_points = [[x,y]])
    214         assert numpy.allclose(v, 4)       
     214        assert allclose(v, 4)       
    215215
    216216        # More test of indices......
    217217        v = quantity.get_maximum_value(indices=[2,3])
    218         assert numpy.allclose(v, 6)
     218        assert allclose(v, 6)
    219219
    220220        i = quantity.get_maximum_index(indices=[2,3])
     
    227227
    228228        v = quantity.get_values(interpolation_points = [[x,y]])
    229         assert numpy.allclose(v, 6)       
     229        assert allclose(v, 6)       
    230230
    231231       
     
    244244        quantity.set_values([[1,2,3], [5,5,5], [0,0,9], [-6, 3, 3]],
    245245                            location = 'vertices')
    246         assert numpy.allclose(quantity.vertex_values,
    247                               [[1,2,3], [5,5,5], [0,0,9], [-6, 3, 3]])
    248         assert numpy.allclose(quantity.centroid_values, [2., 5., 3., 0.]) #Centroid
    249         assert numpy.allclose(quantity.edge_values, [[2.5, 2.0, 1.5],
    250                                                      [5., 5., 5.],
    251                                                      [4.5, 4.5, 0.],
    252                                                      [3.0, -1.5, -1.5]])
     246        assert allclose(quantity.vertex_values,
     247                        [[1,2,3], [5,5,5], [0,0,9], [-6, 3, 3]])
     248        assert allclose(quantity.centroid_values, [2., 5., 3., 0.]) #Centroid
     249        assert allclose(quantity.edge_values, [[2.5, 2.0, 1.5],
     250                                               [5., 5., 5.],
     251                                               [4.5, 4.5, 0.],
     252                                               [3.0, -1.5, -1.5]])
    253253
    254254
    255255        # Test default
    256256        quantity.set_values([[1,2,3], [5,5,5], [0,0,9], [-6, 3, 3]])
    257         assert numpy.allclose(quantity.vertex_values,
    258                               [[1,2,3], [5,5,5], [0,0,9], [-6, 3, 3]])
    259         assert numpy.allclose(quantity.centroid_values, [2., 5., 3., 0.]) #Centroid
    260         assert numpy.allclose(quantity.edge_values, [[2.5, 2.0, 1.5],
    261                                                      [5., 5., 5.],
    262                                                      [4.5, 4.5, 0.],
    263                                                      [3.0, -1.5, -1.5]])
     257        assert allclose(quantity.vertex_values,
     258                        [[1,2,3], [5,5,5], [0,0,9], [-6, 3, 3]])
     259        assert allclose(quantity.centroid_values, [2., 5., 3., 0.]) #Centroid
     260        assert allclose(quantity.edge_values, [[2.5, 2.0, 1.5],
     261                                               [5., 5., 5.],
     262                                               [4.5, 4.5, 0.],
     263                                               [3.0, -1.5, -1.5]])
    264264
    265265        # Test centroids
    266266        quantity.set_values([1,2,3,4], location = 'centroids')
    267         assert numpy.allclose(quantity.centroid_values, [1., 2., 3., 4.]) #Centroid
     267        assert allclose(quantity.centroid_values, [1., 2., 3., 4.]) #Centroid
    268268
    269269        # Test exceptions
     
    288288
    289289        quantity.set_values(1.0, location = 'vertices')
    290         assert numpy.allclose(quantity.vertex_values,
    291                               [[1,1,1], [1,1,1], [1,1,1], [1, 1, 1]])
    292 
    293         assert numpy.allclose(quantity.centroid_values, [1, 1, 1, 1]) #Centroid
    294         assert numpy.allclose(quantity.edge_values, [[1, 1, 1],
    295                                                      [1, 1, 1],
    296                                                      [1, 1, 1],
    297                                                      [1, 1, 1]])
     290        assert allclose(quantity.vertex_values,
     291                        [[1,1,1], [1,1,1], [1,1,1], [1, 1, 1]])
     292
     293        assert allclose(quantity.centroid_values, [1, 1, 1, 1]) #Centroid
     294        assert allclose(quantity.edge_values, [[1, 1, 1],
     295                                               [1, 1, 1],
     296                                               [1, 1, 1],
     297                                               [1, 1, 1]])
    298298
    299299
    300300        quantity.set_values(2.0, location = 'centroids')
    301         assert numpy.allclose(quantity.centroid_values, [2, 2, 2, 2])
     301        assert allclose(quantity.centroid_values, [2, 2, 2, 2])
    302302
    303303
     
    310310        quantity.set_values(f, location = 'vertices')
    311311        #print "quantity.vertex_values",quantity.vertex_values
    312         assert numpy.allclose(quantity.vertex_values,
    313                               [[2,0,2], [2,2,4], [4,2,4], [4,2,4]])
    314         assert numpy.allclose(quantity.centroid_values,
    315                               [4.0/3, 8.0/3, 10.0/3, 10.0/3])
    316         assert numpy.allclose(quantity.edge_values,
    317                               [[1,2,1], [3,3,2], [3,4,3], [3,4,3]])
     312        assert allclose(quantity.vertex_values,
     313                        [[2,0,2], [2,2,4], [4,2,4], [4,2,4]])
     314        assert allclose(quantity.centroid_values,
     315                        [4.0/3, 8.0/3, 10.0/3, 10.0/3])
     316        assert allclose(quantity.edge_values,
     317                        [[1,2,1], [3,3,2], [3,4,3], [3,4,3]])
    318318
    319319
    320320        quantity.set_values(f, location = 'centroids')
    321         assert numpy.allclose(quantity.centroid_values,
    322                               [4.0/3, 8.0/3, 10.0/3, 10.0/3])
     321        assert allclose(quantity.centroid_values,
     322                        [4.0/3, 8.0/3, 10.0/3, 10.0/3])
    323323
    324324
     
    331331        #print 'Q', quantity.get_integral()
    332332
    333         assert numpy.allclose(quantity.get_integral(), self.mesh4.get_area() * const)
     333        assert allclose(quantity.get_integral(), self.mesh4.get_area() * const)
    334334
    335335        #Try with a linear function
     
    342342        ref_integral = (4.0/3 + 8.0/3 + 10.0/3 + 10.0/3) * 2
    343343
    344         assert numpy.allclose (quantity.get_integral(), ref_integral)
     344        assert allclose (quantity.get_integral(), ref_integral)
    345345
    346346
     
    350350        quantity.set_vertex_values([0,1,2,3,4,5])
    351351
    352         assert numpy.allclose(quantity.vertex_values,
    353                               [[1,0,2], [1,2,4], [4,2,5], [3,1,4]])
    354         assert numpy.allclose(quantity.centroid_values,
    355                               [1., 7./3, 11./3, 8./3]) #Centroid
    356         assert numpy.allclose(quantity.edge_values, [[1., 1.5, 0.5],
    357                                                      [3., 2.5, 1.5],
    358                                                      [3.5, 4.5, 3.],
    359                                                      [2.5, 3.5, 2]])
     352        assert allclose(quantity.vertex_values,
     353                        [[1,0,2], [1,2,4], [4,2,5], [3,1,4]])
     354        assert allclose(quantity.centroid_values,
     355                        [1., 7./3, 11./3, 8./3]) #Centroid
     356        assert allclose(quantity.edge_values, [[1., 1.5, 0.5],
     357                                               [3., 2.5, 1.5],
     358                                               [3.5, 4.5, 3.],
     359                                               [2.5, 3.5, 2]])
    360360
    361361
     
    365365        quantity.set_vertex_values([0,20,30,50], indices = [0,2,3,5])
    366366
    367         assert numpy.allclose(quantity.vertex_values,
    368                               [[1,0,20], [1,20,4], [4,20,50], [30,1,4]])
     367        assert allclose(quantity.vertex_values,
     368                        [[1,0,20], [1,20,4], [4,20,50], [30,1,4]])
    369369
    370370
     
    376376
    377377
    378         assert numpy.allclose(quantity.vertex_values,
    379                               [[1,0,2], [1,2,4], [4,2,5], [3,1,4]])
     378        assert allclose(quantity.vertex_values,
     379                        [[1,0,2], [1,2,4], [4,2,5], [3,1,4]])
    380380
    381381        #Centroid
    382         assert numpy.allclose(quantity.centroid_values, [1., 7./3, 11./3, 8./3])
    383 
    384         assert numpy.allclose(quantity.edge_values, [[1., 1.5, 0.5],
    385                                                      [3., 2.5, 1.5],
    386                                                      [3.5, 4.5, 3.],
    387                                                      [2.5, 3.5, 2]])
     382        assert allclose(quantity.centroid_values, [1., 7./3, 11./3, 8./3])
     383
     384        assert allclose(quantity.edge_values, [[1., 1.5, 0.5],
     385                                               [3., 2.5, 1.5],
     386                                               [3.5, 4.5, 3.],
     387                                               [2.5, 3.5, 2]])
    388388
    389389
     
    399399
    400400        quantity.set_values([0,2,3,5], indices=[0,2,3,5])
    401         assert numpy.allclose(quantity.vertex_values,
    402                               [[0,0,2], [0,2,0], [0,2,5], [3,0,0]])
     401        assert allclose(quantity.vertex_values,
     402                        [[0,0,2], [0,2,0], [0,2,5], [3,0,0]])
    403403
    404404
     
    408408
    409409        # Indices refer to triangle numbers
    410         assert numpy.allclose(quantity.vertex_values,
    411                               [[3.14,3.14,3.14], [0,0,0],
    412                                [3.14,3.14,3.14], [0,0,0]])       
     410        assert allclose(quantity.vertex_values,
     411                        [[3.14,3.14,3.14], [0,0,0],
     412                         [3.14,3.14,3.14], [0,0,0]])       
    413413       
    414414
     
    419419        quantity.set_values(3.14, polygon=polygon)
    420420       
    421         assert numpy.allclose(quantity.vertex_values,
    422                               [[0,0,0], [0,0,0], [0,0,0],
    423                                [3.14,3.14,3.14]])               
     421        assert allclose(quantity.vertex_values,
     422                        [[0,0,0], [0,0,0], [0,0,0],
     423                         [3.14,3.14,3.14]])               
    424424
    425425
     
    429429        quantity.set_values(0.0)
    430430        quantity.set_values(3.14, location='centroids', polygon=polygon)
    431         assert numpy.allclose(quantity.vertex_values,
    432                               [[0,0,0],
    433                                [3.14,3.14,3.14],
    434                                [3.14,3.14,3.14],                         
    435                                [0,0,0]])               
     431        assert allclose(quantity.vertex_values,
     432                        [[0,0,0],
     433                         [3.14,3.14,3.14],
     434                         [3.14,3.14,3.14],                         
     435                         [0,0,0]])               
    436436
    437437
     
    441441        #print 'Here 2'
    442442        quantity.set_values(3.14, polygon=polygon)
    443         assert numpy.allclose(quantity.vertex_values,
    444                               [[0,0,0],
    445                                [3.14,3.14,3.14],
    446                                [3.14,3.14,3.14],                         
    447                                [0,0,0]])               
     443        assert allclose(quantity.vertex_values,
     444                        [[0,0,0],
     445                         [3.14,3.14,3.14],
     446                         [3.14,3.14,3.14],                         
     447                         [0,0,0]])               
    448448       
    449449
     
    478478
    479479        # Indices refer to triangle numbers here - not vertices (why?)
    480         assert numpy.allclose(quantity.vertex_values,
    481                               [[3.14,3.14,3.14], [0,0,0],
    482                                [3.14,3.14,3.14], [0,0,0]])       
     480        assert allclose(quantity.vertex_values,
     481                        [[3.14,3.14,3.14], [0,0,0],
     482                         [3.14,3.14,3.14], [0,0,0]])       
    483483       
    484484
    485485
    486486        # Now try with polygon (pick points where y>2)
    487         polygon = numpy.array([[0,2.1], [4,2.1], [4,7], [0,7]])
     487        polygon = array([[0,2.1], [4,2.1], [4,7], [0,7]])
    488488        polygon += [G.xllcorner, G.yllcorner]
    489489       
     
    491491        quantity.set_values(3.14, polygon=polygon, location='centroids')
    492492       
    493         assert numpy.allclose(quantity.vertex_values,
    494                               [[0,0,0], [0,0,0], [0,0,0],
    495                                [3.14,3.14,3.14]])               
     493        assert allclose(quantity.vertex_values,
     494                        [[0,0,0], [0,0,0], [0,0,0],
     495                         [3.14,3.14,3.14]])               
    496496
    497497
    498498        # Another polygon (pick triangle 1 and 2 (rightmost triangles)
    499         polygon = numpy.array([[2.1, 0.0], [3.5,0.1], [2,2.2], [0.2,2]])
     499        polygon = array([[2.1, 0.0], [3.5,0.1], [2,2.2], [0.2,2]])
    500500        polygon += [G.xllcorner, G.yllcorner]
    501501       
     
    503503        quantity.set_values(3.14, polygon=polygon)
    504504
    505         assert numpy.allclose(quantity.vertex_values,
    506                               [[0,0,0],
    507                                [3.14,3.14,3.14],
    508                                [3.14,3.14,3.14],                         
    509                                [0,0,0]])               
     505        assert allclose(quantity.vertex_values,
     506                        [[0,0,0],
     507                         [3.14,3.14,3.14],
     508                         [3.14,3.14,3.14],                         
     509                         [0,0,0]])               
    510510
    511511
     
    540540        answer = linear_function(quantity.domain.get_vertex_coordinates())
    541541        #print quantity.vertex_values, answer
    542         assert numpy.allclose(quantity.vertex_values.ravel(), answer)
     542        assert allclose(quantity.vertex_values.flat, answer)
    543543
    544544
     
    553553        #print vertex_attributes
    554554        quantity.set_values(vertex_attributes)
    555         assert numpy.allclose(quantity.vertex_values.ravel(), answer)
     555        assert allclose(quantity.vertex_values.flat, answer)
    556556
    557557
     
    593593                          alpha = 0)
    594594
    595         assert numpy.allclose( ref, [0,5,5] )
     595        assert allclose( ref, [0,5,5] )
    596596
    597597
     
    610610        #                    data_georef = data_georef,
    611611        #                    alpha = 0)
    612         assert numpy.allclose(quantity.vertex_values.ravel(), ref)
     612        assert allclose(quantity.vertex_values.flat, ref)
    613613
    614614
     
    621621
    622622        quantity.set_values(geospatial_data = geo, alpha = 0)
    623         assert numpy.allclose(quantity.vertex_values.ravel(), ref)
     623        assert allclose(quantity.vertex_values.flat, ref)
    624624
    625625
     
    666666        answer = linear_function(quantity.domain.get_vertex_coordinates())
    667667
    668         #print quantity.vertex_values.ravel()
     668        #print quantity.vertex_values.flat
    669669        #print answer
    670670
    671671
    672         assert numpy.allclose(quantity.vertex_values.ravel(), answer)
     672        assert allclose(quantity.vertex_values.flat, answer)
    673673
    674674
    675675        #Check that values can be set from file using default attribute
    676676        quantity.set_values(filename = ptsfile, alpha = 0)
    677         assert numpy.allclose(quantity.vertex_values.ravel(), answer)
     677        assert allclose(quantity.vertex_values.flat, answer)
    678678
    679679        #Cleanup
     
    730730        #print self.mesh4.nodes
    731731        #print inside_polygon(self.mesh4.nodes, polygon)
    732         assert numpy.allclose(inside_polygon(self.mesh4.nodes, polygon), 4)
     732        assert allclose(inside_polygon(self.mesh4.nodes, polygon), 4)
    733733
    734734        #print quantity.domain.get_vertex_coordinates()
     
    748748        answer = linear_function(points)
    749749
    750         #print quantity.vertex_values.ravel()
     750        #print quantity.vertex_values.flat
    751751        #print answer
    752752
    753753        # Check vertices in polygon have been set
    754         assert numpy.allclose(take(quantity.vertex_values.ravel(), indices),
    755                                    answer)
     754        assert allclose(take(quantity.vertex_values.flat, indices),
     755                             answer)
    756756
    757757        # Check vertices outside polygon are zero
    758758        indices = outside_polygon(quantity.domain.get_vertex_coordinates(),
    759759                                  polygon)       
    760         assert numpy.allclose(take(quantity.vertex_values.ravel(), indices),
    761                                    0.0)       
     760        assert allclose(take(quantity.vertex_values.flat, indices),
     761                             0.0)       
    762762
    763763        #Cleanup
     
    815815                            verbose=False)
    816816        answer = linear_function(quantity.domain.get_vertex_coordinates())
    817         assert numpy.allclose(quantity.vertex_values.ravel(), answer)
     817        assert allclose(quantity.vertex_values.flat, answer)
    818818
    819819
     
    821821        quantity.set_values(filename=ptsfile,
    822822                            alpha=0)
    823         assert numpy.allclose(quantity.vertex_values.ravel(), answer)
     823        assert allclose(quantity.vertex_values.flat, answer)
    824824
    825825        # Check cache
     
    866866        answer = linear_function(quantity.domain.get_vertex_coordinates())
    867867
    868         #print "quantity.vertex_values.ravel()", quantity.vertex_values.ravel()
     868        #print "quantity.vertex_values.flat", quantity.vertex_values.flat
    869869        #print "answer",answer
    870870
    871         assert numpy.allclose(quantity.vertex_values.ravel(), answer)
     871        assert allclose(quantity.vertex_values.flat, answer)
    872872
    873873
    874874        #Check that values can be set from file using default attribute
    875875        quantity.set_values(filename=txt_file, alpha=0)
    876         assert numpy.allclose(quantity.vertex_values.ravel(), answer)
     876        assert allclose(quantity.vertex_values.flat, answer)
    877877
    878878        #Cleanup
     
    910910        answer = linear_function(quantity.domain.get_vertex_coordinates())
    911911
    912         #print "quantity.vertex_values.ravel()", quantity.vertex_values.ravel()
     912        #print "quantity.vertex_values.flat", quantity.vertex_values.flat
    913913        #print "answer",answer
    914914
    915         assert numpy.allclose(quantity.vertex_values.ravel(), answer)
     915        assert allclose(quantity.vertex_values.flat, answer)
    916916
    917917
    918918        #Check that values can be set from file using default attribute
    919919        quantity.set_values(filename=txt_file, alpha=0)
    920         assert numpy.allclose(quantity.vertex_values.ravel(), answer)
     920        assert allclose(quantity.vertex_values.flat, answer)
    921921
    922922        #Cleanup
     
    957957                                      'vertices', None)
    958958        answer = linear_function(quantity.domain.get_vertex_coordinates())
    959         #print "quantity.vertex_values.ravel()", quantity.vertex_values.ravel()
     959        #print "quantity.vertex_values.flat", quantity.vertex_values.flat
    960960        #print "answer",answer
    961         assert numpy.allclose(quantity.vertex_values.ravel(), answer)
     961        assert allclose(quantity.vertex_values.flat, answer)
    962962
    963963        #Check that values can be set from file
     
    965965                            attribute_name=att, alpha=0)
    966966        answer = linear_function(quantity.domain.get_vertex_coordinates())
    967         #print "quantity.vertex_values.ravel()", quantity.vertex_values.ravel()
     967        #print "quantity.vertex_values.flat", quantity.vertex_values.flat
    968968        #print "answer",answer
    969         assert numpy.allclose(quantity.vertex_values.ravel(), answer)
     969        assert allclose(quantity.vertex_values.flat, answer)
    970970
    971971
    972972        #Check that values can be set from file using default attribute
    973973        quantity.set_values(filename=txt_file, alpha=0)
    974         assert numpy.allclose(quantity.vertex_values.ravel(), answer)
     974        assert allclose(quantity.vertex_values.flat, answer)
    975975
    976976        #Cleanup
     
    10391039                                      max_read_lines=2)
    10401040        answer = linear_function(quantity.domain.get_vertex_coordinates())
    1041         #print "quantity.vertex_values.ravel()", quantity.vertex_values.ravel()
     1041        #print "quantity.vertex_values.flat", quantity.vertex_values.flat
    10421042        #print "answer",answer
    1043         assert numpy.allclose(quantity.vertex_values.ravel(), answer)
     1043        assert allclose(quantity.vertex_values.flat, answer)
    10441044
    10451045        #Check that values can be set from file
     
    10471047                            attribute_name=att, alpha=0)
    10481048        answer = linear_function(quantity.domain.get_vertex_coordinates())
    1049         #print "quantity.vertex_values.ravel()", quantity.vertex_values.ravel()
     1049        #print "quantity.vertex_values.flat", quantity.vertex_values.flat
    10501050        #print "answer",answer
    1051         assert numpy.allclose(quantity.vertex_values.ravel(), answer)
     1051        assert allclose(quantity.vertex_values.flat, answer)
    10521052
    10531053
    10541054        #Check that values can be set from file using default attribute
    10551055        quantity.set_values(filename=txt_file, alpha=0)
    1056         assert numpy.allclose(quantity.vertex_values.ravel(), answer)
     1056        assert allclose(quantity.vertex_values.flat, answer)
    10571057
    10581058        #Cleanup
     
    11281128        answer = linear_function(quantity.domain.get_vertex_coordinates())
    11291129
    1130         assert numpy.allclose(quantity.vertex_values.ravel(), answer)
     1130        assert allclose(quantity.vertex_values.flat, answer)
    11311131
    11321132
    11331133        #Check that values can be set from file using default attribute
    11341134        quantity.set_values(filename=ptsfile, alpha=0)
    1135         assert numpy.allclose(quantity.vertex_values.ravel(), answer)
     1135        assert allclose(quantity.vertex_values.flat, answer)
    11361136
    11371137        #Cleanup
     
    12071207
    12081208
    1209         assert numpy.allclose(quantity.vertex_values.ravel(), answer)
     1209        assert allclose(quantity.vertex_values.flat, answer)
    12101210
    12111211
    12121212        #Check that values can be set from file using default attribute
    12131213        quantity.set_values(filename=ptsfile, alpha=0)
    1214         assert numpy.allclose(quantity.vertex_values.ravel(), answer)
     1214        assert allclose(quantity.vertex_values.flat, answer)
    12151215
    12161216        #Cleanup
     
    12261226        quantity1.set_vertex_values([0,1,2,3,4,5])
    12271227
    1228         assert numpy.allclose(quantity1.vertex_values,
    1229                               [[1,0,2], [1,2,4], [4,2,5], [3,1,4]])
     1228        assert allclose(quantity1.vertex_values,
     1229                        [[1,0,2], [1,2,4], [4,2,5], [3,1,4]])
    12301230
    12311231
    12321232        quantity2 = Quantity(self.mesh4)
    12331233        quantity2.set_values(quantity=quantity1)
    1234         assert numpy.allclose(quantity2.vertex_values,
    1235                               [[1,0,2], [1,2,4], [4,2,5], [3,1,4]])
     1234        assert allclose(quantity2.vertex_values,
     1235                        [[1,0,2], [1,2,4], [4,2,5], [3,1,4]])
    12361236
    12371237        quantity2.set_values(quantity = 2*quantity1)
    1238         assert numpy.allclose(quantity2.vertex_values,
    1239                               [[2,0,4], [2,4,8], [8,4,10], [6,2,8]])
     1238        assert allclose(quantity2.vertex_values,
     1239                        [[2,0,4], [2,4,8], [8,4,10], [6,2,8]])
    12401240
    12411241        quantity2.set_values(quantity = 2*quantity1 + 3)
    1242         assert numpy.allclose(quantity2.vertex_values,
    1243                               [[5,3,7], [5,7,11], [11,7,13], [9,5,11]])
     1242        assert allclose(quantity2.vertex_values,
     1243                        [[5,3,7], [5,7,11], [11,7,13], [9,5,11]])
    12441244
    12451245
    12461246        #Check detection of quantity as first orgument
    12471247        quantity2.set_values(2*quantity1 + 3)
    1248         assert numpy.allclose(quantity2.vertex_values,
    1249                               [[5,3,7], [5,7,11], [11,7,13], [9,5,11]])
     1248        assert allclose(quantity2.vertex_values,
     1249                        [[5,3,7], [5,7,11], [11,7,13], [9,5,11]])
    12501250
    12511251
     
    12621262        polygon = [[1.0, 1.0], [4.0, 1.0],
    12631263                   [4.0, 4.0], [1.0, 4.0]]
    1264         assert numpy.allclose(inside_polygon(self.mesh4.nodes, polygon), 4)                   
     1264        assert allclose(inside_polygon(self.mesh4.nodes, polygon), 4)                   
    12651265       
    12661266        quantity1 = Quantity(self.mesh4)
    12671267        quantity1.set_vertex_values([0,1,2,3,4,5])
    12681268
    1269         assert numpy.allclose(quantity1.vertex_values,
    1270                               [[1,0,2], [1,2,4], [4,2,5], [3,1,4]])
     1269        assert allclose(quantity1.vertex_values,
     1270                        [[1,0,2], [1,2,4], [4,2,5], [3,1,4]])
    12711271
    12721272
     
    12761276                             
    12771277        msg = 'Only node #4(e) at (2,2) should have values applied '
    1278         assert numpy.allclose(quantity2.vertex_values,
    1279                               [[0,0,0], [0,0,4], [4,0,0], [0,0,4]]), msg       
    1280                               #bac,     bce,     ecf,     dbe
     1278        assert allclose(quantity2.vertex_values,
     1279                        [[0,0,0], [0,0,4], [4,0,0], [0,0,4]]), msg       
     1280                        #bac,     bce,     ecf,     dbe
    12811281                       
    12821282
     
    12871287        quantity1.set_vertex_values([0,1,2,3,4,5])
    12881288
    1289         assert numpy.allclose(quantity1.vertex_values,
    1290                               [[1,0,2], [1,2,4], [4,2,5], [3,1,4]])
     1289        assert allclose(quantity1.vertex_values,
     1290                        [[1,0,2], [1,2,4], [4,2,5], [3,1,4]])
    12911291
    12921292
     
    13041304        # Negation
    13051305        Q = -quantity1
    1306         assert numpy.allclose(Q.vertex_values, -quantity1.vertex_values)
    1307         assert numpy.allclose(Q.centroid_values, -quantity1.centroid_values)
    1308         assert numpy.allclose(Q.edge_values, -quantity1.edge_values)
     1306        assert allclose(Q.vertex_values, -quantity1.vertex_values)
     1307        assert allclose(Q.centroid_values, -quantity1.centroid_values)
     1308        assert allclose(Q.edge_values, -quantity1.edge_values)
    13091309
    13101310        # Addition
    13111311        Q = quantity1 + 7
    1312         assert numpy.allclose(Q.vertex_values, quantity1.vertex_values + 7)
    1313         assert numpy.allclose(Q.centroid_values, quantity1.centroid_values + 7)
    1314         assert numpy.allclose(Q.edge_values, quantity1.edge_values + 7)
     1312        assert allclose(Q.vertex_values, quantity1.vertex_values + 7)
     1313        assert allclose(Q.centroid_values, quantity1.centroid_values + 7)
     1314        assert allclose(Q.edge_values, quantity1.edge_values + 7)
    13151315
    13161316        Q = 7 + quantity1
    1317         assert numpy.allclose(Q.vertex_values, quantity1.vertex_values + 7)
    1318         assert numpy.allclose(Q.centroid_values, quantity1.centroid_values + 7)
    1319         assert numpy.allclose(Q.edge_values, quantity1.edge_values + 7)
     1317        assert allclose(Q.vertex_values, quantity1.vertex_values + 7)
     1318        assert allclose(Q.centroid_values, quantity1.centroid_values + 7)
     1319        assert allclose(Q.edge_values, quantity1.edge_values + 7)
    13201320
    13211321        Q = quantity1 + quantity2
    1322         assert numpy.allclose(Q.vertex_values,
    1323                               quantity1.vertex_values + quantity2.vertex_values)
    1324         assert numpy.allclose(Q.centroid_values,
    1325                               quantity1.centroid_values + quantity2.centroid_values)
    1326         assert numpy.allclose(Q.edge_values,
    1327                               quantity1.edge_values + quantity2.edge_values)
     1322        assert allclose(Q.vertex_values,
     1323                        quantity1.vertex_values + quantity2.vertex_values)
     1324        assert allclose(Q.centroid_values,
     1325                        quantity1.centroid_values + quantity2.centroid_values)
     1326        assert allclose(Q.edge_values,
     1327                        quantity1.edge_values + quantity2.edge_values)
    13281328
    13291329
    13301330        Q = quantity1 + quantity2 - 3
    1331         assert numpy.allclose(Q.vertex_values,
    1332                               quantity1.vertex_values + quantity2.vertex_values - 3)
     1331        assert allclose(Q.vertex_values,
     1332                        quantity1.vertex_values + quantity2.vertex_values - 3)
    13331333
    13341334        Q = quantity1 - quantity2
    1335         assert numpy.allclose(Q.vertex_values,
    1336                               quantity1.vertex_values - quantity2.vertex_values)
     1335        assert allclose(Q.vertex_values,
     1336                        quantity1.vertex_values - quantity2.vertex_values)
    13371337
    13381338        #Scaling
    13391339        Q = quantity1*3
    1340         assert numpy.allclose(Q.vertex_values, quantity1.vertex_values*3)
    1341         assert numpy.allclose(Q.centroid_values, quantity1.centroid_values*3)
    1342         assert numpy.allclose(Q.edge_values, quantity1.edge_values*3)
     1340        assert allclose(Q.vertex_values, quantity1.vertex_values*3)
     1341        assert allclose(Q.centroid_values, quantity1.centroid_values*3)
     1342        assert allclose(Q.edge_values, quantity1.edge_values*3)
    13431343        Q = 3*quantity1
    1344         assert numpy.allclose(Q.vertex_values, quantity1.vertex_values*3)
     1344        assert allclose(Q.vertex_values, quantity1.vertex_values*3)
    13451345
    13461346        #Multiplication
     
    13511351        #print quantity2.centroid_values
    13521352
    1353         assert numpy.allclose(Q.vertex_values,
    1354                               quantity1.vertex_values * quantity2.vertex_values)
     1353        assert allclose(Q.vertex_values,
     1354                        quantity1.vertex_values * quantity2.vertex_values)
    13551355
    13561356        #Linear combinations
    13571357        Q = 4*quantity1 + 2
    1358         assert numpy.allclose(Q.vertex_values,
    1359                               4*quantity1.vertex_values + 2)
     1358        assert allclose(Q.vertex_values,
     1359                        4*quantity1.vertex_values + 2)
    13601360
    13611361        Q = quantity1*quantity2 + 2
    1362         assert numpy.allclose(Q.vertex_values,
    1363                               quantity1.vertex_values * quantity2.vertex_values + 2)
     1362        assert allclose(Q.vertex_values,
     1363                        quantity1.vertex_values * quantity2.vertex_values + 2)
    13641364
    13651365        Q = quantity1*quantity2 + quantity3
    1366         assert numpy.allclose(Q.vertex_values,
    1367                               quantity1.vertex_values * quantity2.vertex_values +
    1368                               quantity3.vertex_values)
     1366        assert allclose(Q.vertex_values,
     1367                        quantity1.vertex_values * quantity2.vertex_values +
     1368                        quantity3.vertex_values)
    13691369        Q = quantity1*quantity2 + 3*quantity3
    1370         assert numpy.allclose(Q.vertex_values,
    1371                               quantity1.vertex_values * quantity2.vertex_values +
    1372                              3*quantity3.vertex_values)
     1370        assert allclose(Q.vertex_values,
     1371                        quantity1.vertex_values * quantity2.vertex_values +
     1372                        3*quantity3.vertex_values)
    13731373        Q = quantity1*quantity2 + 3*quantity3 + 5.0
    1374         assert numpy.allclose(Q.vertex_values,
    1375                               quantity1.vertex_values * quantity2.vertex_values +
    1376                               3*quantity3.vertex_values + 5)
     1374        assert allclose(Q.vertex_values,
     1375                        quantity1.vertex_values * quantity2.vertex_values +
     1376                        3*quantity3.vertex_values + 5)
    13771377
    13781378        Q = quantity1*quantity2 - quantity3
    1379         assert numpy.allclose(Q.vertex_values,
    1380                               quantity1.vertex_values * quantity2.vertex_values -
    1381                               quantity3.vertex_values)
     1379        assert allclose(Q.vertex_values,
     1380                        quantity1.vertex_values * quantity2.vertex_values -
     1381                        quantity3.vertex_values)
    13821382        Q = 1.5*quantity1*quantity2 - 3*quantity3 + 5.0
    1383         assert numpy.allclose(Q.vertex_values,
    1384                               1.5*quantity1.vertex_values * quantity2.vertex_values -
    1385                               3*quantity3.vertex_values + 5)
     1383        assert allclose(Q.vertex_values,
     1384                        1.5*quantity1.vertex_values * quantity2.vertex_values -
     1385                        3*quantity3.vertex_values + 5)
    13861386
    13871387        #Try combining quantities and arrays and scalars
    1388         Q = 1.5*quantity1*quantity2.vertex_values - \
     1388        Q = 1.5*quantity1*quantity2.vertex_values -\
    13891389            3*quantity3.vertex_values + 5.0
    1390         assert numpy.allclose(Q.vertex_values,
    1391                               1.5*quantity1.vertex_values * quantity2.vertex_values -
    1392                               3*quantity3.vertex_values + 5)
     1390        assert allclose(Q.vertex_values,
     1391                        1.5*quantity1.vertex_values * quantity2.vertex_values -
     1392                        3*quantity3.vertex_values + 5)
    13931393
    13941394
    13951395        #Powers
    13961396        Q = quantity1**2
    1397         assert numpy.allclose(Q.vertex_values, quantity1.vertex_values**2)
     1397        assert allclose(Q.vertex_values, quantity1.vertex_values**2)
    13981398
    13991399        Q = quantity1**2 +quantity2**2
    1400         assert numpy.allclose(Q.vertex_values,
    1401                               quantity1.vertex_values**2 +
    1402                               quantity2.vertex_values**2)
     1400        assert allclose(Q.vertex_values,
     1401                        quantity1.vertex_values**2 + \
     1402                        quantity2.vertex_values**2)
    14031403
    14041404        Q = (quantity1**2 +quantity2**2)**0.5
    1405         assert numpy.allclose(Q.vertex_values,
    1406                               (quantity1.vertex_values**2 +
    1407                                quantity2.vertex_values**2)**0.5)
     1405        assert allclose(Q.vertex_values,
     1406                        (quantity1.vertex_values**2 + \
     1407                        quantity2.vertex_values**2)**0.5)
    14081408
    14091409
     
    14311431        #The central triangle (1)
    14321432        #(using standard gradient based on neigbours controid values)
    1433         assert numpy.allclose(a[1], 2.0)
    1434         assert numpy.allclose(b[1], 0.0)
     1433        assert allclose(a[1], 2.0)
     1434        assert allclose(b[1], 0.0)
    14351435
    14361436
     
    14381438        #q0 = q1 + a*(x0-x1) + b*(y0-y1)  <=>
    14391439        #2  = 4  + a*(-2/3)  + b*(-2/3)
    1440         assert numpy.allclose(a[0] + b[0], 3)
     1440        assert allclose(a[0] + b[0], 3)
    14411441        #From orthogonality (a*(y0-y1) + b*(x0-x1) == 0)
    1442         assert numpy.allclose(a[0] - b[0], 0)
     1442        assert allclose(a[0] - b[0], 0)
    14431443
    14441444
     
    14461446        #q2 = q1 + a*(x2-x1) + b*(y2-y1)  <=>
    14471447        #6  = 4  + a*(4/3)  + b*(-2/3)
    1448         assert numpy.allclose(2*a[2] - b[2], 3)
     1448        assert allclose(2*a[2] - b[2], 3)
    14491449        #From orthogonality (a*(y1-y2) + b*(x2-x1) == 0)
    1450         assert numpy.allclose(a[2] + 2*b[2], 0)
     1450        assert allclose(a[2] + 2*b[2], 0)
    14511451
    14521452
     
    14541454        #q3 = q1 + a*(x3-x1) + b*(y3-y1)  <=>
    14551455        #2  = 4  + a*(-2/3)  + b*(4/3)
    1456         assert numpy.allclose(a[3] - 2*b[3], 3)
     1456        assert allclose(a[3] - 2*b[3], 3)
    14571457        #From orthogonality (a*(y1-y3) + b*(x3-x1) == 0)
    1458         assert numpy.allclose(2*a[3] + b[3], 0)
     1458        assert allclose(2*a[3] + b[3], 0)
    14591459
    14601460
     
    14641464
    14651465        #Apply q(x,y) = qc + a*(x-xc) + b*(y-yc)
    1466         assert numpy.allclose(quantity.vertex_values[0,:], [3., 0.,  3.])
    1467         assert numpy.allclose(quantity.vertex_values[1,:], [4./3, 16./3,  16./3])
     1466        assert allclose(quantity.vertex_values[0,:], [3., 0.,  3.])
     1467        assert allclose(quantity.vertex_values[1,:], [4./3, 16./3,  16./3])
    14681468
    14691469
    14701470        #a = 1.2, b=-0.6
    14711471        #q(4,0) = 6 + a*(4 - 8/3) + b*(-2/3)
    1472         assert numpy.allclose(quantity.vertex_values[2,2], 8)
     1472        assert allclose(quantity.vertex_values[2,2], 8)
    14731473
    14741474    def test_get_gradients(self):
     
    14891489        #The central triangle (1)
    14901490        #(using standard gradient based on neigbours controid values)
    1491         assert numpy.allclose(a[1], 2.0)
    1492         assert numpy.allclose(b[1], 0.0)
     1491        assert allclose(a[1], 2.0)
     1492        assert allclose(b[1], 0.0)
    14931493
    14941494
     
    14961496        #q0 = q1 + a*(x0-x1) + b*(y0-y1)  <=>
    14971497        #2  = 4  + a*(-2/3)  + b*(-2/3)
    1498         assert numpy.allclose(a[0] + b[0], 3)
     1498        assert allclose(a[0] + b[0], 3)
    14991499        #From orthogonality (a*(y0-y1) + b*(x0-x1) == 0)
    1500         assert numpy.allclose(a[0] - b[0], 0)
     1500        assert allclose(a[0] - b[0], 0)
    15011501
    15021502
     
    15041504        #q2 = q1 + a*(x2-x1) + b*(y2-y1)  <=>
    15051505        #6  = 4  + a*(4/3)  + b*(-2/3)
    1506         assert numpy.allclose(2*a[2] - b[2], 3)
     1506        assert allclose(2*a[2] - b[2], 3)
    15071507        #From orthogonality (a*(y1-y2) + b*(x2-x1) == 0)
    1508         assert numpy.allclose(a[2] + 2*b[2], 0)
     1508        assert allclose(a[2] + 2*b[2], 0)
    15091509
    15101510
     
    15121512        #q3 = q1 + a*(x3-x1) + b*(y3-y1)  <=>
    15131513        #2  = 4  + a*(-2/3)  + b*(4/3)
    1514         assert numpy.allclose(a[3] - 2*b[3], 3)
     1514        assert allclose(a[3] - 2*b[3], 3)
    15151515        #From orthogonality (a*(y1-y3) + b*(x3-x1) == 0)
    1516         assert numpy.allclose(2*a[3] + b[3], 0)
     1516        assert allclose(2*a[3] + b[3], 0)
    15171517
    15181518
     
    15321532        #print a, b
    15331533
    1534         assert numpy.allclose(a[1], 3.0)
    1535         assert numpy.allclose(b[1], 1.0)
     1534        assert allclose(a[1], 3.0)
     1535        assert allclose(b[1], 1.0)
    15361536
    15371537        #Work out the others
     
    15401540
    15411541        #print quantity.vertex_values
    1542         assert numpy.allclose(quantity.vertex_values[1,0], 2.0)
    1543         assert numpy.allclose(quantity.vertex_values[1,1], 6.0)
    1544         assert numpy.allclose(quantity.vertex_values[1,2], 8.0)
     1542        assert allclose(quantity.vertex_values[1,0], 2.0)
     1543        assert allclose(quantity.vertex_values[1,1], 6.0)
     1544        assert allclose(quantity.vertex_values[1,2], 8.0)
    15451545
    15461546
     
    15501550
    15511551        #Set up for a gradient of (3,1), f(x) = 3x+y
    1552         c_values = numpy.array([2.0+2.0/3, 4.0+4.0/3, 8.0+2.0/3, 2.0+8.0/3])
    1553         d_values = numpy.array([1.0, 2.0, 3.0, 4.0])
     1552        c_values = array([2.0+2.0/3, 4.0+4.0/3, 8.0+2.0/3, 2.0+8.0/3])
     1553        d_values = array([1.0, 2.0, 3.0, 4.0])
    15541554        quantity.set_values(c_values, location = 'centroids')
    15551555
     
    15581558
    15591559        #print quantity.vertex_values
    1560         assert numpy.allclose(quantity.centroid_values, quantity.centroid_backup_values)
     1560        assert allclose(quantity.centroid_values, quantity.centroid_backup_values)
    15611561
    15621562
     
    15741574        #Test centroids
    15751575        quantity.set_values([1.,2.,3.,4.], location = 'centroids')
    1576         assert numpy.allclose(quantity.centroid_values, [1, 2, 3, 4]) #Centroid
     1576        assert allclose(quantity.centroid_values, [1, 2, 3, 4]) #Centroid
    15771577
    15781578        #Extrapolate
     
    15811581        #Check that gradient is zero
    15821582        a,b = quantity.get_gradients()
    1583         assert numpy.allclose(a, [0,0,0,0])
    1584         assert numpy.allclose(b, [0,0,0,0])
     1583        assert allclose(a, [0,0,0,0])
     1584        assert allclose(b, [0,0,0,0])
    15851585
    15861586        #Check vertices but not edge values
    1587         assert numpy.allclose(quantity.vertex_values,
    1588                               [[1,1,1], [2,2,2], [3,3,3], [4, 4, 4]])
     1587        assert allclose(quantity.vertex_values,
     1588                        [[1,1,1], [2,2,2], [3,3,3], [4, 4, 4]])
    15891589
    15901590
     
    16141614
    16151615        #Assert that quantities are conserved
     1616        from Numeric import sum
    16161617        for k in range(quantity.centroid_values.shape[0]):
    1617             assert numpy.allclose (quantity.centroid_values[k],
    1618                                    numpy.sum(quantity.vertex_values[k,:])/3)
     1618            assert allclose (quantity.centroid_values[k],
     1619                             sum(quantity.vertex_values[k,:])/3)
    16191620
    16201621
     
    16451646
    16461647        #Assert that quantities are conserved
     1648        from Numeric import sum
    16471649        for k in range(quantity.centroid_values.shape[0]):
    1648             assert numpy.allclose (quantity.centroid_values[k],
    1649                                    numpy.sum(quantity.vertex_values[k,:])/3)
     1650            assert allclose (quantity.centroid_values[k],
     1651                             sum(quantity.vertex_values[k,:])/3)
    16501652
    16511653
     
    16741676
    16751677        #Assert that quantities are conserved
     1678        from Numeric import sum
    16761679        for k in range(quantity.centroid_values.shape[0]):
    1677             assert numpy.allclose (quantity.centroid_values[k],
    1678                                    numpy.sum(quantity.vertex_values[k,:])/3)
     1680            assert allclose (quantity.centroid_values[k],
     1681                             sum(quantity.vertex_values[k,:])/3)
    16791682
    16801683
     
    17021705
    17031706        #Assert that quantities are conserved
     1707        from Numeric import sum
    17041708        for k in range(quantity.centroid_values.shape[0]):
    1705             assert numpy.allclose (quantity.centroid_values[k],
    1706                                    numpy.sum(quantity.vertex_values[k,:])/3)
     1709            assert allclose (quantity.centroid_values[k],
     1710                             sum(quantity.vertex_values[k,:])/3)
    17071711
    17081712    def test_limiter2(self):
     
    17141718        #Test centroids
    17151719        quantity.set_values([2.,4.,8.,2.], location = 'centroids')
    1716         assert numpy.allclose(quantity.centroid_values, [2, 4, 8, 2]) #Centroid
     1720        assert allclose(quantity.centroid_values, [2, 4, 8, 2]) #Centroid
    17171721
    17181722
     
    17201724        quantity.extrapolate_second_order()
    17211725
    1722         assert numpy.allclose(quantity.vertex_values[1,:], [0.0, 6, 6])
     1726        assert allclose(quantity.vertex_values[1,:], [0.0, 6, 6])
    17231727
    17241728        #Limit
     
    17271731        # limited value for beta_w = 0.9
    17281732       
    1729         assert numpy.allclose(quantity.vertex_values[1,:], [2.2, 4.9, 4.9])
     1733        assert allclose(quantity.vertex_values[1,:], [2.2, 4.9, 4.9])
    17301734        # limited values for beta_w = 0.5
    1731         #assert numpy.allclose(quantity.vertex_values[1,:], [3.0, 4.5, 4.5])
     1735        #assert allclose(quantity.vertex_values[1,:], [3.0, 4.5, 4.5])
    17321736
    17331737
    17341738        #Assert that quantities are conserved
     1739        from Numeric import sum
    17351740        for k in range(quantity.centroid_values.shape[0]):
    1736             assert numpy.allclose (quantity.centroid_values[k],
    1737                                    numpy.sum(quantity.vertex_values[k,:])/3)
     1741            assert allclose (quantity.centroid_values[k],
     1742                             sum(quantity.vertex_values[k,:])/3)
    17381743
    17391744
     
    17461751        #Test centroids
    17471752        quantity.set_values([1.,2.,3.,4.], location = 'centroids')
    1748         assert numpy.allclose(quantity.centroid_values, [1, 2, 3, 4]) #Centroid
     1753        assert allclose(quantity.centroid_values, [1, 2, 3, 4]) #Centroid
    17491754
    17501755
     
    17551760        #quantity.interpolate_from_vertices_to_edges()
    17561761
    1757         assert numpy.allclose(quantity.vertex_values,
    1758                               [[1,1,1], [2,2,2], [3,3,3], [4, 4, 4]])
    1759         assert numpy.allclose(quantity.edge_values, [[1,1,1], [2,2,2],
    1760                                                      [3,3,3], [4, 4, 4]])
     1762        assert allclose(quantity.vertex_values,
     1763                        [[1,1,1], [2,2,2], [3,3,3], [4, 4, 4]])
     1764        assert allclose(quantity.edge_values, [[1,1,1], [2,2,2],
     1765                                               [3,3,3], [4, 4, 4]])
    17611766
    17621767
     
    17641769        quantity = Quantity(self.mesh4)
    17651770
    1766         quantity.vertex_values = numpy.array([[1,0,2], [1,2,4], [4,2,5], [3,1,4]], numpy.float)
     1771        quantity.vertex_values = array([[1,0,2], [1,2,4], [4,2,5], [3,1,4]],Float)
    17671772
    17681773        quantity.interpolate_from_vertices_to_edges()
    17691774
    1770         assert numpy.allclose(quantity.edge_values, [[1., 1.5, 0.5],
    1771                                                      [3., 2.5, 1.5],
    1772                                                      [3.5, 4.5, 3.],
    1773                                                      [2.5, 3.5, 2]])
     1775        assert allclose(quantity.edge_values, [[1., 1.5, 0.5],
     1776                                               [3., 2.5, 1.5],
     1777                                               [3.5, 4.5, 3.],
     1778                                               [2.5, 3.5, 2]])
    17741779
    17751780
     
    17771782        quantity = Quantity(self.mesh4)
    17781783
    1779         quantity.edge_values = numpy.array([[1., 1.5, 0.5],
    1780                                             [3., 2.5, 1.5],
    1781                                             [3.5, 4.5, 3.],
    1782                                             [2.5, 3.5, 2]], numpy.float)
     1784        quantity.edge_values = array([[1., 1.5, 0.5],
     1785                                [3., 2.5, 1.5],
     1786                                [3.5, 4.5, 3.],
     1787                                [2.5, 3.5, 2]],Float)
    17831788
    17841789        quantity.interpolate_from_edges_to_vertices()
    17851790
    1786         assert numpy.allclose(quantity.vertex_values,
    1787                               [[1,0,2], [1,2,4], [4,2,5], [3,1,4]])
     1791        assert allclose(quantity.vertex_values,
     1792                        [[1,0,2], [1,2,4], [4,2,5], [3,1,4]])
    17881793
    17891794
     
    17941799        #Test centroids
    17951800        quantity.set_values([2.,4.,8.,2.], location = 'centroids')
    1796         assert numpy.allclose(quantity.centroid_values, [2, 4, 8, 2]) #Centroid
     1801        assert allclose(quantity.centroid_values, [2, 4, 8, 2]) #Centroid
    17971802
    17981803
     
    18001805        quantity.extrapolate_second_order()
    18011806
    1802         assert numpy.allclose(quantity.vertex_values[1,:], [0.0, 6, 6])
     1807        assert allclose(quantity.vertex_values[1,:], [0.0, 6, 6])
    18031808
    18041809
     
    18081813        #Test centroids
    18091814        quantity.set_values([1.,2.,3.,4.], location = 'centroids')
    1810         assert numpy.allclose(quantity.centroid_values, [1, 2, 3, 4]) #Centroid
     1815        assert allclose(quantity.centroid_values, [1, 2, 3, 4]) #Centroid
    18111816
    18121817        #Set explicit_update
    1813         quantity.explicit_update = numpy.array( [1.,1.,1.,1.] )
     1818        quantity.explicit_update = array( [1.,1.,1.,1.] )
    18141819
    18151820        #Update with given timestep
    18161821        quantity.update(0.1)
    18171822
    1818         x = numpy.array([1, 2, 3, 4]) + numpy.array( [.1,.1,.1,.1] )
    1819         assert numpy.allclose( quantity.centroid_values, x)
     1823        x = array([1, 2, 3, 4]) + array( [.1,.1,.1,.1] )
     1824        assert allclose( quantity.centroid_values, x)
    18201825
    18211826    def test_update_semi_implicit(self):
     
    18241829        #Test centroids
    18251830        quantity.set_values([1.,2.,3.,4.], location = 'centroids')
    1826         assert numpy.allclose(quantity.centroid_values, [1, 2, 3, 4]) #Centroid
     1831        assert allclose(quantity.centroid_values, [1, 2, 3, 4]) #Centroid
    18271832
    18281833        #Set semi implicit update
    1829         quantity.semi_implicit_update = numpy.array([1.,1.,1.,1.])
     1834        quantity.semi_implicit_update = array([1.,1.,1.,1.])
    18301835
    18311836        #Update with given timestep
     
    18331838        quantity.update(timestep)
    18341839
    1835         sem = numpy.array([1.,1.,1.,1.])/numpy.array([1, 2, 3, 4])
    1836         denom = numpy.ones(4, numpy.float)-timestep*sem
    1837 
    1838         x = numpy.array([1, 2, 3, 4])/denom
    1839         assert numpy.allclose( quantity.centroid_values, x)
     1840        sem = array([1.,1.,1.,1.])/array([1, 2, 3, 4])
     1841        denom = ones(4, Float)-timestep*sem
     1842
     1843        x = array([1, 2, 3, 4])/denom
     1844        assert allclose( quantity.centroid_values, x)
    18401845
    18411846
     
    18451850        #Test centroids
    18461851        quantity.set_values([1.,2.,3.,4.], location = 'centroids')
    1847         assert numpy.allclose(quantity.centroid_values, [1, 2, 3, 4]) #Centroid
     1852        assert allclose(quantity.centroid_values, [1, 2, 3, 4]) #Centroid
    18481853
    18491854        #Set explicit_update
    1850         quantity.explicit_update = numpy.array( [4.,3.,2.,1.] )
     1855        quantity.explicit_update = array( [4.,3.,2.,1.] )
    18511856
    18521857        #Set semi implicit update
    1853         quantity.semi_implicit_update = numpy.array( [1.,1.,1.,1.] )
     1858        quantity.semi_implicit_update = array( [1.,1.,1.,1.] )
    18541859
    18551860        #Update with given timestep
     
    18571862        quantity.update(0.1)
    18581863
    1859         sem = numpy.array([1.,1.,1.,1.])/numpy.array([1, 2, 3, 4])
    1860         denom = numpy.ones(4, numpy.float)-timestep*sem
    1861 
    1862         x = numpy.array([1., 2., 3., 4.])
     1864        sem = array([1.,1.,1.,1.])/array([1, 2, 3, 4])
     1865        denom = ones(4, Float)-timestep*sem
     1866
     1867        x = array([1., 2., 3., 4.])
    18631868        x /= denom
    1864         x += timestep*numpy.array( [4.0, 3.0, 2.0, 1.0] )
    1865 
    1866         assert numpy.allclose( quantity.centroid_values, x)
     1869        x += timestep*array( [4.0, 3.0, 2.0, 1.0] )
     1870
     1871        assert allclose( quantity.centroid_values, x)
    18671872
    18681873
     
    18741879        from mesh_factory import rectangular
    18751880        from shallow_water import Domain, Transmissive_boundary
     1881        from Numeric import zeros, Float
    18761882        from anuga.utilities.numerical_tools import mean
    18771883
     
    19001906
    19011907        bed = domain.quantities['elevation'].vertex_values
    1902         stage = numpy.zeros(bed.shape, numpy.float)
     1908        stage = zeros(bed.shape, Float)
    19031909
    19041910        h = 0.03
     
    19231929
    19241930        #First four points
    1925         assert numpy.allclose(A[0], (Q[0,2] + Q[1,1])/2)
    1926         assert numpy.allclose(A[1], (Q[1,0] + Q[3,1] + Q[2,2])/3)
    1927         assert numpy.allclose(A[2], Q[3,0])
    1928         assert numpy.allclose(A[3], (Q[0,0] + Q[5,1] + Q[4,2])/3)
     1931        assert allclose(A[0], (Q[0,2] + Q[1,1])/2)
     1932        assert allclose(A[1], (Q[1,0] + Q[3,1] + Q[2,2])/3)
     1933        assert allclose(A[2], Q[3,0])
     1934        assert allclose(A[3], (Q[0,0] + Q[5,1] + Q[4,2])/3)
    19291935
    19301936        #Center point
    1931         assert numpy.allclose(A[4], (Q[0,1] + Q[1,2] + Q[2,0] +\
    1932                                      Q[5,0] + Q[6,2] + Q[7,1])/6)
     1937        assert allclose(A[4], (Q[0,1] + Q[1,2] + Q[2,0] +\
     1938                               Q[5,0] + Q[6,2] + Q[7,1])/6)
    19331939
    19341940
    19351941        #Check V
    1936         assert numpy.allclose(V[0,:], [3,4,0])
    1937         assert numpy.allclose(V[1,:], [1,0,4])
    1938         assert numpy.allclose(V[2,:], [4,5,1])
    1939         assert numpy.allclose(V[3,:], [2,1,5])
    1940         assert numpy.allclose(V[4,:], [6,7,3])
    1941         assert numpy.allclose(V[5,:], [4,3,7])
    1942         assert numpy.allclose(V[6,:], [7,8,4])
    1943         assert numpy.allclose(V[7,:], [5,4,8])
     1942        assert allclose(V[0,:], [3,4,0])
     1943        assert allclose(V[1,:], [1,0,4])
     1944        assert allclose(V[2,:], [4,5,1])
     1945        assert allclose(V[3,:], [2,1,5])
     1946        assert allclose(V[4,:], [6,7,3])
     1947        assert allclose(V[5,:], [4,3,7])
     1948        assert allclose(V[6,:], [7,8,4])
     1949        assert allclose(V[7,:], [5,4,8])
    19441950
    19451951        #Get smoothed stage with XY
    19461952        X, Y, A1, V1 = stage.get_vertex_values(xy=True, smooth=True)
    19471953
    1948         assert numpy.allclose(A, A1)
    1949         assert numpy.allclose(V, V1)
     1954        assert allclose(A, A1)
     1955        assert allclose(V, V1)
    19501956
    19511957        #Check XY
    1952         assert numpy.allclose(X[4], 0.5)
    1953         assert numpy.allclose(Y[4], 0.5)
    1954 
    1955         assert numpy.allclose(X[7], 1.0)
    1956         assert numpy.allclose(Y[7], 0.5)
     1958        assert allclose(X[4], 0.5)
     1959        assert allclose(Y[4], 0.5)
     1960
     1961        assert allclose(X[7], 1.0)
     1962        assert allclose(Y[7], 0.5)
    19571963
    19581964
     
    19631969        from mesh_factory import rectangular
    19641970        from shallow_water import Domain, Transmissive_boundary
     1971        from Numeric import zeros, Float
    19651972        from anuga.utilities.numerical_tools import mean
    19661973
     
    19841991
    19851992        bed = domain.quantities['elevation'].vertex_values
    1986         stage = numpy.zeros(bed.shape, numpy.float)
     1993        stage = zeros(bed.shape, Float)
    19871994
    19881995        h = 0.03
     
    19982005        stage = domain.quantities['stage']
    19992006        A, V = stage.get_vertex_values(xy=False, smooth=False)
    2000         Q = stage.vertex_values.ravel()
     2007        Q = stage.vertex_values.flat
    20012008
    20022009        for k in range(8):
    2003             assert numpy.allclose(A[k], Q[k])
     2010            assert allclose(A[k], Q[k])
    20042011
    20052012
     
    20142021
    20152022
    2016         assert numpy.allclose(A, A1)
    2017         assert numpy.allclose(V, V1)
     2023        assert allclose(A, A1)
     2024        assert allclose(V, V1)
    20182025
    20192026        #Check XY
    2020         assert numpy.allclose(X[1], 0.5)
    2021         assert numpy.allclose(Y[1], 0.5)
    2022         assert numpy.allclose(X[4], 0.0)
    2023         assert numpy.allclose(Y[4], 0.0)
    2024         assert numpy.allclose(X[12], 1.0)
    2025         assert numpy.allclose(Y[12], 0.0)
     2027        assert allclose(X[1], 0.5)
     2028        assert allclose(Y[1], 0.5)
     2029        assert allclose(X[4], 0.0)
     2030        assert allclose(Y[4], 0.0)
     2031        assert allclose(X[12], 1.0)
     2032        assert allclose(Y[12], 0.0)
    20262033
    20272034
     
    20312038        from mesh_factory import rectangular
    20322039        from shallow_water import Domain
     2040        from Numeric import zeros, Float
    20332041
    20342042        #Create basic mesh
     
    20462054        #print "quantity.centroid_values",quantity.centroid_values
    20472055
    2048         assert numpy.allclose(quantity.centroid_values, [1,7])
     2056        assert allclose(quantity.centroid_values, [1,7])
    20492057
    20502058        quantity.set_array_values([15,20,25], indices = indices)
    2051         assert numpy.allclose(quantity.centroid_values, [1,20])
     2059        assert allclose(quantity.centroid_values, [1,20])
    20522060
    20532061        quantity.set_array_values([15,20,25], indices = indices)
    2054         assert numpy.allclose(quantity.centroid_values, [1,20])
     2062        assert allclose(quantity.centroid_values, [1,20])
    20552063
    20562064    def test_setting_some_vertex_values(self):
     
    20602068        from mesh_factory import rectangular
    20612069        from shallow_water import Domain
     2070        from Numeric import zeros, Float
    20622071
    20632072        #Create basic mesh
     
    20782087                            indices = indices)
    20792088        #print "quantity.centroid_values",quantity.centroid_values
    2080         assert numpy.allclose(quantity.centroid_values, [1,7,3,4,5,6])
     2089        assert allclose(quantity.centroid_values, [1,7,3,4,5,6])
    20812090       
    20822091        value = [7]
     
    20862095                            indices = indices)
    20872096        #print "quantity.centroid_values",quantity.centroid_values
    2088         assert numpy.allclose(quantity.centroid_values, [1,7,3,4,5,6])
     2097        assert allclose(quantity.centroid_values, [1,7,3,4,5,6])
    20892098
    20902099        value = [[15,20,25]]
    20912100        quantity.set_values(value, indices = indices)
    20922101        #print "1 quantity.vertex_values",quantity.vertex_values
    2093         assert numpy.allclose(quantity.vertex_values[1], value[0])
     2102        assert allclose(quantity.vertex_values[1], value[0])
    20942103
    20952104
     
    20982107        quantity.set_values(values, indices = [0,1,5], location = 'centroids')
    20992108        #print "2 quantity.vertex_values",quantity.vertex_values
    2100         assert numpy.allclose(quantity.vertex_values[0], [10,10,10])
    2101         assert numpy.allclose(quantity.vertex_values[5], [50,50,50])
     2109        assert allclose(quantity.vertex_values[0], [10,10,10])
     2110        assert allclose(quantity.vertex_values[5], [50,50,50])
    21022111        #quantity.interpolate()
    21032112        #print "quantity.centroid_values",quantity.centroid_values
    2104         assert numpy.allclose(quantity.centroid_values, [10,100,3,4,5,50])
     2113        assert allclose(quantity.centroid_values, [10,100,3,4,5,50])
    21052114
    21062115
     
    21122121        quantity.set_values(values, indices = [0,1,5])
    21132122        #print "quantity.vertex_values",quantity.vertex_values
    2114         assert numpy.allclose(quantity.vertex_values[0], [1,50,10])
    2115         assert numpy.allclose(quantity.vertex_values[5], [6,6,6])
    2116         assert numpy.allclose(quantity.vertex_values[1], [100,10,50])
     2123        assert allclose(quantity.vertex_values[0], [1,50,10])
     2124        assert allclose(quantity.vertex_values[5], [6,6,6])
     2125        assert allclose(quantity.vertex_values[1], [100,10,50])
    21172126
    21182127        quantity = Quantity(domain,[[1,1,1],[2,2,2],[3,3,3],
     
    21212130        quantity.set_values(values, indices = [3,3,5])
    21222131        quantity.interpolate()
    2123         assert numpy.allclose(quantity.centroid_values, [1,2,3,400,5,999])
     2132        assert allclose(quantity.centroid_values, [1,2,3,400,5,999])
    21242133
    21252134        values = [[1,1,1],[2,2,2],[3,3,3],
     
    21332142        quantity.set_values(values)
    21342143        #print "1 quantity.vertex_values",quantity.vertex_values
    2135         assert numpy.allclose(quantity.vertex_values,[[ 4.,  5.,  0.],
    2136                                                       [ 1.,  0.,  5.],
    2137                                                       [ 5.,  6.,  1.],
    2138                                                       [ 2.,  1.,  6.],
    2139                                                       [ 6.,  7.,  2.],
    2140                                                       [ 3.,  2.,  7.]])
     2144        assert allclose(quantity.vertex_values,[[ 4.,  5.,  0.],
     2145                                                [ 1.,  0.,  5.],
     2146                                                [ 5.,  6.,  1.],
     2147                                                [ 2.,  1.,  6.],
     2148                                                [ 6.,  7.,  2.],
     2149                                                [ 3.,  2.,  7.]])
    21412150
    21422151    def test_setting_unique_vertex_values(self):
     
    21462155        from mesh_factory import rectangular
    21472156        from shallow_water import Domain
     2157        from Numeric import zeros, Float
    21482158
    21492159        #Create basic mesh
     
    21612171                            indices = indices)
    21622172        #print "quantity.centroid_values",quantity.centroid_values
    2163         assert numpy.allclose(quantity.vertex_values[0], [0,7,0])
    2164         assert numpy.allclose(quantity.vertex_values[1], [7,1,7])
    2165         assert numpy.allclose(quantity.vertex_values[2], [7,2,7])
     2173        assert allclose(quantity.vertex_values[0], [0,7,0])
     2174        assert allclose(quantity.vertex_values[1], [7,1,7])
     2175        assert allclose(quantity.vertex_values[2], [7,2,7])
    21662176
    21672177
     
    21722182        from mesh_factory import rectangular
    21732183        from shallow_water import Domain
     2184        from Numeric import zeros, Float
    21742185
    21752186        #Create basic mesh
     
    21942205
    21952206        answer = [0.5,2,4,5,0,1,3,4.5]
    2196         assert numpy.allclose(answer,
    2197                               quantity.get_values(location = 'unique vertices'))
     2207        assert allclose(answer,
     2208                        quantity.get_values(location = 'unique vertices'))
    21982209
    21992210        indices = [0,5,3]
    22002211        answer = [0.5,1,5]
    2201         assert numpy.allclose(answer,
    2202                               quantity.get_values(indices=indices,
    2203                                                   location = 'unique vertices'))
     2212        assert allclose(answer,
     2213                        quantity.get_values(indices=indices, \
     2214                                            location = 'unique vertices'))
    22042215        #print "quantity.centroid_values",quantity.centroid_values
    22052216        #print "quantity.get_values(location = 'centroids') ",\
     
    22302241        quantity.set_values(lambda x, y: x+2*y) #2 4 4 6
    22312242       
    2232         assert numpy.allclose(quantity.get_values(location='centroids'), [2,4,4,6])
    2233         assert numpy.allclose(quantity.get_values(location='centroids', indices=[1,3]), [4,6])
    2234 
    2235 
    2236         assert numpy.allclose(quantity.get_values(location='vertices'), [[4,0,2],
    2237                                                                          [4,2,6],
    2238                                                                          [6,2,4],
    2239                                                                          [8,4,6]])
    2240        
    2241         assert numpy.allclose(quantity.get_values(location='vertices', indices=[1,3]), [[4,2,6],
    2242                                                                                         [8,4,6]])
    2243 
    2244 
    2245         assert numpy.allclose(quantity.get_values(location='edges'), [[1,3,2],
    2246                                                                       [4,5,3],
    2247                                                                       [3,5,4],
    2248                                                                       [5,7,6]])
    2249         assert numpy.allclose(quantity.get_values(location='edges', indices=[1,3]),
    2250                               [[4,5,3],
    2251                                [5,7,6]])       
     2243        assert allclose(quantity.get_values(location='centroids'), [2,4,4,6])
     2244        assert allclose(quantity.get_values(location='centroids', indices=[1,3]), [4,6])
     2245
     2246
     2247        assert allclose(quantity.get_values(location='vertices'), [[4,0,2],
     2248                                                                   [4,2,6],
     2249                                                                   [6,2,4],
     2250                                                                   [8,4,6]])
     2251       
     2252        assert allclose(quantity.get_values(location='vertices', indices=[1,3]), [[4,2,6],
     2253                                                                                  [8,4,6]])
     2254
     2255
     2256        assert allclose(quantity.get_values(location='edges'), [[1,3,2],
     2257                                                                [4,5,3],
     2258                                                                [3,5,4],
     2259                                                                [5,7,6]])
     2260        assert allclose(quantity.get_values(location='edges', indices=[1,3]),
     2261                        [[4,5,3],
     2262                         [5,7,6]])       
    22522263
    22532264        # Check averaging over vertices
     
    22692280        from mesh_factory import rectangular
    22702281        from shallow_water import Domain
     2282        from Numeric import zeros, Float
    22712283
    22722284        #Create basic mesh
     
    22862298       
    22872299        #print quantity.get_values(points=interpolation_points)
    2288         assert numpy.allclose(answer, quantity.get_values(interpolation_points=interpolation_points))
     2300        assert allclose(answer, quantity.get_values(interpolation_points=interpolation_points))
    22892301
    22902302
     
    22992311        #print answer
    23002312        #print quantity.get_values(interpolation_points=interpolation_points)
    2301         assert numpy.allclose(answer, quantity.get_values(interpolation_points=interpolation_points,
    2302                                                           verbose=False))       
     2313        assert allclose(answer, quantity.get_values(interpolation_points=interpolation_points,
     2314                                                    verbose=False))       
    23032315                       
    23042316
     
    23062318        #indices = [0,5,3]
    23072319        #answer = [0.5,1,5]
    2308         #assert numpy.allclose(answer,
    2309         #                      quantity.get_values(indices=indices,
    2310         #                                          location = 'unique vertices'))
     2320        #assert allclose(answer,
     2321        #                quantity.get_values(indices=indices, \
     2322        #                                    location = 'unique vertices'))
    23112323
    23122324
     
    23332345        x, y = 2.0/3, 8.0/3
    23342346        v = quantity.get_values(interpolation_points = [[x,y]])
    2335         assert numpy.allclose(v, 6)       
     2347        assert allclose(v, 6)       
    23362348
    23372349        # Then another to test that algorithm won't blindly
     
    23392351        x, y = 4.0/3, 4.0/3
    23402352        v = quantity.get_values(interpolation_points = [[x,y]])
    2341         assert numpy.allclose(v, 4)       
     2353        assert allclose(v, 4)       
    23422354
    23432355
     
    23682380        x, y = 2.0/3, 8.0/3
    23692381        v = quantity.get_values(interpolation_points = [[x+xllcorner,y+yllcorner]])
    2370         assert numpy.allclose(v, 6)
     2382        assert allclose(v, 6)
    23712383       
    23722384
     
    23752387        x, y = 4.0/3, 4.0/3
    23762388        v = quantity.get_values(interpolation_points = [[x+xllcorner,y+yllcorner]])
    2377         assert numpy.allclose(v, 4)       
     2389        assert allclose(v, 4)       
    23782390       
    23792391        # Try two points
     
    23812393               [4.0/3 + xllcorner, 4.0/3 + yllcorner]]         
    23822394        v = quantity.get_values(interpolation_points=pts)
    2383         assert numpy.allclose(v, [6, 4])               
     2395        assert allclose(v, [6, 4])               
    23842396       
    23852397        # Test it using the geospatial data format with absolute input points and default georef
    23862398        pts = Geospatial_data(data_points=pts)
    23872399        v = quantity.get_values(interpolation_points=pts)
    2388         assert numpy.allclose(v, [6, 4])                               
     2400        assert allclose(v, [6, 4])                               
    23892401       
    23902402       
     
    23932405                              geo_reference=Geo_reference(zone,xllcorner,yllcorner))
    23942406        v = quantity.get_values(interpolation_points=pts)
    2395         assert numpy.allclose(v, [6, 4])                       
     2407        assert allclose(v, [6, 4])                       
    23962408       
    23972409       
     
    24042416        from mesh_factory import rectangular
    24052417        from shallow_water import Domain
     2418        from Numeric import zeros, Float
    24062419
    24072420        #Create basic mesh
     
    24252438        #print "quantity.get_values(location = 'centroids') ",\
    24262439        #      quantity.get_values(location = 'centroids')
    2427         assert numpy.allclose(quantity.centroid_values,
    2428                               quantity.get_values(location = 'centroids'))
     2440        assert allclose(quantity.centroid_values,
     2441                        quantity.get_values(location = 'centroids'))
    24292442
    24302443
     
    24322445        quantity.set_values(value, indices = indices)
    24332446        #print "1 quantity.vertex_values",quantity.vertex_values
    2434         assert numpy.allclose(quantity.vertex_values, quantity.get_values())
    2435 
    2436         assert numpy.allclose(quantity.edge_values,
    2437                               quantity.get_values(location = 'edges'))
     2447        assert allclose(quantity.vertex_values, quantity.get_values())
     2448
     2449        assert allclose(quantity.edge_values,
     2450                        quantity.get_values(location = 'edges'))
    24382451
    24392452        # get a subset of elements
    24402453        subset = quantity.get_values(location='centroids', indices=[0,5])
    24412454        answer = [quantity.centroid_values[0],quantity.centroid_values[5]]
    2442         assert numpy.allclose(subset, answer)
     2455        assert allclose(subset, answer)
    24432456
    24442457
     
    24472460        #print "subset",subset
    24482461        #print "answer",answer
    2449         assert numpy.allclose(subset, answer)
     2462        assert allclose(subset, answer)
    24502463
    24512464        subset = quantity.get_values( indices=[1,5])
     
    24532466        #print "subset",subset
    24542467        #print "answer",answer
    2455         assert numpy.allclose(subset, answer)
     2468        assert allclose(subset, answer)
    24562469
    24572470    def test_smooth_vertex_values(self):
     
    24612474        from mesh_factory import rectangular
    24622475        from shallow_water import Domain
     2476        from Numeric import zeros, Float
    24632477
    24642478        #Create basic mesh
     
    24872501       
    24882502        #answer = [0.5, 2, 3, 3, 3.5, 4, 4, 5, 6.5]
    2489         #assert numpy.allclose(answer,
    2490         #                      quantity.get_values(location = 'unique vertices'))
     2503        #assert allclose(answer,
     2504        #                quantity.get_values(location = 'unique vertices'))
    24912505
    24922506        quantity.smooth_vertex_values()
     
    24982512                                [4,5,3],[3.5,3,5],[5,6.5,3.5],[4,3.5,6.5]]
    24992513       
    2500         assert numpy.allclose(answer_vertex_values,
    2501                               quantity.vertex_values)
     2514        assert allclose(answer_vertex_values,
     2515                        quantity.vertex_values)
    25022516        #print "quantity.centroid_values",quantity.centroid_values
    25032517        #print "quantity.get_values(location = 'centroids') ",\
     
    25092523if __name__ == "__main__":
    25102524    suite = unittest.makeSuite(Test_Quantity, 'test')   
    2511 #    suite = unittest.makeSuite(Test_Quantity, 'test_get_extrema_1')
     2525    #suite = unittest.makeSuite(Test_Quantity, 'test_set_values_from_file_using_polygon')
     2526
     2527    #suite = unittest.makeSuite(Test_Quantity, 'test_set_vertex_values_using_general_interface_with_subset')
     2528    #print "restricted test"
     2529    #suite = unittest.makeSuite(Test_Quantity,'verbose_test_set_values_from_UTM_pts')
    25122530    runner = unittest.TextTestRunner()
    25132531    runner.run(suite)
  • anuga_core/source/anuga/abstract_2d_finite_volumes/test_region.py

    r5892 r5897  
    66from domain import *
    77from region import *
    8 import numpy
    9 
     8#from anuga.config import epsilon
     9from Numeric import allclose, average #, array, ones, Float
    1010"""
    1111This is what the mesh in these tests look like;
     
    4444        from mesh_factory import rectangular
    4545        from shallow_water import Domain
     46        from Numeric import zeros, Float
    4647
    4748        #Create basic mesh
     
    6364        domain.set_region([a, b])
    6465        #print domain.quantities['friction'].get_values()
    65         assert numpy.allclose(domain.quantities['friction'].get_values(),
    66                               [[ 0.09,  0.09,  0.09],
    67                                [ 0.09,  0.09,  0.09],
    68                                [ 0.07,  0.07,  0.07],
    69                                [ 0.07,  0.07,  0.07],
    70                                [ 1.0,  1.0,  1.0],
    71                                [ 1.0,  1.0,  1.0]])
     66        assert allclose(domain.quantities['friction'].get_values(),\
     67                        [[ 0.09,  0.09,  0.09],
     68                         [ 0.09,  0.09,  0.09],
     69                         [ 0.07,  0.07,  0.07],
     70                         [ 0.07,  0.07,  0.07],
     71                         [ 1.0,  1.0,  1.0],
     72                         [ 1.0,  1.0,  1.0]])
    7273
    7374        #c = Add_Value_To_region('all', 'friction', 10.0)
    7475        domain.set_region(Add_value_to_region('all', 'friction', 10.0))
    7576        #print domain.quantities['friction'].get_values()
    76         assert numpy.allclose(domain.quantities['friction'].get_values(),
    77                               [[ 10.09, 10.09, 10.09],
    78                                [ 10.09, 10.09, 10.09],
    79                                [ 10.07, 10.07, 10.07],
    80                                [ 10.07, 10.07, 10.07],
    81                                [ 11.0,  11.0,  11.0],
    82                                [ 11.0,  11.0,  11.0]])
     77        assert allclose(domain.quantities['friction'].get_values(),
     78                        [[ 10.09, 10.09, 10.09],
     79                         [ 10.09, 10.09, 10.09],
     80                         [ 10.07, 10.07, 10.07],
     81                         [ 10.07, 10.07, 10.07],
     82                         [ 11.0,  11.0,  11.0],
     83                         [ 11.0,  11.0,  11.0]])
    8384
    8485        # trying a function
    8586        domain.set_region(Set_region('top', 'friction', add_x_y))
    8687        #print domain.quantities['friction'].get_values()
    87         assert numpy.allclose(domain.quantities['friction'].get_values(),
    88                               [[ 10.09, 10.09, 10.09],
    89                                [ 10.09, 10.09, 10.09],
    90                                [ 10.07, 10.07, 10.07],
    91                                [ 10.07, 10.07, 10.07],
    92                                [ 5./3,  2.0,  2./3],
    93                                [ 1.0,  2./3,  2.0]])
     88        assert allclose(domain.quantities['friction'].get_values(),
     89                        [[ 10.09, 10.09, 10.09],
     90                         [ 10.09, 10.09, 10.09],
     91                         [ 10.07, 10.07, 10.07],
     92                         [ 10.07, 10.07, 10.07],
     93                         [ 5./3,  2.0,  2./3],
     94                         [ 1.0,  2./3,  2.0]])
    9495
    9596        domain.set_quantity('elevation', 10.0)
     
    9798        domain.set_region(Add_value_to_region('top', 'stage', 1.0,initial_quantity='elevation'))
    9899        #print domain.quantities['stage'].get_values()
    99         assert numpy.allclose(domain.quantities['stage'].get_values(),
    100                               [[ 10., 10., 10.],
    101                                [ 10., 10., 10.],
    102                                [ 10., 10., 10.],
    103                                [ 10., 10., 10.],
    104                                [ 11.0,  11.0,  11.0],
    105                                [ 11.0,  11.0,  11.0]])
     100        assert allclose(domain.quantities['stage'].get_values(),
     101                        [[ 10., 10., 10.],
     102                         [ 10., 10., 10.],
     103                         [ 10., 10., 10.],
     104                         [ 10., 10., 10.],
     105                         [ 11.0,  11.0,  11.0],
     106                         [ 11.0,  11.0,  11.0]])
    106107
    107108       
     
    114115        domain.set_region(Add_quantities('top', 'elevation','stage'))
    115116        #print domain.quantities['stage'].get_values()
    116         assert numpy.allclose(domain.quantities['elevation'].get_values(),
    117                               [[ 10., 10., 10.],
    118                                [ 10., 10., 10.],
    119                                [ 10., 10., 10.],
    120                                [ 10., 10., 10.],
    121                                [ 33.,  33.0,  33.],
    122                                [ 33.0,  33.,  33.]])
     117        assert allclose(domain.quantities['elevation'].get_values(),
     118                        [[ 10., 10., 10.],
     119                         [ 10., 10., 10.],
     120                         [ 10., 10., 10.],
     121                         [ 10., 10., 10.],
     122                         [ 33.,  33.0,  33.],
     123                         [ 33.0,  33.,  33.]])
    123124       
    124125    def test_unique_vertices(self):
     
    128129        from mesh_factory import rectangular
    129130        from shallow_water import Domain
     131        from Numeric import zeros, Float
    130132
    131133        #Create basic mesh
     
    145147        domain.set_region(a)
    146148        #print domain.quantities['friction'].get_values()
    147         assert numpy.allclose(domain.quantities['friction'].get_values(),\
    148                               [[ 0.09,  0.09,  0.09],
    149                                [ 0.09,  0.09,  0.09],
    150                                [ 0.09,  0.07,  0.09],
    151                                [ 0.07,  0.09,  0.07],
    152                                [ 0.07,  0.07,  0.07],
    153                                [ 0.07,  0.07,  0.07]])
     149        assert allclose(domain.quantities['friction'].get_values(),\
     150                        [[ 0.09,  0.09,  0.09],
     151                         [ 0.09,  0.09,  0.09],
     152                         [ 0.09,  0.07,  0.09],
     153                         [ 0.07,  0.09,  0.07],
     154                         [ 0.07,  0.07,  0.07],
     155                         [ 0.07,  0.07,  0.07]])
    154156
    155157
     
    160162        from mesh_factory import rectangular
    161163        from shallow_water import Domain
     164        from Numeric import zeros, Float
    162165
    163166        #Create basic mesh
     
    177180
    178181        #print domain.quantities['friction'].get_values()
    179         assert numpy.allclose(domain.quantities['friction'].get_values(),\
    180                               [[ 1.07,  1.07,  1.07],
    181                                [ 1.07,  1.07,  1.07],
    182                                [ 1.07,  0.07,  1.07],
    183                                [ 0.07,  1.07,  0.07],
    184                                [ 0.07,  0.07,  0.07],
    185                                [ 0.07,  0.07,  0.07]])
     182        assert allclose(domain.quantities['friction'].get_values(),\
     183                        [[ 1.07,  1.07,  1.07],
     184                         [ 1.07,  1.07,  1.07],
     185                         [ 1.07,  0.07,  1.07],
     186                         [ 0.07,  1.07,  0.07],
     187                         [ 0.07,  0.07,  0.07],
     188                         [ 0.07,  0.07,  0.07]])
    186189                         
    187190    def test_unique_vertices_average_loc_vert(self):
     
    191194        from mesh_factory import rectangular
    192195        from shallow_water import Domain
     196        from Numeric import zeros, Float
    193197
    194198        #Create basic mesh
     
    214218        #print domain.quantities['friction'].get_values()
    215219        frict_points = domain.quantities['friction'].get_values()
    216         assert numpy.allclose(frict_points[0],
    217                               [ calc_frict, calc_frict, calc_frict])
    218         assert numpy.allclose(frict_points[1],
    219                               [ calc_frict, calc_frict, calc_frict])
     220        assert allclose(frict_points[0],\
     221                        [ calc_frict, calc_frict, calc_frict])
     222        assert allclose(frict_points[1],\
     223                        [ calc_frict, calc_frict, calc_frict])
    220224 
    221225    def test_unique_vertices_average_loc_unique_vert(self):
     
    225229        from mesh_factory import rectangular
    226230        from shallow_water import Domain
     231        from Numeric import zeros, Float
    227232
    228233        #Create basic mesh
     
    247252        #print domain.quantities['friction'].get_values()
    248253        frict_points = domain.quantities['friction'].get_values()
    249         assert numpy.allclose(frict_points[0],
    250                               [ calc_frict, calc_frict, calc_frict])
    251         assert numpy.allclose(frict_points[1],
    252                               [ calc_frict, calc_frict, calc_frict])
    253         assert numpy.allclose(frict_points[2],
    254                               [ calc_frict, 1.0 + 2.0/3.0, calc_frict])
    255         assert numpy.allclose(frict_points[3],
    256                               [ 2.0/3.0,calc_frict, 1.0 + 2.0/3.0])
     254        assert allclose(frict_points[0],\
     255                        [ calc_frict, calc_frict, calc_frict])
     256        assert allclose(frict_points[1],\
     257                        [ calc_frict, calc_frict, calc_frict])
     258        assert allclose(frict_points[2],\
     259                        [ calc_frict, 1.0 + 2.0/3.0, calc_frict])
     260        assert allclose(frict_points[3],\
     261                        [ 2.0/3.0,calc_frict, 1.0 + 2.0/3.0])
    257262                                               
    258263                         
     
    260265if __name__ == "__main__":
    261266    suite = unittest.makeSuite(Test_Region,'test')
    262 ##    suite = unittest.makeSuite(Test_Region,'test_unique_vertices_average_loc_unique_vert')
    263267    runner = unittest.TextTestRunner()
    264268    runner.run(suite)
  • anuga_core/source/anuga/abstract_2d_finite_volumes/test_util.py

    r5892 r5897  
    11#!/usr/bin/env python
    22
     3
    34import unittest
    4 import numpy
    5 
     5from Numeric import zeros, array, allclose, Float
    66from math import sqrt, pi
    77import tempfile, os
     
    9191
    9292            #Exact linear intpolation
    93             assert numpy.allclose(q[0], 2*t)
     93            assert allclose(q[0], 2*t)
    9494            if i%6 == 0:
    95                 assert numpy.allclose(q[1], t**2)
    96                 assert numpy.allclose(q[2], sin(t*pi/600))
     95                assert allclose(q[1], t**2)
     96                assert allclose(q[2], sin(t*pi/600))
    9797
    9898        #Check non-exact
     
    100100        t = 90 #Halfway between 60 and 120
    101101        q = F(t)
    102         assert numpy.allclose( (120**2 + 60**2)/2, q[1] )
    103         assert numpy.allclose( (sin(120*pi/600) + sin(60*pi/600))/2, q[2] )
     102        assert allclose( (120**2 + 60**2)/2, q[1] )
     103        assert allclose( (sin(120*pi/600) + sin(60*pi/600))/2, q[2] )
    104104
    105105
    106106        t = 100 #Two thirds of the way between between 60 and 120
    107107        q = F(t)
    108         assert numpy.allclose( 2*120**2/3 + 60**2/3, q[1] )
    109         assert numpy.allclose( 2*sin(120*pi/600)/3 + sin(60*pi/600)/3, q[2] )
     108        assert allclose( 2*120**2/3 + 60**2/3, q[1] )
     109        assert allclose( 2*sin(120*pi/600)/3 + sin(60*pi/600)/3, q[2] )
    110110
    111111        os.remove(filename + '.txt')
     
    125125        from shallow_water import Domain, Dirichlet_boundary
    126126        from mesh_factory import rectangular
     127        from Numeric import take, concatenate, reshape
    127128
    128129        #Create basic mesh and shallow water domain
     
    147148
    148149        # Boundary conditions
    149         print 'test_util: 0'
    150150        B0 = Dirichlet_boundary([0,0,0])
    151151        B6 = Dirichlet_boundary([0.6,0,0])
    152         print 'test_util: 1'
    153152        domain1.set_boundary({'left': B6, 'top': B6, 'right': B0, 'bottom': B0})
    154153        domain1.check_integrity()
    155         print 'test_util: 2'
    156154
    157155        finaltime = 8
    158156        #Evolution
    159157        t0 = -1
    160         print 'test_util: 3'
    161 # crash at following line
    162158        for t in domain1.evolve(yieldstep = 0.1, finaltime = finaltime):
    163             print 'test_util: 4'
    164159            #print 'Timesteps: %.16f, %.16f' %(t0, t)
    165160            #if t == t0:
     
    169164             
    170165            #domain1.write_time()
    171         print 'test_util: 5'
    172166
    173167
     
    188182
    189183        last_time_index = len(time)-1 #Last last_time_index
    190         d_stage = numpy.reshape(numpy.take(stage[last_time_index, :], [0,5,10,15], axis=0), (4,1))
    191         d_uh = numpy.reshape(numpy.take(xmomentum[last_time_index, :], [0,5,10,15], axis=0), (4,1))
    192         d_vh = numpy.reshape(numpy.take(ymomentum[last_time_index, :], [0,5,10,15], axis=0), (4,1))
    193         D = numpy.concatenate( (d_stage, d_uh, d_vh), axis=1)
     184        d_stage = reshape(take(stage[last_time_index, :], [0,5,10,15]), (4,1))
     185        d_uh = reshape(take(xmomentum[last_time_index, :], [0,5,10,15]), (4,1))
     186        d_vh = reshape(take(ymomentum[last_time_index, :], [0,5,10,15]), (4,1))
     187        D = concatenate( (d_stage, d_uh, d_vh), axis=1)
    194188
    195189        #Reference interpolated values at midpoints on diagonal at
     
    200194
    201195        #And the midpoints are found now
    202         Dx = numpy.take(numpy.reshape(x, (16,1)), [0,5,10,15], axis=0)
    203         Dy = numpy.take(numpy.reshape(y, (16,1)), [0,5,10,15], axis=0)
    204 
    205         diag = numpy.concatenate( (Dx, Dy), axis=1)
     196        Dx = take(reshape(x, (16,1)), [0,5,10,15])
     197        Dy = take(reshape(y, (16,1)), [0,5,10,15])
     198
     199        diag = concatenate( (Dx, Dy), axis=1)
    206200        d_midpoints = (diag[1:] + diag[:-1])/2
    207201
     
    215209        assert not T[-1] == T[-2], msg
    216210        t = time[last_time_index]
    217         q = f(t, point_id=0); assert numpy.allclose(r0, q)
    218         q = f(t, point_id=1); assert numpy.allclose(r1, q)
    219         q = f(t, point_id=2); assert numpy.allclose(r2, q)
     211        q = f(t, point_id=0); assert allclose(r0, q)
     212        q = f(t, point_id=1); assert allclose(r1, q)
     213        q = f(t, point_id=2); assert allclose(r2, q)
    220214
    221215
     
    224218
    225219        timestep = 0 #First timestep
    226         d_stage = numpy.reshape(numpy.take(stage[timestep, :], [0,5,10,15], axis=0), (4,1))
    227         d_uh = numpy.reshape(numpy.take(xmomentum[timestep, :], [0,5,10,15], axis=0), (4,1))
    228         d_vh = numpy.reshape(numpy.take(ymomentum[timestep, :], [0,5,10,15], axis=0), (4,1))
    229         D = numpy.concatenate( (d_stage, d_uh, d_vh), axis=1)
     220        d_stage = reshape(take(stage[timestep, :], [0,5,10,15]), (4,1))
     221        d_uh = reshape(take(xmomentum[timestep, :], [0,5,10,15]), (4,1))
     222        d_vh = reshape(take(ymomentum[timestep, :], [0,5,10,15]), (4,1))
     223        D = concatenate( (d_stage, d_uh, d_vh), axis=1)
    230224
    231225        #Reference interpolated values at midpoints on diagonal at
     
    237231        #Let us see if the file function can find the correct
    238232        #values
    239         q = f(0, point_id=0); assert numpy.allclose(r0, q)
    240         q = f(0, point_id=1); assert numpy.allclose(r1, q)
    241         q = f(0, point_id=2); assert numpy.allclose(r2, q)
     233        q = f(0, point_id=0); assert allclose(r0, q)
     234        q = f(0, point_id=1); assert allclose(r1, q)
     235        q = f(0, point_id=2); assert allclose(r2, q)
    242236
    243237
     
    246240
    247241        timestep = 33
    248         d_stage = numpy.reshape(numpy.take(stage[timestep, :], [0,5,10,15], axis=0), (4,1))
    249         d_uh = numpy.reshape(numpy.take(xmomentum[timestep, :], [0,5,10,15], axis=0), (4,1))
    250         d_vh = numpy.reshape(numpy.take(ymomentum[timestep, :], [0,5,10,15], axis=0), (4,1))
    251         D = numpy.concatenate( (d_stage, d_uh, d_vh), axis=1)
     242        d_stage = reshape(take(stage[timestep, :], [0,5,10,15]), (4,1))
     243        d_uh = reshape(take(xmomentum[timestep, :], [0,5,10,15]), (4,1))
     244        d_vh = reshape(take(ymomentum[timestep, :], [0,5,10,15]), (4,1))
     245        D = concatenate( (d_stage, d_uh, d_vh), axis=1)
    252246
    253247        #Reference interpolated values at midpoints on diagonal at
     
    257251        r2 = (D[2] + D[3])/2
    258252
    259         q = f(timestep/10., point_id=0); assert numpy.allclose(r0, q)
    260         q = f(timestep/10., point_id=1); assert numpy.allclose(r1, q)
    261         q = f(timestep/10., point_id=2); assert numpy.allclose(r2, q)
     253        q = f(timestep/10., point_id=0); assert allclose(r0, q)
     254        q = f(timestep/10., point_id=1); assert allclose(r1, q)
     255        q = f(timestep/10., point_id=2); assert allclose(r2, q)
    262256
    263257
     
    267261
    268262        timestep = 15
    269         d_stage = numpy.reshape(numpy.take(stage[timestep, :], [0,5,10,15], axis=0), (4,1))
    270         d_uh = numpy.reshape(numpy.take(xmomentum[timestep, :], [0,5,10,15], axis=0), (4,1))
    271         d_vh = numpy.reshape(numpy.take(ymomentum[timestep, :], [0,5,10,15], axis=0), (4,1))
    272         D = numpy.concatenate( (d_stage, d_uh, d_vh), axis=1)
     263        d_stage = reshape(take(stage[timestep, :], [0,5,10,15]), (4,1))
     264        d_uh = reshape(take(xmomentum[timestep, :], [0,5,10,15]), (4,1))
     265        d_vh = reshape(take(ymomentum[timestep, :], [0,5,10,15]), (4,1))
     266        D = concatenate( (d_stage, d_uh, d_vh), axis=1)
    273267
    274268        #Reference interpolated values at midpoints on diagonal at
     
    280274        #
    281275        timestep = 16
    282         d_stage = numpy.reshape(numpy.take(stage[timestep, :], [0,5,10,15], axis=0), (4,1))
    283         d_uh = numpy.reshape(numpy.take(xmomentum[timestep, :], [0,5,10,15], axis=0), (4,1))
    284         d_vh = numpy.reshape(numpy.take(ymomentum[timestep, :], [0,5,10,15], axis=0), (4,1))
    285         D = numpy.concatenate( (d_stage, d_uh, d_vh), axis=1)
     276        d_stage = reshape(take(stage[timestep, :], [0,5,10,15]), (4,1))
     277        d_uh = reshape(take(xmomentum[timestep, :], [0,5,10,15]), (4,1))
     278        d_vh = reshape(take(ymomentum[timestep, :], [0,5,10,15]), (4,1))
     279        D = concatenate( (d_stage, d_uh, d_vh), axis=1)
    286280
    287281        #Reference interpolated values at midpoints on diagonal at
     
    296290        r2 = (r2_0 + r2_1)/2
    297291
    298         q = f((timestep - 0.5)/10., point_id=0); assert numpy.allclose(r0, q)
    299         q = f((timestep - 0.5)/10., point_id=1); assert numpy.allclose(r1, q)
    300         q = f((timestep - 0.5)/10., point_id=2); assert numpy.allclose(r2, q)
     292        q = f((timestep - 0.5)/10., point_id=0); assert allclose(r0, q)
     293        q = f((timestep - 0.5)/10., point_id=1); assert allclose(r1, q)
     294        q = f((timestep - 0.5)/10., point_id=2); assert allclose(r2, q)
    301295
    302296        ##################
     
    310304
    311305        #And the file function gives
    312         q = f((timestep - 1.0/3)/10., point_id=0); assert numpy.allclose(r0, q)
    313         q = f((timestep - 1.0/3)/10., point_id=1); assert numpy.allclose(r1, q)
    314         q = f((timestep - 1.0/3)/10., point_id=2); assert numpy.allclose(r2, q)
     306        q = f((timestep - 1.0/3)/10., point_id=0); assert allclose(r0, q)
     307        q = f((timestep - 1.0/3)/10., point_id=1); assert allclose(r1, q)
     308        q = f((timestep - 1.0/3)/10., point_id=2); assert allclose(r2, q)
    315309
    316310        fid.close()
     
    332326        from shallow_water import Domain, Dirichlet_boundary
    333327        from mesh_factory import rectangular
     328        from Numeric import take, concatenate, reshape
    334329
    335330
     
    391386
    392387        last_time_index = len(time)-1 #Last last_time_index     
    393         d_stage = numpy.reshape(take(stage[last_time_index, :], [0,5,10,15]), (4,1))
    394         d_uh = numpy.reshape(take(xmomentum[last_time_index, :], [0,5,10,15]), (4,1))
    395         d_vh = numpy.reshape(take(ymomentum[last_time_index, :], [0,5,10,15]), (4,1))
    396         D = numpy.concatenate( (d_stage, d_uh, d_vh), axis=1)
     388        d_stage = reshape(take(stage[last_time_index, :], [0,5,10,15]), (4,1))
     389        d_uh = reshape(take(xmomentum[last_time_index, :], [0,5,10,15]), (4,1))
     390        d_vh = reshape(take(ymomentum[last_time_index, :], [0,5,10,15]), (4,1))
     391        D = concatenate( (d_stage, d_uh, d_vh), axis=1)
    397392
    398393        #Reference interpolated values at midpoints on diagonal at
     
    403398
    404399        #And the midpoints are found now
    405         Dx = take(numpy.reshape(x, (16,1)), [0,5,10,15])
    406         Dy = take(numpy.reshape(y, (16,1)), [0,5,10,15])
    407 
    408         diag = numpy.concatenate( (Dx, Dy), axis=1)
     400        Dx = take(reshape(x, (16,1)), [0,5,10,15])
     401        Dy = take(reshape(y, (16,1)), [0,5,10,15])
     402
     403        diag = concatenate( (Dx, Dy), axis=1)
    409404        d_midpoints = (diag[1:] + diag[:-1])/2
    410405
     
    420415
    421416        t = time[last_time_index]                         
    422         q = f(t, point_id=0); assert numpy.allclose(r0, q)
    423         q = f(t, point_id=1); assert numpy.allclose(r1, q)
    424         q = f(t, point_id=2); assert numpy.allclose(r2, q)
     417        q = f(t, point_id=0); assert allclose(r0, q)
     418        q = f(t, point_id=1); assert allclose(r1, q)
     419        q = f(t, point_id=2); assert allclose(r2, q)
    425420
    426421
     
    429424
    430425        timestep = 0 #First timestep
    431         d_stage = numpy.reshape(take(stage[timestep, :], [0,5,10,15]), (4,1))
    432         d_uh = numpy.reshape(take(xmomentum[timestep, :], [0,5,10,15]), (4,1))
    433         d_vh = numpy.reshape(take(ymomentum[timestep, :], [0,5,10,15]), (4,1))
    434         D = numpy.concatenate( (d_stage, d_uh, d_vh), axis=1)
     426        d_stage = reshape(take(stage[timestep, :], [0,5,10,15]), (4,1))
     427        d_uh = reshape(take(xmomentum[timestep, :], [0,5,10,15]), (4,1))
     428        d_vh = reshape(take(ymomentum[timestep, :], [0,5,10,15]), (4,1))
     429        D = concatenate( (d_stage, d_uh, d_vh), axis=1)
    435430
    436431        #Reference interpolated values at midpoints on diagonal at
     
    442437        #Let us see if the file function can find the correct
    443438        #values
    444         q = f(0, point_id=0); assert numpy.allclose(r0, q)
    445         q = f(0, point_id=1); assert numpy.allclose(r1, q)
    446         q = f(0, point_id=2); assert numpy.allclose(r2, q)
     439        q = f(0, point_id=0); assert allclose(r0, q)
     440        q = f(0, point_id=1); assert allclose(r1, q)
     441        q = f(0, point_id=2); assert allclose(r2, q)
    447442
    448443
     
    451446
    452447        timestep = 33
    453         d_stage = numpy.reshape(take(stage[timestep, :], [0,5,10,15]), (4,1))
    454         d_uh = numpy.reshape(take(xmomentum[timestep, :], [0,5,10,15]), (4,1))
    455         d_vh = numpy.reshape(take(ymomentum[timestep, :], [0,5,10,15]), (4,1))
    456         D = numpy.concatenate( (d_stage, d_uh, d_vh), axis=1)
     448        d_stage = reshape(take(stage[timestep, :], [0,5,10,15]), (4,1))
     449        d_uh = reshape(take(xmomentum[timestep, :], [0,5,10,15]), (4,1))
     450        d_vh = reshape(take(ymomentum[timestep, :], [0,5,10,15]), (4,1))
     451        D = concatenate( (d_stage, d_uh, d_vh), axis=1)
    457452
    458453        #Reference interpolated values at midpoints on diagonal at
     
    462457        r2 = (D[2] + D[3])/2
    463458
    464         q = f(timestep/10., point_id=0); assert numpy.allclose(r0, q)
    465         q = f(timestep/10., point_id=1); assert numpy.allclose(r1, q)
    466         q = f(timestep/10., point_id=2); assert numpy.allclose(r2, q)
     459        q = f(timestep/10., point_id=0); assert allclose(r0, q)
     460        q = f(timestep/10., point_id=1); assert allclose(r1, q)
     461        q = f(timestep/10., point_id=2); assert allclose(r2, q)
    467462
    468463
     
    472467
    473468        timestep = 15
    474         d_stage = numpy.reshape(take(stage[timestep, :], [0,5,10,15]), (4,1))
    475         d_uh = numpy.reshape(take(xmomentum[timestep, :], [0,5,10,15]), (4,1))
    476         d_vh = numpy.reshape(take(ymomentum[timestep, :], [0,5,10,15]), (4,1))
    477         D = numpy.concatenate( (d_stage, d_uh, d_vh), axis=1)
     469        d_stage = reshape(take(stage[timestep, :], [0,5,10,15]), (4,1))
     470        d_uh = reshape(take(xmomentum[timestep, :], [0,5,10,15]), (4,1))
     471        d_vh = reshape(take(ymomentum[timestep, :], [0,5,10,15]), (4,1))
     472        D = concatenate( (d_stage, d_uh, d_vh), axis=1)
    478473
    479474        #Reference interpolated values at midpoints on diagonal at
     
    485480        #
    486481        timestep = 16
    487         d_stage = numpy.reshape(take(stage[timestep, :], [0,5,10,15]), (4,1))
    488         d_uh = numpy.reshape(take(xmomentum[timestep, :], [0,5,10,15]), (4,1))
    489         d_vh = numpy.reshape(take(ymomentum[timestep, :], [0,5,10,15]), (4,1))
    490         D = numpy.concatenate( (d_stage, d_uh, d_vh), axis=1)
     482        d_stage = reshape(take(stage[timestep, :], [0,5,10,15]), (4,1))
     483        d_uh = reshape(take(xmomentum[timestep, :], [0,5,10,15]), (4,1))
     484        d_vh = reshape(take(ymomentum[timestep, :], [0,5,10,15]), (4,1))
     485        D = concatenate( (d_stage, d_uh, d_vh), axis=1)
    491486
    492487        #Reference interpolated values at midpoints on diagonal at
     
    501496        r2 = (r2_0 + r2_1)/2
    502497
    503         q = f((timestep - 0.5)/10., point_id=0); assert numpy.allclose(r0, q)
    504         q = f((timestep - 0.5)/10., point_id=1); assert numpy.allclose(r1, q)
    505         q = f((timestep - 0.5)/10., point_id=2); assert numpy.allclose(r2, q)
     498        q = f((timestep - 0.5)/10., point_id=0); assert allclose(r0, q)
     499        q = f((timestep - 0.5)/10., point_id=1); assert allclose(r1, q)
     500        q = f((timestep - 0.5)/10., point_id=2); assert allclose(r2, q)
    506501
    507502        ##################
     
    515510
    516511        #And the file function gives
    517         q = f((timestep - 1.0/3)/10., point_id=0); assert numpy.allclose(r0, q)
    518         q = f((timestep - 1.0/3)/10., point_id=1); assert numpy.allclose(r1, q)
    519         q = f((timestep - 1.0/3)/10., point_id=2); assert numpy.allclose(r2, q)
     512        q = f((timestep - 1.0/3)/10., point_id=0); assert allclose(r0, q)
     513        q = f((timestep - 1.0/3)/10., point_id=1); assert allclose(r1, q)
     514        q = f((timestep - 1.0/3)/10., point_id=2); assert allclose(r2, q)
    520515
    521516        fid.close()
     
    547542        import os, time
    548543        from anuga.config import time_format
     544        from Numeric import sin, pi, exp
    549545        from mesh_factory import rectangular
    550546        from shallow_water import Domain
     
    588584            domain.set_quantity('xmomentum', f2)
    589585
    590             f3 = lambda x,y: x**2 + y**2 * numpy.sin(t*numpy.pi/600)
     586            f3 = lambda x,y: x**2 + y**2 * sin(t*pi/600)
    591587            domain.set_quantity('ymomentum', f3)
    592588
     
    608604
    609605        #Check that FF updates fixes domain starttime
    610         assert numpy.allclose(domain.starttime, start)
     606        assert allclose(domain.starttime, start)
    611607
    612608        #Check that domain.starttime isn't updated if later
     
    615611                          quantities = domain.conserved_quantities,
    616612                          interpolation_points = interpolation_points)
    617         assert numpy.allclose(domain.starttime, start+1)
     613        assert allclose(domain.starttime, start+1)
    618614        domain.starttime = start
    619615
     
    649645                     self.failUnless( q == actual, 'Fail!')
    650646                else:
    651                     assert numpy.allclose(q, actual)
     647                    assert allclose(q, actual)
    652648
    653649
     
    659655            t = 90 #Halfway between 60 and 120
    660656            q = F(t, point_id=id)
    661             assert numpy.allclose( (q120+q60)/2, q )
     657            assert allclose( (q120+q60)/2, q )
    662658
    663659            t = 100 #Two thirds of the way between between 60 and 120
    664660            q = F(t, point_id=id)
    665             assert numpy.allclose(q60/3 + 2*q120/3, q)
     661            assert allclose(q60/3 + 2*q120/3, q)
    666662
    667663
     
    674670                          quantities = domain.conserved_quantities,
    675671                          interpolation_points = interpolation_points)
    676         assert numpy.allclose(domain.starttime, start+delta)
     672        assert allclose(domain.starttime, start+delta)
    677673
    678674
     
    693689
    694690                q = F(t-delta, point_id=id)
    695                 assert numpy.allclose(q, (k*q1 + (6-k)*q0)/6)
     691                assert allclose(q, (k*q1 + (6-k)*q0)/6)
    696692
    697693
     
    707703        import os, time
    708704        from anuga.config import time_format
     705        from Numeric import sin, pi, exp
    709706        from mesh_factory import rectangular
    710707        from shallow_water import Domain
     
    754751            domain.set_quantity('xmomentum', f2)
    755752
    756             f3 = lambda x,y: x**2 + y**2 * numpy.sin(t*numpy.pi/600)
     753            f3 = lambda x,y: x**2 + y**2 * sin(t*pi/600)
    757754            domain.set_quantity('ymomentum', f3)
    758755
     
    777774
    778775        #Check that FF updates fixes domain starttime
    779         assert numpy.allclose(domain.starttime, start)
     776        assert allclose(domain.starttime, start)
    780777
    781778        #Check that domain.starttime isn't updated if later
     
    784781                          quantities = domain.conserved_quantities,
    785782                          interpolation_points = interpolation_points)
    786         assert numpy.allclose(domain.starttime, start+1)
     783        assert allclose(domain.starttime, start+1)
    787784        domain.starttime = start
    788785
     
    820817                     self.failUnless( q == actual, 'Fail!')
    821818                else:
    822                     assert numpy.allclose(q, actual)
     819                    assert allclose(q, actual)
    823820
    824821        # now lets check points inside the mesh
     
    866863                     self.failUnless( q == actual, 'Fail!')
    867864                else:
    868                     assert numpy.allclose(q, actual)
     865                    assert allclose(q, actual)
    869866
    870867
     
    876873            t = 90 #Halfway between 60 and 120
    877874            q = F(t, point_id=id)
    878             assert numpy.allclose( (q120+q60)/2, q )
     875            assert allclose( (q120+q60)/2, q )
    879876
    880877            t = 100 #Two thirds of the way between between 60 and 120
    881878            q = F(t, point_id=id)
    882             assert numpy.allclose(q60/3 + 2*q120/3, q)
     879            assert allclose(q60/3 + 2*q120/3, q)
    883880
    884881
     
    891888                          quantities = domain.conserved_quantities,
    892889                          interpolation_points = interpolation_points)
    893         assert numpy.allclose(domain.starttime, start+delta)
     890        assert allclose(domain.starttime, start+delta)
    894891
    895892
     
    910907
    911908                q = F(t-delta, point_id=id)
    912                 assert numpy.allclose(q, (k*q1 + (6-k)*q0)/6)
     909                assert allclose(q, (k*q1 + (6-k)*q0)/6)
    913910
    914911
     
    958955                          domain,
    959956                          quantities = ['Attribute0', 'Attribute1', 'Attribute2']) 
    960         assert numpy.allclose(domain.starttime, start)
     957        assert allclose(domain.starttime, start)
    961958
    962959        # Check that domain.starttime is updated if too early
     
    965962                          domain,
    966963                          quantities = ['Attribute0', 'Attribute1', 'Attribute2'])
    967         assert numpy.allclose(domain.starttime, start)
     964        assert allclose(domain.starttime, start)
    968965
    969966        # Check that domain.starttime isn't updated if later
     
    972969                          domain,
    973970                          quantities = ['Attribute0', 'Attribute1', 'Attribute2'])
    974         assert numpy.allclose(domain.starttime, start+1)
     971        assert allclose(domain.starttime, start+1)
    975972
    976973        domain.starttime = start
     
    990987
    991988            #Exact linear intpolation
    992             assert numpy.allclose(q[0], 2*t)
     989            assert allclose(q[0], 2*t)
    993990            if i%6 == 0:
    994                 assert numpy.allclose(q[1], t**2)
    995                 assert numpy.allclose(q[2], sin(t*pi/600))
     991                assert allclose(q[1], t**2)
     992                assert allclose(q[2], sin(t*pi/600))
    996993
    997994        #Check non-exact
     
    999996        t = 90 #Halfway between 60 and 120
    1000997        q = F(t)
    1001         assert numpy.allclose( (120**2 + 60**2)/2, q[1] )
    1002         assert numpy.allclose( (sin(120*pi/600) + sin(60*pi/600))/2, q[2] )
     998        assert allclose( (120**2 + 60**2)/2, q[1] )
     999        assert allclose( (sin(120*pi/600) + sin(60*pi/600))/2, q[2] )
    10031000
    10041001
    10051002        t = 100 #Two thirds of the way between between 60 and 120
    10061003        q = F(t)
    1007         assert numpy.allclose( 2*120**2/3 + 60**2/3, q[1] )
    1008         assert numpy.allclose( 2*sin(120*pi/600)/3 + sin(60*pi/600)/3, q[2] )
     1004        assert allclose( 2*120**2/3 + 60**2/3, q[1] )
     1005        assert allclose( 2*sin(120*pi/600)/3 + sin(60*pi/600)/3, q[2] )
    10091006
    10101007        os.remove(filename + '.tms')
     
    10551052        F = file_function(filename + '.tms', domain,
    10561053                          quantities = ['Attribute0', 'Attribute1', 'Attribute2'])       
    1057         assert numpy.allclose(domain.starttime, start+delta)
     1054        assert allclose(domain.starttime, start+delta)
    10581055
    10591056
     
    10661063
    10671064            #Exact linear intpolation
    1068             assert numpy.allclose(q[0], 2*t)
     1065            assert allclose(q[0], 2*t)
    10691066            if i%6 == 0:
    1070                 assert numpy.allclose(q[1], t**2)
    1071                 assert numpy.allclose(q[2], sin(t*pi/600))
     1067                assert allclose(q[1], t**2)
     1068                assert allclose(q[2], sin(t*pi/600))
    10721069
    10731070        #Check non-exact
     
    10751072        t = 90 #Halfway between 60 and 120
    10761073        q = F(t-delta)
    1077         assert numpy.allclose( (120**2 + 60**2)/2, q[1] )
    1078         assert numpy.allclose( (sin(120*pi/600) + sin(60*pi/600))/2, q[2] )
     1074        assert allclose( (120**2 + 60**2)/2, q[1] )
     1075        assert allclose( (sin(120*pi/600) + sin(60*pi/600))/2, q[2] )
    10791076
    10801077
    10811078        t = 100 #Two thirds of the way between between 60 and 120
    10821079        q = F(t-delta)
    1083         assert numpy.allclose( 2*120**2/3 + 60**2/3, q[1] )
    1084         assert numpy.allclose( 2*sin(120*pi/600)/3 + sin(60*pi/600)/3, q[2] )
     1080        assert allclose( 2*120**2/3 + 60**2/3, q[1] )
     1081        assert allclose( 2*sin(120*pi/600)/3 + sin(60*pi/600)/3, q[2] )
    10851082
    10861083
     
    10941091        #FIXME: Division is not expected to work for integers.
    10951092        #This must be caught.
    1096         foo = numpy.array([[1,2,3], [4,5,6]], numpy.float)
    1097 
    1098         bar = numpy.array([[-1,0,5], [6,1,1]], numpy.float)                 
     1093        foo = array([[1,2,3],
     1094                     [4,5,6]], Float)
     1095
     1096        bar = array([[-1,0,5],
     1097                     [6,1,1]], Float)                 
    10991098
    11001099        D = {'X': foo, 'Y': bar}
    11011100
    11021101        Z = apply_expression_to_dictionary('X+Y', D)       
    1103         assert numpy.allclose(Z, foo+bar)
     1102        assert allclose(Z, foo+bar)
    11041103
    11051104        Z = apply_expression_to_dictionary('X*Y', D)       
    1106         assert numpy.allclose(Z, foo*bar)       
     1105        assert allclose(Z, foo*bar)       
    11071106
    11081107        Z = apply_expression_to_dictionary('4*X+Y', D)       
    1109         assert numpy.allclose(Z, 4*foo+bar)       
     1108        assert allclose(Z, 4*foo+bar)       
    11101109
    11111110        # test zero division is OK
    11121111        Z = apply_expression_to_dictionary('X/Y', D)
    1113         assert numpy.allclose(1/Z, 1/(foo/bar)) # can't compare inf to inf
     1112        assert allclose(1/Z, 1/(foo/bar)) # can't compare inf to inf
    11141113
    11151114        # make an error for zero on zero
     
    12691268        tris = [[0,1,2]]
    12701269        new_verts, new_tris = remove_lone_verts(verts, tris)
    1271         assert numpy.alltrue(new_verts == verts)
    1272         assert numpy.alltrue(new_tris == tris)
     1270        assert new_verts == verts
     1271        assert new_tris == tris
    12731272     
    12741273
     
    12851284        new_verts, new_tris = remove_lone_verts(verts, tris)
    12861285        #print "new_verts", new_verts
    1287         assert numpy.alltrue(new_verts == [[0,0],[1,0],[0,1]])
    1288         assert numpy.alltrue(new_tris == [[0,1,2]])
     1286        assert new_verts == [[0,0],[1,0],[0,1]]
     1287        assert new_tris == [[0,1,2]]
    12891288     
    12901289    def test_remove_lone_verts_c(self):
     
    12921291        tris = [[0,1,3]]
    12931292        new_verts, new_tris = remove_lone_verts(verts, tris)
    1294         print "new_verts", new_verts
    1295         assert numpy.alltrue(new_verts == [[0,0],[1,0],[0,1]])
    1296         assert numpy.alltrue(new_tris == [[0,1,2]])
     1293        #print "new_verts", new_verts
     1294        assert new_verts == [[0,0],[1,0],[0,1]]
     1295        assert new_tris == [[0,1,2]]
    12971296       
    12981297    def test_remove_lone_verts_b(self):
     
    13001299        tris = [[0,1,2]]
    13011300        new_verts, new_tris = remove_lone_verts(verts, tris)
    1302         assert numpy.alltrue(new_verts == verts[0:3])
    1303         assert numpy.alltrue(new_tris == tris)
     1301        assert new_verts == verts[0:3]
     1302        assert new_tris == tris
    13041303     
    13051304
     
    13081307        tris = [[0,1,2]]
    13091308        new_verts, new_tris = remove_lone_verts(verts, tris)
    1310         assert numpy.alltrue(new_verts == verts[0:3])
    1311         assert numpy.alltrue(new_tris == tris)
     1309        assert new_verts == verts[0:3]
     1310        assert new_tris == tris
    13121311       
    13131312    def test_get_min_max_values(self):
     
    14971496            line.append([float(row[0]),float(row[1]),float(row[2]),float(row[3]),float(row[4]),float(row[5])])
    14981497            #print 'assert line',line[i],'point1',point1_answers_array[i]
    1499             assert numpy.allclose(line[i], point1_answers_array[i])
     1498            assert allclose(line[i], point1_answers_array[i])
    15001499
    15011500        point2_answers_array = [[0.0,1.0,1.5,-0.5,3.0,4.0], [2.0,10.0,10.5,-0.5,3.0,4.0]]
     
    15101509            line.append([float(row[0]),float(row[1]),float(row[2]),float(row[3]),float(row[4]),float(row[5])])
    15111510            #print 'assert line',line[i],'point1',point1_answers_array[i]
    1512             assert numpy.allclose(line[i], point2_answers_array[i])
     1511            assert allclose(line[i], point2_answers_array[i])
    15131512                         
    15141513        # clean up
     
    16161615            line.append([float(row[0]),float(row[1]),float(row[2])])
    16171616            #print 'line',line[i],'point1',point1_answers_array[i]
    1618             assert numpy.allclose(line[i], point1_answers_array[i])
     1617            assert allclose(line[i], point1_answers_array[i])
    16191618
    16201619        point2_answers_array = [[0.0,1.0,-0.5], [2.0,10.0,-0.5]]
     
    16291628            line.append([float(row[0]),float(row[1]),float(row[2])])
    16301629#            print 'line',line[i],'point1',point1_answers_array[i]
    1631             assert numpy.allclose(line[i], point2_answers_array[i])
     1630            assert allclose(line[i], point2_answers_array[i])
    16321631                         
    16331632        # clean up
     
    17351734            line.append([float(row[0]),float(row[1]),float(row[2]),float(row[3]),float(row[4]),float(row[5])])
    17361735            #print 'assert line',line[i],'point1',point1_answers_array[i]
    1737             assert numpy.allclose(line[i], point1_answers_array[i])
     1736            assert allclose(line[i], point1_answers_array[i])
    17381737
    17391738        point2_answers_array = [[5.0,1.0,1.5,-0.5,3.0,4.0], [7.0,10.0,10.5,-0.5,3.0,4.0]]
     
    17481747            line.append([float(row[0]),float(row[1]),float(row[2]),float(row[3]),float(row[4]),float(row[5])])
    17491748            #print 'assert line',line[i],'point1',point1_answers_array[i]
    1750             assert numpy.allclose(line[i], point2_answers_array[i])
     1749            assert allclose(line[i], point2_answers_array[i])
    17511750                         
    17521751        # clean up
     
    18311830if __name__ == "__main__":
    18321831    suite = unittest.makeSuite(Test_Util,'test')
    1833 #    suite = unittest.makeSuite(Test_Util,'test_spatio_temporal_file_function_basic')
     1832#    suite = unittest.makeSuite(Test_Util,'test_sww2csv')
    18341833#    runner = unittest.TextTestRunner(verbosity=2)
    18351834    runner = unittest.TextTestRunner(verbosity=1)
  • anuga_core/source/anuga/abstract_2d_finite_volumes/util.py

    r5892 r5897  
    1515
    1616from anuga.utilities.numerical_tools import ensure_numeric
    17 import numpy
     17from Numeric import arange, choose, zeros, Float, array, allclose, take, compress
    1818   
    1919from anuga.geospatial_data.geospatial_data import ensure_absolute
     
    237237    from anuga.config import time_format
    238238    from Scientific.IO.NetCDF import NetCDFFile
    239 ##    from numpy.oldnumeric import array, zeros, Float, alltrue, concatenate, reshape
     239    from Numeric import array, zeros, Float, alltrue, concatenate, reshape
    240240
    241241    # Open NetCDF file
     
    303303    # Get variables
    304304    # if verbose: print 'Get variables'   
    305     time = numpy.array(fid.variables['time'][:]    )
     305    time = fid.variables['time'][:]   
    306306
    307307    # Get time independent stuff
     
    317317            triangles = fid.variables['volumes'][:]
    318318
    319         x = numpy.reshape(x, (len(x),1))
    320         y = numpy.reshape(y, (len(y),1))
    321         vertex_coordinates = numpy.concatenate((x,y), axis=1) #m x 2 array
     319        x = reshape(x, (len(x),1))
     320        y = reshape(y, (len(y),1))
     321        vertex_coordinates = concatenate((x,y), axis=1) #m x 2 array
    322322
    323323        if boundary_polygon is not None:
     
    331331            for i in range(len(boundary_polygon)):
    332332                for j in range(len(x)):
    333                     if numpy.allclose(vertex_coordinates[j],boundary_polygon[i],1e-4):
     333                    if allclose(vertex_coordinates[j],boundary_polygon[i],1e-4):
    334334                        #FIX ME:
    335335                        #currently gauges lat and long is stored as float and
     
    351351                gauge_neighbour_id.append(-1)
    352352            gauge_neighbour_id=ensure_numeric(gauge_neighbour_id)
    353             if len(numpy.compress(gauge_neighbour_id>=0,gauge_neighbour_id))!=len(temp)-1:
     353            if len(compress(gauge_neighbour_id>=0,gauge_neighbour_id))!=len(temp)-1:
    354354                msg='incorrect number of segments'
    355355                raise msg
     
    373373        # move time back - relative to domain's time
    374374        if domain_starttime > starttime:
    375 ##            print 'type(time)=%s' % type(time)
    376 ##            print 'type(domain_starttime)=%s' % type(domain_starttime)
    377 ##            print 'type(starttime)=%s' % type(starttime)
    378 ##            a = time - domain_starttime
    379375            time = time - domain_starttime + starttime
    380376
     
    402398        if boundary_polygon is not None:
    403399            #removes sts points that do not lie on boundary
    404             quantities[name] = numpy.take(quantities[name], gauge_id, 1)
     400            quantities[name] = take(quantities[name],gauge_id,1)
    405401           
    406402    # Close sww, tms or sts netcdf file         
     
    524520                raise 'Illegal input to get_textual_float:', value
    525521        else:
    526             return format % float(value)
     522            return format %float(value)
    527523
    528524
     
    10401036    """
    10411037#    from math import sqrt, atan, degrees
    1042 ##    from numpy.oldnumeric import ones, allclose, zeros, Float, ravel
     1038    from Numeric import ones, allclose, zeros, Float, ravel
    10431039    from os import sep, altsep, getcwd, mkdir, access, F_OK, environ
    10441040
     
    10811077    n0 = int(n0)
    10821078    m = len(locations)
    1083     model_time = numpy.zeros((n0,m,p), numpy.float)
    1084     stages = numpy.zeros((n0,m,p), numpy.float)
    1085     elevations = numpy.zeros((n0,m,p), numpy.float)
    1086     momenta = numpy.zeros((n0,m,p), numpy.float)
    1087     xmom = numpy.zeros((n0,m,p), numpy.float)
    1088     ymom = numpy.zeros((n0,m,p), numpy.float)
    1089     speed = numpy.zeros((n0,m,p), numpy.float)
    1090     bearings = numpy.zeros((n0,m,p), numpy.float)
    1091     due_east = 90.0*numpy.ones((n0,1), numpy.float)
    1092     due_west = 270.0*numpy.ones((n0,1), numpy.float)
    1093     depths = numpy.zeros((n0,m,p), numpy.float)
    1094     eastings = numpy.zeros((n0,m,p), numpy.float)
     1079    model_time = zeros((n0,m,p), Float)
     1080    stages = zeros((n0,m,p), Float)
     1081    elevations = zeros((n0,m,p), Float)
     1082    momenta = zeros((n0,m,p), Float)
     1083    xmom = zeros((n0,m,p), Float)
     1084    ymom = zeros((n0,m,p), Float)
     1085    speed = zeros((n0,m,p), Float)
     1086    bearings = zeros((n0,m,p), Float)
     1087    due_east = 90.0*ones((n0,1), Float)
     1088    due_west = 270.0*ones((n0,1), Float)
     1089    depths = zeros((n0,m,p), Float)
     1090    eastings = zeros((n0,m,p), Float)
    10951091    min_stages = []
    10961092    max_stages = []
     
    11041100    min_speeds = []   
    11051101    max_depths = []
    1106     model_time_plot3d = numpy.zeros((n0,m), numpy.float)
    1107     stages_plot3d = numpy.zeros((n0,m), numpy.float)
    1108     eastings_plot3d = numpy.zeros((n0,m),numpy.float)
     1102    model_time_plot3d = zeros((n0,m), Float)
     1103    stages_plot3d = zeros((n0,m), Float)
     1104    eastings_plot3d = zeros((n0,m),Float)
    11091105    if time_unit is 'mins': scale = 60.0
    11101106    if time_unit is 'hours': scale = 3600.0
     
    12061202                else:
    12071203                    #ax.plot_wireframe(model_time[:,:,j],eastings[:,:,j],stages[:,:,j])
    1208                     ax.plot3D(numpy.ravel(eastings[:,:,j]),numpy.ravel(model_time[:,:,j]),numpy.ravel(stages[:,:,j]))
     1204                    ax.plot3D(ravel(eastings[:,:,j]),ravel(model_time[:,:,j]),ravel(stages[:,:,j]))
    12091205                ax.set_xlabel('time')
    12101206                ax.set_ylabel('x')
     
    15051501   
    15061502    # initialise the array to easily find the index of the first loner
    1507     loners=numpy.arange(2*N, N, -1) # if N=3 [6,5,4]
     1503    loners=arange(2*N, N, -1) # if N=3 [6,5,4]
    15081504    for t in triangles:
    15091505        for vert in t:
     
    15391535        #print "loners", loners
    15401536        #print "triangles before", triangles
    1541         triangles = numpy.choose(triangles,loners)
     1537        triangles = choose(triangles,loners)
    15421538        #print "triangles after", triangles
    15431539    return verts, triangles
     
    15541550
    15551551       
    1556     xc = numpy.zeros(triangles.shape[0], numpy.float) # Space for centroid info
     1552    xc = zeros(triangles.shape[0], Float) # Space for centroid info
    15571553   
    15581554    for k in range(triangles.shape[0]):
     
    18361832                #add tide to stage if provided
    18371833                if quantity == 'stage':
    1838                      quantity_value[quantity]=numpy.array(quantity_value[quantity])+directory_add_tide
     1834                     quantity_value[quantity]=array(quantity_value[quantity])+directory_add_tide
    18391835
    18401836                #condition to find max and mins for all the plots
     
    19471943            #get data from dict in to list
    19481944            #do maths to list by changing to array
    1949             t=(numpy.array(directory_quantity_value[directory][filename]['time'])+directory_start_time)/seconds_in_minutes
     1945            t=(array(directory_quantity_value[directory][filename]['time'])+directory_start_time)/seconds_in_minutes
    19501946
    19511947            #finds the maximum elevation, used only as a test
     
    21282124    from csv import reader,writer
    21292125    from anuga.utilities.numerical_tools import ensure_numeric, mean, NAN
    2130 ##    from numpy.oldnumeric import array, resize, shape, Float, zeros, take, argsort, argmin
     2126    from Numeric import array, resize, shape, Float, zeros, take, argsort, argmin
    21312127    import string
    21322128    from anuga.shallow_water.data_manager import get_all_swwfiles
     
    21692165       
    21702166    #convert to array for file_function
    2171     points_array = numpy.array(points, numpy.float)
     2167    points_array = array(points,Float)
    21722168       
    21732169    points_array = ensure_absolute(points_array)
  • anuga_core/source/anuga/caching/caching.py

    r5893 r5897  
    5050else:
    5151  unix = 1
    52 
    53 import numpy
    54 
    5552
    5653cache_dir = '.python_cache'
     
    13421339
    13431340  from types import TupleType, ListType, DictType, InstanceType 
    1344 ##  from numpy.oldnumeric import ArrayType, average
     1341  from Numeric import ArrayType, average
    13451342
    13461343   
     
    13811378      I.sort()   
    13821379      val = myhash(I, ids)
    1383   elif isinstance(T, numpy.ndarray):
     1380  elif type(T) == ArrayType:
    13841381      # Use mean value for efficiency 
    1385       val = hash(numpy.average(T.ravel()))
     1382      val = hash(average(T.flat))
    13861383  elif type(T) == InstanceType:
    13871384      val = myhash(T.__dict__, ids)
     
    14071404
    14081405    from types import TupleType, ListType, DictType, InstanceType
    1409 ##    from numpy.oldnumeric import ArrayType, alltrue   
     1406    from Numeric import ArrayType, alltrue   
    14101407   
    14111408    # Keep track of unique id's to protect against infinite recursion
     
    14501447            identical = compare(a, b, ids)
    14511448           
    1452     elif isinstance(A, numpy.ndarray):
     1449    elif type(A) == ArrayType:
    14531450        # Use element by element comparison
    1454         identical = numpy.alltrue(A==B)
     1451        identical = alltrue(A==B)
    14551452
    14561453    elif type(A) == InstanceType:
     
    23992396      argstr = argstr + "'"+str(args)+"'"
    24002397    else:
    2401       # Truncate large arrays before using str()
    2402       if isinstance(args, numpy.ndarray):
    2403 #        if len(args.ravel()) > textwidth: 
    2404 #        Changed by Duncan and Nick 21/2/07 .ravel() has problems with
    2405 #        non-contigous arrays and ravel is equal to .ravel() except it
     2398      # Truncate large Numeric arrays before using str()
     2399      import Numeric
     2400      if type(args) == Numeric.ArrayType:
     2401#        if len(args.flat) > textwidth: 
     2402#        Changed by Duncan and Nick 21/2/07 .flat has problems with
     2403#        non-contigous arrays and ravel is equal to .flat except it
    24062404#        can work with non-contiguous  arrays
    2407         if len(numpy.ravel(args)) > textwidth:
     2405        if len(Numeric.ravel(args)) > textwidth:
    24082406          args = 'Array: ' + str(args.shape)
    24092407
  • anuga_core/source/anuga/caching/test_caching.py

    r5893 r5897  
     1
    12import unittest
    2 import numpy
     3from Numeric import arange, array
    34
    45from copy import deepcopy
     
    127128       
    128129        # Make some test input arguments
    129         A0 = numpy.arange(5)
    130         B0 = numpy.array([1.1, 2.2, 0.0, -5, -5])
     130        A0 = arange(5)
     131        B0 = array([1.1, 2.2, 0.0, -5, -5])
    131132       
    132133        A1 = A0.copy()
     
    158159
    159160
    160             assert numpy.alltrue(T1 == T2), 'Cached result does not match computed result'
    161             assert numpy.alltrue(T2 == T3), 'Cached result does not match computed result'
     161            assert T1 == T2, 'Cached result does not match computed result'
     162            assert T2 == T3, 'Cached result does not match computed result'
    162163           
    163164
     
    171172       
    172173        # Make test input arguments
    173         A0 = numpy.arange(5)*1.0
     174        A0 = arange(5)*1.0
    174175        B = ('x', 15)
    175176       
    176177        # Create different A that hashes to the same address (having the same average)
    177         A1 = numpy.array([2.0, 2.0, 2.0, 2.0, 2.0])       
     178        A1 = array([2.0, 2.0, 2.0, 2.0, 2.0])       
    178179       
    179180        assert myhash(A0) == myhash(A1)
     
    202203           
    203204
    204             print 'T1=%s' % str(T1)
    205             print 'T2=%s' % str(T2)
    206             assert numpy.alltrue(T2 != T1)
     205            #print T1
     206            #print T2
     207            assert T2 != T1
    207208
    208209           
     
    388389        A = Dummy(5, 7)
    389390        B = {'x': 10, 'A': A}
    390         C = [B, numpy.array([1.2, 3, 5, 0.1])]
     391        C = [B, array([1.2, 3, 5, 0.1])]
    391392        A.value = C # Make it circular
    392393
     
    394395        AA = Dummy(None, None)
    395396        BB = {'A': AA, 'x': 10}
    396         CC = [BB, numpy.array([1.200, 3.000, 5.00, 1.0/10])]
     397        CC = [BB, array([1.200, 3.000, 5.00, 1.0/10])]
    397398        AA.value = CC # Make it circular
    398399        AA.another = 3+4       
  • anuga_core/source/anuga/utilities/cg_solve.py

    r5891 r5897  
    1 
    21import exceptions
    32class VectorShapeError(exceptions.Exception): pass
    43class ConvergenceError(exceptions.Exception): pass
    54
    6 import numpy
     5from Numeric import dot, array, Float, zeros
    76   
    87import logging, logging.config
     
    2524   
    2625    if x0 is None:
    27         x0 = numpy.zeros(b.shape, dtype=numpy.float)
     26        x0 = zeros(b.shape, typecode=Float)
    2827    else:
    29         x0 = numpy.array(x0, dtype=numpy.float)
     28        x0 = array(x0, typecode=Float)
    3029
    31     b  = numpy.array(b, dtype=numpy.float)
     30    b  = array(b, typecode=Float)
    3231    if len(b.shape) != 1 :
    3332       
     
    5857
    5958
    60    b  = numpy.array(b, dtype=numpy.float)
     59   b  = array(b, typecode=Float)
    6160   if len(b.shape) != 1 :
    6261      raise VectorShapeError, 'input vector should consist of only one column'
    6362
    6463   if x0 is None:
    65       x0 = numpy.zeros(b.shape, dtype=numpy.float)
     64      x0 = zeros(b.shape, typecode=Float)
    6665   else:
    67       x0 = numpy.array(x0, dtype=numpy.float)
     66      x0 = array(x0, typecode=Float)
    6867
    6968
     
    7675   r = b - A*x
    7776   d = r
    78    rTr = numpy.dot(r,r)
     77   rTr = dot(r,r)
    7978   rTr0 = rTr
    8079
    8180   while (i<imax and rTr>tol**2*rTr0):
    8281       q = A*d
    83        alpha = rTr/numpy.dot(d,q)
     82       alpha = rTr/dot(d,q)
    8483       x = x + alpha*d
    8584       if i%50 :
     
    8887           r = r - alpha*q
    8988       rTrOld = rTr
    90        rTr = numpy.dot(r,r)
     89       rTr = dot(r,r)
    9190       bt = rTr/rTrOld
    9291
  • anuga_core/source/anuga/utilities/compile.py

    r5891 r5897  
    1010   Ole Nielsen, Duncan Gray Oct 2001     
    1111"""     
    12 
    13 #NumPy ------------------------------------
    14 # Something like these lines recommended in "Converting from NUMARRAY to NUMPY"
    15 import numpy
    16 numpyincludedirs = numpy.get_include()
    17 I_dirs = '-I"%s" ' % numpyincludedirs
    18 #NumPy ------------------------------------
    1912
    2013# FIXME (Ole): Although this script says it works with a range of compilers,
     
    262255    else:
    263256      if FN == "triangle.c" or FN == "mesh_engine_c_layer.c":
    264 #NumPy        s = '%s -c %s -I"%s" -I"%s" -o "%s.o" -O3 -DTRILIBRARY=1 -DNO_TIMER=1'\
    265         s = '%s -c %s %s -I"%s" -I"%s" -o "%s.o" -O3 -DTRILIBRARY=1 -DNO_TIMER=1'\
    266             %(compiler, FN, I_dirs, python_include, utilities_include_dir, root)
     257        s = '%s -c %s -I"%s" -I"%s" -o "%s.o" -O3 -DTRILIBRARY=1 -DNO_TIMER=1'\
     258            %(compiler, FN, python_include, utilities_include_dir, root)
    267259      else:
    268 #NumPy        s = '%s -c %s -I"%s" -I"%s" -o "%s.o" -Wall -O3'\
    269         s = '%s -c %s %s -I"%s" -I"%s" -o "%s.o" -Wall -O3'\
    270             %(compiler, FN, I_dirs, python_include, utilities_include_dir, root)
     260        s = '%s -c %s -I"%s" -I"%s" -o "%s.o" -Wall -O3'\
     261            %(compiler, FN, python_include, utilities_include_dir, root)
    271262
    272263    if os.name == 'posix' and os.uname()[4] == 'x86_64':
  • anuga_core/source/anuga/utilities/interp.py

    r5891 r5897  
    111111
    112112    >>> from interp import interp
    113     >>> import numpy.oldnumeric as N
     113    >>> import Numeric as N
    114114    >>> x = N.array([1., 2., 3., 4., 5.])
    115115    >>> y = N.array([3., 6., 2.,-5.,-3.])
     
    138138    """
    139139    import arrayfns
    140     import numpy.ma as MA
    141     import numpy as N
     140    import MA
     141    import Numeric as N
    142142    from where_close import where_close
    143143
     
    216216
    217217    >>> from interp import interp
    218     >>> import numpy.oldnumeric as N
     218    >>> import Numeric as N
    219219    >>> x = N.array([1.,    2., 3.,  4.,  5.,  6.])
    220220    >>> y = N.array([3., 1e+20, 2., -5., -3., -4.])
     
    284284    >>> ['%.7g' % yint[i] for i in range(len(yint))]
    285285    ['3.4', '2.3']
    286     >>> yint.dtype.char
     286    >>> yint.typecode()
    287287    'd'
    288288    >>> x = N.arange(6)
     
    292292    >>> ['%.7g' % yint[i] for i in range(len(yint))]
    293293    ['3', '2']
    294     >>> yint.dtype.char
     294    >>> yint.typecode()
    295295    'd'
    296296    """}
  • anuga_core/source/anuga/utilities/numerical_tools.py

    r5891 r5897  
    77from warnings import warn
    88
    9 ##from numpy import ndarray, array, sum, inner, ravel, sqrt, searchsorted, sort, concatenate, float, arange
    10 import numpy
     9#Establish which Numeric package to use
     10#(this should move to somewhere central)
     11#try:
     12#    from scipy import ArrayType, array, sum, innerproduct, ravel, sqrt,
     13# searchsorted, sort, concatenate, Float, arange   
     14#except:
     15#    #print 'Could not find scipy - using Numeric'
     16#    from Numeric import ArrayType, array, sum, innerproduct, ravel, sqrt,
     17#searchsorted, sort, concatenate, Float, arange
     18
     19from Numeric import ArrayType, array, sum, innerproduct, ravel, sqrt,\
     20     searchsorted, sort, concatenate, Float, arange   
    1121
    1222# Getting an infinite number to use when using Numeric
    1323#INF = (array([1])/0.)[0]
    1424
    15 NAN = (numpy.array([1])/0.)[0]
     25NAN = (array([1])/0.)[0]
    1626# Note, INF is used instead of NAN (Not a number), since Numeric has no NAN
    1727# if we use a package that has NAN, this should be updated to use NAN.
     
    7989        v2 = [1.0, 0.0] # Unit vector along the x-axis
    8090       
    81     v1 = ensure_numeric(v1, numpy.float)
    82     v2 = ensure_numeric(v2, numpy.float)   
     91    v1 = ensure_numeric(v1, Float)
     92    v2 = ensure_numeric(v2, Float)   
    8393   
    8494    # Normalise
    85     v1 = v1/numpy.sqrt(numpy.sum(v1**2))
    86     v2 = v2/numpy.sqrt(numpy.sum(v2**2))
     95    v1 = v1/sqrt(sum(v1**2))
     96    v2 = v2/sqrt(sum(v2**2))
    8797
    8898    # Compute angle
    89     p = numpy.inner(v1, v2)
    90     c = numpy.inner(v1, normal_vector(v2)) # Projection onto normal
     99    p = innerproduct(v1, v2)
     100    c = innerproduct(v1, normal_vector(v2)) # Projection onto normal
    91101                                            # (negative cross product)
    92102       
     
    130140    """
    131141   
    132     return numpy.array([-v[1], v[0]], numpy.float)
     142    return array([-v[1], v[0]], Float)
    133143
    134144   
     
    140150    """Mean value of a vector
    141151    """
    142     return(float(numpy.sum(x))/len(x))
     152    return(float(sum(x))/len(x))
    143153
    144154
     
    161171    cy = y - mean(y) 
    162172
    163     p = numpy.inner(cx,cy)/N
     173    p = innerproduct(cx,cy)/N
    164174    return(p)
    165175
     
    210220    """
    211221 
    212     y = numpy.ravel(x)
    213     p = numpy.sqrt(numpy.inner(y,y))
     222    y = ravel(x)
     223    p = sqrt(innerproduct(y,y))
    214224    return p
    215225   
     
    252262
    253263    if typecode is None:
    254 ##NumPy        if isinstance(A, ArrayType):
    255         if type(A) == numpy.ndarray:
     264        if type(A) == ArrayType:
    256265            return A
    257266        else:
    258             return numpy.array(A)
     267            return array(A)
    259268    else:
    260 ##NumPy        if isinstance(A, ArrayType):
    261         if type(A) == numpy.ndarray:
    262 ##NumPy            if A.typecode == typecode:
    263             if A.dtype == typecode:
    264                 return numpy.array(A)  #FIXME: Shouldn't this just return A?
     269        if type(A) == ArrayType:
     270            if A.typecode == typecode:
     271                return array(A)  #FIXME: Shouldn't this just return A?
    265272            else:
    266                 return numpy.array(A, typecode)
     273                return array(A,typecode)
    267274        else:
    268             import types                            ##
    269             from numpy import str                   ##
    270             if isinstance(A, types.StringType):     ##
    271                 return numpy.array(A, dtype=int)          ##
    272             return numpy.array(A, typecode)
     275            return array(A,typecode)
     276
    273277
    274278
     
    281285    """
    282286
    283     n = numpy.searchsorted(numpy.sort(a), bins)
    284     n = numpy.concatenate( [n, [len(a)]] )
     287    n = searchsorted(sort(a), bins)
     288    n = concatenate( [n, [len(a)]] )
    285289
    286290    hist = n[1:]-n[:-1]
    287291
    288292    if relative is True:
    289         hist = hist/float(numpy.sum(hist))
     293        hist = hist/float(sum(hist))
    290294       
    291295    return hist
     
    297301    """
    298302
    299     mx = numpy.max(data)
    300     mn = numpy.min(data)
     303    mx = max(data)
     304    mn = min(data)
    301305
    302306    if mx == mn:
    303         bins = numpy.array([mn])
     307        bins = array([mn])
    304308    else:
    305309        if number_of_bins is None:
    306310            number_of_bins = 10
    307311           
    308         bins = numpy.arange(mn, mx, (mx-mn)/number_of_bins)
     312        bins = arange(mn, mx, (mx-mn)/number_of_bins)
    309313
    310314    return bins
  • anuga_core/source/anuga/utilities/polygon.py

    r5891 r5897  
    1010#    #print 'Could not find scipy - using Numeric'
    1111
    12 ##from numpy import float, int, zeros, ones, array, concatenate, reshape, dot, allclose, newaxis, ascontiguousarray
    13 import numpy
     12from Numeric import Float, Int, zeros, ones, array, concatenate, reshape, dot, allclose
    1413
    1514
     
    7776    # FIXME (Ole): Write this in C
    7877
    79     line0 = ensure_numeric(line0, numpy.float)
    80     line1 = ensure_numeric(line1, numpy.float)   
     78    line0 = ensure_numeric(line0, Float)
     79    line1 = ensure_numeric(line1, Float)   
    8180
    8281    x0 = line0[0,0]; y0 = line0[0,1]
     
    9089    u1 = (x2-x0)*(y1-y0) - (y2-y0)*(x1-x0)
    9190       
    92     if numpy.allclose(denom, 0.0):
     91    if allclose(denom, 0.0):
    9392        # Lines are parallel - check if they coincide on a shared a segment
    9493
    95         if numpy.allclose( [u0, u1], 0.0 ):
     94        if allclose( [u0, u1], 0.0 ):
    9695            # We now know that the lines if continued coincide
    9796            # The remaining check will establish if the finite lines share a segment
     
    121120            if line0_starts_on_line1 and line0_ends_on_line1:
    122121                # Shared segment is line0 fully included in line1
    123                 segment = numpy.array([[x0, y0], [x1, y1]])               
     122                segment = array([[x0, y0], [x1, y1]])               
    124123
    125124            if line1_starts_on_line0 and line1_ends_on_line0:
    126125                # Shared segment is line1 fully included in line0
    127                 segment = numpy.array([[x2, y2], [x3, y3]])
     126                segment = array([[x2, y2], [x3, y3]])
    128127           
    129128
     
    131130            if line0_starts_on_line1 and line1_ends_on_line0:
    132131                # Shared segment from line0 start to line 1 end
    133                 segment = numpy.array([[x0, y0], [x3, y3]])
     132                segment = array([[x0, y0], [x3, y3]])
    134133
    135134            if line1_starts_on_line0 and line0_ends_on_line1:
    136135                # Shared segment from line1 start to line 0 end
    137                 segment = numpy.array([[x2, y2], [x1, y1]])                               
     136                segment = array([[x2, y2], [x1, y1]])                               
    138137
    139138
     
    141140            if line0_starts_on_line1 and line1_starts_on_line0:
    142141                # Shared segment from line0 start to line 1 end
    143                 segment = numpy.array([[x0, y0], [x2, y2]])
     142                segment = array([[x0, y0], [x2, y2]])
    144143
    145144            if line0_ends_on_line1 and line1_ends_on_line0:
    146145                # Shared segment from line0 start to line 1 end
    147                 segment = numpy.array([[x3, y3], [x1, y1]])               
     146                segment = array([[x3, y3], [x1, y1]])               
    148147
    149148               
     
    162161
    163162        # Sanity check - can be removed to speed up if needed
    164         assert numpy.allclose(x, x2 + u1*(x3-x2))
    165         assert numpy.allclose(y, y2 + u1*(y3-y2))       
     163        assert allclose(x, x2 + u1*(x3-x2))
     164        assert allclose(y, y2 + u1*(y3-y2))       
    166165
    167166        # Check if point found lies within given line segments
     
    169168            # We have intersection
    170169
    171             return 1, numpy.array([x, y])
     170            return 1, array([x, y])
    172171        else:
    173172            # No intersection
     
    204203
    205204
    206     line0 = ensure_numeric(line0, numpy.float)
    207     line1 = ensure_numeric(line1, numpy.float)   
     205    line0 = ensure_numeric(line0, Float)
     206    line1 = ensure_numeric(line1, Float)   
    208207
    209208    status, value = _intersection(line0[0,0], line0[0,1],
     
    257256        # converted to a numeric array.
    258257        msg = 'Points could not be converted to Numeric array'
    259         raise TypeError, msg
     258        raise msg
    260259
    261260    try:
     
    266265        # If this fails it is going to be because the points can't be
    267266        # converted to a numeric array.
    268         msg = 'Polygon %s could not be converted to Numeric array' % (str(polygon))
    269         raise TypeError, msg
     267        msg = 'Polygon %s could not be converted to Numeric array' %(str(polygon))
     268        raise msg
    270269
    271270    if len(points.shape) == 1:
    272271        # Only one point was passed in. Convert to array of points
    273         points = numpy.reshape(points, (1,2))
     272        points = reshape(points, (1,2))
    274273
    275274    indices, count = separate_points_by_polygon(points, polygon,
     
    313312    #if verbose: print 'Checking input to outside_polygon'
    314313    try:
    315         points = ensure_numeric(points, numpy.float)
     314        points = ensure_numeric(points, Float)
    316315    except NameError, e:
    317316        raise NameError, e
     
    321320
    322321    try:
    323         polygon = ensure_numeric(polygon, numpy.float)
     322        polygon = ensure_numeric(polygon, Float)
    324323    except NameError, e:
    325324        raise NameError, e
     
    331330    if len(points.shape) == 1:
    332331        # Only one point was passed in. Convert to array of points
    333         points = numpy.reshape(points, (1,2))
     332        points = reshape(points, (1,2))
    334333
    335334    indices, count = separate_points_by_polygon(points, polygon,
     
    340339    if count == len(indices):
    341340        # No points are outside
    342         return numpy.array([])
     341        return array([])
    343342    else:
    344343        return indices[count:][::-1]  #return reversed
     
    355354    #if verbose: print 'Checking input to outside_polygon'
    356355    try:
    357         points = ensure_numeric(points, numpy.float)
     356        points = ensure_numeric(points, Float)
    358357    except NameError, e:
    359358        raise NameError, e
     
    363362
    364363    try:
    365         polygon = ensure_numeric(polygon, numpy.float)
     364        polygon = ensure_numeric(polygon, Float)
    366365    except NameError, e:
    367366        raise NameError, e
     
    372371    if len(points.shape) == 1:
    373372        # Only one point was passed in. Convert to array of points
    374         points = numpy.reshape(points, (1,2))
     373        points = reshape(points, (1,2))
    375374
    376375
     
    440439    assert isinstance(verbose, bool), 'Keyword argument "verbose" must be boolean'
    441440
    442 ##    print 'Before: points=%s, flags=%s' % (type(points), str(points.flags))
     441
    443442    try:
    444 ##        points = numpy.ascontiguousarray(ensure_numeric(points, numpy.float))
    445         points = ensure_numeric(points, numpy.float)
     443        points = ensure_numeric(points, Float)
    446444    except NameError, e:
    447445        raise NameError, e
    448446    except:
    449447        msg = 'Points could not be converted to Numeric array'
    450         raise TypeError, msg
    451 ##    print 'After: points=%s, flags=%s' % (type(points), str(points.flags))
     448        raise msg
    452449
    453450    #if verbose: print 'Checking input to separate_points_by_polygon 2'
    454451    try:
    455 ##        polygon = numpy.ascontiguousarray(ensure_numeric(polygon, numpy.float))
    456         polygon = ensure_numeric(polygon, numpy.float)
     452        polygon = ensure_numeric(polygon, Float)
    457453    except NameError, e:
    458454        raise NameError, e
    459455    except:
    460456        msg = 'Polygon could not be converted to Numeric array'
    461         raise TypeError, msg
     457        raise msg
    462458
    463459    msg = 'Polygon array must be a 2d array of vertices'
     
    476472        # Only one point was passed in.
    477473        # Convert to array of points
    478         points = numpy.reshape(points, (1,2))
     474        points = reshape(points, (1,2))
    479475
    480476   
    481477    msg = 'Point array must have two columns (x,y), '
    482     msg += 'I got points.shape[1] == %d' % points.shape[1]
     478    msg += 'I got points.shape[1] == %d' %points.shape[0]
    483479    assert points.shape[1] == 2, msg
    484480
     
    495491
    496492
    497     indices = numpy.zeros( M, numpy.int )
     493    indices = zeros( M, Int )
    498494
    499495    count = _separate_points_by_polygon(points, polygon, indices,
     
    622618
    623619    try:
    624         polygon = ensure_numeric(polygon, numpy.float)
     620        polygon = ensure_numeric(polygon, Float)
    625621    except NameError, e:
    626622        raise NameError, e
     
    631627    x = polygon[:,0]
    632628    y = polygon[:,1]
    633     x = numpy.concatenate((x, [polygon[0,0]]), axis = 0)
    634     y = numpy.concatenate((y, [polygon[0,1]]), axis = 0)
     629    x = concatenate((x, [polygon[0,0]]), axis = 0)
     630    y = concatenate((y, [polygon[0,1]]), axis = 0)
    635631   
    636632    return x, y
     
    684680    """
    685681
    686     def __init__(self, regions, default=0.0, geo_reference=None, verbose=False):
     682    def __init__(self, regions, default=0.0, geo_reference=None):
    687683
    688684        try:
     
    727723            self.regions.append( (P, value) )
    728724
    729         self.verbose = verbose
    730 
    731725
    732726
    733727
    734728    def __call__(self, x, y):
    735         x = numpy.array(x).astype(numpy.float)
    736         y = numpy.array(y).astype(numpy.float)
    737 
    738         assert len(x.shape) == 1 and len(y.shape) == 1
    739        
    740         N = x.shape[0]
    741         assert y.shape[0] == N
    742 
    743         points = numpy.ascontiguousarray(numpy.concatenate( (x[:,numpy.newaxis], y[:,numpy.newaxis]), axis=1 ))
    744        
     729        x = array(x).astype(Float)
     730        y = array(y).astype(Float)
     731
     732        N = len(x)
     733        assert len(y) == N
     734
     735        points = concatenate( (reshape(x, (N, 1)),
     736                               reshape(y, (N, 1))), axis=1 )
     737
    745738        if callable(self.default):
    746             z = self.default(x, y)
     739            z = self.default(x,y)
    747740        else:
    748             z = numpy.ones(N, numpy.float) * self.default
     741            z = ones(N, Float) * self.default
    749742
    750743        for polygon, value in self.regions:
    751             indices = inside_polygon(points, polygon, verbose=self.verbose)
     744            indices = inside_polygon(points, polygon)
    752745
    753746            # FIXME: This needs to be vectorised
    754747            if callable(value):
    755748                for i in indices:
    756                     xx = numpy.array([x[i]])
    757                     yy = numpy.array([y[i]])
     749                    xx = array([x[i]])
     750                    yy = array([y[i]])
    758751                    z[i] = value(xx, yy)[0]
    759752            else:
  • anuga_core/source/anuga/utilities/polygon_ext.c

    r5891 r5897  
    1515
    1616#include "Python.h"
    17 #include "numpy/arrayobject.h"
     17#include "Numeric/arrayobject.h"
    1818#include "math.h"
    1919
     
    222222  } 
    223223  for (k=0; k<M; k++) {
     224    if (verbose){
     225      if (k %((M+10)/10)==0) printf("Doing %d of %d\n", k, M);
     226    }
     227   
    224228    x = points[2*k];
    225229    y = points[2*k + 1];
    226230
    227     if (verbose){
    228       if (k %((M+10)/10)==0) printf("Doing %d of %d, x=%f, y=%f\n", k, M, x, y);
    229     }
    230    
    231231    inside = 0;
    232232
     
    376376    *polygon,
    377377    *indices;
    378 //  PyObject *xxxx;
    379378
    380379  int closed, verbose; //Flags
     
    394393    return NULL;
    395394  }
    396  
    397 //  points = (PyArrayObject *) PyArray_ContiguousFromObject(xxxx, PyArray_DOUBLE, 1, 1);
    398395
    399396  M = points -> dimensions[0];   //Number of points
  • anuga_core/source/anuga/utilities/quad.py

    r5895 r5897  
    1 
    21"""quad.py - quad tree data structure for fast indexing of points in the plane
    32
     
    223222            triangles = {}
    224223            verts = self.retrieve_vertices()
     224            # print "verts", verts
    225225            for vert in verts:
    226226                triangle_list = self.mesh.get_triangles_and_vertices_per_node(vert)
     
    228228                    if not triangles.has_key(k):
    229229                        # print 'k',k
    230                         tri = self.mesh.get_vertex_coordinates(k, absolute=True)
     230                        tri = self.mesh.get_vertex_coordinates(k,
     231                                                               absolute=True)
    231232                        n0 = self.mesh.get_normal(k, 0)
    232233                        n1 = self.mesh.get_normal(k, 1)
     
    434435    """
    435436
     437    from Numeric import minimum, maximum
     438
     439
    436440    #Make root cell
    437441    #print mesh.coordinates
  • anuga_core/source/anuga/utilities/sparse.py

    r5891 r5897  
    1 
    21"""Proof of concept sparse matrix code
    32"""
    43
    5 import numpy
    64
    75class Sparse:
     
    1917           
    2018        if len(args) == 1:
     19            from Numeric import array
    2120            try:
    22                 A = numpy.array(args[0])
     21                A = array(args[0])
    2322            except:
    2423                raise 'Input must be convertable to a Numeric array'
     
    9392
    9493    def todense(self):
    95         D = numpy.zeros( (self.M, self.N), numpy.float)
     94        from Numeric import zeros, Float
     95
     96        D = zeros( (self.M, self.N), Float)
    9697       
    9798        for i in range(self.M):
     
    108109        """
    109110
     111        from Numeric import array, zeros, Float
     112       
    110113        try:
    111             B = numpy.array(other)
     114            B = array(other)
    112115        except:
    113116            msg = 'FIXME: Only Numeric types implemented so far'
     
    127130            assert B.shape[0] == self.N, msg
    128131
    129             R = numpy.zeros(self.M, numpy.float) #Result
     132            R = zeros(self.M, Float) #Result
    130133           
    131134            # Multiply nonzero elements
     
    137140       
    138141           
    139             R = numpy.zeros((self.M, B.shape[1]), numpy.float) #Result matrix
     142            R = zeros((self.M, B.shape[1]), Float) #Result matrix
    140143
    141144            # Multiply nonzero elements
     
    159162        """
    160163
     164        from Numeric import array, zeros, Float
     165       
    161166        new = other.copy()
    162167        for key in self.Data.keys():
     
    172177        """
    173178
     179        from Numeric import array, zeros, Float
     180       
    174181        try:
    175182            other = float(other)
     
    193200        """
    194201
     202        from Numeric import array, zeros, Float
     203       
    195204        try:
    196             B = numpy.array(other)
     205            B = array(other)
    197206        except:
    198207            print 'FIXME: Only Numeric types implemented so far'
     
    205214            assert B.shape[0] == self.M, 'Mismatching dimensions'
    206215
    207             R = numpy.zeros((self.N,), numpy.float) #Result
     216            R = zeros((self.N,), Float) #Result
    208217
    209218            #Multiply nonzero elements
     
    242251        """
    243252
     253        from Numeric import array, Float, Int
     254
    244255        if isinstance(A,Sparse):
    245256
     257            from Numeric import zeros
    246258            keys = A.Data.keys()
    247259            keys.sort()
    248260            nnz = len(keys)
    249             data    = numpy.zeros ( (nnz,), numpy.float)
    250             colind  = numpy.zeros ( (nnz,), numpy.int)
    251             row_ptr = numpy.zeros ( (A.M+1,), numpy.int)
     261            data    = zeros ( (nnz,), Float)
     262            colind  = zeros ( (nnz,), Int)
     263            row_ptr = zeros ( (A.M+1,), Int)
    252264            current_row = -1
    253265            k = 0
     
    287299
    288300    def todense(self):
    289 
    290         D = numpy.zeros( (self.M, self.N), numpy.float)
     301        from Numeric import zeros, Float
     302
     303        D = zeros( (self.M, self.N), Float)
    291304       
    292305        for i in range(self.M):
     
    301314        """
    302315
     316        from Numeric import array, zeros, Float
     317       
    303318        try:
    304             B = numpy.array(other)
     319            B = array(other)
    305320        except:
    306321            print 'FIXME: Only Numeric types implemented so far'
     
    318333if __name__ == '__main__':
    319334    # A little selftest
     335   
     336    from Numeric import allclose, array, Float
     337   
    320338    A = Sparse(3,3)
    321339
     
    348366    u = A*v
    349367    print u
    350     assert numpy.allclose(u, [6,14,4])
     368    assert allclose(u, [6,14,4])
    351369
    352370    u = A.trans_mult(v)
    353371    print u
    354     assert numpy.allclose(u, [6,6,10])
     372    assert allclose(u, [6,6,10])
    355373
    356374    #Right hand side column
    357     v = numpy.array([[2,4],[3,4],[4,4]])
     375    v = array([[2,4],[3,4],[4,4]])
    358376
    359377    u = A*v[:,0]
    360     assert numpy.allclose(u, [6,14,4])
     378    assert allclose(u, [6,14,4])
    361379
    362380    #u = A*v[:,1]
  • anuga_core/source/anuga/utilities/sparse_ext.c

    r5891 r5897  
    1111       
    1212#include "Python.h"
    13 #include "numpy/arrayobject.h"
     13#include "Numeric/arrayobject.h"
    1414#include "math.h"
    1515#include "stdio.h"
  • anuga_core/source/anuga/utilities/test_cg_solve.py

    r5891 r5897  
    55import unittest
    66
    7 import numpy
     7
     8from Numeric import dot, allclose, array, transpose, arange, ones, Float
    89from anuga.utilities.cg_solve import *
    910from anuga.utilities.cg_solve import _conjugate_gradient
     
    2930        x = conjugate_gradient(A,b,x,iprint=0)
    3031
    31         assert numpy.allclose(x,xe)
     32        assert allclose(x,xe)
    3233
    3334    def test_max_iter(self):
     
    6061        A = Sparse(n,n)
    6162
    62         for i in numpy.arange(0,n):
     63        for i in arange(0,n):
    6364            A[i,i] = 1.0
    6465            if i > 0 :
     
    6768                A[i,i+1] = -0.5
    6869
    69         xe = numpy.ones( (n,), numpy.float)
     70        xe = ones( (n,), Float)
    7071
    7172        b  = A*xe
    7273        x = conjugate_gradient(A,b,b,tol=1.0e-5,iprint=1)
    7374
    74         assert numpy.allclose(x,xe)
     75        assert allclose(x,xe)
    7576
    7677    def test_solve_large_2d(self):
     
    8283        A = Sparse(m*n, m*n)
    8384
    84         for i in numpy.arange(0,n):
    85             for j in numpy.arange(0,m):
     85        for i in arange(0,n):
     86            for j in arange(0,m):
    8687                I = j+m*i
    8788                A[I,I] = 4.0
     
    9596                    A[I,I+1] = -1.0
    9697
    97         xe = numpy.ones( (n*m,), numpy.float)
     98        xe = ones( (n*m,), Float)
    9899
    99100        b  = A*xe
    100101        x = conjugate_gradient(A,b,b,iprint=0)
    101102
    102         assert numpy.allclose(x,xe)
     103        assert allclose(x,xe)
    103104
    104105    def test_solve_large_2d_csr_matrix(self):
     
    111112        A = Sparse(m*n, m*n)
    112113
    113         for i in numpy.arange(0,n):
    114             for j in numpy.arange(0,m):
     114        for i in arange(0,n):
     115            for j in arange(0,m):
    115116                I = j+m*i
    116117                A[I,I] = 4.0
     
    124125                    A[I,I+1] = -1.0
    125126
    126         xe = numpy.ones( (n*m,), numpy.float)
     127        xe = ones( (n*m,), Float)
    127128
    128129        # Convert to csr format
     
    133134        x = conjugate_gradient(A,b,b,iprint=20)
    134135
    135         assert numpy.allclose(x,xe)
     136        assert allclose(x,xe)
    136137
    137138
     
    144145        A = Sparse(m*n, m*n)
    145146
    146         for i in numpy.arange(0,n):
    147             for j in numpy.arange(0,m):
     147        for i in arange(0,n):
     148            for j in arange(0,m):
    148149                I = j+m*i
    149150                A[I,I] = 4.0
     
    157158                    A[I,I+1] = -1.0
    158159
    159         xe = numpy.ones( (n*m,), numpy.float)
     160        xe = ones( (n*m,), Float)
    160161
    161162        b  = A*xe
    162163        x = conjugate_gradient(A,b)
    163164
    164         assert numpy.allclose(x,xe)
     165        assert allclose(x,xe)
    165166
    166167
     
    201202        x = conjugate_gradient(A,b,x,iprint=0)
    202203
    203         assert numpy.allclose(x,xe)
     204        assert allclose(x,xe)
    204205
    205206#-------------------------------------------------------------
  • anuga_core/source/anuga/utilities/test_data_audit.py

    r5891 r5897  
    33
    44import unittest
     5from Numeric import zeros, array, allclose, Float
    56from tempfile import mkstemp
    67import os
  • anuga_core/source/anuga/utilities/test_numerical_tools.py

    r5891 r5897  
    33
    44import unittest
    5 import numpy
     5from Numeric import zeros, array, allclose
     6from Numeric import ArrayType, Float, Int, array, alltrue
    67
    78from math import sqrt, pi
     
    2223        """Test angles between one vector and the x-axis
    2324        """
    24         assert numpy.allclose(angle([1.0, 0.0])/pi*180, 0.0)       
    25         assert numpy.allclose(angle([1.0, 1.0])/pi*180, 45.0)
    26         assert numpy.allclose(angle([0.0, 1.0])/pi*180, 90.0)           
    27         assert numpy.allclose(angle([-1.0, 1.0])/pi*180, 135.0)         
    28         assert numpy.allclose(angle([-1.0, 0.0])/pi*180, 180.0)
    29         assert numpy.allclose(angle([-1.0, -1.0])/pi*180, 225.0)
    30         assert numpy.allclose(angle([0.0, -1.0])/pi*180, 270.0)
    31         assert numpy.allclose(angle([1.0, -1.0])/pi*180, 315.0)
     25        assert allclose(angle([1.0, 0.0])/pi*180, 0.0)     
     26        assert allclose(angle([1.0, 1.0])/pi*180, 45.0)
     27        assert allclose(angle([0.0, 1.0])/pi*180, 90.0)         
     28        assert allclose(angle([-1.0, 1.0])/pi*180, 135.0)               
     29        assert allclose(angle([-1.0, 0.0])/pi*180, 180.0)
     30        assert allclose(angle([-1.0, -1.0])/pi*180, 225.0)
     31        assert allclose(angle([0.0, -1.0])/pi*180, 270.0)
     32        assert allclose(angle([1.0, -1.0])/pi*180, 315.0)
    3233               
    3334                                                         
     
    3637        """   
    3738       
    38         assert numpy.allclose(angle([1.0, 0.0], [1.0, 1.0])/pi*180, 315.0)
    39         assert numpy.allclose(angle([1.0, 1.0], [1.0, 0.0])/pi*180, 45.0)
     39        assert allclose(angle([1.0, 0.0], [1.0, 1.0])/pi*180, 315.0)
     40        assert allclose(angle([1.0, 1.0], [1.0, 0.0])/pi*180, 45.0)
    4041               
    41         assert numpy.allclose(angle([-1.0, -1.0], [1.0, 1.0])/pi*180, 180)     
    42         assert numpy.allclose(angle([-1.0, -1.0], [-1.0, 1.0])/pi*180, 90.0)   
     42        assert allclose(angle([-1.0, -1.0], [1.0, 1.0])/pi*180, 180)   
     43        assert allclose(angle([-1.0, -1.0], [-1.0, 1.0])/pi*180, 90.0) 
    4344       
    44         assert numpy.allclose(angle([-1.0, 0.0], [1.0, 1.0])/pi*180, 135.0)
    45         assert numpy.allclose(angle([0.0, -1.0], [1.0, 1.0])/pi*180, 225.0)     
     45        assert allclose(angle([-1.0, 0.0], [1.0, 1.0])/pi*180, 135.0)
     46        assert allclose(angle([0.0, -1.0], [1.0, 1.0])/pi*180, 225.0)   
    4647       
    47         assert numpy.allclose(angle([1.0, -1.0], [1.0, 1.0])/pi*180, 270.0)     
    48         assert numpy.allclose(angle([1.0, 0.0], [0.0, 1.0])/pi*180, 270.0)
     48        assert allclose(angle([1.0, -1.0], [1.0, 1.0])/pi*180, 270.0)   
     49        assert allclose(angle([1.0, 0.0], [0.0, 1.0])/pi*180, 270.0)
    4950
    5051        #From test_get_boundary_polygon_V
    5152        v_prev = [-0.5, -0.5]
    5253        vc = [ 0.0,  -0.5]
    53         assert numpy.allclose(angle(vc, v_prev)/pi*180, 45.0)
     54        assert allclose(angle(vc, v_prev)/pi*180, 45.0)
    5455
    5556        vc = [ 0.5,  0.0]
    56         assert numpy.allclose(angle(vc, v_prev)/pi*180, 135.0)
     57        assert allclose(angle(vc, v_prev)/pi*180, 135.0)
    5758
    5859        vc = [ -0.5,  0.5]
    59         assert numpy.allclose(angle(vc, v_prev)/pi*180, 270.0)               
     60        assert allclose(angle(vc, v_prev)/pi*180, 270.0)               
    6061
    6162
    6263    def test_anglediff(self):
    63         assert numpy.allclose(anglediff([0.0, 1.], [1.0, 1.0])/pi*180, 45.0)
     64        assert allclose(anglediff([0.0, 1.], [1.0, 1.0])/pi*180, 45.0)
    6465
    6566       
     
    6768        A = [1,2,3,4]
    6869        B = ensure_numeric(A)
    69         assert isinstance(B, numpy.ndarray)
    70         assert B.dtype.char == 'l'
     70        assert type(B) == ArrayType
     71        assert B.typecode() == 'l'
    7172        assert B[0] == 1 and B[1] == 2 and B[2] == 3 and B[3] == 4
    7273
    7374        A = [1,2,3.14,4]
    7475        B = ensure_numeric(A)
    75         assert isinstance(B, numpy.ndarray)
    76         assert B.dtype.char == 'd'
     76        assert type(B) == ArrayType
     77        assert B.typecode() == 'd'
    7778        assert B[0] == 1 and B[1] == 2 and B[2] == 3.14 and B[3] == 4
    7879
    7980        A = [1,2,3,4]
    80         B = ensure_numeric(A, numpy.float)
    81         assert isinstance(B, numpy.ndarray)
    82         assert B.dtype.char == 'd'
     81        B = ensure_numeric(A, Float)
     82        assert type(B) == ArrayType
     83        assert B.typecode() == 'd'
    8384        assert B[0] == 1.0 and B[1] == 2.0 and B[2] == 3.0 and B[3] == 4.0
    8485
    8586        A = [1,2,3,4]
    86         B = ensure_numeric(A, numpy.float)
    87         assert isinstance(B, numpy.ndarray)
    88         assert B.dtype.char == 'd'
     87        B = ensure_numeric(A, Float)
     88        assert type(B) == ArrayType
     89        assert B.typecode() == 'd'
    8990        assert B[0] == 1.0 and B[1] == 2.0 and B[2] == 3.0 and B[3] == 4.0
    9091
    91         A = numpy.array([1,2,3,4])
     92        A = array([1,2,3,4])
    9293        B = ensure_numeric(A)
    93         assert isinstance(B, numpy.ndarray)
    94         assert B.dtype.char == 'l'       
    95         assert numpy.alltrue(A == B)   
     94        assert type(B) == ArrayType
     95        assert B.typecode() == 'l'       
     96        assert alltrue(A == B)   
    9697        assert A is B   #Same object
    9798
    98         A = numpy.array([1,2,3,4])
    99         B = ensure_numeric(A, numpy.float)
    100         assert isinstance(B, numpy.ndarray)
    101         assert B.dtype.char == 'd'       
    102         assert numpy.alltrue(A == B)   
     99        A = array([1,2,3,4])
     100        B = ensure_numeric(A, Float)
     101        assert type(B) == ArrayType
     102        assert B.typecode() == 'd'       
     103        assert alltrue(A == B)   
    103104        assert A is not B   #Not the same object
    104105
    105106        # Check scalars
    106107        A = 1
    107         B = ensure_numeric(A, numpy.float)
     108        B = ensure_numeric(A, Float)
    108109        #print A, B[0], len(B), type(B)
    109110        #print B.shape
    110         assert numpy.alltrue(A == B)
    111 
    112         B = ensure_numeric(A, numpy.int)       
     111        assert alltrue(A == B)
     112
     113        B = ensure_numeric(A, Int)       
    113114        #print A, B
    114115        #print B.shape
    115         assert numpy.alltrue(A == B)
    116 
    117     def NO_test_ensure_numeric_char(self):
     116        assert alltrue(A == B)
     117
    118118        # Error situation
    119         B = ensure_numeric('hello', numpy.int)
    120         print 'B=%s %s' % (str(B), type(B))
    121         assert numpy.allclose(B, [104, 101, 108, 108, 111])
     119
     120        B = ensure_numeric('hello', Int)               
     121        assert allclose(B, [104, 101, 108, 108, 111])
    122122
    123123
     
    160160        zx, zy = gradient(x0, y0, x1, y1, x2, y2, z0, z1, z2)
    161161        a, b = gradient2(x0, y0, x1, y1, z0, z1)
    162        
     162
    163163        assert zx == a
    164164        assert zy == b
     
    208208        #There are four elements greater than or equal to 3
    209209        bins = [3]
    210         assert numpy.allclose(histogram(a, bins), [4])
     210        assert allclose(histogram(a, bins), [4])
    211211
    212212        bins = [ min(a) ]
    213         assert numpy.allclose(histogram(a, bins), [len(a)])
     213        assert allclose(histogram(a, bins), [len(a)])
    214214
    215215        bins = [ max(a)+0.00001 ]
    216         assert numpy.allclose(histogram(a, bins), [0])       
     216        assert allclose(histogram(a, bins), [0])       
    217217       
    218218        bins = [1,2,3,4]
    219         assert numpy.allclose(histogram(a, bins), [8,3,3,1])
     219        assert allclose(histogram(a, bins), [8,3,3,1])
    220220
    221221        bins = [1.1,2,3.1,4]
    222222        #print histogram(a, bins)
    223         assert numpy.allclose(histogram(a, bins), [0,6,0,1])
     223        assert allclose(histogram(a, bins), [0,6,0,1])
    224224
    225225        bins = [0,1.5,2,3]
    226         assert numpy.allclose(histogram(a, bins), [8,0,3,4])
    227         assert numpy.allclose(histogram(a, [0,3]), histogram(a, [-0.5,3]))
     226        assert allclose(histogram(a, bins), [8,0,3,4])
     227        assert allclose(histogram(a, [0,3]), histogram(a, [-0.5,3]))
    228228
    229229        # Check situation with #bins >= #datapoints
    230230        a = [1.7]
    231231        bins = [0,1.5,2,3]
    232         assert numpy.allclose(histogram(a, bins), [0,1,0,0])
     232        assert allclose(histogram(a, bins), [0,1,0,0])
    233233
    234234        a = [1.7]
    235235        bins = [0]
    236         assert numpy.allclose(histogram(a, bins), [1])
     236        assert allclose(histogram(a, bins), [1])
    237237
    238238        a = [-1.7]
    239239        bins = [0]
    240         assert numpy.allclose(histogram(a, bins), [0])
     240        assert allclose(histogram(a, bins), [0])
    241241
    242242        a = [-1.7]
    243243        bins = [-1.7]
    244         assert numpy.allclose(histogram(a, bins), [1])       
     244        assert allclose(histogram(a, bins), [1])       
    245245       
    246246
     
    281281        from util_ext import gradient as gradient_c
    282282
    283         from numpy.random import uniform, seed
    284         seed(53)    # numeric was seed(17, 53)
     283        from RandomArray import uniform, seed
     284        seed(17, 53)
    285285
    286286        x0, x1, x2, y0, y1, y2 = uniform(0.0,3.0,6)
     
    312312        # sqrt(sum_over_x&y((xi - yi)^2))
    313313        err__1 = err(x,y,2,False)
    314        
    315314        assert err__1 == sqrt(20)
    316315        #print "err_", err_
  • anuga_core/source/anuga/utilities/test_polygon.py

    r5891 r5897  
    33
    44import unittest
    5 import numpy
     5from Numeric import zeros, array, allclose
    66from math import sqrt, pi
    77from anuga.utilities.numerical_tools import ensure_numeric
     
    4343        p2 = [[0,0], [10,10], [15,5], [20, 10], [25,0], [30,10], [40,-10]]
    4444
    45         f = Polygon_function( [(p1, 1.0)], verbose=False )
     45        f = Polygon_function( [(p1, 1.0)] )
    4646        z = f([5, 5, 27, 35], [5, 9, 8, -5]) #Two first inside p1
    47         assert numpy.allclose(z, [1,1,0,0])
     47        assert allclose(z, [1,1,0,0])
    4848
    4949
    5050        f = Polygon_function( [(p2, 2.0)] )
    5151        z = f([5, 5, 27, 35], [5, 9, 8, -5]) # First and last inside p2
    52         assert numpy.allclose(z, [2,0,0,2])
     52        assert allclose(z, [2,0,0,2])
    5353
    5454
     
    5656        f = Polygon_function( [(p1, 1.0), (p2, 2.0)] )
    5757        z = f([5, 5, 27, 35], [5, 9, 8, -5])
    58         assert numpy.allclose(z, [2,1,0,2])
    59 
    60 
    61     def test_polygon_function_constants_tuple(self):
    62         polygon = [[0,0], [10,0], [10,10], [0,10]]
    63         points = ((5, 5), (5, 9), (27, 8), (35, -5))
    64 
    65         (indices, count) = separate_points_by_polygon(points, polygon, verbose=False)
     58        assert allclose(z, [2,1,0,2])
    6659
    6760    def test_polygon_function_csvfile(self):
     
    7972        z = f([430000,480000], [490000,7720000]) # first outside, second inside
    8073       
    81         assert numpy.allclose(z, [0,10])
     74        assert allclose(z, [0,10])
    8275
    8376    def test_polygon_function_georef(self):
     
    9790        z = f([5, 5, 27, 35], [5, 9, 8, -5]) #Two first inside p1
    9891
    99         assert numpy.allclose(z, [1,1,0,0])
     92        assert allclose(z, [1,1,0,0])
    10093
    10194
    10295        f = Polygon_function( [(p2, 2.0)], geo_reference=geo)
    10396        z = f([5, 5, 27, 35], [5, 9, 8, -5]) #First and last inside p2
    104         assert numpy.allclose(z, [2,0,0,2])
     97        assert allclose(z, [2,0,0,2])
    10598
    10699
     
    108101        f = Polygon_function( [(p1, 1.0), (p2, 2.0)], geo_reference=geo)
    109102        z = f([5, 5, 27, 35], [5, 9, 8, -5])
    110         assert numpy.allclose(z, [2,1,0,2])
     103        assert allclose(z, [2,1,0,2])
    111104
    112105
     
    114107        f = Polygon_function( [(p1, 1.0), (p2, 2.0)])
    115108        z = f([5, 5, 27, 35], [5, 9, 8, -5])
    116         assert not numpy.allclose(z, [2,1,0,2])       
     109        assert not allclose(z, [2,1,0,2])       
    117110
    118111
     
    127120        f = Polygon_function( [(p1, test_function)] )
    128121        z = f([5, 5, 27, 35], [5, 9, 8, -5]) #Two first inside p1
    129         assert numpy.allclose(z, [10,14,0,0])
     122        assert allclose(z, [10,14,0,0])
    130123
    131124        # Combined
    132125        f = Polygon_function( [(p1, test_function), (p2, 2.0)] )
    133126        z = f([5, 5, 27, 35], [5, 9, 8, -5])
    134         assert numpy.allclose(z, [2,14,0,2])
     127        assert allclose(z, [2,14,0,2])
    135128
    136129
     
    138131        f = Polygon_function( [(p1, test_function), (p2, 2.0)], default = 3.14)
    139132        z = f([5, 5, 27, 35], [5, 9, 8, -5])
    140         assert numpy.allclose(z, [2,14,3.14,2])
     133        assert allclose(z, [2,14,3.14,2])
    141134
    142135
     
    145138                              default = test_function)
    146139        z = f([5, 5, 27, 35], [5, 9, 8, -5])
    147         assert numpy.allclose(z, [2,14,35,2])
     140        assert allclose(z, [2,14,35,2])
    148141
    149142
     
    217210        res = inside_polygon(points, polygon)
    218211        assert len(res) == 2
    219         assert numpy.allclose(res, [0,1])     ## alltrue?
     212        assert allclose(res, [0,1])
    220213
    221214
     
    312305        res = inside_polygon( points, polygon, verbose=False )
    313306
    314         assert numpy.allclose( res, [0,1,2] )
     307        assert allclose( res, [0,1,2] )
    315308
    316309    def test_outside_polygon(self):
     
    324317       
    325318        indices = outside_polygon( [[0.5, 0.5], [1, -0.5], [0.3, 0.2]], U )
    326         assert numpy.allclose( indices, [1] )
     319        assert allclose( indices, [1] )
    327320       
    328321        # One more test of vector formulation returning indices
     
    331324        res = outside_polygon( points, polygon )
    332325
    333         assert numpy.allclose( res, [3, 4] )
     326        assert allclose( res, [3, 4] )
    334327
    335328
     
    339332        res = outside_polygon( points, polygon )
    340333
    341         assert numpy.allclose( res, [0, 4, 5] )       
     334        assert allclose( res, [0, 4, 5] )       
    342335     
    343336    def test_outside_polygon2(self):
     
    362355        #print indices, count
    363356        assert count == 0 #None inside
    364         assert numpy.allclose(indices, [3,2,1,0])
     357        assert allclose(indices, [3,2,1,0])
    365358
    366359        indices = outside_polygon(points, U, closed = True)
    367         assert numpy.allclose(indices, [0,1,2,3])
     360        assert allclose(indices, [0,1,2,3])
    368361
    369362        indices = inside_polygon(points, U, closed = True)
    370         assert numpy.allclose(indices, [])               
     363        assert allclose(indices, [])               
    371364
    372365
     
    382375        indices, count = separate_points_by_polygon(points, U)
    383376        assert count == 3 #All inside
    384         assert numpy.allclose(indices, [0,1,2])
     377        assert allclose(indices, [0,1,2])
    385378
    386379        indices = outside_polygon(points, U, closed = True)
    387         assert numpy.allclose(indices, [])
     380        assert allclose(indices, [])
    388381
    389382        indices = inside_polygon(points, U, closed = True)
    390         assert numpy.allclose(indices, [0,1,2])
     383        assert allclose(indices, [0,1,2])
    391384       
    392385
     
    395388
    396389        indices, count = separate_points_by_polygon( [[0.5, 0.5], [1, -0.5], [0.3, 0.2]], U )
    397         assert numpy.allclose( indices, [0,2,1] )
     390        assert allclose( indices, [0,2,1] )
    398391        assert count == 2
    399392       
     
    403396        res, count = separate_points_by_polygon( points, polygon )
    404397
    405         assert numpy.allclose( res, [0,1,2,4,3] )
     398        assert allclose( res, [0,1,2,4,3] )
    406399        assert count == 3
    407400
     
    411404        res, count = separate_points_by_polygon( points, polygon )
    412405
    413         assert numpy.allclose( res, [1,2,3,5,4,0] )       
     406        assert allclose( res, [1,2,3,5,4,0] )       
    414407        assert count == 3
    415408       
     
    595588        status, value = intersection(line0, line1)
    596589        assert status == 1
    597         assert numpy.allclose(value, [0.0, 0.0])
     590        assert allclose(value, [0.0, 0.0])
    598591
    599592    def test_intersection2(self):
     
    603596        status, value = intersection(line0, line1)
    604597        assert status == 1
    605         assert numpy.allclose(value, [12.0, 6.0])
     598        assert allclose(value, [12.0, 6.0])
    606599
    607600        # Swap direction of one line
     
    610603        status, value = intersection(line0, line1)
    611604        assert status == 1
    612         assert numpy.allclose(value, [12.0, 6.0])
     605        assert allclose(value, [12.0, 6.0])
    613606
    614607        # Swap order of lines
    615608        status, value = intersection(line1, line0)
    616609        assert status == 1
    617         assert numpy.allclose(value, [12.0, 6.0])       
     610        assert allclose(value, [12.0, 6.0])       
    618611       
    619612    def test_intersection3(self):
     
    623616        status, value = intersection(line0, line1)
    624617        assert status == 1
    625         assert numpy.allclose(value, [14.068965517, 7.0344827586])
     618        assert allclose(value, [14.068965517, 7.0344827586])
    626619
    627620        # Swap direction of one line
     
    630623        status, value = intersection(line0, line1)
    631624        assert status == 1
    632         assert numpy.allclose(value, [14.068965517, 7.0344827586])       
     625        assert allclose(value, [14.068965517, 7.0344827586])       
    633626
    634627        # Swap order of lines
    635628        status, value = intersection(line1, line0)
    636629        assert status == 1       
    637         assert numpy.allclose(value, [14.068965517, 7.0344827586])       
     630        assert allclose(value, [14.068965517, 7.0344827586])       
    638631
    639632
     
    648641        status, value = intersection(line0, line1)
    649642        assert status == 1
    650         assert numpy.allclose(value, [1.0, 1.0])
     643        assert allclose(value, [1.0, 1.0])
    651644
    652645
     
    656649        status, value = intersection(line0, line1)
    657650        assert status == 1
    658         assert numpy.allclose(value, [1.0, 1.0])       
     651        assert allclose(value, [1.0, 1.0])       
    659652       
    660653
     
    686679                                                          common_end_point[1])
    687680            msg += ' gave %s, \nbut when reversed we got %s' %(p1, p2)
    688             assert numpy.allclose(p1, p2), msg
     681            assert allclose(p1, p2), msg
    689682
    690683            # Swap order of lines
     
    692685            assert status == 1                       
    693686            msg = 'Order of lines gave different results'
    694             assert numpy.allclose(p1, p3), msg
     687            assert allclose(p1, p3), msg
    695688           
    696689
     
    732725        status, value = intersection(line0, line1)
    733726        assert status == 2
    734         assert numpy.allclose(value, [[0,0], [3,0]])
     727        assert allclose(value, [[0,0], [3,0]])
    735728
    736729        # Overlap 2
     
    740733        status, value = intersection(line0, line1)
    741734        assert status == 2
    742         assert numpy.allclose(value, [[-3, 0], [5,0]])       
     735        assert allclose(value, [[-3, 0], [5,0]])       
    743736
    744737        # Inclusion 1
     
    748741        status, value = intersection(line0, line1)
    749742        assert status == 2       
    750         assert numpy.allclose(value, line1)
     743        assert allclose(value, line1)
    751744
    752745        # Inclusion 2
     
    756749        status, value = intersection(line0, line1)
    757750        assert status == 2       
    758         assert numpy.allclose(value, line0)                                       
     751        assert allclose(value, line0)                                       
    759752
    760753
     
    775768        status, value = intersection(line0, line1)
    776769        assert status == 2               
    777         assert numpy.allclose(value, [[1, 7], [7, 19]])
     770        assert allclose(value, [[1, 7], [7, 19]])
    778771
    779772        status, value = intersection(line1, line0)
    780773        assert status == 2
    781         assert numpy.allclose(value, [[1, 7], [7, 19]])
     774        assert allclose(value, [[1, 7], [7, 19]])
    782775
    783776        # Swap direction
     
    786779        status, value = intersection(line0, line1)
    787780        assert status == 2
    788         assert numpy.allclose(value, [[7, 19], [1, 7]])
     781        assert allclose(value, [[7, 19], [1, 7]])
    789782
    790783        line0 = [[0,5], [7,19]]
     
    792785        status, value = intersection(line0, line1)
    793786        assert status == 2
    794         assert numpy.allclose(value, [[1, 7], [7, 19]])       
     787        assert allclose(value, [[1, 7], [7, 19]])       
    795788       
    796789
     
    800793        status, value = intersection(line0, line1)
    801794        assert status == 2                       
    802         assert numpy.allclose(value, [[1,7], [7, 19]])               
     795        assert allclose(value, [[1,7], [7, 19]])               
    803796
    804797        line0 = [[0,5], [10,25]]
     
    806799        status, value = intersection(line0, line1)
    807800        assert status == 2                       
    808         assert numpy.allclose(value, [[1,7], [7, 19]])
     801        assert allclose(value, [[1,7], [7, 19]])
    809802
    810803
     
    813806        status, value = intersection(line0, line1)
    814807        assert status == 2                       
    815         assert numpy.allclose(value, [[7, 19], [1, 7]])                       
     808        assert allclose(value, [[7, 19], [1, 7]])                       
    816809       
    817810       
     
    850843        res = inside_polygon(points, polygon)
    851844        assert len(res) == 2
    852         assert numpy.allclose(res, [0,1])
     845        assert allclose(res, [0,1])
    853846
    854847    def test_polygon_area(self):
     
    997990if __name__ == "__main__":
    998991    suite = unittest.makeSuite(Test_Polygon,'test')
    999 ##    suite = unittest.makeSuite(Test_Polygon,'test_polygon_function_constantsX')
     992    #suite = unittest.makeSuite(Test_Polygon,'test_inside_polygon_geo_ref')
    1000993    runner = unittest.TextTestRunner()
    1001994    runner.run(suite)
  • anuga_core/source/anuga/utilities/test_quad.py

    r5891 r5897  
    11import unittest
    2 ##import numpy
     2from Numeric import array, allclose
    33
    44from quad import Cell, build_quadtree
     
    236236                     [ 0.,  -1.]]
    237237                     
    238         # assert numpy.allclose(numpy.array(results),[[[ 2.,  1.],
     238        # assert allclose(array(results),[[[ 2.,  1.],
    239239        #[ 4.,  1.], [ 4.,  4.]], [[ 4.,  1.],[ 5.,  4.],[ 4.,  4.]]] )
    240240        results = Q.search(5,4.)
     
    253253                     [ 5.,  4.],
    254254                     [ 4.,  4.]]
    255         #assert numpy.allclose(numpy.array(results),[[[ 2.,  1.],[ 4.,  1.], [ 4.,  4.]]
     255        #assert allclose(array(results),[[[ 2.,  1.],[ 4.,  1.], [ 4.,  4.]]
    256256         #                               ,[[ 2.,  1.],[ 4.,  4.], [ 2.,  4.]],
    257257        #[[ 4.,  1.],  [ 5.,  4.], [ 4.,  4.]],
  • anuga_core/source/anuga/utilities/test_sparse.py

    r5891 r5897  
    55
    66from sparse import *
    7 import numpy
     7from Numeric import allclose, array, transpose, Float
    88
    99class Test_Sparse(unittest.TestCase):
     
    4343        C = Sparse(B)
    4444
    45         assert numpy.allclose(C.todense(), B)
     45        assert allclose(C.todense(), B)
    4646
    4747
     
    5050        A[1,1] = 4
    5151
    52         assert numpy.allclose(A.todense(), [[0,0,0], [0,4,0], [0,0,0], [0,0,0]])
     52        assert allclose(A.todense(), [[0,0,0], [0,4,0], [0,0,0], [0,0,0]])
    5353
    5454
     
    6363
    6464        assert len(A) == 0
    65         assert numpy.allclose(A.todense(), [[0,0,0], [0,0,0], [0,0,0]])
     65        assert allclose(A.todense(), [[0,0,0], [0,0,0], [0,0,0]])
    6666
    6767        #Set an existing zero element to zero
    6868        A[1,2] = 0
    6969        assert len(A) == 0
    70         assert numpy.allclose(A.todense(), [[0,0,0], [0,0,0], [0,0,0]])
     70        assert allclose(A.todense(), [[0,0,0], [0,0,0], [0,0,0]])
    7171
    7272    def test_sparse_multiplication_vector(self):
     
    8282
    8383        u = A*v
    84         assert numpy.allclose(u, [6,14,4])
     84        assert allclose(u, [6,14,4])
    8585
    8686        #Right hand side column
    87         v = numpy.array([[2,4],[3,4],[4,4]])
     87        v = array([[2,4],[3,4],[4,4]])
    8888
    8989        u = A*v[:,0]
    90         assert numpy.allclose(u, [6,14,4])
     90        assert allclose(u, [6,14,4])
    9191
    9292        u = A*v[:,1]
    93         assert numpy.allclose(u, [12,16,4])
     93        assert allclose(u, [12,16,4])
    9494
    9595
     
    103103
    104104        #Right hand side matrix
    105         v = numpy.array([[2,4],[3,4],[4,4]])
     105        v = array([[2,4],[3,4],[4,4]])
    106106
    107107        u = A*v
    108         assert numpy.allclose(u, [[6,12], [14,16], [4,4]])
     108        assert allclose(u, [[6,12], [14,16], [4,4]])
    109109
    110110
     
    122122
    123123        u = A.trans_mult(v)
    124         assert numpy.allclose(u, [6,6,10])
     124        assert allclose(u, [6,6,10])
    125125
    126126
     
    137137
    138138        B = 3*A
    139         assert numpy.allclose(B.todense(), 3*A.todense())
     139        assert allclose(B.todense(), 3*A.todense())
    140140
    141141        B = A*3
    142         assert numpy.allclose(B.todense(), 3*A.todense())
     142        assert allclose(B.todense(), 3*A.todense())
    143143
    144144        try:
     
    166166        C = A+B
    167167
    168         assert numpy.allclose(C.todense(), [[12,0,0], [2,8,8], [0,0,4]])
     168        assert allclose(C.todense(), [[12,0,0], [2,8,8], [0,0,4]])
    169169
    170170    def test_sparse_tocsr(self):
     
    190190        C = [1, 2, 3]
    191191
    192         assert numpy.allclose(B*C, [15.0, 10.0 ,8.0, 0.0])
     192        assert allclose(B*C, [15.0, 10.0 ,8.0, 0.0])
    193193
    194194        C2 = [[1,2],[2,4],[3,6]]
     
    196196        #print B*C2
    197197
    198         assert numpy.allclose(B*C2, [[15.0, 30.0],[10.0, 20.0],[8.0, 16.0],[0.0, 0.0]])
     198        assert allclose(B*C2, [[15.0, 30.0],[10.0, 20.0],[8.0, 16.0],[0.0, 0.0]])
    199199
    200200
  • anuga_core/source/anuga/utilities/test_system_tools.py

    r5891 r5897  
    11#!/usr/bin/env python
    22
     3
    34import unittest
    4 import numpy
     5from Numeric import zeros, array, allclose, Float
    56import zlib
    67from os.path import join, split, sep
     
    8081            pass
    8182        else:
    82             test_array = numpy.array([[7.0, 3.14], [-31.333, 0.0]])
     83            test_array = array([[7.0, 3.14], [-31.333, 0.0]])
    8384
    8485            # First file
     
    8687            fid = NetCDFFile(filename1, 'w')
    8788            fid.createDimension('two', 2)
    88             fid.createVariable('test_array', numpy.dtype(numpy.float).char, ('two', 'two'))
     89            fid.createVariable('test_array', Float,
     90                               ('two', 'two'))
    8991            fid.variables['test_array'][:] = test_array
    9092            fid.close()
     
    9496            fid = NetCDFFile(filename2, 'w')
    9597            fid.createDimension('two', 2)
    96             fid.createVariable('test_array', numpy.dtype(numpy.float).char, ('two', 'two'))
     98            fid.createVariable('test_array', Float,
     99                               ('two', 'two'))
    97100            fid.variables['test_array'][:] = test_array
    98101            fid.close()
  • anuga_core/source/anuga/utilities/test_xml_tools.py

    r5891 r5897  
    33
    44import unittest
     5from Numeric import zeros, array, allclose, Float
    56from tempfile import mkstemp, mktemp
    67
  • anuga_core/source/anuga/utilities/util_ext.c

    r5891 r5897  
    1616
    1717#include "Python.h"
    18 #include "numpy/arrayobject.h"
     18#include "Numeric/arrayobject.h"
    1919#include "math.h"
    2020
  • anuga_core/source/anuga/utilities/util_ext.h

    r5891 r5897  
    1111       
    1212#include "Python.h"     
    13 #include "numpy/arrayobject.h"
     13#include "Numeric/arrayobject.h"
    1414#include "math.h"
    1515
Note: See TracChangeset for help on using the changeset viewer.