Changeset 8396 for trunk/anuga_work/development/gareth/tests/util.py
- Timestamp:
- Apr 12, 2012, 9:00:47 PM (13 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/anuga_work/development/gareth/tests/util.py
r8385 r8396 13 13 transect (e.g. a channel cross-section) -- see example below 14 14 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 16 19 17 20 Here is an example ipython session which uses some of these functions: … … 24 27 > pyplot.ion() # Interactive plotting 25 28 > 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. 26 33 27 34 """ … … 80 87 p1.yvel, p1.vel, p1.minimum_allowed_height 81 88 82 89 #################### 90 91 def 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 ############## 83 118 84 119 class get_output:
Note: See TracChangeset
for help on using the changeset viewer.