Ignore:
Timestamp:
Feb 1, 2005, 5:18:44 PM (20 years ago)
Author:
ole
Message:

Played with DEM's and NetCDF

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
     3It is also a clearing house for function tat may later earn a module
     4of their own.
     5"""
    26
    37def angle(v):
     
    286290            return res
    287291
    288 def read_xya(file_name):
     292def read_xya(filename):
    289293    """Read simple xya file, no header, just
    290294    x y [attributes]
    291295    separated by whitespace
     296
     297    If xya is a NetCDF file it will be read otherwise attemot to read as ASCII
    292298   
    293299    Return list of points and list of attributes
    294300    """
    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]
    308330   
    309331
    310332#####################################
    311 #POLYFON STUFF
     333#POLYGON STUFF
    312334#
    313335#FIXME: ALl these should be put into new module polygon.py
Note: See TracChangeset for help on using the changeset viewer.