Changeset 4304


Ignore:
Timestamp:
Mar 15, 2007, 4:48:11 PM (18 years ago)
Author:
nick
Message:

added get_data_from_file()

File:
1 edited

Legend:

Unmodified
Added
Removed
  • anuga_core/source/anuga/abstract_2d_finite_volumes/util.py

    r4278 r4304  
    504504##################### end of obsolete stuff ? ############
    505505
    506 def start_screen_catcher(dir_name, myid=0, numprocs=1, print_to_screen=False,
    507                           verbose=False):
    508     """Used to store screen output and errors to file, if run on multiple
     506def start_screen_catcher(dir_name, myid='', numprocs='', extra_info='',
     507                         print_to_screen=False, verbose=False):
     508    """
     509    Used to store screen output and errors to file, if run on multiple
    509510    processes eachprocessor will have its own output and error file.
     511   
     512    extra_info - is used as a string that can identify outputs with another
     513    string eg. '_other'
    510514    """
    511515
     
    515519        if verbose: print "myid", myid
    516520        mkdir (dir_name,0777)
    517     screen_output_name = dir_name + "screen_output_%d_%d.txt" %(myid,numprocs)
    518     screen_error_name = dir_name + "screen_error_%d_%d.txt" %(myid,numprocs)
     521    if myid <>'':
     522        myid = '_'+str(myid)
     523    if numprocs <>'':
     524        numprocs = '_'+str(numprocs)
     525    if extra_info <>'':
     526        extra_info = '_'+str(extra_info)
     527    screen_output_name = dir_name + "screen_output%s%s%s.txt" %(myid,numprocs,extra_info)
     528    screen_error_name = dir_name + "screen_error%s%s%s.txt" %(myid,numprocs,extra_info)
    519529    print screen_output_name
    520530    #used to catch screen output to file
     
    667677                   time_max = None,
    668678                   title_on = None,
     679                   use_cache = False,
    669680                   verbose = False):
    670681   
     
    689700                          such as a geospatial data object
    690701                     
     702    production_dirs -  A list of list, example {20061101_121212: '1 in 10000',
     703                                                'boundaries': 'urs boundary'}
     704                      this will use the second part as the label and the first part
     705                      as the ?
     706                     
    691707    report          - if True, then write figures to report_figures directory in
    692708                      relevant production directory
     
    744760    ['stage', 'elevation', 'xmomentum', 'ymomentum']
    745761    If this has not occurred then sww2timeseries will not work.
    746                      
    747762    """
    748763
     
    759774                        time_max,
    760775                        title_on,
     776                        use_cache,
    761777                        verbose)
    762778
     
    774790                    time_max = None,
    775791                    title_on = None,
     792                    use_cache = False,
    776793                    verbose = False):   
    777794       
     
    827844                          interpolation_points = gauges,
    828845                          verbose = True,
    829                           use_cache = True)
     846                          use_cache = use_cache)
    830847
    831848        # determine which gauges are contained in sww file
     
    10541071            thisfile = file_loc[j]+sep+'gauges_time_series'+'_'+gaugeloc+'.csv'
    10551072            fid_out = open(thisfile, 'w')
    1056             s = 'Time, Stage, Momentum, Speed, Elevation \n'
     1073            s = 'Time, Stage, Momentum, Speed, Elevation, xmom, ymom \n'
    10571074            fid_out.write(s)
    10581075           
     
    10821099                    thisgauge = gauges[k]
    10831100                    eastings[i,k,j] = thisgauge[0]
    1084                     s = '%.2f, %.2f, %.2f, %.2f, %.2f\n' %(t, w, m, vel, z)
     1101                    s = '%.2f, %.2f, %.2f, %.2f, %.2f, %.2f, %.2f\n' %(t, w, m, vel, z, uh, vh)
    10851102                    fid_out.write(s)
    10861103                    if t/60.0 <= 13920: tindex = i
     
    13681385    return dir
    13691386
    1370 
    1371 
     1387def get_data_from_file(filename):
     1388    """ Read in data information from file
     1389    WARNING THERE IS NO UNIT TEST FOR THIS!
     1390    or the get_gauges_from_file()
     1391    """
     1392    from os import sep, getcwd, access, F_OK, mkdir
     1393    fid = open(filename)
     1394    lines = fid.readlines()
     1395    fid.close()
     1396   
     1397#    seperated_value = ','
     1398   
     1399    time = []
     1400    speed = []
     1401    stage = []
     1402    momentum = []
     1403    elevation = []
     1404    line1 = lines[0]
     1405    line11 = line1.split(',')
     1406#    east_index = len(line11)+1
     1407#    north_index = len(line11)+1
     1408#    name_index = len(line11)+1
     1409#    elev_index = len(line11)+1
     1410#    Time     Stage     Momentum     Speed     Elevation
     1411   
     1412    #read header to find the position (index) of each column of data
     1413    for i in range(len(line11)):
     1414        if line11[i].strip('\n').strip(' ').lower() == 'time':
     1415            time_index = i
     1416            print'time index', time_index
     1417        if line11[i].strip('\n').strip(' ').lower() == 'stage': stage_index = i
     1418        if line11[i].strip('\n').strip(' ').lower() == 'momentum': momentum_index = i
     1419        if line11[i].strip('\n').strip(' ').lower() == 'speed': speed_index = i
     1420        if line11[i].strip('\n').strip(' ').lower() == 'elevation': elevation_index = i
     1421        print'i',i
     1422    print'time',time_index,'stage',stage_index,'elevation',elevation_index
     1423   
     1424
     1425    for line in lines[1:]:
     1426        fields = line.split(',')
     1427        if elevation_index < len(line11): elevation.append(float(fields[elevation_index]))
     1428        if time_index < len(line11): time.append(float(fields[time_index]))
     1429        if momentum_index < len(line11): momentum.append(float(fields[momentum_index]))
     1430        if speed_index < len(line11): speed.append(float(fields[speed_index]))
     1431        if stage_index < len(line11): stage.append(float(fields[stage_index]))
     1432       
     1433       
     1434    '''       
     1435        if east_index < len(line11) and north_index < len(line11):
     1436            gauges.append([float(fields[east_index]), float(fields[north_index])])
     1437        else:
     1438            msg = 'WARNING: %s does not contain location information' %(filename)
     1439            raise Exception, msg
     1440        if elev_index < len(line11): elev.append(float(fields[elev_index]))
     1441        if name_index < len(line11):
     1442            loc = fields[name_index]
     1443            gaugelocation.append(loc.strip('\n'))
     1444    '''
     1445    return time, stage, momentum, speed, elevation
     1446
     1447
     1448
Note: See TracChangeset for help on using the changeset viewer.