Ignore:
Timestamp:
Apr 12, 2012, 9:00:47 PM (13 years ago)
Author:
davies
Message:

balanced_dev: Discouraging use of balanced_basic, and updates to
util.py, and experimental boundary conditions

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/anuga_work/development/gareth/tests/util.py

    r8385 r8396  
    1313                       transect (e.g. a channel cross-section) -- see example below
    1414
    15 
     15    util.sort_sww_filenames -- match sww filenames by a wildcard, and order
     16                               them according to their 'time'. This means that
     17                               they can be stuck together using 'combine_outputs' correctly
     18 
    1619
    1720    Here is an example ipython session which uses some of these functions:
     
    2427    > pyplot.ion() # Interactive plotting
    2528    > pyplot.scatter(xxx[1],p.vel[140,xxx[0]],color='red') # Plot along the transect
     29
     30    FIXME: TODO -- Convert to a single function 'get_output', which can either take a
     31          single filename, a list of filenames, or a wildcard defining a number of
     32          filenames, and ensure that in each case, the output will be as desired.
    2633
    2734"""
     
    8087                p1.yvel, p1.vel, p1.minimum_allowed_height
    8188
    82 
     89####################
     90
     91def sort_sww_filenames(sww_wildcard):
     92    # Function to take a 'wildcard' sww filename,
     93    # and return a list of all filenames of this type,
     94    # sorted by their time.
     95    # This can then be used efficiently in 'combine_outputs'
     96    # if you have many filenames starting with the same pattern
     97    import glob
     98    filenames=glob.glob(sww_wildcard)
     99   
     100    # Extract time from filenames
     101    file_time=range(len(filenames)) # Predefine
     102     
     103    for i,filename in enumerate(filenames):
     104        filesplit=filename.rsplit('_time_')
     105        if(len(filesplit)>1):
     106            file_time[i]=int(filesplit[1].split('_0.sww')[0])
     107        else:
     108            file_time[i]=0         
     109   
     110    name_and_time=zip(file_time,filenames)
     111    name_and_time.sort() # Sort by file_time
     112   
     113    output_times, output_names = zip(*name_and_time)
     114   
     115    return list(output_names)
     116
     117##############
    83118
    84119class get_output:
Note: See TracChangeset for help on using the changeset viewer.