Ignore:
Timestamp:
Feb 10, 2009, 11:11:04 AM (16 years ago)
Author:
rwilson
Message:

Initial commit of numpy changes. Still a long way to go.

Location:
branches/numpy
Files:
1 edited
1 copied

Legend:

Unmodified
Added
Removed
  • branches/numpy/anuga/shallow_water/data_manager.py

    r6224 r6304  
    6161from os import sep, path, remove, mkdir, access, F_OK, W_OK, getcwd
    6262
    63 import Numeric as num
     63import numpy as num
    6464
    6565from Scientific.IO.NetCDF import NetCDFFile
     
    7676     default_minimum_storable_height
    7777from anuga.config import netcdf_mode_r, netcdf_mode_w, netcdf_mode_a
     78from anuga.config import netcdf_float, netcdf_float32, netcdf_int
    7879from anuga.config import max_float
    7980from anuga.utilities.numerical_tools import ensure_numeric,  mean
     
    343344        from Scientific.IO.NetCDF import NetCDFFile
    344345
    345         self.precision = num.Float32 #Use single precision for quantities
     346        self.precision = netcdf_float32 #Use single precision for quantities
    346347        self.recursion = recursion
    347348        self.mode = mode
     
    438439
    439440        # store the connectivity data
    440         points = num.concatenate( (X[:,num.NewAxis],Y[:,num.NewAxis]), axis=1 )
     441        points = num.concatenate( (X[:,num.newaxis],Y[:,num.newaxis]), axis=1 )
    441442        self.writer.store_triangulation(fid,
    442443                                        points,
    443 #                                        V.astype(volumes.typecode()),
    444                                         V.astype(num.Float32),
     444                                        V.astype(num.float32),
    445445                                        Z,
    446446                                        points_georeference=\
     
    561561                # Define a zero vector of same size and type as A
    562562                # for use with momenta
    563                 null = num.zeros(num.size(A), A.typecode())
     563                null = num.zeros(num.size(A), A.dtype.char) #??#
    564564
    565565                # Get xmomentum where depth exceeds minimum_storable_height
     
    622622        from Scientific.IO.NetCDF import NetCDFFile
    623623
    624         self.precision = num.Float #Use full precision
     624        self.precision = netcdf_float #Use full precision
    625625
    626626        Data_format.__init__(self, domain, 'sww', mode)
     
    650650
    651651
    652             fid.createVariable('volumes', num.Int, ('number_of_volumes',
    653                                                     'number_of_vertices'))
     652            fid.createVariable('volumes', netcdf_int, ('number_of_volumes',
     653                                                       'number_of_vertices'))
    654654
    655655            fid.createVariable('time', self.precision, ('number_of_timesteps',))
     
    13041304
    13051305    M = size  #Number of lines
    1306     xx = num.zeros((M,3), num.Float)
    1307     yy = num.zeros((M,3), num.Float)
    1308     zz = num.zeros((M,3), num.Float)
     1306    xx = num.zeros((M,3), num.float)
     1307    yy = num.zeros((M,3), num.float)
     1308    zz = num.zeros((M,3), num.float)
    13091309
    13101310    for i in range(M):
     
    13491349
    13501350    M = len(lines)  #Number of lines
    1351     x = num.zeros((M,3), num.Float)
    1352     y = num.zeros((M,3), num.Float)
    1353     z = num.zeros((M,3), num.Float)
     1351    x = num.zeros((M,3), num.float)
     1352    y = num.zeros((M,3), num.float)
     1353    z = num.zeros((M,3), num.float)
    13541354
    13551355    for i, line in enumerate(lines):
     
    14091409# @param step Timestep stride.
    14101410def filter_netcdf(filename1, filename2, first=0, last=None, step=1):
    1411     """Read netcdf filename1, pick timesteps first:step:last and save to
     1411    """Filter data file, selecting timesteps first:step:last.
     1412   
     1413    Read netcdf filename1, pick timesteps first:step:last and save to
    14121414    nettcdf file filename2
    14131415    """
     
    14261428    for name in infile.variables:
    14271429        var = infile.variables[name]
    1428         outfile.createVariable(name, var.typecode(), var.dimensions)
     1430        outfile.createVariable(name, var.dtype.char, var.dimensions)    #??#
    14291431
    14301432    # Copy the static variables
     
    14991501    Convert to NetCDF pts format which is
    15001502
    1501     points:  (Nx2) Float array
    1502     elevation: N Float array
     1503    points:  (Nx2) float array
     1504    elevation: N float array
    15031505    """
    15041506
     
    16581660
    16591661    # Variable definitions
    1660     outfile.createVariable('points', num.Float, ('number_of_points',
    1661                                                  'number_of_dimensions'))
    1662     outfile.createVariable('elevation', num.Float, ('number_of_points',))
     1662    outfile.createVariable('points', netcdf_float, ('number_of_points',
     1663                                                    'number_of_dimensions'))
     1664    outfile.createVariable('elevation', netcdf_float, ('number_of_points',))
    16631665
    16641666    # Get handles to the variables
     
    16841686            newcols = lenv              # ncols_in_bounding_box
    16851687
    1686         telev = num.zeros(newcols, num.Float)
    1687         tpoints = num.zeros((newcols, 2), num.Float)
     1688        telev = num.zeros(newcols, num.float)
     1689        tpoints = num.zeros((newcols, 2), num.float)
    16881690
    16891691        local_index = 0
     
    18011803    Convert to NetCDF pts format which is
    18021804
    1803     points:  (Nx2) Float array
    1804     elevation: N Float array
     1805    points:  (Nx2) float array
     1806    elevation: N float array
    18051807    """
    18061808
     
    22452247        # Comment out for reduced memory consumption
    22462248        for name in ['stage', 'xmomentum', 'ymomentum']:
    2247             q = fid.variables[name][:].flat
     2249            q = fid.variables[name][:].flatten()
    22482250            if timestep is not None:
    22492251                q = q[timestep*len(x):(timestep+1)*len(x)]
    22502252            if verbose: print '    %s in [%f, %f]' %(name, min(q), max(q))
    22512253        for name in ['elevation']:
    2252             q = fid.variables[name][:].flat
     2254            q = fid.variables[name][:].flatten()
    22532255            if verbose: print '    %s in [%f, %f]' %(name, min(q), max(q))
    22542256
     
    22562258    if verbose: print 'Processing quantity %s' %quantity
    22572259
    2258     # Turn NetCDF objects into Numeric arrays
     2260    # Turn NetCDF objects into numeric arrays
    22592261    try:
    22602262        q = fid.variables[quantity][:]
     
    22692271        #q has a time component, must be reduced alongthe temporal dimension
    22702272        if verbose: print 'Reducing quantity %s' %quantity
    2271         q_reduced = num.zeros(number_of_points, num.Float)
     2273        q_reduced = num.zeros(number_of_points, num.float)
    22722274
    22732275        if timestep is not None:
     
    23292331    y = y + yllcorner - newyllcorner
    23302332
    2331     vertex_points = num.concatenate ((x[:,num.NewAxis], y[:,num.NewAxis]), axis=1)
     2333    vertex_points = num.concatenate ((x[:,num.newaxis], y[:,num.newaxis]), axis=1)
    23322334    assert len(vertex_points.shape) == 2
    23332335
    2334     grid_points = num.zeros ((ncols*nrows, 2), num.Float)
     2336    grid_points = num.zeros ((ncols*nrows, 2), num.float)
    23352337
    23362338    for i in xrange(nrows):
     
    23592361    #Interpolate using quantity values
    23602362    if verbose: print 'Interpolating'
    2361     grid_values = interp.interpolate(q, grid_points).flat
     2363    grid_values = interp.interpolate(q, grid_points).flatten()
    23622364
    23632365    if verbose:
    2364         print 'Interpolated values are in [%f, %f]' %(min(grid_values),
    2365                                                       max(grid_values))
     2366        print 'Interpolated values are in [%f, %f]' %(min(grid_values.flat),
     2367                                                      max(grid_values.flat))
    23662368
    23672369    #Assign NODATA_value to all points outside bounding polygon (from interpolation mesh)
     
    26312633    if verbose: print 'Processing quantity %s' % quantity
    26322634
    2633     # Turn NetCDF objects into Numeric arrays
     2635    # Turn NetCDF objects into numeric arrays
    26342636    quantity_dict = {}
    26352637    for name in fid.variables.keys():
     
    26442646        if verbose: print 'Reducing quantity %s' % quantity
    26452647
    2646         q_reduced = num.zeros(number_of_points, num.Float)
     2648        q_reduced = num.zeros(number_of_points, num.float)
    26472649        for k in range(number_of_points):
    26482650            q_reduced[k] = reduction(q[:,k])
     
    26582660
    26592661    # Create grid and update xll/yll corner and x,y
    2660     vertex_points = num.concatenate((x[:, num.NewAxis], y[:, num.NewAxis]), axis=1)
     2662    vertex_points = num.concatenate((x[:, num.newaxis], y[:, num.newaxis]), axis=1)
    26612663    assert len(vertex_points.shape) == 2
    26622664
     
    26672669    # Interpolate using quantity values
    26682670    if verbose: print 'Interpolating'
    2669     interpolated_values = interp.interpolate(q, data_points).flat
     2671    interpolated_values = interp.interpolate(q, data_points).flatten
    26702672
    26712673    if verbose:
    2672         print 'Interpolated values are in [%f, %f]' % (min(interpolated_values),
    2673                                                        max(interpolated_values))
     2674        print 'Interpolated values are in [%f, %f]' \
     2675              % (min(interpolated_values.flat), max(interpolated_values.flat))
    26742676
    26752677    # Assign NODATA_value to all points outside bounding polygon
     
    28782880
    28792881    # variable definitions
    2880     fid.createVariable('elevation', num.Float, ('number_of_rows',
    2881                                                 'number_of_columns'))
     2882    fid.createVariable('elevation', netcdf_float, ('number_of_rows',
     2883                                                   'number_of_columns'))
    28822884
    28832885    # Get handles to the variables
     
    29592961    from Scientific.IO.NetCDF import NetCDFFile
    29602962
    2961     precision = num.Float
     2963    precision = num.float
    29622964
    29632965    msg = 'Must use latitudes and longitudes for minlat, maxlon etc'
     
    30783080    #        elevations = file_e.variables['ELEVATION'][kmin:kmax, lmin:lmax]
    30793081    #    elif latitudes2[0]==latitudes[-1] and latitudes2[-1]==latitudes[0]:
    3080     #        from Numeric import asarray
     3082    #        from numpy import asarray
    30813083    #        elevations=elevations.tolist()
    30823084    #        elevations.reverse()
    30833085    #        elevations=asarray(elevations)
    30843086    #    else:
    3085     #        from Numeric import asarray
     3087    #        from numpy import asarray
    30863088    #        elevations=elevations.tolist()
    30873089    #        elevations.reverse()
     
    31953197    sww.store_header(outfile, times, number_of_volumes,
    31963198                     number_of_points, description=description,
    3197                      verbose=verbose, sww_precision=num.Float)
     3199                     verbose=verbose, sww_precision=netcdf_float)
    31983200
    31993201    # Store
    32003202    from anuga.coordinate_transforms.redfearn import redfearn
    3201     x = num.zeros(number_of_points, num.Float)  #Easting
    3202     y = num.zeros(number_of_points, num.Float)  #Northing
     3203    x = num.zeros(number_of_points, num.float)  #Easting
     3204    y = num.zeros(number_of_points, num.float)  #Northing
    32033205
    32043206    if verbose: print 'Making triangular grid'
     
    32343236            volumes.append([v4,v3,v2]) #Lower element
    32353237
    3236     volumes = num.array(volumes, num.Int)      #array default#
     3238    volumes = num.array(volumes)
    32373239
    32383240    if origin is None:
     
    32553257    outfile.variables['z'][:] = z             #FIXME HACK for bacwards compat.
    32563258    outfile.variables['elevation'][:] = z
    3257     outfile.variables['volumes'][:] = volumes.astype(num.Int32) #For Opteron 64
     3259    outfile.variables['volumes'][:] = volumes.astype(num.int32) #For Opteron 64
    32583260
    32593261    #Time stepping
     
    33873389    d = len(q)
    33883390
    3389     T = num.zeros(N, num.Float)       # Time
    3390     Q = num.zeros((N, d), num.Float)  # Values
     3391    T = num.zeros(N, num.float)       # Time
     3392    Q = num.zeros((N, d), num.float)  # Values
    33913393
    33923394    for i, line in enumerate(lines):
     
    34243426    fid.createDimension('number_of_timesteps', len(T))
    34253427
    3426     fid.createVariable('time', num.Float, ('number_of_timesteps',))
     3428    fid.createVariable('time', netcdf_float, ('number_of_timesteps',))
    34273429
    34283430    fid.variables['time'][:] = T
     
    34343436            name = 'Attribute%d' % i
    34353437
    3436         fid.createVariable(name, num.Float, ('number_of_timesteps',))
     3438        fid.createVariable(name, netcdf_float, ('number_of_timesteps',))
    34373439        fid.variables[name][:] = Q[:,i]
    34383440
     
    35053507    time_interp = get_time_interp(time,t)
    35063508
    3507     # Get the variables as Numeric arrays
     3509    # Get the variables as numeric arrays
    35083510    x = fid.variables['x'][:]                   # x-coordinates of vertices
    35093511    y = fid.variables['y'][:]                   # y-coordinates of vertices
     
    35183520    # FIXME (Ole): Something like this might be better:
    35193521    #                 concatenate((x, y), axis=1)
    3520     # or              concatenate((x[:,num.NewAxis], x[:,num.NewAxis]), axis=1)
     3522    # or              concatenate((x[:,num.newaxis], x[:,num.newaxis]), axis=1)
    35213523
    35223524    conserved_quantities = []
     
    37063708# @param boundary
    37073709def weed(coordinates, volumes, boundary=None):
    3708     if type(coordinates) == num.ArrayType:
     3710    if isinstance(coordinates, num.ndarray):
    37093711        coordinates = coordinates.tolist()
    3710     if type(volumes) == num.ArrayType:
     3712    if isinstance(volumes, num.ndarray):
    37113713        volumes = volumes.tolist()
    37123714
     
    38543856
    38553857    # variable definition
    3856     outfile.createVariable('elevation', num.Float, ('number_of_points',))
     3858    outfile.createVariable('elevation', netcdf_float, ('number_of_points',))
    38573859
    38583860    # Get handle to the variable
     
    38673869
    38683870        lower_index = global_index
    3869         telev = num.zeros(ncols_new, num.Float)
     3871        telev = num.zeros(ncols_new, num.float)
    38703872        local_index = 0
    38713873        trow = i * cellsize_ratio
     
    39953997    from anuga.coordinate_transforms.redfearn import redfearn
    39963998
    3997     precision = num.Float # So if we want to change the precision its done here
     3999    precision = netcdf_float # So if we want to change the precision its done here
    39984000
    39994001    # go in to the bath dir and load the only file,
     
    40964098    #################################
    40974099
    4098     outfile.createVariable('volumes', num.Int, ('number_of_volumes',
    4099                                                 'number_of_vertices'))
     4100    outfile.createVariable('volumes', netcdf_int, ('number_of_volumes',
     4101                                                   'number_of_vertices'))
    41004102
    41014103    outfile.createVariable('time', precision, ('number_of_timesteps',))
     
    41134115    from anuga.coordinate_transforms.redfearn import redfearn
    41144116
    4115     x = num.zeros(number_of_points, num.Float)  #Easting
    4116     y = num.zeros(number_of_points, num.Float)  #Northing
     4117    x = num.zeros(number_of_points, num.float)  #Easting
     4118    y = num.zeros(number_of_points, num.float)  #Northing
    41174119
    41184120    if verbose: print 'Making triangular grid'
     
    41504152            volumes.append([v4,v2,v3]) #Lower element
    41514153
    4152     volumes = num.array(volumes, num.Int)      #array default#
     4154    volumes = num.array(volumes)
    41534155
    41544156    geo_ref = Geo_reference(refzone, min(x), min(y))
     
    41754177    outfile.variables['z'][:] = z
    41764178    outfile.variables['elevation'][:] = z
    4177     outfile.variables['volumes'][:] = volumes.astype(num.Int32) # On Opteron 64
     4179    outfile.variables['volumes'][:] = volumes.astype(num.int32) # On Opteron 64
    41784180
    41794181    stage = outfile.variables['stage']
     
    43674369lat_name = 'LAT'
    43684370time_name = 'TIME'
    4369 precision = num.Float # So if we want to change the precision its done here
     4371precision = netcdf_float # So if we want to change the precision its done here
    43704372
    43714373##
     
    46484650    lonlatdep = p_array.array('f')
    46494651    lonlatdep.read(mux_file, columns * points_num)
    4650     lonlatdep = num.array(lonlatdep, typecode=num.Float)
     4652    lonlatdep = num.array(lonlatdep, dtype=num.float)
    46514653    lonlatdep = num.reshape(lonlatdep, (points_num, columns))
    46524654
     
    46554657    lon_sorted.sort()
    46564658
    4657     if not lon == lon_sorted:
     4659    if not num.alltrue(lon == lon_sorted):
    46584660        msg = "Longitudes in mux file are not in ascending order"
    46594661        raise IOError, msg
     
    46614663    lat_sorted = list(lat)
    46624664    lat_sorted.sort()
    4663 
    4664 # UNUSED?
    4665 ##    if not lat == lat_sorted:
    4666 ##        msg = "Latitudes in mux file are not in ascending order"
    46674665
    46684666    nc_file = Write_nc(quantity,
     
    46774675        hz_p_array = p_array.array('f')
    46784676        hz_p_array.read(mux_file, points_num)
    4679         hz_p = num.array(hz_p_array, typecode=num.Float)
     4677        hz_p = num.array(hz_p_array, dtype=num.float)
    46804678        hz_p = num.reshape(hz_p, (len(lon), len(lat)))
    46814679        hz_p = num.transpose(hz_p)  # mux has lat varying fastest, nc has long v.f.
     
    47754773    QUANTITY = 2
    47764774
    4777     long_lat_dep = ensure_numeric(long_lat_dep, num.Float)
     4775    long_lat_dep = ensure_numeric(long_lat_dep, num.float)
    47784776
    47794777    num_points = long_lat_dep.shape[0]
     
    48134811    # FIXME - make this faster/do this a better way
    48144812    # use numeric transpose, after reshaping the quantity vector
    4815     quantity = num.zeros(num_points, num.Float)
     4813    quantity = num.zeros(num_points, num.float)
    48164814
    48174815    for lat_i, _ in enumerate(lat):
     
    52665264
    52675265    points_utm=ensure_numeric(points_utm)
    5268     assert ensure_numeric(mesh_dic['generatedpointlist']) \
    5269            == ensure_numeric(points_utm)
     5266    assert num.alltrue(ensure_numeric(mesh_dic['generatedpointlist'])
     5267                       == ensure_numeric(points_utm))
    52705268
    52715269    volumes = mesh_dic['generatedtrianglelist']
     
    52855283    sww = Write_sww()
    52865284    sww.store_header(outfile, times, len(volumes), len(points_utm),
    5287                      verbose=verbose, sww_precision=num.Float)
     5285                     verbose=verbose, sww_precision=netcdf_float)
    52885286    outfile.mean_stage = mean_stage
    52895287    outfile.zscale = zscale
     
    53095307                                 xmomentum=xmomentum,
    53105308                                 ymomentum=ymomentum,
    5311                                  sww_precision=num.Float)
     5309                                 sww_precision=num.float)
    53125310        j += 1
    53135311
     
    53565354    numSrc = len(filenames)
    53575355
    5358     file_params = -1 * num.ones(3, num.Float)                    # [nsta,dt,nt]
     5356    file_params = -1 * num.ones(3, num.float)                    # [nsta,dt,nt]
    53595357
    53605358    # Convert verbose to int C flag
     
    53655363
    53665364    if weights is None:
    5367         weights = num.ones(numSrc)
     5365        weights = num.ones(numSrc, num.int)     #array default#
    53685366
    53695367    if permutation is None:
    5370         permutation = ensure_numeric([], num.Float)
     5368        permutation = ensure_numeric([], num.float)
    53715369
    53725370    # Call underlying C implementation urs2sts_ext.c
     
    54165414
    54175415    times = dt * num.arange(parameters_index)
    5418     latitudes = num.zeros(number_of_selected_stations, num.Float)
    5419     longitudes = num.zeros(number_of_selected_stations, num.Float)
    5420     elevation = num.zeros(number_of_selected_stations, num.Float)
    5421     quantity = num.zeros((number_of_selected_stations, parameters_index), num.Float)
     5416    latitudes = num.zeros(number_of_selected_stations, num.float)
     5417    longitudes = num.zeros(number_of_selected_stations, num.float)
     5418    elevation = num.zeros(number_of_selected_stations, num.float)
     5419    quantity = num.zeros((number_of_selected_stations, parameters_index), num.float)
    54225420
    54235421    starttime = 1e16
     
    55435541    if weights is None:
    55445542        # Default is equal weighting
    5545         weights = num.ones(numSrc, num.Float) / numSrc
     5543        weights = num.ones(numSrc, num.float) / numSrc
    55465544    else:
    55475545        weights = ensure_numeric(weights)
     
    56655663    # 0 to number_of_points-1
    56665664    if permutation is None:
    5667         permutation = num.arange(number_of_points, typecode=num.Int)
     5665        permutation = num.arange(number_of_points, dtype=num.int)
    56685666
    56695667    # NetCDF file definition
     
    56795677                     description=description,
    56805678                     verbose=verbose,
    5681                      sts_precision=num.Float)
     5679                     sts_precision=netcdf_float)
    56825680
    56835681    # Store
    56845682    from anuga.coordinate_transforms.redfearn import redfearn
    56855683
    5686     x = num.zeros(number_of_points, num.Float)  # Easting
    5687     y = num.zeros(number_of_points, num.Float)  # Northing
     5684    x = num.zeros(number_of_points, num.float)  # Easting
     5685    y = num.zeros(number_of_points, num.float)  # Northing
    56885686
    56895687    # Check zone boundaries
     
    57165714
    57175715    elevation = num.resize(elevation, outfile.variables['elevation'][:].shape)
    5718     outfile.variables['permutation'][:] = permutation.astype(num.Int32) # Opteron 64
     5716    outfile.variables['permutation'][:] = permutation.astype(num.int32) # Opteron 64
    57195717    outfile.variables['x'][:] = x - geo_ref.get_xllcorner()
    57205718    outfile.variables['y'][:] = y - geo_ref.get_yllcorner()
     
    58215819    # @param smoothing True if smoothing is to be used.
    58225820    # @param order
    5823     # @param sww_precision Data type of the quantitiy to be written (Float32)
     5821    # @param sww_precision Data type of the quantitiy written (netcdf constant)
    58245822    # @param verbose True if this function is to be verbose.
    58255823    # @note If 'times' is a list, the info will be made relative.
     
    58325830                     smoothing=True,
    58335831                     order=1,
    5834                      sww_precision=num.Float32,
     5832                     sww_precision=netcdf_float32,
    58355833                     verbose=False):
    58365834        """Write an SWW file header.
     
    58655863        # This is being used to seperate one number from a list.
    58665864        # what it is actually doing is sorting lists from numeric arrays.
    5867         if type(times) is list or type(times) is num.ArrayType:
     5865        if type(times) is list or isinstance(times, num.ndarray):
    58685866            number_of_times = len(times)
    58695867            times = ensure_numeric(times)
     
    59145912        outfile.createVariable('z', sww_precision, ('number_of_points',))
    59155913
    5916         outfile.createVariable('volumes', num.Int, ('number_of_volumes',
    5917                                                     'number_of_vertices'))
     5914        outfile.createVariable('volumes', netcdf_int, ('number_of_volumes',
     5915                                                       'number_of_vertices'))
    59185916
    59195917        # Doing sww_precision instead of Float gives cast errors.
    5920         outfile.createVariable('time', num.Float,
     5918        outfile.createVariable('time', netcdf_float,
    59215919                               ('number_of_timesteps',))
    59225920
     
    59325930            #outfile.variables[q+Write_sww.RANGE][1] = -max_float # Max
    59335931
    5934         if type(times) is list or type(times) is num.ArrayType:
     5932        if type(times) is list or isinstance(times, num.ndarray):
    59355933            outfile.variables['time'][:] = times    #Store time relative
    59365934
     
    60356033        outfile.variables['z'][:] = elevation
    60366034        outfile.variables['elevation'][:] = elevation  #FIXME HACK
    6037         outfile.variables['volumes'][:] = volumes.astype(num.Int32) #On Opteron 64
     6035        outfile.variables['volumes'][:] = volumes.astype(num.int32) #On Opteron 64
    60386036
    60396037        q = 'elevation'
     
    60516049    # @param verbose True if this function is to be verbose.
    60526050    # @param **quant
    6053     def store_quantities(self, outfile, sww_precision=num.Float32,
     6051    def store_quantities(self, outfile, sww_precision=num.float32,
    60546052                         slice_index=None, time=None,
    60556053                         verbose=False, **quant):
     
    62366234    # @param number_of_points The number of URS gauge sites.
    62376235    # @param description Description string to write into the STS file.
    6238     # @param sts_precision Format of data to write (default Float32).
     6236    # @param sts_precision Format of data to write (netcdf constant ONLY).
    62396237    # @param verbose True if this function is to be verbose.
    62406238    # @note If 'times' is a list, the info will be made relative.
     
    62446242                     number_of_points,
    62456243                     description='Converted from URS mux2 format',
    6246                      sts_precision=num.Float32,
     6244                     sts_precision=netcdf_float32,
    62476245                     verbose=False):
    62486246        """
     
    62676265        # This is being used to seperate one number from a list.
    62686266        # what it is actually doing is sorting lists from numeric arrays.
    6269         if type(times) is list or type(times) is num.ArrayType:
     6267        if type(times) is list or isinstance(times, num.ndarray):
    62706268            number_of_times = len(times)
    62716269            times = ensure_numeric(times)
     
    62876285
    62886286        # Variable definitions
    6289         outfile.createVariable('permutation', num.Int, ('number_of_points',))
     6287        outfile.createVariable('permutation', netcdf_int, ('number_of_points',))
    62906288        outfile.createVariable('x', sts_precision, ('number_of_points',))
    62916289        outfile.createVariable('y', sts_precision, ('number_of_points',))
     
    63026300
    63036301        # Doing sts_precision instead of Float gives cast errors.
    6304         outfile.createVariable('time', num.Float, ('number_of_timesteps',))
     6302        outfile.createVariable('time', netcdf_float, ('number_of_timesteps',))
    63056303
    63066304        for q in Write_sts.sts_quantities:
     
    63146312            outfile.variables[q + Write_sts.RANGE][1] = -max_float # Max
    63156313
    6316         if type(times) is list or type(times) is num.ArrayType:
     6314        if type(times) is list or isinstance(times, num.ndarray):
    63176315            outfile.variables['time'][:] = times    #Store time relative
    63186316
     
    64236421    # @param verboseTrue if this function is to be verbose.
    64246422    # @param **quant Extra keyword args.
    6425     def store_quantities(self, outfile, sts_precision=num.Float32,
     6423    def store_quantities(self, outfile, sts_precision=num.float32,
    64266424                         slice_index=None, time=None,
    64276425                         verbose=False, **quant):
     
    65146512        lonlatdep = p_array.array('f')
    65156513        lonlatdep.read(mux_file, columns * self.points_num)
    6516         lonlatdep = num.array(lonlatdep, typecode=num.Float)
     6514        lonlatdep = num.array(lonlatdep, dtype=num.float)
    65176515        lonlatdep = num.reshape(lonlatdep, (self.points_num, columns))
    65186516        self.lonlatdep = lonlatdep
     
    65506548        hz_p_array = p_array.array('f')
    65516549        hz_p_array.read(self.mux_file, self.points_num)
    6552         hz_p = num.array(hz_p_array, typecode=num.Float)
     6550        hz_p = num.array(hz_p_array, dtype=num.float)
    65536551        self.iter_time_step += 1
    65546552
     
    66956693    # array to store data, number in there is to allow float...
    66966694    # i'm sure there is a better way!
    6697     data = num.array([], typecode=num.Float)
     6695    data = num.array([], dtype=num.float)
    66986696    data = num.resize(data, ((len(lines)-1), len(header_fields)))
    66996697
     
    68616859    time += fid.starttime[0]
    68626860
    6863     # Get the variables as Numeric arrays
     6861    # Get the variables as numeric arrays
    68646862    x = fid.variables['x'][:]                   # x-coordinates of nodes
    68656863    y = fid.variables['y'][:]                   # y-coordinates of nodes
     
    68706868
    68716869    # Mesh (nodes (Mx2), triangles (Nx3))
    6872     nodes = num.concatenate((x[:,num.NewAxis], y[:,num.NewAxis]), axis=1)
     6870    nodes = num.concatenate((x[:,num.newaxis], y[:,num.newaxis]), axis=1)
    68736871    triangles = fid.variables['volumes'][:]
    68746872
     
    72937291
    72947292        # Get the relevant quantities (Convert from single precison)
    7295         elevation = num.array(fid.variables['elevation'][:], num.Float)
    7296         stage = num.array(fid.variables['stage'][:], num.Float)
     7293        elevation = num.array(fid.variables['elevation'][:], num.float)
     7294        stage = num.array(fid.variables['stage'][:], num.float)
    72977295
    72987296        # Here's where one could convert nodal information to centroid
     
    73117309            # and call it here
    73127310
    7313             points = num.concatenate((x[:,num.NewAxis], y[:,num.NewAxis]), axis=1)
     7311            points = num.concatenate((x[:,num.newaxis], y[:,num.newaxis]), axis=1)
    73147312
    73157313            point_indices = inside_polygon(points, polygon)
Note: See TracChangeset for help on using the changeset viewer.