Changeset 826 for inundation/ga/storm_surge/pyvolution/util.py
- Timestamp:
- Feb 1, 2005, 5:18:44 PM (20 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
inundation/ga/storm_surge/pyvolution/util.py
r820 r826 1 1 """This modul contains various auxiliary function used by pyvolution. 2 3 It is also a clearing house for function tat may later earn a module 4 of their own. 5 """ 2 6 3 7 def angle(v): … … 286 290 return res 287 291 288 def read_xya(file _name):292 def read_xya(filename): 289 293 """Read simple xya file, no header, just 290 294 x y [attributes] 291 295 separated by whitespace 296 297 If xya is a NetCDF file it will be read otherwise attemot to read as ASCII 292 298 293 299 Return list of points and list of attributes 294 300 """ 295 296 fid = open(file_name) 297 lines = fid.readlines() 298 299 points = [] 300 attributes = [] 301 for line in lines: 302 fields = line.strip().split() 303 304 points.append( (float(fields[0]), float(fields[1])) ) 305 attributes.append( [float(z) for z in fields[2:] ] ) 306 307 return points, attributes 301 302 303 from Scientific.IO.NetCDF import NetCDFFile 304 305 306 try: 307 #Get NetCDF 308 fid = NetCDFFile(filename, 'r') 309 310 # Get the variables 311 points = fid.variables['points'] 312 attributes = fid.variables['attributes'] 313 ncols = fid.ncols 314 nrows = fid.nrows 315 #fid.close() #Don't close - arrays are needed outside this function 316 except: 317 #Read as ASCII 318 fid = open(filename) 319 lines = fid.readlines() 320 321 points = [] 322 attributes = [] 323 for line in lines: 324 fields = line.strip().split() 325 points.append( (float(fields[0]), float(fields[1])) ) 326 attributes.append( [float(z) for z in fields[2:] ] ) 327 nrows = ncols = None #FIXME: HACK 328 329 return points, attributes #, nrows[0], ncols[0] 308 330 309 331 310 332 ##################################### 311 #POLY FON STUFF333 #POLYGON STUFF 312 334 # 313 335 #FIXME: ALl these should be put into new module polygon.py
Note: See TracChangeset
for help on using the changeset viewer.