Changeset 5880
- Timestamp:
- Oct 31, 2008, 1:27:11 PM (16 years ago)
- Location:
- anuga_core/source/anuga/shallow_water
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
anuga_core/source/anuga/shallow_water/data_manager.py
r5865 r5880 4907 4907 4908 4908 numSrc=len(filenames) 4909 4909 4910 4910 file_params=-1*ones(3,Float) #[nsta,dt,nt] 4911 4911 … … 4919 4919 permutation = ensure_numeric([], Float) 4920 4920 4921 #print 'filenames', filenames 4922 #print 'weights', weights 4923 4921 4924 # Call underlying C implementation urs2sts_ext.c 4922 4925 data = read_mux2(numSrc, filenames, weights, file_params, permutation, verbose) … … 4972 4975 quantity=zeros((number_of_selected_stations, parameters_index), Float) 4973 4976 4974 4977 4978 #print 'number_of_selected_stations', number_of_selected_stations 4975 4979 starttime=1e16 4976 4980 for i in range(number_of_selected_stations): 4977 4981 quantity[i][:]=data[i][:parameters_index] 4982 4983 #print i, parameters_index 4984 #print quantity[i][:] 4978 4985 4979 4986 latitudes[i]=data[i][parameters_index] … … 5150 5157 mux={} 5151 5158 for i, quantity in enumerate(quantities): 5159 5160 #print 5161 #print quantity 5152 5162 5153 5163 # For each quantity read the associated list of source mux2 file with -
anuga_core/source/anuga/shallow_water/test_data_manager.py
r5867 r5880 6265 6265 weights=ones(1, Float) 6266 6266 #ensure that files are indeed mux2 files 6267 times, latitudes, longitudes, elevation, stage, starttime=read_mux2_py([files[0]],weights)6268 ua_times, ua_latitudes, ua_longitudes, ua_elevation, xvelocity, starttime_ua=read_mux2_py([files[1]],weights)6267 times, latitudes, longitudes, elevation, stage, starttime=read_mux2_py([files[0]],weights) 6268 ua_times, ua_latitudes, ua_longitudes, ua_elevation, xvelocity, starttime_ua=read_mux2_py([files[1]],weights) 6269 6269 msg='ha and ua have different gauge meta data' 6270 6270 assert allclose(times,ua_times) and allclose(latitudes,ua_latitudes) and allclose(longitudes,ua_longitudes) and allclose(elevation,ua_elevation) and allclose(starttime,starttime_ua), msg … … 6303 6303 msg='incorrect gauge va time series returned' 6304 6304 assert allclose(yvelocity,va) 6305 6306 6307 def test_read_mux_platform_problem(self): 6308 """test_read_mux_platform_problem 6309 6310 This is to test a situation where read_mux returned 6311 wrong values Win32 6312 """ 6313 6314 from Numeric import sin, cos 6315 from urs_ext import read_mux2 6316 6317 verbose = False 6318 6319 tide = 1.5 6320 time_step_count = 10 6321 time_step = 0.2 6322 6323 times_ref = arange(0, time_step_count*time_step, time_step) 6324 #print 'time vector', times_ref 6325 6326 lat_long_points = [(-21.5,114.5), (-21,114.5), (-21.5,115), (-21.,115.), (-22., 117.)] 6327 n = len(lat_long_points) 6328 6329 6330 # Create different timeseries starting and ending at different times 6331 first_tstep=ones(n,Int) 6332 first_tstep[0]+=2 # Point 0 starts at 2 6333 first_tstep[1]+=4 # Point 1 starts at 4 6334 first_tstep[2]+=3 # Point 2 starts at 3 6335 6336 last_tstep=(time_step_count)*ones(n,Int) 6337 last_tstep[0]-=1 # Point 0 ends 1 step early 6338 last_tstep[1]-=2 # Point 1 ends 2 steps early 6339 last_tstep[4]-=3 # Point 4 ends 3 steps early 6340 6341 6342 6343 # Create varying elevation data (positive values for seafloor) 6344 gauge_depth=20*ones(n,Float) 6345 for i in range(n): 6346 gauge_depth[i] += i**2 6347 6348 #print 'gauge_depth', gauge_depth 6349 6350 # Create data to be written to first mux file 6351 ha0=2*ones((n,time_step_count),Float) 6352 ha0[0]=arange(0,time_step_count) 6353 ha0[1]=arange(time_step_count,2*time_step_count) 6354 ha0[2]=arange(2*time_step_count,3*time_step_count) 6355 ha0[3]=arange(3*time_step_count,4*time_step_count) 6356 ua0=5*ones((n,time_step_count),Float) 6357 va0=-10*ones((n,time_step_count),Float) 6358 6359 # Ensure data used to write mux file to be zero when gauges are 6360 # not recording 6361 for i in range(n): 6362 # For each point 6363 6364 for j in range(0, first_tstep[i]-1) + range(last_tstep[i], time_step_count): 6365 # For timesteps before and after recording range 6366 ha0[i][j] = ua0[i][j] = va0[i][j] = 0.0 6367 6368 6369 6370 # Write first mux file to be combined by urs2sts 6371 base_nameI, filesI = self.write_mux2(lat_long_points, 6372 time_step_count, time_step, 6373 first_tstep, last_tstep, 6374 depth=gauge_depth, 6375 ha=ha0, 6376 ua=ua0, 6377 va=va0) 6378 6379 6380 6381 # Create data to be written to second mux file 6382 ha1=ones((n,time_step_count),Float) 6383 ha1[0]=sin(times_ref) 6384 ha1[1]=2*sin(times_ref - 3) 6385 ha1[2]=5*sin(4*times_ref) 6386 ha1[3]=sin(times_ref) 6387 ha1[4]=sin(2*times_ref-0.7) 6388 6389 ua1=zeros((n,time_step_count),Float) 6390 ua1[0]=3*cos(times_ref) 6391 ua1[1]=2*sin(times_ref-0.7) 6392 ua1[2]=arange(3*time_step_count,4*time_step_count) 6393 ua1[4]=2*ones(time_step_count) 6394 6395 va1=zeros((n,time_step_count),Float) 6396 va1[0]=2*cos(times_ref-0.87) 6397 va1[1]=3*ones(time_step_count) 6398 va1[3]=2*sin(times_ref-0.71) 6399 6400 6401 # Ensure data used to write mux file to be zero when gauges are 6402 # not recording 6403 for i in range(n): 6404 # For each point 6405 6406 for j in range(0, first_tstep[i]-1) + range(last_tstep[i], time_step_count): 6407 # For timesteps before and after recording range 6408 ha1[i][j] = ua1[i][j] = va1[i][j] = 0.0 6409 6410 6411 6412 # Write second mux file to be combined by urs2sts 6413 base_nameII, filesII = self.write_mux2(lat_long_points, 6414 time_step_count, time_step, 6415 first_tstep, last_tstep, 6416 depth=gauge_depth, 6417 ha=ha1, 6418 ua=ua1, 6419 va=va1) 6420 6421 6422 # Create ordering file 6423 permutation = ensure_numeric([4,0,2]) 6424 6425 _, ordering_filename = tempfile.mkstemp('') 6426 order_fid = open(ordering_filename, 'w') 6427 order_fid.write('index, longitude, latitude\n') 6428 for index in permutation: 6429 order_fid.write('%d, %f, %f\n' %(index, 6430 lat_long_points[index][1], 6431 lat_long_points[index][0])) 6432 order_fid.close() 6433 6434 6435 6436 # ------------------------------------- 6437 # Now read files back and check values 6438 weights = ensure_numeric([1.0]) 6439 6440 # For each quantity read the associated list of source mux2 file with 6441 # extention associated with that quantity 6442 file_params=-1*ones(3,Float) #[nsta,dt,nt] 6443 OFFSET = 5 6444 6445 # FILE I 6446 for j, file in enumerate(filesI): 6447 data = read_mux2(1, [file], weights, file_params, permutation, verbose) 6448 6449 nsta=int(file_params[0]) 6450 dt=file_params[1] 6451 6452 number_of_selected_stations = data.shape[0] 6453 6454 # Index where data ends and parameters begin 6455 parameters_index = data.shape[1]-OFFSET 6456 6457 times=dt*arange(parameters_index) 6458 latitudes=zeros(number_of_selected_stations, Float) 6459 longitudes=zeros(number_of_selected_stations, Float) 6460 elevation=zeros(number_of_selected_stations, Float) 6461 quantity=zeros((number_of_selected_stations, parameters_index), Float) 6462 6463 starttime=1e16 6464 6465 for i in range(number_of_selected_stations): 6466 quantity[i][:]=data[i][:parameters_index] 6467 6468 #print i, j, parameters_index 6469 #print quantity[i][:] 6470 6471 if j == 0: 6472 # HA 6473 if i == 0: 6474 assert allclose(quantity[i][:], 6475 [2., 2., 2., 2., 2., 2., 2., 0., 0., 0.]) 6476 if i == 1: 6477 assert allclose(quantity[i][:], 6478 [0., 0., 2., 3., 4., 5., 6., 7., 8., 0.]) 6479 if i == 2: 6480 assert allclose(quantity[i][:], 6481 [0., 0., 0., 23., 24., 25., 26., 27., 28., 29.]) 6482 6483 if j == 1: 6484 # UA 6485 if i == 0: 6486 assert allclose(quantity[i][:], 6487 [5., 5., 5., 5., 5., 5., 5., 0., 0., 0.]) 6488 if i == 1: 6489 assert allclose(quantity[i][:], 6490 [0., 0., 5., 5., 5., 5., 5., 5., 5., 0.]) 6491 if i == 2: 6492 assert allclose(quantity[i][:], 6493 [0., 0., 0., 5., 5., 5., 5., 5., 5., 5.]) 6494 if j == 2: 6495 # VA 6496 if i == 0: 6497 assert allclose(quantity[i][:], 6498 [-10., -10., -10., -10., -10., -10., -10., 0., 0., 0.]) 6499 if i == 1: 6500 assert allclose(quantity[i][:], 6501 [0., 0., -10., -10., -10., -10., -10., -10., -10., 0.]) 6502 if i == 2: 6503 assert allclose(quantity[i][:], 6504 [0., 0., 0., -10., -10., -10., -10., -10., -10., -10.]) 6505 6506 6507 # FILE II 6508 for j, file in enumerate(filesII): 6509 data = read_mux2(1, [file], weights, file_params, permutation, verbose) 6510 6511 nsta=int(file_params[0]) 6512 dt=file_params[1] 6513 6514 number_of_selected_stations = data.shape[0] 6515 6516 # Index where data ends and parameters begin 6517 parameters_index = data.shape[1]-OFFSET 6518 6519 times=dt*arange(parameters_index) 6520 latitudes=zeros(number_of_selected_stations, Float) 6521 longitudes=zeros(number_of_selected_stations, Float) 6522 elevation=zeros(number_of_selected_stations, Float) 6523 quantity=zeros((number_of_selected_stations, parameters_index), Float) 6524 6525 starttime=1e16 6526 6527 for i in range(number_of_selected_stations): 6528 quantity[i][:]=data[i][:parameters_index] 6529 6530 #print i, parameters_index 6531 #print quantity[i][:] 6532 6533 6534 if j == 0: 6535 # HA 6536 if i == 0: 6537 assert allclose(quantity[i][:], 6538 [-0.64421767, -0.29552022, 0.09983341, 0.47942555, 6539 0.78332692, 0.9635582, 0.99166483, 0., 0., 0.]) 6540 if i == 1: 6541 assert allclose(quantity[i][:], 6542 [0., 0., 0.38941833, 0.56464249, 0.71735609, 0.84147096, 6543 0.93203908, 0.98544973, 0.99957359, 0.]) 6544 if i == 2: 6545 assert allclose(quantity[i][:], 6546 [0., 0., 0., 3.377316, -0.29187071, -3.78401256, 6547 -4.98082304, -3.15633321, 0.58274603, 3.9683392]) 6548 6549 6550 if j == 1: 6551 # UA 6552 if i == 0: 6553 assert allclose(quantity[i][:], 6554 [2., 2., 2., 2., 2., 2., 2., 0., 0., 0.]) 6555 if i == 1: 6556 assert allclose(quantity[i][:], 6557 [0., 0., 2.76318288, 2.47600675, 2.09012008, 1.62090695, 6558 1.08707321, 0.5099014, -0.08759857, 0.]) 6559 if i == 2: 6560 assert allclose(quantity[i][:], 6561 [0., 0., 0., 33., 34., 35., 36., 37., 38., 39.]) 6562 6563 if j == 2: 6564 # VA 6565 if i == 0: 6566 assert allclose(quantity[i][:], 6567 [0., 0., 0., 0., 0., 0., 0., 0., 0., 0.]) 6568 if i == 1: 6569 assert allclose(quantity[i][:], 6570 [0., 0., 1.78313661, 1.92754185, 1.99510205, 1.98312378, 6571 1.89208472, 1.72561419, 1.49034882, 0.]) 6572 if i == 2: 6573 assert allclose(quantity[i][:], 6574 [0., 0., 0., 0., 0., 0., 0., 0., 0., 0.]) 6575 6576 6577 6305 6578 6306 6579 def test_urs2sts0(self): … … 7447 7720 sts_file = base_nameI + '.sts' 7448 7721 fid = NetCDFFile(sts_file) 7722 7449 7723 7450 7724 # Check that original indices have been stored … … 7504 7778 va_ref = take(va0, permutation) 7505 7779 7506 gauge_depth_ref = take(gauge_depth, permutation) 7507 7508 7509 #print 7510 #print stage0 7511 #print transpose(ha_ref)+tide - stage0 7512 7780 gauge_depth_ref = take(gauge_depth, permutation) 7513 7781 7514 7782 assert allclose(transpose(ha_ref)+tide, stage0) # Meters 7783 7784 7515 7785 7516 7786 #Check the momentums - ua … … 7561 7831 sts_file = base_nameI + '.sts' 7562 7832 fid = NetCDFFile(sts_file) 7833 7563 7834 7564 7835 # Check that original indices have been stored … … 10661 10932 #suite = unittest.makeSuite(Test_Data_Manager,'covered_') 10662 10933 #suite = unittest.makeSuite(Test_Data_Manager,'test_urs2sts_individual_sources') 10663 #suite = unittest.makeSuite(Test_Data_Manager,'test_urs2sts_ combined_sources')10664 #suite = unittest.makeSuite(Test_Data_Manager,'test_ urs2sts')10934 #suite = unittest.makeSuite(Test_Data_Manager,'test_urs2sts_ordering_different_sources') 10935 #suite = unittest.makeSuite(Test_Data_Manager,'test_read_mux_platform_prob') 10665 10936 10666 10937
Note: See TracChangeset
for help on using the changeset viewer.