Changeset 1835
- Timestamp:
- Sep 15, 2005, 5:32:31 PM (18 years ago)
- Location:
- inundation
- Files:
-
- 10 edited
Legend:
- Unmodified
- Added
- Removed
-
inundation/pyvolution/data_manager.py
r1833 r1835 2014 2014 2015 2015 2016 def timefile2 swww(filename, quantity_names = None):2016 def timefile2netcdf(filename, quantity_names = None): 2017 2017 """Template for converting typical text files with time series to 2018 NetCDF swwfile.2018 NetCDF tms file. 2019 2019 2020 2020 … … 2097 2097 2098 2098 2099 #Create swwfile2099 #Create NetCDF file 2100 2100 from Scientific.IO.NetCDF import NetCDFFile 2101 2101 2102 2103 2104 fid = NetCDFFile(filename + '.sww', 'w') 2102 fid = NetCDFFile(filename + '.tms', 'w') 2105 2103 2106 2104 … … 2121 2119 2122 2120 fid.createDimension('number_of_timesteps', len(T)) 2123 2124 #if geo_reference is not None:2125 # geo_reference.write_NetCDF(fid)2126 2127 2121 2128 2122 fid.createVariable('time', Float, ('number_of_timesteps',)) … … 2419 2413 2420 2414 2415 2416 2417 2418 2419 2420 2421 2422 ############################################### 2421 2423 #OBSOLETE STUFF 2422 2424 #Native checkpoint format. … … 2470 2472 """Writes x,y,z,z,z coordinates of triangles constituting the bed 2471 2473 elevation. 2472 Not in use pt2474 FIXME: Not in use pt 2473 2475 """ 2474 2476 2475 2477 M, N = v0.shape 2478 2476 2479 2477 2480 print X0 … … 2900 2903 if verbose: print 'Writing %s' %ersfile 2901 2904 ermapper_grids.write_ermapper_grid(ersfile,grid_values, header) 2905 2906 fid.close() 2902 2907 2903 2908 ## ascid = open(ascfile, 'w') -
inundation/pyvolution/domain.py
r1830 r1835 345 345 msg = '' 346 346 if self.min_timestep == self.max_timestep: 347 msg += 'Time = %.4f, delta t = %.8f, steps=%d (%d) \n'\347 msg += 'Time = %.4f, delta t = %.8f, steps=%d (%d)'\ 348 348 %(self.time, self.min_timestep, self.number_of_steps, 349 349 self.number_of_first_order_steps) 350 350 elif self.min_timestep > self.max_timestep: 351 msg += 'Time = %.4f, steps=%d (%d) \n'\351 msg += 'Time = %.4f, steps=%d (%d)'\ 352 352 %(self.time, self.number_of_steps, 353 353 self.number_of_first_order_steps) 354 354 else: 355 msg += 'Time = %.4f, delta t in [%.8f, %.8f], steps=%d (%d) \n'\355 msg += 'Time = %.4f, delta t in [%.8f, %.8f], steps=%d (%d)'\ 356 356 %(self.time, self.min_timestep, 357 357 self.max_timestep, self.number_of_steps, -
inundation/pyvolution/ermapper_grids.py
r1833 r1835 127 127 # Write the registration coordinate information 128 128 fid.write('\t\tRegistrationCoord Begin\n') 129 print X_Class129 ###print X_Class 130 130 fid.write('\t\t\t' + X_Class + '\t\t\t = ' + header[X_Class.lower()] + '\n') 131 131 fid.write('\t\t\t' + Y_Class + '\t\t\t = ' + header[Y_Class.lower()] + '\n') -
inundation/pyvolution/test_data_manager.py
r1833 r1835 1735 1735 1736 1736 1737 1737 #FIXME This fails - smooth makes the comparism too hard for allclose 1738 1738 def ztest_sww2domain3(self): 1739 1739 ################################################ … … 2181 2181 2182 2182 fid.close() 2183 print fid2183 2184 2184 #Cleanup 2185 2185 #FIXME the file clean-up doesn't work (eg Permission Denied Error) 2186 #os.remove(sww.filename) 2187 2188 def testz_sww2ers_real(self): 2186 #Done - it was because sww2ers didn't close it's sww file 2187 os.remove(sww.filename) 2188 2189 2190 def xxxtestz_sww2ers_real(self): 2189 2191 """Test that sww information can be converted correctly to asc/prj 2190 2192 format readable by e.g. ArcView … … 2209 2211 #------------------------------------------------------------- 2210 2212 if __name__ == "__main__": 2211 suite = unittest.makeSuite(Test_Data_Manager,'test z')2213 suite = unittest.makeSuite(Test_Data_Manager,'test') 2212 2214 #suite = unittest.makeSuite(Test_Data_Manager,'test_dem2pts_bounding_box') 2213 2215 #suite = unittest.makeSuite(Test_Data_Manager,'test_decimate_dem') -
inundation/pyvolution/test_generic_boundary_conditions.py
r1671 r1835 103 103 def test_fileboundary_time_only(self): 104 104 """Test that boundary values can be read from file and interpolated 105 This is using the .tms file format 105 106 """ 106 107 … … 151 152 #Convert ASCII file to NetCDF (Which is what we really like!) 152 153 153 from data_manager import timefile2 swww154 timefile2 swww(filename, quantity_names = ['stage', 'ymomentum'])155 156 157 158 F = File_boundary(filename + '. sww', domain)154 from data_manager import timefile2netcdf 155 timefile2netcdf(filename, quantity_names = ['stage', 'ymomentum']) 156 157 158 159 F = File_boundary(filename + '.tms', domain) 159 160 160 161 161 162 os.remove(filename + '.txt') 162 os.remove(filename + '. sww')163 os.remove(filename + '.tms') 163 164 164 165 … … 243 244 244 245 #Convert ASCII file to NetCDF (Which is what we really like!) 245 from data_manager import timefile2 swww246 timefile2 swww(filename, quantity_names = ['stage', 'xmomentum'])247 248 249 try: 250 F = File_boundary(filename + '. sww', domain)246 from data_manager import timefile2netcdf 247 timefile2netcdf(filename, quantity_names = ['stage', 'xmomentum']) 248 249 250 try: 251 F = File_boundary(filename + '.tms', domain) 251 252 except: 252 253 pass … … 255 256 256 257 os.remove(filename + '.txt') 257 os.remove(filename + '. sww')258 os.remove(filename + '.tms') 258 259 259 260 -
inundation/pyvolution/test_shallow_water.py
r1753 r1835 1011 1011 1012 1012 #Convert ASCII file to NetCDF (Which is what we really like!) 1013 from data_manager import timefile2 swww1014 timefile2 swww(filename)1013 from data_manager import timefile2netcdf 1014 timefile2netcdf(filename) 1015 1015 1016 1016 1017 1017 1018 1018 #Setup wind stress 1019 F = file_function(filename + '. sww', quantities = ['Attribute0',1019 F = file_function(filename + '.tms', quantities = ['Attribute0', 1020 1020 'Attribute1']) 1021 1021 -
inundation/pyvolution/test_util.py
r1828 r1835 8 8 from util import * 9 9 from config import epsilon 10 from data_manager import timefile2 swww10 from data_manager import timefile2netcdf 11 11 12 12 … … 246 246 247 247 #Convert ASCII file to NetCDF (Which is what we really like!) 248 timefile2swww(filename) 249 250 251 #Create file function 252 F = file_function(filename + '.sww', quantities = ['Attribute0', 253 'Attribute1', 254 'Attribute2']) 248 timefile2netcdf(filename) 249 250 251 #Create file function from time series 252 F = file_function(filename + '.tms', 253 quantities = ['Attribute0', 254 'Attribute1', 255 'Attribute2']) 255 256 256 257 #Now try interpolation … … 279 280 280 281 os.remove(filename + '.txt') 281 os.remove(filename + '. sww')282 os.remove(filename + '.tms') 282 283 283 284 … … 670 671 671 672 #Convert ASCII file to NetCDF (Which is what we really like!) 672 timefile2 swww(filename)673 timefile2netcdf(filename) 673 674 674 675 … … 683 684 684 685 #Check that domain.starttime is updated if non-existing 685 F = file_function(filename + '. sww', domain)686 F = file_function(filename + '.tms', domain) 686 687 687 688 assert allclose(domain.starttime, start) … … 689 690 #Check that domain.starttime is updated if too early 690 691 domain.starttime = start - 1 691 F = file_function(filename + '. sww', domain)692 F = file_function(filename + '.tms', domain) 692 693 assert allclose(domain.starttime, start) 693 694 694 695 #Check that domain.starttime isn't updated if later 695 696 domain.starttime = start + 1 696 F = file_function(filename + '. sww', domain)697 F = file_function(filename + '.tms', domain) 697 698 assert allclose(domain.starttime, start+1) 698 699 699 700 domain.starttime = start 700 F = file_function(filename + '. sww', domain,701 F = file_function(filename + '.tms', domain, 701 702 quantities = ['Attribute0', 'Attribute1', 'Attribute2']) 702 703 … … 730 731 assert allclose( 2*sin(120*pi/600)/3 + sin(60*pi/600)/3, q[2] ) 731 732 732 os.remove(filename + '. sww')733 os.remove(filename + '.tms') 733 734 os.remove(filename + '.txt') 734 735 … … 761 762 762 763 #Convert ASCII file to NetCDF (Which is what we really like!) 763 timefile2 swww(filename)764 timefile2netcdf(filename) 764 765 765 766 a = [0.0, 0.0] … … 775 776 delta = 23 776 777 domain.starttime = start + delta 777 #F = file_function(filename + '.sww', domain) 778 F = file_function(filename + '.sww', domain, 778 F = file_function(filename + '.tms', domain, 779 779 quantities = ['Attribute0', 'Attribute1', 'Attribute2']) 780 780 assert allclose(domain.starttime, start+delta) … … 808 808 809 809 810 os.remove(filename + '. sww')810 os.remove(filename + '.tms') 811 811 os.remove(filename + '.txt') 812 812 -
inundation/pyvolution/util.py
r1819 r1835 137 137 quantities = None, 138 138 interpolation_points = None, verbose = False): 139 """If quantities is not specified, derive them from domain 140 (if that is specified) 141 142 143 see get_netcdf_file_function 144 """ 145 139 """Read time history of spatial data from NetCDF file and return 140 a callable object. 141 142 If the file has extension 'sww' then it is assumed to be spatio-temporal 143 or temporal and the callable object will have the form f(t,x,y) or f(t) 144 depending on whether the file contains spatial data 145 146 If the file has extension 'tms' then it is assumed to be temporal only 147 and the callable object will have the form f(t) 148 149 Either form will return interpolated values based on the input file 150 using the underlying interpolation_function. 151 152 If domain is specified, model time (domain.starttime) 153 will be checked and possibly modified. 154 155 All times are assumed to be in UTC 156 157 All spatial information is assumed to be in UTM coordinates. 158 159 See Interpolation function for further documentation 160 """ 161 146 162 147 163 #FIXME (OLE): Should check origin of domain against that of file … … 230 246 #are present in file 231 247 missing = [] 232 for quantity in ['time'] + quantity_names: #FIXME: Add x, y back248 for quantity in ['time'] + quantity_names: 233 249 if not fid.variables.has_key(quantity): 234 250 missing.append(quantity) … … 241 257 242 258 #Decide whether this data has a spatial dimension 243 #FIXME: Let us split this up into two functions: One that reads244 #sww and one that reads tms (time series only)245 #Definitely! (Ole 25 August 2005)246 259 spatial = True 247 260 for quantity in ['x', 'y']: … … 249 262 spatial = False 250 263 251 264 if filename[-3:] == 'tms' and spatial is True: 265 msg = 'Files of type tms must not contain spatial information' 266 raise msg 267 268 if filename[-3:] == 'sww' and spatial is False: 269 msg = 'Files of type sww must contain spatial information' 270 raise msg 252 271 253 272 #Get first timestep -
inundation/validation/Completed/LWRU2/extract_timeseries.py
r1742 r1835 1 """Read in swwfile, interpolate at specified locations (ch 5,7,9) and compare1 """Read in tms file, interpolate at specified locations (ch 5,7,9) and compare 2 2 """ 3 3 … … 19 19 20 20 #Input wave 21 filename = 'Benchmark_2_input. sww'21 filename = 'Benchmark_2_input.tms' 22 22 print 'Reading', filename 23 23 from Scientific.IO.NetCDF import NetCDFFile -
inundation/validation/Completed/LWRU2/lwru2.py
r1817 r1835 15 15 16 16 17 18 17 import sys 19 18 from os import sep … … 21 20 22 21 def prepare_timeboundary(filename): 23 """Converting benchmark 2 time series to NetCDF sww file. 22 """Converting benchmark 2 time series to NetCDF tms file. 23 This is a 'throw-away' code taylor made for files like 24 'Benchmark_2_input.txt' from the LWRU2 benchmark 24 25 """ 25 26 26 27 27 print 'Preparing time boundary from %s' %filename … … 33 33 line = fid.readline() 34 34 35 #Read remaining lines 35 36 lines = fid.readlines() 36 37 fid.close() 37 38 39 38 40 N = len(lines) 39 40 41 T = zeros(N, Float) #Time 41 42 Q = zeros(N, Float) #Values … … 47 48 Q[i] = float(fields[1]) 48 49 49 #Create sww file 50 51 #Create tms file 50 52 from Scientific.IO.NetCDF import NetCDFFile 51 53 52 outfile = filename[:-4] + '. sww'54 outfile = filename[:-4] + '.tms' 53 55 print 'Writing to', outfile 54 56 fid = NetCDFFile(outfile, 'w') … … 91 93 92 94 95 93 96 ####################### 94 # Domain97 # Create Domain 95 98 if use_variable_mesh is True: 96 99 print 'Creating domain from', project.mesh_filename … … 99 102 (project.mesh_filename, Domain), 100 103 dependencies = [project.mesh_filename]) 101 102 103 104 104 105 else: … … 114 115 115 116 116 print "Number of triangles = ", len(domain) 117 import sys, os 118 base = os.path.basename(sys.argv[0]) 119 domain.filename, _ = os.path.splitext(base) 120 domain.default_order = 2 121 domain.store = True #Store for visualisation purposes 122 123 domain.check_integrity() 124 print 'Number of triangles = ', len(domain) 117 125 print 'The extent is ', domain.get_extent() 118 126 119 127 120 #domain.check_integrity()121 domain.default_order = 2122 128 123 print "Number of triangles = ", len(domain) 124 domain.store = True #Store for visualisation purposes 125 126 import sys, os 127 base = os.path.basename(sys.argv[0]) 128 domain.filename, _ = os.path.splitext(base) 129 129 ####################### 130 # Initial Conditions 130 131 print 'Initial values' 131 132 … … 142 143 143 144 ###################### 144 # Boundary conditions145 # Boundary Conditions 145 146 # 146 147 print 'Boundaries' … … 148 149 149 150 from pyvolution.util import file_function 150 function = file_function(project.boundary_filename[:-4] + '.sww', domain, 151 function = file_function(project.boundary_filename[:-4] + '.tms', 152 domain, 151 153 verbose = True) 152 154 Bts = Transmissive_Momentum_Set_Stage_boundary(domain, function) … … 159 161 160 162 161 #Evolve 163 164 ####################### 165 # Evolve 162 166 import time 163 167 t0 = time.time()
Note: See TracChangeset
for help on using the changeset viewer.