Changeset 3826
- Timestamp:
- Oct 19, 2006, 5:34:56 PM (18 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
anuga_core/source/anuga/shallow_water/data_manager.py
r3824 r3826 4230 4230 (points_num,)= unpack('i',f.read(4)) 4231 4231 4232 #print 'points_num', points_num 4233 #import sys; sys.exit() 4232 4234 # nt, int - Number of time steps 4233 4235 (time_step_count,)= unpack('i',f.read(4)) … … 4248 4250 4249 4251 lonlatdep = p_array.array('f') 4252 points_num = 2914 4250 4253 lonlatdep.read(f, columns * points_num) 4251 4254 lonlatdep = array(lonlatdep, typecode=Float) 4252 lonlatdep = reshape(lonlatdep, ( 4255 lonlatdep = reshape(lonlatdep, (points_num, columns)) 4253 4256 4254 4257 #print "lonlatdep", lonlatdep … … 4258 4261 lon_sorted.sort() 4259 4262 4260 if not lon == lon_sorted: 4263 # if not lon == lon_sorted: 4264 if not allclose(lon, lon_sorted): 4261 4265 msg = "Longitudes in mux file are not in ascending order" 4262 4266 raise IOError, msg 4263 4267 lat_sorted = lat[:] 4264 4268 lat_sorted.sort() 4265 if not lat == lat_sorted: 4269 # if not lat == lat_sorted: 4270 if not allclose(lat, lat_sorted): 4266 4271 msg = "Latitudes in mux file are not in ascending order" 4267 4272 4268 4273 nc_file = Write_nc(quantity, 4269 4274 file_out, 4270 4271 4272 4273 4275 time_step_count, 4276 time_step, 4277 lon, 4278 lat) 4274 4279 4275 4280 for i in range(time_step_count): … … 4348 4353 LAT = 1 4349 4354 QUANTITY = 2 4350 points_num = len(long_lat_dep)4351 lat = [long_lat_dep[0][LAT]]4352 this_rows_long = long_lat_dep[0][LONG]4353 i = 1 # Index of long_lat_dep4354 4355 4355 #Working out the lat's 4356 while long_lat_dep[i][LONG] == this_rows_long and i < points_num: 4357 lat.append(long_lat_dep[i][LAT]) 4358 i += 1 4359 4360 lats_per_long = i 4361 long = [long_lat_dep[0][LONG]] 4362 #Working out the longs 4363 while i < points_num: 4356 # print 'long_lat_dep', type(long_lat_dep), long_lat_dep.shape 4357 # print 'long_lat_dep', long_lat_dep 4358 4359 num_points = long_lat_dep.shape[0] 4360 this_rows_long = long_lat_dep[0,LONG] 4361 4362 # Count the length of unique latitudes 4363 i = 0 4364 while long_lat_dep[i,LONG] == this_rows_long and i < num_points: 4365 i += 1 4366 4367 lat = long_lat_dep[:i, LAT] 4368 long = long_lat_dep[::i, LONG] 4369 lenlong = len(long) 4370 lenlat = len(lat) 4371 # print 'len lat', lat, len(lat) 4372 # print 'len long', long, len(long) 4373 4374 msg = 'Input data is not gridded' 4375 assert num_points % lenlat == 0, msg 4376 assert num_points % lenlong == 0, msg 4377 4378 # Test that data is gridded 4379 for i in range(lenlong): 4364 4380 msg = 'Data is not gridded. It must be for this operation' 4365 assert long_lat_dep[i][LAT] == lat[i%lats_per_long], msg 4366 if i%lats_per_long == 0: 4367 long.append(long_lat_dep[i][LONG]) 4368 i += 1 4381 first = i*lenlat 4382 last = first + lenlat 4383 4384 assert allclose(long_lat_dep[first:last,LAT], lat), msg 4385 assert allclose(long_lat_dep[first:last,LONG], long[i]), msg 4369 4386 4370 msg = 'Our of range latitudes/longitudes' 4387 4388 # print 'range long', min(long), max(long) 4389 # print 'range lat', min(lat), max(lat) 4390 # print 'ref long', min(long_lat_dep[:,0]), max(long_lat_dep[:,0]) 4391 # print 'ref lat', min(long_lat_dep[:,1]), max(long_lat_dep[:,1]) 4392 4393 4394 4395 msg = 'Out of range latitudes/longitudes' 4371 4396 for l in lat:assert -90 < l < 90 , msg 4372 4397 for l in long:assert -180 < l < 180 , msg 4373 4398 4374 # changing quantity from lat being the fastest varying dimension to4399 # Changing quantity from lat being the fastest varying dimension to 4375 4400 # long being the fastest varying dimension 4376 4401 # FIXME - make this faster/do this a better way 4377 4402 # use numeric transpose, after reshaping the quantity vector 4378 quantity = zeros(len(long_lat_dep), Float) 4379 lenlong = len(long) 4380 lenlat = len(lat) 4403 # quantity = zeros(len(long_lat_dep), Float) 4404 quantity = zeros(num_points, Float) 4405 4406 # print 'num',num_points 4381 4407 for lat_i, _ in enumerate(lat): 4382 4408 for long_i, _ in enumerate(long): 4383 4409 q_index = lat_i*lenlong+long_i 4384 4410 lld_index = long_i*lenlat+lat_i 4385 quantity[q_index] = long_lat_dep[lld_index][QUANTITY] 4411 # print 'lat_i', lat_i, 'long_i',long_i, 'q_index', q_index, 'lld_index', lld_index 4412 temp = long_lat_dep[lld_index, QUANTITY] 4413 quantity[q_index] = temp 4386 4414 4387 4415 return long, lat, quantity
Note: See TracChangeset
for help on using the changeset viewer.