Ignore:
Timestamp:
Jan 13, 2009, 5:42:30 PM (15 years ago)
Author:
rwilson
Message:

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

File:
1 edited

Legend:

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

    r6132 r6157  
    6161from os import sep, path, remove, mkdir, access, F_OK, W_OK, getcwd
    6262
    63 from Numeric import concatenate, array, Float, Int, Int32, resize, \
    64      sometrue, searchsorted, zeros, allclose, around, reshape, \
    65      transpose, sort, NewAxis, ArrayType, compress, take, arange, \
    66      argmax, alltrue, shape, Float32, size
     63import Numeric as num
    6764
    6865from Scientific.IO.NetCDF import NetCDFFile
     
    345342    def __init__(self, domain, mode=netcdf_mode_w, max_size=2000000000, recursion=False):
    346343        from Scientific.IO.NetCDF import NetCDFFile
    347         from Numeric import Int, Float, Float32
    348 
    349         self.precision = Float32 #Use single precision for quantities
     344
     345        self.precision = num.Float32 #Use single precision for quantities
    350346        self.recursion = recursion
    351347        self.mode = mode
     
    425421
    426422        from Scientific.IO.NetCDF import NetCDFFile
    427         from Numeric import concatenate, Int
    428423
    429424        domain = self.domain
     
    443438
    444439        # store the connectivity data
    445         points = concatenate( (X[:,NewAxis],Y[:,NewAxis]), axis=1 )
     440        points = num.concatenate( (X[:,num.NewAxis],Y[:,num.NewAxis]), axis=1 )
    446441        self.writer.store_triangulation(fid,
    447442                                        points,
    448443#                                        V.astype(volumes.typecode()),
    449                                         V.astype(Float32),
     444                                        V.astype(num.Float32),
    450445                                        Z,
    451446                                        points_georeference=\
     
    466461        from time import sleep
    467462        from os import stat
    468         from Numeric import choose
    469463
    470464        if names is None:
     
    563557
    564558                storable_indices = (A-z[:] >= self.minimum_storable_height)
    565                 stage = choose(storable_indices, (z[:], A))
     559                stage = num.choose(storable_indices, (z[:], A))
    566560
    567561                # Define a zero vector of same size and type as A
    568562                # for use with momenta
    569                 null = zeros(size(A), A.typecode())
     563                null = num.zeros(num.size(A), A.typecode())
    570564
    571565                # Get xmomentum where depth exceeds minimum_storable_height
     
    573567                xmom, _ = Q.get_vertex_values(xy=False,
    574568                                              precision=self.precision)
    575                 xmomentum = choose(storable_indices, (null, xmom))
     569                xmomentum = num.choose(storable_indices, (null, xmom))
    576570
    577571
     
    580574                ymom, _ = Q.get_vertex_values(xy=False,
    581575                                              precision=self.precision)
    582                 ymomentum = choose(storable_indices, (null, ymom))
     576                ymomentum = num.choose(storable_indices, (null, ymom))
    583577
    584578                # Write quantities to underlying data  file
     
    627621    def __init__(self, domain, mode=netcdf_mode_w):
    628622        from Scientific.IO.NetCDF import NetCDFFile
    629         from Numeric import Int, Float, Float
    630 
    631         self.precision = Float #Use full precision
     623
     624        self.precision = num.Float #Use full precision
    632625
    633626        Data_format.__init__(self, domain, 'sww', mode)
     
    657650
    658651
    659             fid.createVariable('volumes', Int, ('number_of_volumes',
    660                                                 'number_of_vertices'))
     652            fid.createVariable('volumes', num.Int, ('number_of_volumes',
     653                                                    'number_of_vertices'))
    661654
    662655            fid.createVariable('time', self.precision, ('number_of_timesteps',))
     
    680673
    681674        from Scientific.IO.NetCDF import NetCDFFile
    682         from Numeric import concatenate
    683675
    684676        domain = self.domain
     
    11511143    Y = {}
    11521144    for key in X.keys():
    1153         Y[key] = array([float(x) for x in X[key]])
     1145        Y[key] = num.array([float(x) for x in X[key]])
    11541146
    11551147    return Y
     
    12691261
    12701262    from Scientific.IO.NetCDF import NetCDFFile
    1271     from Numeric import Float, zeros
    12721263
    12731264    # Get NetCDF
     
    12841275
    12851276    M = size  #Number of lines
    1286     xx = zeros((M,3), Float)
    1287     yy = zeros((M,3), Float)
    1288     zz = zeros((M,3), Float)
     1277    xx = num.zeros((M,3), num.Float)
     1278    yy = num.zeros((M,3), num.Float)
     1279    zz = num.zeros((M,3), num.Float)
    12891280
    12901281    for i in range(M):
     
    13241315    import glob, os
    13251316    from anuga.config import data_dir
    1326     from Numeric import zeros, Float
    13271317
    13281318    # Get bathymetry and x,y's
     
    13301320
    13311321    M = len(lines)  #Number of lines
    1332     x = zeros((M,3), Float)
    1333     y = zeros((M,3), Float)
    1334     z = zeros((M,3), Float)
     1322    x = num.zeros((M,3), num.Float)
     1323    y = num.zeros((M,3), num.Float)
     1324    z = num.zeros((M,3), num.Float)
    13351325
    13361326    for i, line in enumerate(lines):
     
    15241514    import os
    15251515    from Scientific.IO.NetCDF import NetCDFFile
    1526     from Numeric import Float, zeros, reshape, sum
    15271516
    15281517    root = basename_in
     
    15911580    outfile.nrows = nrows
    15921581
    1593     dem_elevation_r = reshape(dem_elevation, (nrows, ncols))
     1582    dem_elevation_r = num.reshape(dem_elevation, (nrows, ncols))
    15941583    totalnopoints = nrows*ncols
    15951584
     
    16401629
    16411630    # Variable definitions
    1642     outfile.createVariable('points', Float, ('number_of_points',
    1643                                              'number_of_dimensions'))
    1644     outfile.createVariable('elevation', Float, ('number_of_points',))
     1631    outfile.createVariable('points', num.Float, ('number_of_points',
     1632                                                 'number_of_dimensions'))
     1633    outfile.createVariable('elevation', num.Float, ('number_of_points',))
    16451634
    16461635    # Get handles to the variables
     
    16601649
    16611650        v = dem_elevation_r[i,index1:index2+1]
    1662         no_NODATA = sum(v == NODATA_value)
     1651        no_NODATA = num.sum(v == NODATA_value)
    16631652        if no_NODATA > 0:
    16641653            newcols = lenv - no_NODATA  # ncols_in_bounding_box - no_NODATA
     
    16661655            newcols = lenv              # ncols_in_bounding_box
    16671656
    1668         telev = zeros(newcols, Float)
    1669         tpoints = zeros((newcols, 2), Float)
     1657        telev = num.zeros(newcols, num.Float)
     1658        tpoints = num.zeros((newcols, 2), num.Float)
    16701659
    16711660        local_index = 0
     
    17891778    import os
    17901779    from Scientific.IO.NetCDF import NetCDFFile
    1791     from Numeric import Float, zeros, reshape
    17921780
    17931781    root = basename_in
     
    21332121
    21342122    import sys
    2135     from Numeric import array, Float, concatenate, NewAxis, zeros, reshape
    2136     from Numeric import array2string, sometrue
    21372123
    21382124    from anuga.utilities.polygon import inside_polygon, outside_polygon, \
     
    22542240        #q has a time component, must be reduced alongthe temporal dimension
    22552241        if verbose: print 'Reducing quantity %s' %quantity
    2256         q_reduced = zeros(number_of_points, Float)
     2242        q_reduced = num.zeros(number_of_points, num.Float)
    22572243
    22582244        if timestep is not None:
     
    23142300    y = y + yllcorner - newyllcorner
    23152301
    2316     vertex_points = concatenate ((x[:,NewAxis], y[:,NewAxis]), axis=1)
     2302    vertex_points = num.concatenate ((x[:,num.NewAxis], y[:,num.NewAxis]), axis=1)
    23172303    assert len(vertex_points.shape) == 2
    23182304
    2319     grid_points = zeros ((ncols*nrows, 2), Float)
     2305    grid_points = num.zeros ((ncols*nrows, 2), num.Float)
    23202306
    23212307    for i in xrange(nrows):
     
    23592345    if format.lower() == 'ers':
    23602346        # setup ERS header information
    2361         grid_values = reshape(grid_values, (nrows, ncols))
     2347        grid_values = num.reshape(grid_values, (nrows, ncols))
    23622348        header = {}
    23632349        header['datum'] = '"' + datum + '"'
     
    24262412            slice = grid_values[base_index:base_index+ncols]
    24272413            #s = array2string(slice, max_line_width=sys.maxint)
    2428             s = array2string(slice, max_line_width=sys.maxint,
    2429                              precision=number_of_decimal_places)
     2414            s = num.array2string(slice, max_line_width=sys.maxint,
     2415                                 precision=number_of_decimal_places)
    24302416            ascid.write(s[1:-1] + '\n')
    24312417
     
    25432529
    25442530    import sys
    2545     from Numeric import array, Float, concatenate, NewAxis, zeros, reshape
    2546     from Numeric import array2string, sometrue
    25472531    from anuga.utilities.polygon import inside_polygon, outside_polygon, \
    25482532             separate_points_by_polygon
     
    26312615        if verbose: print 'Reducing quantity %s' % quantity
    26322616
    2633         q_reduced = zeros(number_of_points, Float)
     2617        q_reduced = num.zeros(number_of_points, num.Float)
    26342618        for k in range(number_of_points):
    26352619            q_reduced[k] = reduction(q[:,k])
     
    26452629
    26462630    # Create grid and update xll/yll corner and x,y
    2647     vertex_points = concatenate((x[:, NewAxis], y[:, NewAxis]), axis=1)
     2631    vertex_points = num.concatenate((x[:, num.NewAxis], y[:, num.NewAxis]), axis=1)
    26482632    assert len(vertex_points.shape) == 2
    26492633
     
    27482732    import os
    27492733    from Scientific.IO.NetCDF import NetCDFFile
    2750     from Numeric import Float, array
    27512734
    27522735    root = basename_in
     
    28662849
    28672850    # variable definitions
    2868     fid.createVariable('elevation', Float, ('number_of_rows',
    2869                                             'number_of_columns'))
     2851    fid.createVariable('elevation', num.Float, ('number_of_rows',
     2852                                                'number_of_columns'))
    28702853
    28712854    # Get handles to the variables
     
    28782861        if verbose and i % ((n+10)/10) == 0:
    28792862            print 'Processing row %d of %d' % (i, nrows)
    2880         elevation[i, :] = array([float(x) for x in fields])
     2863        elevation[i, :] = num.array([float(x) for x in fields])
    28812864
    28822865    fid.close()
     
    29462929    import os
    29472930    from Scientific.IO.NetCDF import NetCDFFile
    2948     from Numeric import Float, Int, Int32, searchsorted, zeros, array
    2949     from Numeric import allclose, around
    2950 
    2951     precision = Float
     2931
     2932    precision = num.Float
    29522933
    29532934    msg = 'Must use latitudes and longitudes for minlat, maxlon etc'
     
    30223003
    30233004    # Precision used by most for lat/lon is 4 or 5 decimals
    3024     e_lat = around(file_e.variables[dim_e_latitude][:], 5)
    3025     e_lon = around(file_e.variables[dim_e_longitude][:], 5)
     3005    e_lat = num.around(file_e.variables[dim_e_latitude][:], 5)
     3006    e_lon = num.around(file_e.variables[dim_e_longitude][:], 5)
    30263007
    30273008    # Check that files are compatible
    3028     assert allclose(latitudes, file_u.variables[dim_u_latitude])
    3029     assert allclose(latitudes, file_v.variables[dim_v_latitude])
    3030     assert allclose(latitudes, e_lat)
    3031 
    3032     assert allclose(longitudes, file_u.variables[dim_u_longitude])
    3033     assert allclose(longitudes, file_v.variables[dim_v_longitude])
    3034     assert allclose(longitudes, e_lon)
     3009    assert num.allclose(latitudes, file_u.variables[dim_u_latitude])
     3010    assert num.allclose(latitudes, file_v.variables[dim_v_latitude])
     3011    assert num.allclose(latitudes, e_lat)
     3012
     3013    assert num.allclose(longitudes, file_u.variables[dim_u_longitude])
     3014    assert num.allclose(longitudes, file_v.variables[dim_v_longitude])
     3015    assert num.allclose(longitudes, e_lon)
    30353016
    30363017    if mint is None:
     
    30383019        mint = times[0]
    30393020    else:
    3040         jmin = searchsorted(times, mint)
     3021        jmin = num.searchsorted(times, mint)
    30413022
    30423023    if maxt is None:
     
    30443025        maxt = times[-1]
    30453026    else:
    3046         jmax = searchsorted(times, maxt)
     3027        jmax = num.searchsorted(times, maxt)
    30473028
    30483029    kmin, kmax, lmin, lmax = _get_min_max_indexes(latitudes[:],
     
    30893070
    30903071    #Cleanup
    3091     from Numeric import sometrue
    3092 
    30933072    missing = (amplitudes == nan_ha)
    3094     if sometrue (missing):
     3073    if num.sometrue (missing):
    30953074        if fail_on_NaN:
    30963075            msg = 'NetCDFFile %s contains missing values' \
     
    31013080
    31023081    missing = (uspeed == nan_ua)
    3103     if sometrue (missing):
     3082    if num.sometrue (missing):
    31043083        if fail_on_NaN:
    31053084            msg = 'NetCDFFile %s contains missing values' \
     
    31103089
    31113090    missing = (vspeed == nan_va)
    3112     if sometrue (missing):
     3091    if num.sometrue (missing):
    31133092        if fail_on_NaN:
    31143093            msg = 'NetCDFFile %s contains missing values' \
     
    31193098
    31203099    missing = (elevations == nan_e)
    3121     if sometrue (missing):
     3100    if num.sometrue (missing):
    31223101        if fail_on_NaN:
    31233102            msg = 'NetCDFFile %s contains missing values' \
     
    31873166    sww.store_header(outfile, times, number_of_volumes,
    31883167                     number_of_points, description=description,
    3189                      verbose=verbose, sww_precision=Float)
     3168                     verbose=verbose, sww_precision=num.Float)
    31903169
    31913170    # Store
    31923171    from anuga.coordinate_transforms.redfearn import redfearn
    3193     x = zeros(number_of_points, Float)  #Easting
    3194     y = zeros(number_of_points, Float)  #Northing
     3172    x = num.zeros(number_of_points, num.Float)  #Easting
     3173    y = num.zeros(number_of_points, num.Float)  #Northing
    31953174
    31963175    if verbose: print 'Making triangular grid'
     
    32263205            volumes.append([v4,v3,v2]) #Lower element
    32273206
    3228     volumes = array(volumes)
     3207    volumes = num.array(volumes)
    32293208
    32303209    if origin is None:
     
    32423221
    32433222    #FIXME use the Write_sww instance(sww) to write this info
    3244     from Numeric import resize
    3245     z = resize(z, outfile.variables['z'][:].shape)
     3223    z = num.resize(z, outfile.variables['z'][:].shape)
    32463224    outfile.variables['x'][:] = x - geo_ref.get_xllcorner()
    32473225    outfile.variables['y'][:] = y - geo_ref.get_yllcorner()
    32483226    outfile.variables['z'][:] = z             #FIXME HACK for bacwards compat.
    32493227    outfile.variables['elevation'][:] = z
    3250     outfile.variables['volumes'][:] = volumes.astype(Int32) #For Opteron 64
     3228    outfile.variables['volumes'][:] = volumes.astype(num.Int32) #For Opteron 64
    32513229
    32523230    #Time stepping
     
    33313309
    33323310    import time, calendar
    3333     from Numeric import array
    33343311    from anuga.config import time_format
    33353312    from anuga.utilities.numerical_tools import ensure_numeric
     
    33713348
    33723349    # Read times proper
    3373     from Numeric import zeros, Float, alltrue
    33743350    from anuga.config import time_format
    33753351    import time, calendar
     
    33823358    d = len(q)
    33833359
    3384     T = zeros(N, Float)       # Time
    3385     Q = zeros((N, d), Float)  # Values
     3360    T = num.zeros(N, num.Float)       # Time
     3361    Q = num.zeros((N, d), num.Float)  # Values
    33863362
    33873363    for i, line in enumerate(lines):
     
    33983374    msg = 'File %s must list time as a monotonuosly ' % filename
    33993375    msg += 'increasing sequence'
    3400     assert alltrue(T[1:] - T[:-1] > 0), msg
     3376    assert num.alltrue(T[1:] - T[:-1] > 0), msg
    34013377
    34023378    #Create NetCDF file
     
    34193395    fid.createDimension('number_of_timesteps', len(T))
    34203396
    3421     fid.createVariable('time', Float, ('number_of_timesteps',))
     3397    fid.createVariable('time', num.Float, ('number_of_timesteps',))
    34223398
    34233399    fid.variables['time'][:] = T
     
    34293405            name = 'Attribute%d' % i
    34303406
    3431         fid.createVariable(name, Float, ('number_of_timesteps',))
     3407        fid.createVariable(name, num.Float, ('number_of_timesteps',))
    34323408        fid.variables[name][:] = Q[:,i]
    34333409
     
    34883464    from Scientific.IO.NetCDF import NetCDFFile
    34893465    from shallow_water import Domain
    3490     from Numeric import asarray, transpose, resize
    34913466
    34923467    # initialise NaN.
     
    35113486    starttime = fid.starttime[0]
    35123487    volumes = fid.variables['volumes'][:]       # Connectivity
    3513     coordinates = transpose(asarray([x.tolist(), y.tolist()]))
     3488    coordinates = num.transpose(num.asarray([x.tolist(), y.tolist()]))
    35143489    # FIXME (Ole): Something like this might be better:
    35153490    #                 concatenate((x, y), axis=1)
    3516     # or              concatenate((x[:,NewAxis], x[:,NewAxis]), axis=1)
     3491    # or              concatenate((x[:,num.NewAxis], x[:,num.NewAxis]), axis=1)
    35173492
    35183493    conserved_quantities = []
     
    36083583                X = (X*data) + (data==0)*NaN_filler
    36093584        if unique:
    3610             X = resize(X, (len(X)/3, 3))
     3585            X = num.resize(X, (len(X)/3, 3))
    36113586        domain.set_quantity(quantity, X)
    36123587    #
     
    36333608                X = (X*data) + (data==0)*NaN_filler
    36343609        if unique:
    3635             X = resize(X, (X.shape[0]/3, 3))
     3610            X = num.resize(X, (X.shape[0]/3, 3))
    36363611        domain.set_quantity(quantity, X)
    36373612
     
    37023677# @param boundary
    37033678def weed(coordinates, volumes, boundary=None):
    3704     if type(coordinates) == ArrayType:
     3679    if type(coordinates) == num.ArrayType:
    37053680        coordinates = coordinates.tolist()
    3706     if type(volumes) == ArrayType:
     3681    if type(volumes) == num.ArrayType:
    37073682        volumes = volumes.tolist()
    37083683
     
    37813756    import os
    37823757    from Scientific.IO.NetCDF import NetCDFFile
    3783     from Numeric import Float, zeros, sum, reshape, equal
    37843758
    37853759    root = basename_in
     
    38513825
    38523826    # variable definition
    3853     outfile.createVariable('elevation', Float, ('number_of_points',))
     3827    outfile.createVariable('elevation', num.Float, ('number_of_points',))
    38543828
    38553829    # Get handle to the variable
    38563830    elevation = outfile.variables['elevation']
    38573831
    3858     dem_elevation_r = reshape(dem_elevation, (nrows, ncols))
     3832    dem_elevation_r = num.reshape(dem_elevation, (nrows, ncols))
    38593833
    38603834    #Store data
     
    38643838
    38653839        lower_index = global_index
    3866         telev = zeros(ncols_new, Float)
     3840        telev = num.zeros(ncols_new, num.Float)
    38673841        local_index = 0
    38683842        trow = i * cellsize_ratio
     
    38763850            #decimated dem to NODATA_value, else compute decimated
    38773851            #value using stencil
    3878             if sum(sum(equal(tmp, NODATA_value))) > 0:
     3852            if num.sum(num.sum(num.equal(tmp, NODATA_value))) > 0:
    38793853                telev[local_index] = NODATA_value
    38803854            else:
    3881                 telev[local_index] = sum(sum(tmp * stencil))
     3855                telev[local_index] = num.sum(num.sum(tmp * stencil))
    38823856
    38833857            global_index += 1
     
    39923966    from anuga.coordinate_transforms.redfearn import redfearn
    39933967
    3994     precision = Float # So if we want to change the precision its done here
     3968    precision = num.Float # So if we want to change the precision its done here
    39953969
    39963970    # go in to the bath dir and load the only file,
     
    40934067    #################################
    40944068
    4095     outfile.createVariable('volumes', Int, ('number_of_volumes',
    4096                                             'number_of_vertices'))
     4069    outfile.createVariable('volumes', num.Int, ('number_of_volumes',
     4070                                                'number_of_vertices'))
    40974071
    40984072    outfile.createVariable('time', precision, ('number_of_timesteps',))
     
    41104084    from anuga.coordinate_transforms.redfearn import redfearn
    41114085
    4112     x = zeros(number_of_points, Float)  #Easting
    4113     y = zeros(number_of_points, Float)  #Northing
     4086    x = num.zeros(number_of_points, num.Float)  #Easting
     4087    y = num.zeros(number_of_points, num.Float)  #Northing
    41144088
    41154089    if verbose: print 'Making triangular grid'
     
    41474121            volumes.append([v4,v2,v3]) #Lower element
    41484122
    4149     volumes = array(volumes)
     4123    volumes = num.array(volumes)
    41504124
    41514125    geo_ref = Geo_reference(refzone, min(x), min(y))
     
    41654139        print 'geo_ref: ', geo_ref
    41664140
    4167     z = resize(bath_grid,outfile.variables['z'][:].shape)
     4141    z = num.resize(bath_grid,outfile.variables['z'][:].shape)
    41684142    outfile.variables['x'][:] = x - geo_ref.get_xllcorner()
    41694143    outfile.variables['y'][:] = y - geo_ref.get_yllcorner()
     
    41724146    outfile.variables['z'][:] = z
    41734147    outfile.variables['elevation'][:] = z
    4174     outfile.variables['volumes'][:] = volumes.astype(Int32) # On Opteron 64
     4148    outfile.variables['volumes'][:] = volumes.astype(num.Int32) # On Opteron 64
    41754149
    41764150    stage = outfile.variables['stage']
     
    41984172        # handle missing values
    41994173        missing = (elevation_grid == elevation_meta['NODATA_value'])
    4200         if sometrue (missing):
     4174        if num.sometrue (missing):
    42014175            if fail_on_NaN:
    42024176                msg = 'File %s contains missing values' \
     
    42544228    longitudes = ensure_numeric(longitudes)
    42554229
    4256     assert allclose(sort(longitudes), longitudes)
     4230    assert num.allclose(num.sort(longitudes), longitudes)
    42574231
    42584232    #print latitudes[0],longitudes[0]
     
    42614235
    42624236    lat_ascending = True
    4263     if not allclose(sort(latitudes), latitudes):
     4237    if not num.allclose(num.sort(latitudes), latitudes):
    42644238        lat_ascending = False
    42654239        # reverse order of lat, so it's in ascending order
    42664240        latitudes = latitudes[::-1]
    4267         assert allclose(sort(latitudes), latitudes)
     4241        assert num.allclose(num.sort(latitudes), latitudes)
    42684242
    42694243    largest_lat_index = len(latitudes)-1
     
    42734247        lat_min_index = 0
    42744248    else:
    4275         lat_min_index = searchsorted(latitudes, minlat)-1
     4249        lat_min_index = num.searchsorted(latitudes, minlat)-1
    42764250        if lat_min_index <0:
    42774251            lat_min_index = 0
     
    42804254        lat_max_index = largest_lat_index #len(latitudes)
    42814255    else:
    4282         lat_max_index = searchsorted(latitudes, maxlat)
     4256        lat_max_index = num.searchsorted(latitudes, maxlat)
    42834257        if lat_max_index > largest_lat_index:
    42844258            lat_max_index = largest_lat_index
     
    42874261        lon_min_index = 0
    42884262    else:
    4289         lon_min_index = searchsorted(longitudes, minlon)-1
     4263        lon_min_index = num.searchsorted(longitudes, minlon)-1
    42904264        if lon_min_index <0:
    42914265            lon_min_index = 0
     
    42944268        lon_max_index = len(longitudes)
    42954269    else:
    4296         lon_max_index = searchsorted(longitudes, maxlon)
     4270        lon_max_index = num.searchsorted(longitudes, maxlon)
    42974271
    42984272    # Reversing the indexes, if the lat array is decending
     
    43494323        cells = line.split()
    43504324        assert len(cells) == ncols
    4351         grid.append(array([float(x) for x in cells]))
    4352     grid = array(grid)
     4325        grid.append(num.array([float(x) for x in cells]))
     4326    grid = num.array(grid)
    43534327
    43544328    return {'xllcorner':xllcorner,
     
    43644338lat_name = 'LAT'
    43654339time_name = 'TIME'
    4366 precision = Float # So if we want to change the precision its done here
     4340precision = num.Float # So if we want to change the precision its done here
    43674341
    43684342##
     
    46454619    lonlatdep = p_array.array('f')
    46464620    lonlatdep.read(mux_file, columns * points_num)
    4647     lonlatdep = array(lonlatdep, typecode=Float)
    4648     lonlatdep = reshape(lonlatdep, (points_num, columns))
     4621    lonlatdep = num.array(lonlatdep, typecode=num.Float)
     4622    lonlatdep = num.reshape(lonlatdep, (points_num, columns))
    46494623
    46504624    lon, lat, depth = lon_lat2grid(lonlatdep)
     
    46744648        hz_p_array = p_array.array('f')
    46754649        hz_p_array.read(mux_file, points_num)
    4676         hz_p = array(hz_p_array, typecode=Float)
    4677         hz_p = reshape(hz_p, (len(lon), len(lat)))
    4678         hz_p = transpose(hz_p)  # mux has lat varying fastest, nc has long v.f.
     4650        hz_p = num.array(hz_p_array, typecode=num.Float)
     4651        hz_p = num.reshape(hz_p, (len(lon), len(lat)))
     4652        hz_p = num.transpose(hz_p)  # mux has lat varying fastest, nc has long v.f.
    46794653
    46804654        #write time slice to nc file
     
    47114685    outfile.variables[lat_name][:] = ensure_numeric(lat)
    47124686
    4713     depth = reshape(depth_vector, (len(lat), len(lon)))
     4687    depth = num.reshape(depth_vector, (len(lat), len(lon)))
    47144688    outfile.variables[zname][:] = depth
    47154689
     
    47724746    QUANTITY = 2
    47734747
    4774     long_lat_dep = ensure_numeric(long_lat_dep, Float)
     4748    long_lat_dep = ensure_numeric(long_lat_dep, num.Float)
    47754749
    47764750    num_points = long_lat_dep.shape[0]
     
    47994773        last = first + lenlat
    48004774
    4801         assert allclose(long_lat_dep[first:last,LAT], lat), msg
    4802         assert allclose(long_lat_dep[first:last,LONG], long[i]), msg
     4775        assert num.allclose(long_lat_dep[first:last,LAT], lat), msg
     4776        assert num.allclose(long_lat_dep[first:last,LONG], long[i]), msg
    48034777
    48044778    msg = 'Out of range latitudes/longitudes'
     
    48104784    # FIXME - make this faster/do this a better way
    48114785    # use numeric transpose, after reshaping the quantity vector
    4812     quantity = zeros(num_points, Float)
     4786    quantity = num.zeros(num_points, num.Float)
    48134787
    48144788    for lat_i, _ in enumerate(lat):
     
    52825256    sww = Write_sww()
    52835257    sww.store_header(outfile, times, len(volumes), len(points_utm),
    5284                      verbose=verbose, sww_precision=Float)
     5258                     verbose=verbose, sww_precision=num.Float)
    52855259    outfile.mean_stage = mean_stage
    52865260    outfile.zscale = zscale
     
    53065280                                 xmomentum=xmomentum,
    53075281                                 ymomentum=ymomentum,
    5308                                  sww_precision=Float)
     5282                                 sww_precision=num.Float)
    53095283        j += 1
    53105284
     
    53495323    """
    53505324
    5351     from Numeric import ones,Float,compress,zeros,arange
    53525325    from urs_ext import read_mux2
    53535326
    53545327    numSrc = len(filenames)
    53555328
    5356     file_params = -1 * ones(3, Float)                    # [nsta,dt,nt]
     5329    file_params = -1 * num.ones(3, num.Float)                    # [nsta,dt,nt]
    53575330
    53585331    # Convert verbose to int C flag
     
    53635336
    53645337    if weights is None:
    5365         weights = ones(numSrc)
     5338        weights = num.ones(numSrc)
    53665339
    53675340    if permutation is None:
    5368         permutation = ensure_numeric([], Float)
     5341        permutation = ensure_numeric([], num.Float)
    53695342
    53705343    # Call underlying C implementation urs2sts_ext.c
     
    53735346
    53745347    msg = 'File parameter values were not read in correctly from c file'
    5375     assert len(compress(file_params > 0, file_params)) != 0, msg
     5348    assert len(num.compress(file_params > 0, file_params)) != 0, msg
    53765349
    53775350    msg = 'The number of stations specifed in the c array and in the file ' \
     
    54135386    parameters_index = data.shape[1] - OFFSET
    54145387
    5415     times = dt * arange(parameters_index)
    5416     latitudes = zeros(number_of_selected_stations, Float)
    5417     longitudes = zeros(number_of_selected_stations, Float)
    5418     elevation = zeros(number_of_selected_stations, Float)
    5419     quantity = zeros((number_of_selected_stations, parameters_index), Float)
     5388    times = dt * num.arange(parameters_index)
     5389    latitudes = num.zeros(number_of_selected_stations, num.Float)
     5390    longitudes = num.zeros(number_of_selected_stations, num.Float)
     5391    elevation = num.zeros(number_of_selected_stations, num.Float)
     5392    quantity = num.zeros((number_of_selected_stations, parameters_index), num.Float)
    54205393
    54215394    starttime = 1e16
     
    54445417        mux_times_start_i = 0
    54455418    else:
    5446         mux_times_start_i = searchsorted(mux_times, mint)
     5419        mux_times_start_i = num.searchsorted(mux_times, mint)
    54475420
    54485421    if maxt == None:
     
    54515424        maxt += 0.5 # so if you specify a time where there is
    54525425                    # data that time will be included
    5453         mux_times_fin_i = searchsorted(mux_times, maxt)
     5426        mux_times_fin_i = num.searchsorted(mux_times, maxt)
    54545427
    54555428    return mux_times_start_i, mux_times_fin_i
     
    55185491    import os
    55195492    from Scientific.IO.NetCDF import NetCDFFile
    5520     from Numeric import Float, Int, Int32, searchsorted, zeros, array
    5521     from Numeric import allclose, around,ones,Float
    55225493    from types import ListType,StringType
    55235494    from operator import __and__
     
    55435514    if weights is None:
    55445515        # Default is equal weighting
    5545         weights = ones(numSrc, Float) / numSrc
     5516        weights = num.ones(numSrc, num.Float) / numSrc
    55465517    else:
    55475518        weights = ensure_numeric(weights)
     
    56225593            msg = '%s, %s and %s have inconsistent gauge data' \
    56235594                  % (files_in[0], files_in[1], files_in[2])
    5624             assert allclose(times, times_old), msg
    5625             assert allclose(latitudes, latitudes_old), msg
    5626             assert allclose(longitudes, longitudes_old), msg
    5627             assert allclose(elevation, elevation_old), msg
    5628             assert allclose(starttime, starttime_old), msg
     5595            assert num.allclose(times, times_old), msg
     5596            assert num.allclose(latitudes, latitudes_old), msg
     5597            assert num.allclose(longitudes, longitudes_old), msg
     5598            assert num.allclose(elevation, elevation_old), msg
     5599            assert num.allclose(starttime, starttime_old), msg
    56295600        times_old = times
    56305601        latitudes_old = latitudes
     
    56655636    # 0 to number_of_points-1
    56665637    if permutation is None:
    5667         permutation = arange(number_of_points, typecode=Int)
     5638        permutation = num.arange(number_of_points, typecode=num.Int)
    56685639
    56695640    # NetCDF file definition
     
    56795650                     description=description,
    56805651                     verbose=verbose,
    5681                      sts_precision=Float)
     5652                     sts_precision=num.Float)
    56825653
    56835654    # Store
    56845655    from anuga.coordinate_transforms.redfearn import redfearn
    56855656
    5686     x = zeros(number_of_points, Float)  # Easting
    5687     y = zeros(number_of_points, Float)  # Northing
     5657    x = num.zeros(number_of_points, num.Float)  # Easting
     5658    y = num.zeros(number_of_points, num.Float)  # Northing
    56885659
    56895660    # Check zone boundaries
     
    57155686    geo_ref = write_NetCDF_georeference(origin, outfile)
    57165687
    5717     elevation = resize(elevation, outfile.variables['elevation'][:].shape)
    5718     outfile.variables['permutation'][:] = permutation.astype(Int32) # Opteron 64
     5688    elevation = num.resize(elevation, outfile.variables['elevation'][:].shape)
     5689    outfile.variables['permutation'][:] = permutation.astype(num.Int32) # Opteron 64
    57195690    outfile.variables['x'][:] = x - geo_ref.get_xllcorner()
    57205691    outfile.variables['y'][:] = y - geo_ref.get_yllcorner()
     
    57825753    y = fid.variables['y'][:] + yllcorner
    57835754
    5784     x = reshape(x, (len(x),1))
    5785     y = reshape(y, (len(y),1))
    5786     sts_points = concatenate((x,y), axis=1)
     5755    x = num.reshape(x, (len(x),1))
     5756    y = num.reshape(y, (len(y),1))
     5757    sts_points = num.concatenate((x,y), axis=1)
    57875758
    57885759    return sts_points.tolist()
     
    58325803                     smoothing=True,
    58335804                     order=1,
    5834                      sww_precision=Float32,
     5805                     sww_precision=num.Float32,
    58355806                     verbose=False):
    58365807        """Write an SWW file header.
     
    58655836        # This is being used to seperate one number from a list.
    58665837        # what it is actually doing is sorting lists from numeric arrays.
    5867         if type(times) is list or type(times) is ArrayType:
     5838        if type(times) is list or type(times) is num.ArrayType:
    58685839            number_of_times = len(times)
    58695840            times = ensure_numeric(times)
     
    59145885        outfile.createVariable('z', sww_precision, ('number_of_points',))
    59155886
    5916         outfile.createVariable('volumes', Int, ('number_of_volumes',
    5917                                                 'number_of_vertices'))
     5887        outfile.createVariable('volumes', num.Int, ('number_of_volumes',
     5888                                                    'number_of_vertices'))
    59185889
    59195890        # Doing sww_precision instead of Float gives cast errors.
    5920         outfile.createVariable('time', Float,
     5891        outfile.createVariable('time', num.Float,
    59215892                               ('number_of_timesteps',))
    59225893
     
    59325903            outfile.variables[q+Write_sww.RANGE][1] = -max_float # Max
    59335904
    5934         if type(times) is list or type(times) is ArrayType:
     5905        if type(times) is list or type(times) is num.ArrayType:
    59355906            outfile.variables['time'][:] = times    #Store time relative
    59365907
     
    59875958
    59885959        number_of_points = len(points_utm)
    5989         volumes = array(volumes)
    5990         points_utm = array(points_utm)
     5960        volumes = num.array(volumes)
     5961        points_utm = num.array(points_utm)
    59915962
    59925963        # given the two geo_refs and the points, do the stuff
     
    60356006        outfile.variables['z'][:] = elevation
    60366007        outfile.variables['elevation'][:] = elevation  #FIXME HACK
    6037         outfile.variables['volumes'][:] = volumes.astype(Int32) #On Opteron 64
     6008        outfile.variables['volumes'][:] = volumes.astype(num.Int32) #On Opteron 64
    60386009
    60396010        q = 'elevation'
     
    60516022    # @param verbose True if this function is to be verbose.
    60526023    # @param **quant
    6053     def store_quantities(self, outfile, sww_precision=Float32,
     6024    def store_quantities(self, outfile, sww_precision=num.Float32,
    60546025                         slice_index=None, time=None,
    60556026                         verbose=False, **quant):
     
    62446215                     number_of_points,
    62456216                     description='Converted from URS mux2 format',
    6246                      sts_precision=Float32,
     6217                     sts_precision=num.Float32,
    62476218                     verbose=False):
    62486219        """
     
    62676238        # This is being used to seperate one number from a list.
    62686239        # what it is actually doing is sorting lists from numeric arrays.
    6269         if type(times) is list or type(times) is ArrayType:
     6240        if type(times) is list or type(times) is num.ArrayType:
    62706241            number_of_times = len(times)
    62716242            times = ensure_numeric(times)
     
    62876258
    62886259        # Variable definitions
    6289         outfile.createVariable('permutation', Int, ('number_of_points',))
     6260        outfile.createVariable('permutation', num.Int, ('number_of_points',))
    62906261        outfile.createVariable('x', sts_precision, ('number_of_points',))
    62916262        outfile.createVariable('y', sts_precision, ('number_of_points',))
     
    63026273
    63036274        # Doing sts_precision instead of Float gives cast errors.
    6304         outfile.createVariable('time', Float, ('number_of_timesteps',))
     6275        outfile.createVariable('time', num.Float, ('number_of_timesteps',))
    63056276
    63066277        for q in Write_sts.sts_quantities:
     
    63146285            outfile.variables[q + Write_sts.RANGE][1] = -max_float # Max
    63156286
    6316         if type(times) is list or type(times) is ArrayType:
     6287        if type(times) is list or type(times) is num.ArrayType:
    63176288            outfile.variables['time'][:] = times    #Store time relative
    63186289
     
    63656336
    63666337        number_of_points = len(points_utm)
    6367         points_utm = array(points_utm)
     6338        points_utm = num.array(points_utm)
    63686339
    63696340        # given the two geo_refs and the points, do the stuff
     
    64236394    # @param verboseTrue if this function is to be verbose.
    64246395    # @param **quant Extra keyword args.
    6425     def store_quantities(self, outfile, sts_precision=Float32,
     6396    def store_quantities(self, outfile, sts_precision=num.Float32,
    64266397                         slice_index=None, time=None,
    64276398                         verbose=False, **quant):
     
    65146485        lonlatdep = p_array.array('f')
    65156486        lonlatdep.read(mux_file, columns * self.points_num)
    6516         lonlatdep = array(lonlatdep, typecode=Float)
    6517         lonlatdep = reshape(lonlatdep, (self.points_num, columns))
     6487        lonlatdep = num.array(lonlatdep, typecode=num.Float)
     6488        lonlatdep = num.reshape(lonlatdep, (self.points_num, columns))
    65186489        self.lonlatdep = lonlatdep
    65196490
     
    65506521        hz_p_array = p_array.array('f')
    65516522        hz_p_array.read(self.mux_file, self.points_num)
    6552         hz_p = array(hz_p_array, typecode=Float)
     6523        hz_p = num.array(hz_p_array, typecode=num.Float)
    65536524        self.iter_time_step += 1
    65546525
     
    66956666    # array to store data, number in there is to allow float...
    66966667    # i'm sure there is a better way!
    6697     data = array([], typecode=Float)
    6698     data = resize(data, ((len(lines)-1), len(header_fields)))
     6668    data = num.array([], typecode=num.Float)
     6669    data = num.resize(data, ((len(lines)-1), len(header_fields)))
    66996670
    67006671    array_number = 0
     
    68536824    from Scientific.IO.NetCDF import NetCDFFile
    68546825    from shallow_water import Domain
    6855     from Numeric import asarray, transpose, resize
    68566826    from anuga.abstract_2d_finite_volumes.neighbour_mesh import Mesh
    68576827
     
    68716841
    68726842    # Mesh (nodes (Mx2), triangles (Nx3))
    6873     nodes = concatenate((x[:,NewAxis], y[:,NewAxis]), axis=1)
     6843    nodes = num.concatenate((x[:,num.NewAxis], y[:,num.NewAxis]), axis=1)
    68746844    triangles = fid.variables['volumes'][:]
    68756845
     
    72947264
    72957265        # Get the relevant quantities (Convert from single precison)
    7296         elevation = array(fid.variables['elevation'][:], Float)
    7297         stage = array(fid.variables['stage'][:], Float)
     7266        elevation = num.array(fid.variables['elevation'][:], num.Float)
     7267        stage = num.array(fid.variables['stage'][:], num.Float)
    72987268
    72997269        # Here's where one could convert nodal information to centroid
     
    73127282            # and call it here
    73137283
    7314             points = concatenate((x[:,NewAxis], y[:,NewAxis]), axis=1)
     7284            points = num.concatenate((x[:,num.NewAxis], y[:,num.NewAxis]), axis=1)
    73157285
    73167286            point_indices = inside_polygon(points, polygon)
    73177287
    73187288            # Restrict quantities to polygon
    7319             elevation = take(elevation, point_indices)
    7320             stage = take(stage, point_indices, axis=1)
     7289            elevation = num.take(elevation, point_indices)
     7290            stage = num.take(stage, point_indices, axis=1)
    73217291
    73227292            # Get info for location of maximal runup
    7323             points_in_polygon = take(points, point_indices)
     7293            points_in_polygon = num.take(points, point_indices)
    73247294            x = points_in_polygon[:,0]
    73257295            y = points_in_polygon[:,1]
    73267296        else:
    73277297            # Take all points
    7328             point_indices = arange(len(x))
     7298            point_indices = num.arange(len(x))
    73297299
    73307300        # Temporal restriction
    73317301        time = fid.variables['time'][:]
    7332         all_timeindices = arange(len(time))
     7302        all_timeindices = num.arange(len(time))
    73337303        if time_interval is not None:
    73347304            msg = 'time_interval must be a sequence of length 2.'
     
    73437313
    73447314            # Take time indices corresponding to interval (& is bitwise AND)
    7345             timesteps = compress((time_interval[0] <= time) \
     7315            timesteps = num.compress((time_interval[0] <= time) \
    73467316                                     & (time <= time_interval[1]),
    7347                                  all_timeindices)
     7317                                     all_timeindices)
    73487318
    73497319            msg = 'time_interval %s did not include any model timesteps.' \
    73507320                  % time_interval
    7351             assert not alltrue(timesteps == 0), msg
     7321            assert not num.alltrue(timesteps == 0), msg
    73527322        else:
    73537323            # Take them all
     
    73727342            # Get wet nodes i.e. nodes with depth>0 within given region
    73737343            # and timesteps
    7374             wet_nodes = compress(depth > minimum_allowed_height,
    7375                                  arange(len(depth)))
    7376 
    7377             if alltrue(wet_nodes == 0):
     7344            wet_nodes = num.compress(depth > minimum_allowed_height,
     7345                                     num.arange(len(depth)))
     7346
     7347            if num.alltrue(wet_nodes == 0):
    73787348                runup = None
    73797349            else:
    73807350                # Find maximum elevation among wet nodes
    7381                 wet_elevation = take(elevation, wet_nodes)
    7382                 runup_index = argmax(wet_elevation)
     7351                wet_elevation = num.take(elevation, wet_nodes)
     7352                runup_index = num.argmax(wet_elevation)
    73837353                runup = max(wet_elevation)
    73847354                assert wet_elevation[runup_index] == runup       # Must be True
     
    73887358
    73897359                # Record location
    7390                 wet_x = take(x, wet_nodes)
    7391                 wet_y = take(y, wet_nodes)
     7360                wet_x = num.take(x, wet_nodes)
     7361                wet_y = num.take(y, wet_nodes)
    73927362                maximal_runup_location = [wet_x[runup_index],wet_y[runup_index]]
    73937363
Note: See TracChangeset for help on using the changeset viewer.