Changeset 6157 for anuga_core/source/anuga/shallow_water/data_manager.py
- Timestamp:
- Jan 13, 2009, 5:42:30 PM (15 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
anuga_core/source/anuga/shallow_water/data_manager.py
r6132 r6157 61 61 from os import sep, path, remove, mkdir, access, F_OK, W_OK, getcwd 62 62 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 63 import Numeric as num 67 64 68 65 from Scientific.IO.NetCDF import NetCDFFile … … 345 342 def __init__(self, domain, mode=netcdf_mode_w, max_size=2000000000, recursion=False): 346 343 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 350 346 self.recursion = recursion 351 347 self.mode = mode … … 425 421 426 422 from Scientific.IO.NetCDF import NetCDFFile 427 from Numeric import concatenate, Int428 423 429 424 domain = self.domain … … 443 438 444 439 # 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 ) 446 441 self.writer.store_triangulation(fid, 447 442 points, 448 443 # V.astype(volumes.typecode()), 449 V.astype( Float32),444 V.astype(num.Float32), 450 445 Z, 451 446 points_georeference=\ … … 466 461 from time import sleep 467 462 from os import stat 468 from Numeric import choose469 463 470 464 if names is None: … … 563 557 564 558 storable_indices = (A-z[:] >= self.minimum_storable_height) 565 stage = choose(storable_indices, (z[:], A))559 stage = num.choose(storable_indices, (z[:], A)) 566 560 567 561 # Define a zero vector of same size and type as A 568 562 # for use with momenta 569 null = zeros(size(A), A.typecode())563 null = num.zeros(num.size(A), A.typecode()) 570 564 571 565 # Get xmomentum where depth exceeds minimum_storable_height … … 573 567 xmom, _ = Q.get_vertex_values(xy=False, 574 568 precision=self.precision) 575 xmomentum = choose(storable_indices, (null, xmom))569 xmomentum = num.choose(storable_indices, (null, xmom)) 576 570 577 571 … … 580 574 ymom, _ = Q.get_vertex_values(xy=False, 581 575 precision=self.precision) 582 ymomentum = choose(storable_indices, (null, ymom))576 ymomentum = num.choose(storable_indices, (null, ymom)) 583 577 584 578 # Write quantities to underlying data file … … 627 621 def __init__(self, domain, mode=netcdf_mode_w): 628 622 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 632 625 633 626 Data_format.__init__(self, domain, 'sww', mode) … … 657 650 658 651 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')) 661 654 662 655 fid.createVariable('time', self.precision, ('number_of_timesteps',)) … … 680 673 681 674 from Scientific.IO.NetCDF import NetCDFFile 682 from Numeric import concatenate683 675 684 676 domain = self.domain … … 1151 1143 Y = {} 1152 1144 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]]) 1154 1146 1155 1147 return Y … … 1269 1261 1270 1262 from Scientific.IO.NetCDF import NetCDFFile 1271 from Numeric import Float, zeros1272 1263 1273 1264 # Get NetCDF … … 1284 1275 1285 1276 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) 1289 1280 1290 1281 for i in range(M): … … 1324 1315 import glob, os 1325 1316 from anuga.config import data_dir 1326 from Numeric import zeros, Float1327 1317 1328 1318 # Get bathymetry and x,y's … … 1330 1320 1331 1321 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) 1335 1325 1336 1326 for i, line in enumerate(lines): … … 1524 1514 import os 1525 1515 from Scientific.IO.NetCDF import NetCDFFile 1526 from Numeric import Float, zeros, reshape, sum1527 1516 1528 1517 root = basename_in … … 1591 1580 outfile.nrows = nrows 1592 1581 1593 dem_elevation_r = reshape(dem_elevation, (nrows, ncols))1582 dem_elevation_r = num.reshape(dem_elevation, (nrows, ncols)) 1594 1583 totalnopoints = nrows*ncols 1595 1584 … … 1640 1629 1641 1630 # 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',)) 1645 1634 1646 1635 # Get handles to the variables … … 1660 1649 1661 1650 v = dem_elevation_r[i,index1:index2+1] 1662 no_NODATA = sum(v == NODATA_value)1651 no_NODATA = num.sum(v == NODATA_value) 1663 1652 if no_NODATA > 0: 1664 1653 newcols = lenv - no_NODATA # ncols_in_bounding_box - no_NODATA … … 1666 1655 newcols = lenv # ncols_in_bounding_box 1667 1656 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) 1670 1659 1671 1660 local_index = 0 … … 1789 1778 import os 1790 1779 from Scientific.IO.NetCDF import NetCDFFile 1791 from Numeric import Float, zeros, reshape1792 1780 1793 1781 root = basename_in … … 2133 2121 2134 2122 import sys 2135 from Numeric import array, Float, concatenate, NewAxis, zeros, reshape2136 from Numeric import array2string, sometrue2137 2123 2138 2124 from anuga.utilities.polygon import inside_polygon, outside_polygon, \ … … 2254 2240 #q has a time component, must be reduced alongthe temporal dimension 2255 2241 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) 2257 2243 2258 2244 if timestep is not None: … … 2314 2300 y = y + yllcorner - newyllcorner 2315 2301 2316 vertex_points = concatenate ((x[:,NewAxis], y[:,NewAxis]), axis=1)2302 vertex_points = num.concatenate ((x[:,num.NewAxis], y[:,num.NewAxis]), axis=1) 2317 2303 assert len(vertex_points.shape) == 2 2318 2304 2319 grid_points = zeros ((ncols*nrows, 2),Float)2305 grid_points = num.zeros ((ncols*nrows, 2), num.Float) 2320 2306 2321 2307 for i in xrange(nrows): … … 2359 2345 if format.lower() == 'ers': 2360 2346 # setup ERS header information 2361 grid_values = reshape(grid_values, (nrows, ncols))2347 grid_values = num.reshape(grid_values, (nrows, ncols)) 2362 2348 header = {} 2363 2349 header['datum'] = '"' + datum + '"' … … 2426 2412 slice = grid_values[base_index:base_index+ncols] 2427 2413 #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) 2430 2416 ascid.write(s[1:-1] + '\n') 2431 2417 … … 2543 2529 2544 2530 import sys 2545 from Numeric import array, Float, concatenate, NewAxis, zeros, reshape2546 from Numeric import array2string, sometrue2547 2531 from anuga.utilities.polygon import inside_polygon, outside_polygon, \ 2548 2532 separate_points_by_polygon … … 2631 2615 if verbose: print 'Reducing quantity %s' % quantity 2632 2616 2633 q_reduced = zeros(number_of_points,Float)2617 q_reduced = num.zeros(number_of_points, num.Float) 2634 2618 for k in range(number_of_points): 2635 2619 q_reduced[k] = reduction(q[:,k]) … … 2645 2629 2646 2630 # 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) 2648 2632 assert len(vertex_points.shape) == 2 2649 2633 … … 2748 2732 import os 2749 2733 from Scientific.IO.NetCDF import NetCDFFile 2750 from Numeric import Float, array2751 2734 2752 2735 root = basename_in … … 2866 2849 2867 2850 # 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')) 2870 2853 2871 2854 # Get handles to the variables … … 2878 2861 if verbose and i % ((n+10)/10) == 0: 2879 2862 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]) 2881 2864 2882 2865 fid.close() … … 2946 2929 import os 2947 2930 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 2952 2933 2953 2934 msg = 'Must use latitudes and longitudes for minlat, maxlon etc' … … 3022 3003 3023 3004 # 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) 3026 3007 3027 3008 # 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) 3035 3016 3036 3017 if mint is None: … … 3038 3019 mint = times[0] 3039 3020 else: 3040 jmin = searchsorted(times, mint)3021 jmin = num.searchsorted(times, mint) 3041 3022 3042 3023 if maxt is None: … … 3044 3025 maxt = times[-1] 3045 3026 else: 3046 jmax = searchsorted(times, maxt)3027 jmax = num.searchsorted(times, maxt) 3047 3028 3048 3029 kmin, kmax, lmin, lmax = _get_min_max_indexes(latitudes[:], … … 3089 3070 3090 3071 #Cleanup 3091 from Numeric import sometrue3092 3093 3072 missing = (amplitudes == nan_ha) 3094 if sometrue (missing):3073 if num.sometrue (missing): 3095 3074 if fail_on_NaN: 3096 3075 msg = 'NetCDFFile %s contains missing values' \ … … 3101 3080 3102 3081 missing = (uspeed == nan_ua) 3103 if sometrue (missing):3082 if num.sometrue (missing): 3104 3083 if fail_on_NaN: 3105 3084 msg = 'NetCDFFile %s contains missing values' \ … … 3110 3089 3111 3090 missing = (vspeed == nan_va) 3112 if sometrue (missing):3091 if num.sometrue (missing): 3113 3092 if fail_on_NaN: 3114 3093 msg = 'NetCDFFile %s contains missing values' \ … … 3119 3098 3120 3099 missing = (elevations == nan_e) 3121 if sometrue (missing):3100 if num.sometrue (missing): 3122 3101 if fail_on_NaN: 3123 3102 msg = 'NetCDFFile %s contains missing values' \ … … 3187 3166 sww.store_header(outfile, times, number_of_volumes, 3188 3167 number_of_points, description=description, 3189 verbose=verbose, sww_precision= Float)3168 verbose=verbose, sww_precision=num.Float) 3190 3169 3191 3170 # Store 3192 3171 from anuga.coordinate_transforms.redfearn import redfearn 3193 x = zeros(number_of_points,Float) #Easting3194 y = zeros(number_of_points,Float) #Northing3172 x = num.zeros(number_of_points, num.Float) #Easting 3173 y = num.zeros(number_of_points, num.Float) #Northing 3195 3174 3196 3175 if verbose: print 'Making triangular grid' … … 3226 3205 volumes.append([v4,v3,v2]) #Lower element 3227 3206 3228 volumes = array(volumes)3207 volumes = num.array(volumes) 3229 3208 3230 3209 if origin is None: … … 3242 3221 3243 3222 #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) 3246 3224 outfile.variables['x'][:] = x - geo_ref.get_xllcorner() 3247 3225 outfile.variables['y'][:] = y - geo_ref.get_yllcorner() 3248 3226 outfile.variables['z'][:] = z #FIXME HACK for bacwards compat. 3249 3227 outfile.variables['elevation'][:] = z 3250 outfile.variables['volumes'][:] = volumes.astype( Int32) #For Opteron 643228 outfile.variables['volumes'][:] = volumes.astype(num.Int32) #For Opteron 64 3251 3229 3252 3230 #Time stepping … … 3331 3309 3332 3310 import time, calendar 3333 from Numeric import array3334 3311 from anuga.config import time_format 3335 3312 from anuga.utilities.numerical_tools import ensure_numeric … … 3371 3348 3372 3349 # Read times proper 3373 from Numeric import zeros, Float, alltrue3374 3350 from anuga.config import time_format 3375 3351 import time, calendar … … 3382 3358 d = len(q) 3383 3359 3384 T = zeros(N,Float) # Time3385 Q = zeros((N, d),Float) # Values3360 T = num.zeros(N, num.Float) # Time 3361 Q = num.zeros((N, d), num.Float) # Values 3386 3362 3387 3363 for i, line in enumerate(lines): … … 3398 3374 msg = 'File %s must list time as a monotonuosly ' % filename 3399 3375 msg += 'increasing sequence' 3400 assert alltrue(T[1:] - T[:-1] > 0), msg3376 assert num.alltrue(T[1:] - T[:-1] > 0), msg 3401 3377 3402 3378 #Create NetCDF file … … 3419 3395 fid.createDimension('number_of_timesteps', len(T)) 3420 3396 3421 fid.createVariable('time', Float, ('number_of_timesteps',))3397 fid.createVariable('time', num.Float, ('number_of_timesteps',)) 3422 3398 3423 3399 fid.variables['time'][:] = T … … 3429 3405 name = 'Attribute%d' % i 3430 3406 3431 fid.createVariable(name, Float, ('number_of_timesteps',))3407 fid.createVariable(name, num.Float, ('number_of_timesteps',)) 3432 3408 fid.variables[name][:] = Q[:,i] 3433 3409 … … 3488 3464 from Scientific.IO.NetCDF import NetCDFFile 3489 3465 from shallow_water import Domain 3490 from Numeric import asarray, transpose, resize3491 3466 3492 3467 # initialise NaN. … … 3511 3486 starttime = fid.starttime[0] 3512 3487 volumes = fid.variables['volumes'][:] # Connectivity 3513 coordinates = transpose(asarray([x.tolist(), y.tolist()]))3488 coordinates = num.transpose(num.asarray([x.tolist(), y.tolist()])) 3514 3489 # FIXME (Ole): Something like this might be better: 3515 3490 # 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) 3517 3492 3518 3493 conserved_quantities = [] … … 3608 3583 X = (X*data) + (data==0)*NaN_filler 3609 3584 if unique: 3610 X = resize(X, (len(X)/3, 3))3585 X = num.resize(X, (len(X)/3, 3)) 3611 3586 domain.set_quantity(quantity, X) 3612 3587 # … … 3633 3608 X = (X*data) + (data==0)*NaN_filler 3634 3609 if unique: 3635 X = resize(X, (X.shape[0]/3, 3))3610 X = num.resize(X, (X.shape[0]/3, 3)) 3636 3611 domain.set_quantity(quantity, X) 3637 3612 … … 3702 3677 # @param boundary 3703 3678 def weed(coordinates, volumes, boundary=None): 3704 if type(coordinates) == ArrayType:3679 if type(coordinates) == num.ArrayType: 3705 3680 coordinates = coordinates.tolist() 3706 if type(volumes) == ArrayType:3681 if type(volumes) == num.ArrayType: 3707 3682 volumes = volumes.tolist() 3708 3683 … … 3781 3756 import os 3782 3757 from Scientific.IO.NetCDF import NetCDFFile 3783 from Numeric import Float, zeros, sum, reshape, equal3784 3758 3785 3759 root = basename_in … … 3851 3825 3852 3826 # variable definition 3853 outfile.createVariable('elevation', Float, ('number_of_points',))3827 outfile.createVariable('elevation', num.Float, ('number_of_points',)) 3854 3828 3855 3829 # Get handle to the variable 3856 3830 elevation = outfile.variables['elevation'] 3857 3831 3858 dem_elevation_r = reshape(dem_elevation, (nrows, ncols))3832 dem_elevation_r = num.reshape(dem_elevation, (nrows, ncols)) 3859 3833 3860 3834 #Store data … … 3864 3838 3865 3839 lower_index = global_index 3866 telev = zeros(ncols_new,Float)3840 telev = num.zeros(ncols_new, num.Float) 3867 3841 local_index = 0 3868 3842 trow = i * cellsize_ratio … … 3876 3850 #decimated dem to NODATA_value, else compute decimated 3877 3851 #value using stencil 3878 if sum(sum(equal(tmp, NODATA_value))) > 0:3852 if num.sum(num.sum(num.equal(tmp, NODATA_value))) > 0: 3879 3853 telev[local_index] = NODATA_value 3880 3854 else: 3881 telev[local_index] = sum(sum(tmp * stencil))3855 telev[local_index] = num.sum(num.sum(tmp * stencil)) 3882 3856 3883 3857 global_index += 1 … … 3992 3966 from anuga.coordinate_transforms.redfearn import redfearn 3993 3967 3994 precision = Float # So if we want to change the precision its done here3968 precision = num.Float # So if we want to change the precision its done here 3995 3969 3996 3970 # go in to the bath dir and load the only file, … … 4093 4067 ################################# 4094 4068 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')) 4097 4071 4098 4072 outfile.createVariable('time', precision, ('number_of_timesteps',)) … … 4110 4084 from anuga.coordinate_transforms.redfearn import redfearn 4111 4085 4112 x = zeros(number_of_points,Float) #Easting4113 y = zeros(number_of_points,Float) #Northing4086 x = num.zeros(number_of_points, num.Float) #Easting 4087 y = num.zeros(number_of_points, num.Float) #Northing 4114 4088 4115 4089 if verbose: print 'Making triangular grid' … … 4147 4121 volumes.append([v4,v2,v3]) #Lower element 4148 4122 4149 volumes = array(volumes)4123 volumes = num.array(volumes) 4150 4124 4151 4125 geo_ref = Geo_reference(refzone, min(x), min(y)) … … 4165 4139 print 'geo_ref: ', geo_ref 4166 4140 4167 z = resize(bath_grid,outfile.variables['z'][:].shape)4141 z = num.resize(bath_grid,outfile.variables['z'][:].shape) 4168 4142 outfile.variables['x'][:] = x - geo_ref.get_xllcorner() 4169 4143 outfile.variables['y'][:] = y - geo_ref.get_yllcorner() … … 4172 4146 outfile.variables['z'][:] = z 4173 4147 outfile.variables['elevation'][:] = z 4174 outfile.variables['volumes'][:] = volumes.astype( Int32) # On Opteron 644148 outfile.variables['volumes'][:] = volumes.astype(num.Int32) # On Opteron 64 4175 4149 4176 4150 stage = outfile.variables['stage'] … … 4198 4172 # handle missing values 4199 4173 missing = (elevation_grid == elevation_meta['NODATA_value']) 4200 if sometrue (missing):4174 if num.sometrue (missing): 4201 4175 if fail_on_NaN: 4202 4176 msg = 'File %s contains missing values' \ … … 4254 4228 longitudes = ensure_numeric(longitudes) 4255 4229 4256 assert allclose(sort(longitudes), longitudes)4230 assert num.allclose(num.sort(longitudes), longitudes) 4257 4231 4258 4232 #print latitudes[0],longitudes[0] … … 4261 4235 4262 4236 lat_ascending = True 4263 if not allclose(sort(latitudes), latitudes):4237 if not num.allclose(num.sort(latitudes), latitudes): 4264 4238 lat_ascending = False 4265 4239 # reverse order of lat, so it's in ascending order 4266 4240 latitudes = latitudes[::-1] 4267 assert allclose(sort(latitudes), latitudes)4241 assert num.allclose(num.sort(latitudes), latitudes) 4268 4242 4269 4243 largest_lat_index = len(latitudes)-1 … … 4273 4247 lat_min_index = 0 4274 4248 else: 4275 lat_min_index = searchsorted(latitudes, minlat)-14249 lat_min_index = num.searchsorted(latitudes, minlat)-1 4276 4250 if lat_min_index <0: 4277 4251 lat_min_index = 0 … … 4280 4254 lat_max_index = largest_lat_index #len(latitudes) 4281 4255 else: 4282 lat_max_index = searchsorted(latitudes, maxlat)4256 lat_max_index = num.searchsorted(latitudes, maxlat) 4283 4257 if lat_max_index > largest_lat_index: 4284 4258 lat_max_index = largest_lat_index … … 4287 4261 lon_min_index = 0 4288 4262 else: 4289 lon_min_index = searchsorted(longitudes, minlon)-14263 lon_min_index = num.searchsorted(longitudes, minlon)-1 4290 4264 if lon_min_index <0: 4291 4265 lon_min_index = 0 … … 4294 4268 lon_max_index = len(longitudes) 4295 4269 else: 4296 lon_max_index = searchsorted(longitudes, maxlon)4270 lon_max_index = num.searchsorted(longitudes, maxlon) 4297 4271 4298 4272 # Reversing the indexes, if the lat array is decending … … 4349 4323 cells = line.split() 4350 4324 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) 4353 4327 4354 4328 return {'xllcorner':xllcorner, … … 4364 4338 lat_name = 'LAT' 4365 4339 time_name = 'TIME' 4366 precision = Float # So if we want to change the precision its done here4340 precision = num.Float # So if we want to change the precision its done here 4367 4341 4368 4342 ## … … 4645 4619 lonlatdep = p_array.array('f') 4646 4620 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)) 4649 4623 4650 4624 lon, lat, depth = lon_lat2grid(lonlatdep) … … 4674 4648 hz_p_array = p_array.array('f') 4675 4649 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. 4679 4653 4680 4654 #write time slice to nc file … … 4711 4685 outfile.variables[lat_name][:] = ensure_numeric(lat) 4712 4686 4713 depth = reshape(depth_vector, (len(lat), len(lon)))4687 depth = num.reshape(depth_vector, (len(lat), len(lon))) 4714 4688 outfile.variables[zname][:] = depth 4715 4689 … … 4772 4746 QUANTITY = 2 4773 4747 4774 long_lat_dep = ensure_numeric(long_lat_dep, Float)4748 long_lat_dep = ensure_numeric(long_lat_dep, num.Float) 4775 4749 4776 4750 num_points = long_lat_dep.shape[0] … … 4799 4773 last = first + lenlat 4800 4774 4801 assert allclose(long_lat_dep[first:last,LAT], lat), msg4802 assert allclose(long_lat_dep[first:last,LONG], long[i]), msg4775 assert num.allclose(long_lat_dep[first:last,LAT], lat), msg 4776 assert num.allclose(long_lat_dep[first:last,LONG], long[i]), msg 4803 4777 4804 4778 msg = 'Out of range latitudes/longitudes' … … 4810 4784 # FIXME - make this faster/do this a better way 4811 4785 # use numeric transpose, after reshaping the quantity vector 4812 quantity = zeros(num_points,Float)4786 quantity = num.zeros(num_points, num.Float) 4813 4787 4814 4788 for lat_i, _ in enumerate(lat): … … 5282 5256 sww = Write_sww() 5283 5257 sww.store_header(outfile, times, len(volumes), len(points_utm), 5284 verbose=verbose, sww_precision= Float)5258 verbose=verbose, sww_precision=num.Float) 5285 5259 outfile.mean_stage = mean_stage 5286 5260 outfile.zscale = zscale … … 5306 5280 xmomentum=xmomentum, 5307 5281 ymomentum=ymomentum, 5308 sww_precision= Float)5282 sww_precision=num.Float) 5309 5283 j += 1 5310 5284 … … 5349 5323 """ 5350 5324 5351 from Numeric import ones,Float,compress,zeros,arange5352 5325 from urs_ext import read_mux2 5353 5326 5354 5327 numSrc = len(filenames) 5355 5328 5356 file_params = -1 * ones(3,Float) # [nsta,dt,nt]5329 file_params = -1 * num.ones(3, num.Float) # [nsta,dt,nt] 5357 5330 5358 5331 # Convert verbose to int C flag … … 5363 5336 5364 5337 if weights is None: 5365 weights = ones(numSrc)5338 weights = num.ones(numSrc) 5366 5339 5367 5340 if permutation is None: 5368 permutation = ensure_numeric([], Float)5341 permutation = ensure_numeric([], num.Float) 5369 5342 5370 5343 # Call underlying C implementation urs2sts_ext.c … … 5373 5346 5374 5347 msg = 'File parameter values were not read in correctly from c file' 5375 assert len( compress(file_params > 0, file_params)) != 0, msg5348 assert len(num.compress(file_params > 0, file_params)) != 0, msg 5376 5349 5377 5350 msg = 'The number of stations specifed in the c array and in the file ' \ … … 5413 5386 parameters_index = data.shape[1] - OFFSET 5414 5387 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) 5420 5393 5421 5394 starttime = 1e16 … … 5444 5417 mux_times_start_i = 0 5445 5418 else: 5446 mux_times_start_i = searchsorted(mux_times, mint)5419 mux_times_start_i = num.searchsorted(mux_times, mint) 5447 5420 5448 5421 if maxt == None: … … 5451 5424 maxt += 0.5 # so if you specify a time where there is 5452 5425 # 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) 5454 5427 5455 5428 return mux_times_start_i, mux_times_fin_i … … 5518 5491 import os 5519 5492 from Scientific.IO.NetCDF import NetCDFFile 5520 from Numeric import Float, Int, Int32, searchsorted, zeros, array5521 from Numeric import allclose, around,ones,Float5522 5493 from types import ListType,StringType 5523 5494 from operator import __and__ … … 5543 5514 if weights is None: 5544 5515 # Default is equal weighting 5545 weights = ones(numSrc,Float) / numSrc5516 weights = num.ones(numSrc, num.Float) / numSrc 5546 5517 else: 5547 5518 weights = ensure_numeric(weights) … … 5622 5593 msg = '%s, %s and %s have inconsistent gauge data' \ 5623 5594 % (files_in[0], files_in[1], files_in[2]) 5624 assert allclose(times, times_old), msg5625 assert allclose(latitudes, latitudes_old), msg5626 assert allclose(longitudes, longitudes_old), msg5627 assert allclose(elevation, elevation_old), msg5628 assert allclose(starttime, starttime_old), msg5595 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 5629 5600 times_old = times 5630 5601 latitudes_old = latitudes … … 5665 5636 # 0 to number_of_points-1 5666 5637 if permutation is None: 5667 permutation = arange(number_of_points, typecode=Int)5638 permutation = num.arange(number_of_points, typecode=num.Int) 5668 5639 5669 5640 # NetCDF file definition … … 5679 5650 description=description, 5680 5651 verbose=verbose, 5681 sts_precision= Float)5652 sts_precision=num.Float) 5682 5653 5683 5654 # Store 5684 5655 from anuga.coordinate_transforms.redfearn import redfearn 5685 5656 5686 x = zeros(number_of_points,Float) # Easting5687 y = zeros(number_of_points,Float) # Northing5657 x = num.zeros(number_of_points, num.Float) # Easting 5658 y = num.zeros(number_of_points, num.Float) # Northing 5688 5659 5689 5660 # Check zone boundaries … … 5715 5686 geo_ref = write_NetCDF_georeference(origin, outfile) 5716 5687 5717 elevation = resize(elevation, outfile.variables['elevation'][:].shape)5718 outfile.variables['permutation'][:] = permutation.astype( Int32) # Opteron 645688 elevation = num.resize(elevation, outfile.variables['elevation'][:].shape) 5689 outfile.variables['permutation'][:] = permutation.astype(num.Int32) # Opteron 64 5719 5690 outfile.variables['x'][:] = x - geo_ref.get_xllcorner() 5720 5691 outfile.variables['y'][:] = y - geo_ref.get_yllcorner() … … 5782 5753 y = fid.variables['y'][:] + yllcorner 5783 5754 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) 5787 5758 5788 5759 return sts_points.tolist() … … 5832 5803 smoothing=True, 5833 5804 order=1, 5834 sww_precision= Float32,5805 sww_precision=num.Float32, 5835 5806 verbose=False): 5836 5807 """Write an SWW file header. … … 5865 5836 # This is being used to seperate one number from a list. 5866 5837 # 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: 5868 5839 number_of_times = len(times) 5869 5840 times = ensure_numeric(times) … … 5914 5885 outfile.createVariable('z', sww_precision, ('number_of_points',)) 5915 5886 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')) 5918 5889 5919 5890 # Doing sww_precision instead of Float gives cast errors. 5920 outfile.createVariable('time', Float,5891 outfile.createVariable('time', num.Float, 5921 5892 ('number_of_timesteps',)) 5922 5893 … … 5932 5903 outfile.variables[q+Write_sww.RANGE][1] = -max_float # Max 5933 5904 5934 if type(times) is list or type(times) is ArrayType:5905 if type(times) is list or type(times) is num.ArrayType: 5935 5906 outfile.variables['time'][:] = times #Store time relative 5936 5907 … … 5987 5958 5988 5959 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) 5991 5962 5992 5963 # given the two geo_refs and the points, do the stuff … … 6035 6006 outfile.variables['z'][:] = elevation 6036 6007 outfile.variables['elevation'][:] = elevation #FIXME HACK 6037 outfile.variables['volumes'][:] = volumes.astype( Int32) #On Opteron 646008 outfile.variables['volumes'][:] = volumes.astype(num.Int32) #On Opteron 64 6038 6009 6039 6010 q = 'elevation' … … 6051 6022 # @param verbose True if this function is to be verbose. 6052 6023 # @param **quant 6053 def store_quantities(self, outfile, sww_precision= Float32,6024 def store_quantities(self, outfile, sww_precision=num.Float32, 6054 6025 slice_index=None, time=None, 6055 6026 verbose=False, **quant): … … 6244 6215 number_of_points, 6245 6216 description='Converted from URS mux2 format', 6246 sts_precision= Float32,6217 sts_precision=num.Float32, 6247 6218 verbose=False): 6248 6219 """ … … 6267 6238 # This is being used to seperate one number from a list. 6268 6239 # 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: 6270 6241 number_of_times = len(times) 6271 6242 times = ensure_numeric(times) … … 6287 6258 6288 6259 # Variable definitions 6289 outfile.createVariable('permutation', Int, ('number_of_points',))6260 outfile.createVariable('permutation', num.Int, ('number_of_points',)) 6290 6261 outfile.createVariable('x', sts_precision, ('number_of_points',)) 6291 6262 outfile.createVariable('y', sts_precision, ('number_of_points',)) … … 6302 6273 6303 6274 # 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',)) 6305 6276 6306 6277 for q in Write_sts.sts_quantities: … … 6314 6285 outfile.variables[q + Write_sts.RANGE][1] = -max_float # Max 6315 6286 6316 if type(times) is list or type(times) is ArrayType:6287 if type(times) is list or type(times) is num.ArrayType: 6317 6288 outfile.variables['time'][:] = times #Store time relative 6318 6289 … … 6365 6336 6366 6337 number_of_points = len(points_utm) 6367 points_utm = array(points_utm)6338 points_utm = num.array(points_utm) 6368 6339 6369 6340 # given the two geo_refs and the points, do the stuff … … 6423 6394 # @param verboseTrue if this function is to be verbose. 6424 6395 # @param **quant Extra keyword args. 6425 def store_quantities(self, outfile, sts_precision= Float32,6396 def store_quantities(self, outfile, sts_precision=num.Float32, 6426 6397 slice_index=None, time=None, 6427 6398 verbose=False, **quant): … … 6514 6485 lonlatdep = p_array.array('f') 6515 6486 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)) 6518 6489 self.lonlatdep = lonlatdep 6519 6490 … … 6550 6521 hz_p_array = p_array.array('f') 6551 6522 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) 6553 6524 self.iter_time_step += 1 6554 6525 … … 6695 6666 # array to store data, number in there is to allow float... 6696 6667 # 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))) 6699 6670 6700 6671 array_number = 0 … … 6853 6824 from Scientific.IO.NetCDF import NetCDFFile 6854 6825 from shallow_water import Domain 6855 from Numeric import asarray, transpose, resize6856 6826 from anuga.abstract_2d_finite_volumes.neighbour_mesh import Mesh 6857 6827 … … 6871 6841 6872 6842 # 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) 6874 6844 triangles = fid.variables['volumes'][:] 6875 6845 … … 7294 7264 7295 7265 # 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) 7298 7268 7299 7269 # Here's where one could convert nodal information to centroid … … 7312 7282 # and call it here 7313 7283 7314 points = concatenate((x[:,NewAxis], y[:,NewAxis]), axis=1)7284 points = num.concatenate((x[:,num.NewAxis], y[:,num.NewAxis]), axis=1) 7315 7285 7316 7286 point_indices = inside_polygon(points, polygon) 7317 7287 7318 7288 # 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) 7321 7291 7322 7292 # Get info for location of maximal runup 7323 points_in_polygon = take(points, point_indices)7293 points_in_polygon = num.take(points, point_indices) 7324 7294 x = points_in_polygon[:,0] 7325 7295 y = points_in_polygon[:,1] 7326 7296 else: 7327 7297 # Take all points 7328 point_indices = arange(len(x))7298 point_indices = num.arange(len(x)) 7329 7299 7330 7300 # Temporal restriction 7331 7301 time = fid.variables['time'][:] 7332 all_timeindices = arange(len(time))7302 all_timeindices = num.arange(len(time)) 7333 7303 if time_interval is not None: 7334 7304 msg = 'time_interval must be a sequence of length 2.' … … 7343 7313 7344 7314 # Take time indices corresponding to interval (& is bitwise AND) 7345 timesteps = compress((time_interval[0] <= time) \7315 timesteps = num.compress((time_interval[0] <= time) \ 7346 7316 & (time <= time_interval[1]), 7347 all_timeindices)7317 all_timeindices) 7348 7318 7349 7319 msg = 'time_interval %s did not include any model timesteps.' \ 7350 7320 % time_interval 7351 assert not alltrue(timesteps == 0), msg7321 assert not num.alltrue(timesteps == 0), msg 7352 7322 else: 7353 7323 # Take them all … … 7372 7342 # Get wet nodes i.e. nodes with depth>0 within given region 7373 7343 # 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): 7378 7348 runup = None 7379 7349 else: 7380 7350 # 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) 7383 7353 runup = max(wet_elevation) 7384 7354 assert wet_elevation[runup_index] == runup # Must be True … … 7388 7358 7389 7359 # 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) 7392 7362 maximal_runup_location = [wet_x[runup_index],wet_y[runup_index]] 7393 7363
Note: See TracChangeset
for help on using the changeset viewer.