- Timestamp:
- Aug 1, 2008, 1:35:21 PM (16 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
anuga_core/source/anuga/shallow_water/test_data_manager.py
r5589 r5593 6551 6551 6552 6552 ordering_filename='thinned_bound_order_test.txt' 6553 dir = 'urs_test_data'6553 testdir = 'urs_test_data' 6554 6554 sources = ['1-z.grd','2-z.grd','3-z.grd'] 6555 source_number = 0 6556 6557 # make sts file for each source 6558 for source in sources: 6559 source_number += 1 6560 urs_filenames = os.path.join(dir,source) 6555 6556 6557 # Start times by source and station taken manually from urs header files 6558 time_start_z = array([[10.0,11.5,13,14.5,17.7], 6559 [9.8,11.2,12.7,14.2,17.4], 6560 [9.5,10.9,12.4,13.9,17.1]]) 6561 6562 6563 6564 # Make sts file for each source 6565 for k, source_filename in enumerate(sources): 6566 source_number = k + 1 # Source numbering starts at 1 6567 6568 urs_filenames = os.path.join(testdir, source_filename) 6561 6569 weights = [1.] 6562 6570 sts_name_out = 'test' … … 6569 6577 verbose=False) 6570 6578 6571 # read in sts file for first source6572 fid = NetCDFFile(sts_name_out+'.sts', 'r') #Open existing file for read6573 x = fid.variables['x'][:]+fid.xllcorner #x-coordinates of vertices6574 y = fid.variables['y'][:]+fid.yllcorner #y-coordinates of vertices6579 # Read in sts file for this source file 6580 fid = NetCDFFile(sts_name_out+'.sts', 'r') # Open existing file for read 6581 x = fid.variables['x'][:]+fid.xllcorner # x-coordinates of vertices 6582 y = fid.variables['y'][:]+fid.yllcorner # y-coordinates of vertices 6575 6583 points=transpose(asarray([x.tolist(),y.tolist()])) 6576 6584 time=fid.variables['time'][:]+fid.starttime 6577 6585 6578 # make sure start time is 9.5 which is the minimum time across all quantities, i.e. starting time 6579 6580 # get quantity data from sts file 6586 6587 # Get quantity data from sts file 6581 6588 quantity_names=['stage','xmomentum','ymomentum'] 6582 6589 quantities = {} … … 6584 6591 quantities[name] = fid.variables[name][:] 6585 6592 6586 # for each station, compare urs2sts output to known urs output6593 # For each station, compare urs2sts output to known urs output 6587 6594 6588 # taken manually from header files from urs output 6589 time_start_z = [[10.0,11.5,13,14.5,17.7], 6590 [9.8,11.2,12.7,14.2,17.4], 6591 [9.5,10.9,12.4,13.9,17.1]] 6595 6596 # Make sure start time from sts file is the minimum starttime 6597 # across all stations (for this source) 6598 #print k, time_start_z[k,:] 6599 starttime = min(time_start_z[k, :]) 6600 msg = 'Starttime for source %d was %f. Should have been %f'\ 6601 %(source_number, fid.starttime, starttime) 6602 assert allclose(fid.starttime, starttime), msg 6603 6604 6592 6605 delta_t = 0.1 6593 6606 #time_start_e = time_start_z … … 6601 6614 count = 0 6602 6615 urs_file_name = 'z_'+str(source_number)+'_'+str(j)+'.csv' 6603 dict = csv2array(os.path.join( dir,urs_file_name))6616 dict = csv2array(os.path.join(testdir, urs_file_name)) 6604 6617 urs_stage = dict['urs_stage'] 6605 6618 for i in range(len(urs_stage)): … … 6613 6626 6614 6627 start_times = time_start_z[source_number-1] 6615 # check that actual start time matches header information 6616 msg = 'start time from urs file is not the same as the header file for source %i and station %i' %(source_number,j) 6628 6629 # Check that actual start time matches header information 6630 msg = 'start time from urs file is not the same as the ' 6631 msg += 'header file for source %i and station %i' %(source_number,j) 6617 6632 assert allclose(index_start_urs,start_times[j]/delta_t), msg 6618 6633 … … 6633 6648 # check that the lengths of urs stage and sts stage are the same 6634 6649 msg = 'Length of urs stage is not equal to the length of sts stage for station %i' %j 6635 assert allclose(len(urs_stage[index_start_urs:index_end_urs]), len(sts_stage[index_start:index_end])), msg 6650 assert allclose(len(urs_stage[index_start_urs:index_end_urs]), 6651 len(sts_stage[index_start:index_end])), msg 6636 6652 6637 6653 #print urs_stage[index_start_urs:index_end_urs] 6638 6654 #print sts_stage[index_start:index_end] 6655 6639 6656 # check that urs stage and sts stage are the same 6640 6657 msg = 'urs stage is not equal to sts stage for station %i' %j 6641 max_error = max(urs_stage[index_start_urs:index_end_urs] - sts_stage[index_start:index_end])6642 min_error = min(urs_stage[index_start_urs:index_end_urs] - sts_stage[index_start:index_end])6643 assert max_error < 1.e-5, msg6644 assert abs(min_error) < 1.e5, msg6658 assert allclose(urs_stage[index_start_urs:index_end_urs], 6659 sts_stage[index_start:index_end], 6660 rtol=1.0e-6, atol=1.0e-5 ), msg 6661 6645 6662 6663 # Now check momentum (when csv files have been checked in) 6664 sts_xmomentum = quantities['xmomentum'][:,j] 6665 6666 6667 6646 6668 fid.close() 6647 6648 #from os import sys 6649 #sys.exit() 6669 6650 6670 os.remove(sts_name_out+'.sts') 6651 6671 … … 6661 6681 weights = [1., 2., 3.] 6662 6682 ordering_filename='thinned_bound_order_test.txt' 6663 dir = 'urs_test_data' 6664 urs_filenames = [os.path.join(dir,'1-z.grd'),os.path.join(dir,'2-z.grd'),os.path.join(dir,'3-z.grd')] 6683 testdir = 'urs_test_data' 6684 urs_filenames = [os.path.join(testdir,'1-z.grd'), 6685 os.path.join(testdir,'2-z.grd'), 6686 os.path.join(testdir,'3-z.grd')] 6665 6687 sts_name_out = 'test' 6666 6688 … … 6688 6710 6689 6711 os.remove(sts_name_out+'.sts') 6712 6713 6690 6714 6691 6715 def test_urs2sts_ordering(self):
Note: See TracChangeset
for help on using the changeset viewer.