Changeset 7770 for trunk/anuga_core/source/anuga/file/sww.py
- Timestamp:
- Jun 2, 2010, 5:17:47 PM (13 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/anuga_core/source/anuga/file/sww.py
r7767 r7770 1196 1196 1197 1197 ## 1198 # @brief Get mesh and quantity data from an SWW file. 1199 # @param filename Path to data file to read. 1200 # @param quantities UNUSED! 1201 # @param verbose True if this function is to be verbose. 1202 # @return (mesh, quantities, time) where mesh is the mesh data, quantities is 1203 # a dictionary of {name: value}, and time is the time vector. 1204 # @note Quantities extracted: 'elevation', 'stage', 'xmomentum' and 'ymomentum' 1205 def get_mesh_and_quantities_from_file(filename, 1206 quantities=None, 1207 verbose=False): 1208 """Get and rebuild mesh structure and associated quantities from sww file 1209 1210 Input: 1211 filename - Name os sww file 1212 quantities - Names of quantities to load 1213 1214 Output: 1215 mesh - instance of class Interpolate 1216 (including mesh and interpolation functionality) 1217 quantities - arrays with quantity values at each mesh node 1218 time - vector of stored timesteps 1219 1220 This function is used by e.g.: 1221 get_interpolated_quantities_at_polyline_midpoints 1222 """ 1223 1224 # FIXME (Ole): Maybe refactor filefunction using this more fundamental code. 1225 1226 import types 1227 from Scientific.IO.NetCDF import NetCDFFile 1228 from shallow_water import Domain 1229 from anuga.abstract_2d_finite_volumes.neighbour_mesh import Mesh 1230 1231 if verbose: log.critical('Reading from %s' % filename) 1232 1233 fid = NetCDFFile(filename, netcdf_mode_r) # Open existing file for read 1234 time = fid.variables['time'][:] # Time vector 1235 time += fid.starttime[0] 1236 1237 # Get the variables as numeric arrays 1238 x = fid.variables['x'][:] # x-coordinates of nodes 1239 y = fid.variables['y'][:] # y-coordinates of nodes 1240 elevation = fid.variables['elevation'][:] # Elevation 1241 stage = fid.variables['stage'][:] # Water level 1242 xmomentum = fid.variables['xmomentum'][:] # Momentum in the x-direction 1243 ymomentum = fid.variables['ymomentum'][:] # Momentum in the y-direction 1244 1245 # Mesh (nodes (Mx2), triangles (Nx3)) 1246 nodes = num.concatenate((x[:,num.newaxis], y[:,num.newaxis]), axis=1) 1247 triangles = fid.variables['volumes'][:] 1248 1249 # Get geo_reference 1250 try: 1251 geo_reference = Geo_reference(NetCDFObject=fid) 1252 except: #AttributeError, e: 1253 # Sww files don't have to have a geo_ref 1254 geo_reference = None 1255 1256 if verbose: log.critical(' building mesh from sww file %s' % filename) 1257 1258 boundary = None 1259 1260 #FIXME (Peter Row): Should this be in mesh? 1261 if fid.smoothing != 'Yes': 1262 nodes = nodes.tolist() 1263 triangles = triangles.tolist() 1264 nodes, triangles, boundary = weed(nodes, triangles, boundary) 1265 1266 try: 1267 mesh = Mesh(nodes, triangles, boundary, geo_reference=geo_reference) 1268 except AssertionError, e: 1269 fid.close() 1270 msg = 'Domain could not be created: %s. "' % e 1271 raise DataDomainError, msg 1272 1273 quantities = {} 1274 quantities['elevation'] = elevation 1275 quantities['stage'] = stage 1276 quantities['xmomentum'] = xmomentum 1277 quantities['ymomentum'] = ymomentum 1278 1279 fid.close() 1280 1281 return mesh, quantities, time 1282 1283 1284 1285 ## 1198 1286 # @brief 1199 1287 # @parm time … … 1251 1339 1252 1340 1253 1254 1255 1341 ## 1256 1342 # @brief … … 1310 1396 1311 1397 return coordinates, volumes, boundary 1398 1399 1400
Note: See TracChangeset
for help on using the changeset viewer.