Exemplo n.º 1
0
def TestOSTools():

    path1 = "C://basin_data//Chile//lat26p0//"
    path2 = "M:/Yo/ma/yoyo.ma"
    path3 = "/home/smudd/devel_projects/LSDTopoTools/branches/LSDModel"
    path4 = "C:\\basin_data\\Chile\\lat26p0\\heyJude_DEM.flt"

    newpath1 = LSDost.ReformatSeperators(path1)
    print "Old path: " + path1
    print "New path: " + newpath1

    newpath2 = LSDost.ReformatSeperators(path2)
    print "Old path: " + path2
    print "New path: " + newpath2

    newpath3 = LSDost.ReformatSeperators(path3)
    print "Old path: " + path3
    print "New path: " + newpath3

    newpath4 = LSDost.ReformatSeperators(path4)
    print "Old path: " + path4
    print "New path: " + newpath4

    # test the directory adder
    # test the directory adder
    print "\n\n"
    newpath = LSDost.AppendSepToDirectoryPath(path1)
    print "Sep appended path is: " + newpath

    print "\n\n"
    newpath = LSDost.AppendSepToDirectoryPath(path3)
    print "Sep appended path is: " + newpath

    # Test the file prefix grabber
    fprefix = LSDost.GetFilePrefix(path4)
    print "\n\n"
    print "File prefix is: " + fprefix

    # Test the remove path level
    print "\n\n"
    print "Removing a directory level from: " + newpath
    newnewpath = LSDost.RemoveDirectoryLevel(newpath)
    print "The new directory is: " + newnewpath

    # Test the last directory name function
    print "\n\n"
    print "The last directory name in: " + newnewpath
    name = LSDost.GetLastDirectoryLevel(newnewpath)
    print "is: " + name
Exemplo n.º 2
0
    def __init__(self, FileName):

        # This gets the filename without the .csv
        file_prefix = LSDOst.GetFilePrefix(FileName)

        self.FilePrefix = file_prefix
        print "The object file prefix is: " + self.FilePrefix

        #See if the parameter files exist
        if os.access(FileName, os.F_OK):
            this_file = open(FileName, 'r')
            lines = this_file.readlines()

            # get rid of the control characters
            this_line = LSDOst.RemoveEscapeCharacters(lines[0])

            # Now get a list with the names of the parameters
            self.VariableList = []
            TestList = this_line.split(',')

            for name in TestList:
                this_name = LSDOst.RemoveEscapeCharacters(name)
                self.VariableList.append(this_name.lower())

            print "Variable list is: "
            print self.VariableList

            # get rid of the names
            del lines[0]

            # now you need to make a dict that contains a list for each varaible name
            DataDict = {}
            TypeList = []
            for name in self.VariableList:
                DataDict[name] = []

            # now get the data into the dict
            #firstline = True
            for line in lines:
                this_line = LSDOst.RemoveEscapeCharacters(line)
                split_line = this_line.split(',')

                for index, name in enumerate(self.VariableList):
                    this_var = LSDOst.RemoveEscapeCharacters(split_line[index])
                    #this_variable = LSDOst.ParseStringToType(this_var)
                    DataDict[name].append(this_var)

            # now go back and get the correct type
            DataDictTyped = {}
            for name in self.VariableList:
                this_list = DataDict[name]
                typed_list = LSDOst.ParseListToType(this_list)
                DataDictTyped[name] = typed_list

                TypeList.append(type(typed_list[0]))

            self.PointData = DataDictTyped
            self.DataTypes = TypeList
        else:
            print "Uh oh I could not open that file"
            self.VariableList = []
            self.DataTypes = []
            self.PointData = {}

        # now make sure the data has latitude and longitude entries
        if "latitude" not in self.VariableList:
            print "Something has gone wrong, latitude is not in the variable list"
            print "Here is the variable list: "
            print self.VariableList
        if "longitude" not in self.VariableList:
            print "Something has gone wrong, longitude is not in the variable list"
            print "Here is the variable list: "
            print self.VariableList

        # Add the latitude and longitude to their own data members and get rid
        # of those from the VariableList
        self.Latitude = self.PointData["latitude"]
        self.Longitude = self.PointData["longitude"]
Exemplo n.º 3
0
    def __init__(self, FileName):

        # This gets the filename without the .csv
        file_prefix = LSDOst.GetFilePrefix(FileName)

        print "Loading a file, the file prefix is: " + file_prefix

        if file_prefix.endswith('_CRNResults'):
            file_prefix = file_prefix[:-11]
            self.FilePrefix = file_prefix
        else:
            self.FilePrefix = 'NULL'

        print "The object file prefix is: " + self.FilePrefix

        #See if the parameter files exist
        if os.access(FileName, os.F_OK):
            this_file = open(FileName, 'r')
            lines = this_file.readlines()

            # get rid of the header
            del lines[0:3]

            # get rid of the control characters
            this_line = LSDOst.RemoveEscapeCharacters(lines[0])

            # Now get a list with the names of the parameters
            self.VariableList = this_line.split(',')

            #print "Variable list is: "
            #print self.VariableList

            # get rid of the names
            del lines[0]

            # now you need to make a dict that contains a vist for each varaible name
            DataDict = {}
            for name in self.VariableList:
                DataDict[name] = []

            # now get the data into the dict
            for line in lines:
                this_line = LSDOst.RemoveEscapeCharacters(line)
                split_line = this_line.split(',')

                for index, name in enumerate(self.VariableList):
                    if name == 'sample_name':
                        DataDict[name].append(split_line[index])
                    elif name == 'nuclide':
                        DataDict[name].append(split_line[index])
                    else:
                        DataDict[name].append(float(split_line[index]))

                    #if name == 'basin_relief':
                    #    print "getting relief of: " +str(float(split_line[index]))

                #print "Finished assimilating Data Dict"

            self.CRNData = DataDict
        else:
            print "Uh oh I could not open that file"
            self.VariableList = []
            self.CRNData = {}

        # add a bool to let other modules know if you've got the data from CRONUS
        self.HaveCRONUSData = False