Ignore:
Timestamp:
Jul 8, 2014, 12:59:46 PM (10 years ago)
Author:
davies
Message:

Code to read list of riverwall input files

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/anuga_core/source/anuga/utilities/spatialInputUtil.py

    r9242 r9252  
    916916        return allBreakLines
    917917   
     918    #########################################
     919    def readListOfRiverWalls(rwfileList):
     920        """
     921            Take a list with the names of riverwall input files [should be comma-separated x,y,elevation files]
     922
     923            The input file can optionally have a first line defining some hydraulic parameters. A valid example
     924            is
     925
     926            Qfactor: 1.5, s1: 0.94
     927            200., 300., 0.5
     928            300., 400., 0.7
     929            ....and so on..
     930       
     931            Read their coordinates into a dict with their names, read for use by ANUGA
     932   
     933            INPUT: rwfileList -- a list of riverwall filenames [e.g. from glob.glob('GIS/RiverWalls/*.csv')]
     934   
     935            OUTPUT:
     936                dictionary with riverwalls [filenames are keys] AND
     937                dictionary with hydraulic parameters [filenames are keys]
     938        """
     939        import numpy
     940   
     941        allRiverWalls={}
     942        allRiverWallPar={}
     943        for rwfile in rwfileList:
     944            f=open(rwfile)
     945            firstLine=f.readline()
     946            # If the top line has any letters, assume it is a hydraulic variables line
     947            hasLetters=any(c.isalpha() for c in firstLine)
     948            if(not hasLetters):
     949                allRiverWalls[rwfile]=numpy.genfromtxt(rwfile,delimiter=",").tolist()
     950                allRiverWallPar[rwfile]={}
     951            else:
     952                # Get the wall geometry
     953                allRiverWalls[rwfile]=numpy.genfromtxt(rwfile,delimiter=",",skip_header=1).tolist()
     954                # Get the hydraulic par
     955                firstLine=firstLine.replace(' ', '') # No whitespace
     956                wallPar=firstLine.split(',')
     957                allRiverWallPar[rwfile]={}
     958                for wp in wallPar:
     959                    keyNameValue=wp.split(':')
     960                    allRiverWallPar[rwfile][keyNameValue[0]]=float(keyNameValue[1])
     961       
     962        return allRiverWalls, allRiverWallPar
     963   
    918964    ############################################################################
    919965    def polygon_from_matching_breaklines(pattern,breakLinesIn, reverse2nd=None):
Note: See TracChangeset for help on using the changeset viewer.