Ignore:
Timestamp:
Aug 1, 2008, 1:35:21 PM (16 years ago)
Author:
ole
Message:

Work on urs2sts tests

File:
1 edited

Legend:

Unmodified
Added
Removed
  • anuga_core/source/anuga/shallow_water/test_data_manager.py

    r5589 r5593  
    65516551       
    65526552        ordering_filename='thinned_bound_order_test.txt'
    6553         dir = 'urs_test_data'
     6553        testdir = 'urs_test_data'
    65546554        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)
    65616569            weights = [1.]
    65626570            sts_name_out = 'test'
     
    65696577                    verbose=False)
    65706578
    6571             # read in sts file for first source
    6572             fid = NetCDFFile(sts_name_out+'.sts', 'r')    #Open existing file for read
    6573             x = fid.variables['x'][:]+fid.xllcorner   #x-coordinates of vertices
    6574             y = fid.variables['y'][:]+fid.yllcorner   #y-coordinates of vertices
     6579            # 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
    65756583            points=transpose(asarray([x.tolist(),y.tolist()]))
    65766584            time=fid.variables['time'][:]+fid.starttime
    65776585
    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
    65816588            quantity_names=['stage','xmomentum','ymomentum']
    65826589            quantities = {}
     
    65846591                quantities[name] = fid.variables[name][:]
    65856592
    6586             # for each station, compare urs2sts output to known urs output
     6593            # For each station, compare urs2sts output to known urs output
    65876594           
    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                           
    65926605            delta_t = 0.1
    65936606            #time_start_e = time_start_z
     
    66016614                count = 0
    66026615                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))
    66046617                urs_stage = dict['urs_stage']
    66056618                for i in range(len(urs_stage)):
     
    66136626
    66146627                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)
    66176632                assert allclose(index_start_urs,start_times[j]/delta_t), msg
    66186633
     
    66336648                # check that the lengths of urs stage and sts stage are the same
    66346649                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
    66366652
    66376653                #print urs_stage[index_start_urs:index_end_urs]
    66386654                #print sts_stage[index_start:index_end]
     6655               
    66396656                # check that urs stage and sts stage are the same
    66406657                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, msg
    6644                 assert abs(min_error) < 1.e5, msg
     6658                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                               
    66456662               
     6663                # Now check momentum (when csv files have been checked in)
     6664                sts_xmomentum = quantities['xmomentum'][:,j]                               
     6665                               
     6666                               
     6667                               
    66466668            fid.close()
    6647 
    6648         #from os import sys
    6649         #sys.exit()
     6669           
    66506670        os.remove(sts_name_out+'.sts')
    66516671
     
    66616681        weights = [1., 2., 3.]
    66626682        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')]
    66656687        sts_name_out = 'test'
    66666688       
     
    66886710       
    66896711        os.remove(sts_name_out+'.sts')
     6712       
     6713       
    66906714       
    66916715    def test_urs2sts_ordering(self):
Note: See TracChangeset for help on using the changeset viewer.