Ignore:
Timestamp:
Nov 6, 2008, 3:41:41 PM (16 years ago)
Author:
rwilson
Message:

NumPy? conversion.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • anuga_core/source_numpy_conversion/anuga/fit_interpolate/interpolate.py

    r5869 r5905  
    2424from csv import writer, DictWriter
    2525
    26 from Numeric import zeros, array, Float, Int, dot, transpose, concatenate, \
    27      ArrayType, allclose, take, NewAxis, arange
     26import numpy
    2827
    2928from anuga.caching.caching import cache
     
    116115
    117116    # Create interpolation object with matrix
    118     args = (ensure_numeric(vertex_coordinates, Float),
     117    args = (ensure_numeric(vertex_coordinates, numpy.float),
    119118            ensure_numeric(triangles))
    120119    kwargs = {'mesh_origin': mesh_origin,
     
    224223 
    225224        from utilities.polygon import point_on_line
    226         from Numeric import ones
    227         z=ones(len(point_coordinates),Float)
     225        z=numpy.ones(len(point_coordinates),numpy.float)
    228226
    229227        msg='point coordinates are not given (interpolate.py)'
     
    343341                # creating a dummy array to concatenate to.
    344342               
    345                 f = ensure_numeric(f, Float)
     343                f = ensure_numeric(f, numpy.float)
    346344                #print "f.shape",f.shape
    347345                if len(f.shape) > 1:
    348                     z = zeros((0,f.shape[1]))
     346                    z = numpy.zeros((0,f.shape[1]), numpy.float)
    349347                else:
    350                     z = zeros((0,))
     348                    z = numpy.zeros((0,), numpy.float)
    351349                   
    352350                for end in range(start_blocking_len,
     
    358356                    #print "t", t
    359357                    #print "z", z
    360                     z = concatenate((z,t))
     358                    z = numpy.concatenate((z,t))
    361359                    start = end
    362360                   
     
    364362                t = self.interpolate_block(f, point_coordinates[start:end],
    365363                                           verbose=verbose)
    366                 z = concatenate((z,t))
     364                z = numpy.concatenate((z,t))
    367365        return z
    368366   
     
    389387
    390388        # Convert lists to Numeric arrays if necessary
    391         point_coordinates = ensure_numeric(point_coordinates, Float)
    392         f = ensure_numeric(f, Float)               
     389        point_coordinates = ensure_numeric(point_coordinates, numpy.float)
     390        f = ensure_numeric(f, numpy.float)               
    393391
    394392        from anuga.caching import myhash
    395         from Numeric import alltrue
    396393        import sys
    397394        if use_cache is True:
     
    412409                if self.interpolation_matrices.has_key(key):
    413410                    X, stored_points = self.interpolation_matrices[key]
    414                     if alltrue(stored_points == point_coordinates):
     411                    if numpy.alltrue(stored_points == point_coordinates):
    415412                        reuse_A = True # Reuse interpolation matrix
    416413               
     
    487484
    488485        # Convert point_coordinates to Numeric arrays, in case it was a list.
    489         point_coordinates = ensure_numeric(point_coordinates, Float)
     486        point_coordinates = ensure_numeric(point_coordinates, numpy.float)
    490487       
    491488       
     
    752749        """
    753750
    754         from Numeric import array, zeros, Float, alltrue, concatenate,\
    755              reshape, ArrayType
    756 
    757 
    758751        from anuga.config import time_format
    759752        import types
    760 
    761753
    762754        # Check temporal info
     
    764756        msg = 'Time must be a monotonuosly '
    765757        msg += 'increasing sequence %s' %time
    766         assert alltrue(time[1:] - time[:-1] >= 0 ), msg
     758        assert numpy.alltrue(time[1:] - time[:-1] >= 0 ), msg
    767759
    768760
     
    795787        # Thin timesteps if needed
    796788        # Note array() is used to make the thinned arrays contiguous in memory
    797         self.time = array(time[::time_thinning])         
     789        self.time = numpy.array(time[::time_thinning])         
    798790        for name in quantity_names:
    799791            if len(quantities[name].shape) == 2:
    800                 quantities[name] = array(quantities[name][::time_thinning,:])
     792                quantities[name] = numpy.array(quantities[name][::time_thinning,:])
    801793             
    802794        # Save for use with statistics
    803795        self.quantities_range = {}
    804796        for name in quantity_names:
    805             q = quantities[name][:].flat
     797##            q = quantities[name][:].ravel()
     798            q = numpy.ravel(quantities[name][:])
    806799            self.quantities_range[name] = [min(q), max(q)]
    807800       
     
    863856                        if sys.platform == 'win32': # FIXME (Ole): Why only Windoze?
    864857                            from anuga.utilities.polygon import plot_polygons
    865                             #out_interp_pts = take(interpolation_points,[indices])
     858                            #out_interp_pts = numpy.take(interpolation_points,[indices], axis=0)
    866859                            title = 'Interpolation points fall outside specified mesh'
    867860                            plot_polygons([mesh_boundary_polygon,
     
    905898           
    906899            for name in quantity_names:
    907                 self.precomputed_values[name] = zeros((p, m), Float)
     900                self.precomputed_values[name] = numpy.zeros((p, m), numpy.float)
    908901
    909902            # Build interpolator
     
    995988
    996989        from math import pi, cos, sin, sqrt
    997         from Numeric import zeros, Float
    998990        from anuga.abstract_2d_finite_volumes.util import mean       
    999991
     
    10311023
    10321024        # Compute interpolated values
    1033         q = zeros(len(self.quantity_names), Float)
     1025        q = numpy.zeros(len(self.quantity_names), numpy.float)
    10341026        # print "self.precomputed_values", self.precomputed_values
    10351027        for i, name in enumerate(self.quantity_names):
     
    10861078                    return q
    10871079                else:
    1088                     from Numeric import ones, Float
    10891080                    # x is a vector - Create one constant column for each value
    10901081                    N = len(x)
     
    10921083                    res = []
    10931084                    for col in q:
    1094                         res.append(col*ones(N, Float))
     1085                        res.append(col*numpy.ones(N, numpy.float))
    10951086                       
    10961087                return res
     
    11291120            minq, maxq = self.quantities_range[name]
    11301121            str += '    %s in [%f, %f]\n' %(name, minq, maxq)           
    1131             #q = quantities[name][:].flat
     1122            #q = quantities[name][:].ravel()
    11321123            #str += '    %s in [%f, %f]\n' %(name, min(q), max(q))
    11331124
     
    11421133       
    11431134            for name in quantity_names:
    1144                 q = precomputed_values[name][:].flat
     1135##NumPy                q = precomputed_values[name][:].ravel()
     1136                q = numpy.ravel(precomputed_values[name][:])
    11451137                str += '    %s at interpolation points in [%f, %f]\n'\
    11461138                       %(name, min(q), max(q))
     
    11651157
    11661158    #Add the x and y together
    1167     vertex_coordinates = concatenate((x[:,NewAxis], y[:,NewAxis]),axis=1)
     1159    vertex_coordinates = numpy.concatenate((x[:,numpy.newaxis], y[:,numpy.newaxis]),axis=1)
    11681160
    11691161    #Will return the quantity values at the specified times and locations
Note: See TracChangeset for help on using the changeset viewer.