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

More NumPy? changes.

Location:
anuga_core/source_numpy_conversion/anuga/shallow_water
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • anuga_core/source_numpy_conversion/anuga/shallow_water/data_manager.py

    r5947 r5951  
    602602        from Scientific.IO.NetCDF import NetCDFFile
    603603
    604         self.precision = numpy.float #Use full precision
     604        self.precision = Float #Use full precision
    605605
    606606        Data_format.__init__(self, domain, 'sww', mode)
     
    10801080
    10811081    M = size  #Number of lines
    1082     xx = numpy.zeros((M,3), numpy.float)
    1083     yy = numpy.zeros((M,3), numpy.float)
    1084     zz = numpy.zeros((M,3), numpy.float)
     1082    xx = numpy.zeros((M,3), Float)
     1083    yy = numpy.zeros((M,3), Float)
     1084    zz = numpy.zeros((M,3), Float)
    10851085
    10861086    for i in range(M):
     
    11261126
    11271127    M = len(lines)  #Number of lines
    1128     x = numpy.zeros((M,3), numpy.float)
    1129     y = numpy.zeros((M,3), numpy.float)
    1130     z = numpy.zeros((M,3), numpy.float)
     1128    x = numpy.zeros((M,3), Float)
     1129    y = numpy.zeros((M,3), Float)
     1130    z = numpy.zeros((M,3), Float)
    11311131
    11321132    ##i = 0
     
    14431443            newcols = lenv # ncols_in_bounding_box
    14441444
    1445         telev = numpy.zeros(newcols, numpy.float)
    1446         tpoints = numpy.zeros((newcols, 2), numpy.float)
     1445        telev = numpy.zeros(newcols, Float)
     1446        tpoints = numpy.zeros((newcols, 2), Float)
    14471447
    14481448        local_index = 0
     
    19931993        #the temporal dimension
    19941994        if verbose: print 'Reducing quantity %s' %quantity
    1995         q_reduced = numpy.zeros( number_of_points, numpy.float )
     1995        q_reduced = numpy.zeros( number_of_points, Float )
    19961996       
    19971997        if timestep is not None:
     
    20592059    assert len(vertex_points.shape) == 2
    20602060
    2061     grid_points = numpy.zeros ( (ncols*nrows, 2), numpy.float )
     2061    grid_points = numpy.zeros ( (ncols*nrows, 2), Float )
    20622062
    20632063
     
    23582358        # the temporal dimension
    23592359        if verbose: print 'Reducing quantity %s' %quantity
    2360         q_reduced = numpy.zeros( number_of_points, numpy.float )
     2360        q_reduced = numpy.zeros( number_of_points, Float )
    23612361
    23622362        for k in range(number_of_points):
     
    26672667    from Scientific.IO.NetCDF import NetCDFFile
    26682668
    2669     precision = numpy.float
     2669    precision = Float
    26702670
    26712671    msg = 'Must use latitudes and longitudes for minlat, maxlon etc'
     
    28212821    #Cleanup
    28222822    missing = (amplitudes == nan_ha)
    2823     if sometrue(missing):
     2823    if numpy.sometrue(missing):
    28242824        if fail_on_NaN:
    28252825            msg = 'NetCDFFile %s contains missing values'\
     
    29252925    sww.store_header(outfile, times, number_of_volumes,
    29262926                     number_of_points, description=description,
    2927                      verbose=verbose,sww_precision=numpy.float)
     2927                     verbose=verbose,sww_precision=Float)
    29282928
    29292929    # Store
    29302930    from anuga.coordinate_transforms.redfearn import redfearn
    2931     x = numpy.zeros(number_of_points, numpy.float)  #Easting
    2932     y = numpy.zeros(number_of_points, numpy.float)  #Northing
     2931    x = numpy.zeros(number_of_points, Float)  #Easting
     2932    y = numpy.zeros(number_of_points, Float)  #Northing
    29332933
    29342934
     
    29872987    outfile.variables['z'][:] = z             #FIXME HACK for bacwards compat.
    29882988    outfile.variables['elevation'][:] = z
    2989     outfile.variables['volumes'][:] = volumes.astype(numpy.int32) #For Opteron 64
     2989    outfile.variables['volumes'][:] = volumes.astype(Int) #For Opteron 64
    29902990
    29912991
     
    31233123    d = len(q)
    31243124
    3125     T = numpy.zeros(N, numpy.float)       #Time
    3126     Q = numpy.zeros((N, d), numpy.float)  #Values
     3125    T = numpy.zeros(N, Float)       #Time
     3126    Q = numpy.zeros((N, d), Float)  #Values
    31273127
    31283128    for i, line in enumerate(lines):
     
    35703570        if verbose: print 'Processing row %d of %d' %(i, nrows_new)
    35713571        lower_index = global_index
    3572         telev =  numpy.zeros(ncols_new, numpy.float)
     3572        telev =  numpy.zeros(ncols_new, Float)
    35733573        local_index = 0
    35743574        trow = i * cellsize_ratio
     
    36683668    from anuga.coordinate_transforms.redfearn import redfearn
    36693669
    3670     precision = numpy.float # So if we want to change the precision its done here
     3670    precision = Float # So if we want to change the precision its done here
    36713671
    36723672    # go in to the bath dir and load the only file,
     
    37953795    #Store
    37963796    from anuga.coordinate_transforms.redfearn import redfearn
    3797     x = numpy.zeros(number_of_points, numpy.float)  #Easting
    3798     y = numpy.zeros(number_of_points, numpy.float)  #Northing
     3797    x = numpy.zeros(number_of_points, Float)  #Easting
     3798    y = numpy.zeros(number_of_points, Float)  #Northing
    37993799
    38003800    if verbose: print 'Making triangular grid'
     
    38593859    outfile.variables['z'][:] = z # FIXME (Ole): Remove once viewer has been recompiled and changed to use elevation instead of z
    38603860    outfile.variables['elevation'][:] = z 
    3861     outfile.variables['volumes'][:] = volumes.astype(numpy.int32) # On Opteron 64
     3861    outfile.variables['volumes'][:] = volumes.astype(Int) # On Opteron 64
    38623862
    38633863    stage = outfile.variables['stage']
     
    40354035lat_name = 'LAT'
    40364036time_name = 'TIME'
    4037 precision = numpy.float # So if we want to change the precision its done here       
     4037precision = Float # So if we want to change the precision its done here       
    40384038class Write_nc:
    40394039    """
     
    42604260    lonlatdep = p_array.array('f')      ###NumPy?
    42614261    lonlatdep.read(mux_file, columns * points_num)
    4262     lonlatdep = numpy.array(lonlatdep, typecode=numpy.float)   
     4262    lonlatdep = numpy.array(lonlatdep, dtype=Float)   
    42634263    lonlatdep = numpy.reshape(lonlatdep, (points_num, columns))
    42644264   
     
    42674267    lon_sorted.sort()
    42684268
    4269     if not lon == lon_sorted:
     4269    if not numpy.alltrue(lon == lon_sorted):
    42704270        msg = "Longitudes in mux file are not in ascending order"
    42714271        raise IOError, msg
     
    42734273    lat_sorted.sort()
    42744274
    4275     if not lat == lat_sorted:
     4275    if not numpy.alltrue(lat == lat_sorted):
    42764276        msg = "Latitudes in mux file are not in ascending order"
    42774277   
     
    42874287        hz_p_array = p_array.array('f')
    42884288        hz_p_array.read(mux_file, points_num)
    4289         hz_p = numpy.array(hz_p_array, typecode=numpy.float)
     4289        hz_p = numpy.array(hz_p_array, dtype=Float)
    42904290        hz_p = numpy.reshape(hz_p, (len(lon), len(lat)))
    42914291        hz_p = numpy.transpose(hz_p) #mux has lat varying fastest, nc has long v.f.
     
    43654365    QUANTITY = 2
    43664366
    4367     long_lat_dep = ensure_numeric(long_lat_dep, numpy.float)
     4367    long_lat_dep = ensure_numeric(long_lat_dep, Float)
    43684368   
    43694369    num_points = long_lat_dep.shape[0]
     
    44134413    # use numeric transpose, after reshaping the quantity vector
    44144414#    quantity = zeros(len(long_lat_dep), Float)
    4415     quantity = numpy.zeros(num_points, numpy.float)
     4415    quantity = numpy.zeros(num_points, Float)
    44164416   
    44174417#    print 'num',num_points
     
    47954795           
    47964796    points_utm=ensure_numeric(points_utm)
    4797     assert ensure_numeric(mesh_dic['generatedpointlist']) == \
    4798            ensure_numeric(points_utm)
     4797    assert numpy.alltrue(ensure_numeric(mesh_dic['generatedpointlist']) ==
     4798                         ensure_numeric(points_utm))
    47994799   
    48004800    volumes = mesh_dic['generatedtrianglelist']
     
    48124812    sww = Write_sww()
    48134813    sww.store_header(outfile, times, len(volumes), len(points_utm),
    4814                      verbose=verbose,sww_precision=numpy.float)
     4814                     verbose=verbose,sww_precision=Float)
    48154815    outfile.mean_stage = mean_stage
    48164816    outfile.zscale = zscale
     
    48354835                                 xmomentum=xmomentum,
    48364836                                 ymomentum=ymomentum,
    4837                                  sww_precision=numpy.float)
     4837                                 sww_precision=Float)
    48384838        j += 1
    48394839    if verbose: sww.verbose_quantities(outfile)
     
    48714871    numSrc=len(filenames)
    48724872
    4873     file_params=-1*numpy.ones(3,numpy.float) #[nsta,dt,nt]
     4873    file_params=-1*numpy.ones(3,Float) #[nsta,dt,nt]
    48744874   
    48754875    # Convert verbose to int C flag
     
    48804880       
    48814881    if permutation is None:
    4882         permutation = ensure_numeric([], numpy.float)   
     4882        permutation = ensure_numeric([], Float)   
    48834883
    48844884    # Call underlying C implementation urs2sts_ext.c   
     
    49304930             
    49314931    times=dt*numpy.arange(parameters_index)   
    4932     latitudes=numpy.zeros(number_of_selected_stations, numpy.float)
    4933     longitudes=numpy.zeros(number_of_selected_stations, numpy.float)
    4934     elevation=numpy.zeros(number_of_selected_stations, numpy.float)
    4935     quantity=numpy.zeros((number_of_selected_stations, parameters_index), numpy.float)
     4932    latitudes=numpy.zeros(number_of_selected_stations, Float)
     4933    longitudes=numpy.zeros(number_of_selected_stations, Float)
     4934    elevation=numpy.zeros(number_of_selected_stations, Float)
     4935    quantity=numpy.zeros((number_of_selected_stations, parameters_index), Float)
    49364936   
    49374937   
     
    50405040    if weights is None:
    50415041        # Default is equal weighting
    5042         weights=numpy.ones(numSrc,numpy.float)/numSrc
     5042        weights=numpy.ones(numSrc,Float)/numSrc
    50435043    else:
    50445044        weights = ensure_numeric(weights)
     
    51745174    # 0 to number_of_points-1
    51755175    if permutation is None:
    5176         permutation = numpy.arange(number_of_points, typecode=numpy.int)
     5176        permutation = numpy.arange(number_of_points, dtype=Int)
    51775177   
    51785178   
     
    51915191                     description=description,
    51925192                     verbose=verbose,
    5193                      sts_precision=numpy.float)
     5193                     sts_precision=Float)
    51945194   
    51955195    # Store
    51965196    from anuga.coordinate_transforms.redfearn import redfearn
    5197     x = numpy.zeros(number_of_points, numpy.float)  # Easting
    5198     y = numpy.zeros(number_of_points, numpy.float)  # Northing
     5197    x = numpy.zeros(number_of_points, Float)  # Easting
     5198    y = numpy.zeros(number_of_points, Float)  # Northing
    51995199
    52005200    # Check zone boundaries
     
    52295229
    52305230    elevation = numpy.resize(elevation,outfile.variables['elevation'][:].shape)
    5231     outfile.variables['permutation'][:] = permutation.astype(numpy.int32) # On Opteron 64
     5231    outfile.variables['permutation'][:] = permutation.astype(Int) # On Opteron 64
    52325232    outfile.variables['x'][:] = x - geo_ref.get_xllcorner()
    52335233    outfile.variables['y'][:] = y - geo_ref.get_yllcorner()
     
    55315531        outfile.variables['z'][:] = elevation
    55325532        outfile.variables['elevation'][:] = elevation  #FIXME HACK
    5533         outfile.variables['volumes'][:] = volumes.astype(numpy.int32) #On Opteron 64
     5533        outfile.variables['volumes'][:] = volumes.astype(Int) #On Opteron 64
    55345534
    55355535        q = 'elevation'
     
    55395539
    55405540
    5541     def store_quantities(self, outfile, sww_precision=numpy.float32,
     5541    def store_quantities(self, outfile, sww_precision=Float32,
    55425542                         slice_index=None, time=None,
    55435543                         verbose=False, **quant):
     
    57065706                     number_of_points,
    57075707                     description='Converted from URS mux2 format',
    5708                      sts_precision=numpy.float32,
     5708                     sts_precision=Float32,
    57095709                     verbose=False):
    57105710        """
     
    57655765
    57665766        # Doing sts_precision instead of Float gives cast errors.
    5767         outfile.createVariable('time', Floatr, ('number_of_timesteps',))
     5767        outfile.createVariable('time', Float, ('number_of_timesteps',))
    57685768
    57695769        for q in Write_sts.sts_quantities:
     
    58745874        outfile.variables[q+Write_sts.RANGE][1] = max(elevation)
    58755875
    5876     def store_quantities(self, outfile, sts_precision=numpy.float32,
     5876    def store_quantities(self, outfile, sts_precision=Float32,
    58775877                         slice_index=None, time=None,
    58785878                         verbose=False, **quant):
     
    59645964        lonlatdep = p_array.array('f')
    59655965        lonlatdep.read(mux_file, columns * self.points_num)
    5966         lonlatdep = numpy.array(lonlatdep, typecode=numpy.float)   
     5966        lonlatdep = numpy.array(lonlatdep, dtype=Float)   
    59675967        lonlatdep = numpy.reshape(lonlatdep, (self.points_num, columns))
    59685968        #print 'lonlatdep',lonlatdep
     
    59935993        hz_p_array = p_array.array('f')
    59945994        hz_p_array.read(self.mux_file, self.points_num)
    5995         hz_p = numpy.array(hz_p_array, typecode=numpy.float)
     5995        hz_p = numpy.array(hz_p_array, dtype=Float)
    59965996        self.iter_time_step += 1
    59975997       
     
    61086108    #array to store data, number in there is to allow float...
    61096109    #i'm sure there is a better way!
    6110     data=numpy.array([],typecode=numpy.float)
     6110    data=numpy.array([],dtype=Float)
    61116111    data=numpy.resize(data,((len(lines)-1),len(header_fields)))
    61126112#    print 'number of fields',range(len(header_fields))
     
    66856685   
    66866686        # Get the relevant quantities (Convert from single precison)
    6687         elevation = numpy.array(fid.variables['elevation'][:], numpy.float)
    6688         stage = numpy.array(fid.variables['stage'][:], numpy.float)
     6687        elevation = numpy.array(fid.variables['elevation'][:], Float)
     6688        stage = numpy.array(fid.variables['stage'][:], Float)
    66896689   
    66906690   
  • anuga_core/source_numpy_conversion/anuga/shallow_water/test_data_manager.py

    r5947 r5951  
    49644964                         'failed')
    49654965
    4966         self.failUnless(m2d == [[5,6],[9,10]],
    4967                          'failed')
     4966        self.failUnless(numpy.alltrue(m2d == [[5,6],[9,10]]),
     4967                        'failed')
    49684968
    49694969    def test_get_min_max_indexes_lat_ascending(self):
     
    50305030        self.failUnless(latitudes_new == [-30, -35, -40] and \
    50315031                        longitudes_new == [148, 149,150],
    5032                          'failed')
    5033         self.failUnless(m2d == [[0,1,2],[4,5,6],[8,9,10]],
    5034                          'failed')
     5032                        'failed')
     5033        self.failUnless(numpy.alltrue(m2d == [[0,1,2],[4,5,6],[8,9,10]]),
     5034                        'failed')
    50355035
    50365036    def test_get_min_max_indexes3(self):
  • anuga_core/source_numpy_conversion/anuga/shallow_water/tsunami_okada.py

    r5901 r5951  
    3131
    3232import numpy
     33from anuga.config import Float
     34
    3335
    3436def earthquake_tsunami(ns,NSMAX,length, width, strike, depth,\
     
    4446    zrec=zrec0.get_vertex_values(xy=True)
    4547   
    46     x0= numpy.zeros(ns,numpy.float)
    47     y0= numpy.zeros(ns,numpy.float)
     48    x0= numpy.zeros(ns,Float)
     49    y0= numpy.zeros(ns,Float)
    4850    if ns ==1:
    4951        x0[0]=xi
     
    150152        zrec=self.zrec
    151153        #initialization
    152         disp0=numpy.zeros(3,numpy.float)
    153         strain0=numpy.zeros(6,numpy.float)
    154         tilt0 = numpy.zeros(2,numpy.float)
    155         dislocations=numpy.zeros(ns,numpy.float)
    156         depths=numpy.zeros(ns,numpy.float)
    157         strikes= numpy.zeros(ns,numpy.float)
    158         lengths= numpy.zeros(ns,numpy.float)
    159         slips= numpy.zeros(ns,numpy.float)
    160         rakes= numpy.zeros(ns,numpy.float)
    161         widths= numpy.zeros(ns,numpy.float)
    162         dips= numpy.zeros(ns,numpy.float)
    163         strikes= numpy.zeros(ns,numpy.float)
    164         strikes= numpy.zeros(ns,numpy.float)
    165         strain = numpy.zeros((N,6),numpy.float)
    166         disp = numpy.zeros((N,3),numpy.float)
    167         tilt = numpy.zeros((N,2),numpy.float)
    168         xs =numpy.zeros(ns,numpy.float)
    169         ys =numpy.zeros(ns,numpy.float)
     154        disp0=numpy.zeros(3,Float)
     155        strain0=numpy.zeros(6,Float)
     156        tilt0 = numpy.zeros(2,Float)
     157        dislocations=numpy.zeros(ns,Float)
     158        depths=numpy.zeros(ns,Float)
     159        strikes= numpy.zeros(ns,Float)
     160        lengths= numpy.zeros(ns,Float)
     161        slips= numpy.zeros(ns,Float)
     162        rakes= numpy.zeros(ns,Float)
     163        widths= numpy.zeros(ns,Float)
     164        dips= numpy.zeros(ns,Float)
     165        strikes= numpy.zeros(ns,Float)
     166        strikes= numpy.zeros(ns,Float)
     167        strain = numpy.zeros((N,6),Float)
     168        disp = numpy.zeros((N,3),Float)
     169        tilt = numpy.zeros((N,2),Float)
     170        xs =numpy.zeros(ns,Float)
     171        ys =numpy.zeros(ns,Float)
    170172        z=[]
    171173        if ns==1:
     
    213215            xrec=y
    214216            yrec=x
     217##            print 'xrec=%s' % str(xrec)
     218##            print 'yrec=%s' % str(yrec)
     219##            print 'zrec=%s' % str(zrec)
    215220            for i in range(0,len(zrec[0])):
    216                 if zrec[0][i]==yrec and zrec[1][i]==xrec:
     221                if numpy.alltrue(zrec[0][i]==yrec) and \
     222                   numpy.alltrue(zrec[1][i]==xrec):
     223##                    print 'Setting Z!'
    217224                    Z=zrec[2][i]
    218225                    Z=0.001*Z
     
    377384         
    378385          F0=0.0                                                   
    379           U=numpy.zeros((12,1),numpy.float)
    380           DUA=numpy.zeros((12,1),numpy.float)
    381           DUB=numpy.zeros((12,1),numpy.float)
    382           DUC=numpy.zeros((12,1),numpy.float)
     386          U=numpy.zeros((12,1),Float)
     387          DUA=numpy.zeros((12,1),Float)
     388          DUB=numpy.zeros((12,1),Float)
     389          DUC=numpy.zeros((12,1),Float)
    383390         
    384391         
     
    523530       WZ=self.WZ
    524531
    525        DUA=numpy.zeros((12,1),numpy.float)
    526        DU=numpy.zeros((12,1),numpy.float)
    527        U=numpy.zeros((12,1),numpy.float)
     532       DUA=numpy.zeros((12,1),Float)
     533       DU=numpy.zeros((12,1),Float)
     534       U=numpy.zeros((12,1),Float)
    528535#-----                                                               
    529536       for I in range(0,12):                                                   
     
    633640#      DATA PI2/6.283185307179586D0/
    634641       
    635         DUB=numpy.zeros((12,1),numpy.float)
    636         DU=numpy.zeros((12,1),numpy.float)
    637         U=numpy.zeros((12,1),numpy.float)
     642        DUB=numpy.zeros((12,1),Float)
     643        DU=numpy.zeros((12,1),Float)
     644        U=numpy.zeros((12,1),Float)
    638645       
    639646        F0=0.0
     
    807814#      DATA PI2/6.283185307179586D0/
    808815       
    809       DUC=numpy.zeros((12,1),numpy.float)
    810       DU=numpy.zeros((12,1),numpy.float)
    811       U=numpy.zeros((12,1),numpy.float)
     816      DUC=numpy.zeros((12,1),Float)
     817      DU=numpy.zeros((12,1),Float)
     818      U=numpy.zeros((12,1),Float)
    812819             
    813820      F0=0.0
     
    10011008      EPS=0.000001
    10021009       
    1003       XI=numpy.zeros(2,numpy.float)
    1004       ET=numpy.zeros(2,numpy.float)
    1005       KXI=numpy.zeros(2,numpy.float)
    1006       KET=numpy.zeros(2,numpy.float)
    1007       U=numpy.zeros(12,numpy.float)
    1008       DU=numpy.zeros(12,numpy.float)
    1009       DUA=numpy.zeros(12,numpy.float)
    1010       DUB=numpy.zeros(12,numpy.float)
    1011       DUC=numpy.zeros(12,numpy.float)
     1010      XI=numpy.zeros(2,Float)
     1011      ET=numpy.zeros(2,Float)
     1012      KXI=numpy.zeros(2,Float)
     1013      KET=numpy.zeros(2,Float)
     1014      U=numpy.zeros(12,Float)
     1015      DU=numpy.zeros(12,Float)
     1016      DUA=numpy.zeros(12,Float)
     1017      DUB=numpy.zeros(12,Float)
     1018      DUC=numpy.zeros(12,Float)
    10121019
    10131020#-----                                                                 
     
    12061213#      DATA F0,F2,PI2/0.D0,2.D0,6.283185307179586D0/
    12071214
    1208       U=numpy.zeros(12,numpy.float)
    1209       DU=numpy.zeros(12,numpy.float)
    1210       DUA=numpy.zeros(12,numpy.float)
     1215      U=numpy.zeros(12,Float)
     1216      DU=numpy.zeros(12,Float)
     1217      DUA=numpy.zeros(12,Float)
    12111218      F0 =0.0
    12121219      F2=2.0
     
    13371344#      DATA  F0,F1,F2,PI2/0.D0,1.D0,2.D0,6.283185307179586D0/
    13381345
    1339       DUB=numpy.zeros(12,numpy.float)
    1340       DU=numpy.zeros(12,numpy.float)
    1341       U=numpy.zeros(12,numpy.float)
     1346      DUB=numpy.zeros(12,Float)
     1347      DU=numpy.zeros(12,Float)
     1348      U=numpy.zeros(12,Float)
    13421349     
    13431350      F0=0.0
     
    15021509 #     DATA F0,F1,F2,F3,PI2/0.D0,1.D0,2.D0,3.D0,6.283185307179586D0/
    15031510
    1504       DUC=numpy.zeros(12,numpy.float)
    1505       DU=numpy.zeros(12,numpy.float)
    1506       U=numpy.zeros(12,numpy.float)
     1511      DUC=numpy.zeros(12,Float)
     1512      DU=numpy.zeros(12,Float)
     1513      U=numpy.zeros(12,Float)
    15071514     
    15081515      F0=0.0
Note: See TracChangeset for help on using the changeset viewer.