def main():
    speedmap = pd.read_csv(SPEEDMAP, skiprows=6, header=None, sep=r"\s+")
    header = extractheader(HEADER)
    attinxcol = speedmap.shape
    indexlen = attinxcol[0]
    columnlen = attinxcol[1]
    attrmap = pd.DataFrame(index=range(indexlen), columns=range(columnlen)) #initialize costmap with nan
    attrmap = attrmap.fillna(0)    #initialize costmap with 0

    with open(CENTERLIST, 'r') as p:
        centerlist = p.readlines()

    for i in range(99):
        (disW, disN, weight) = centerlist[i].strip('\n').split(',')
        costmapfile = outfilename(disW, disN, TRAVELCOSTPATH, TRAVELCOSTMAP, "NW", 100)
        try:
           newattrmap = costmap2attrmap(costmapfile)
        except IOError:
            print "file not found: ", outfilename
            continue
        print "\nstart adding...\n"
        start = time.time()
        attrmap = attrmap + (int)(weight)*newattrmap
        end = time.time()
        print "done map using time: "
        print (end-start)

    #normalizer = np.matrix(attrmap).max()
    #attrmap /= normalizer
    attrmap.round() # round to integer
    outputmap(attrmap, header, ATTRACTIVEMAP)
Beispiel #2
0
def main():
    speedmap = pd.read_csv(SPEEDMAP, skiprows=6, header=None, sep=r"\s+")
    header = extractheader(HEADER)
    attinxcol = speedmap.shape
    indexlen = attinxcol[0]
    columnlen = attinxcol[1]
    attrmap = pd.DataFrame(
        index=range(indexlen),
        columns=range(columnlen))  #initialize costmap with nan
    attrmap = attrmap.fillna(0)  #initialize costmap with 0

    with open(CENTERLIST, 'r') as p:
        centerlist = p.readlines()

    for i in range(99):
        (disW, disN, weight) = centerlist[i].strip('\n').split(',')
        costmapfile = outfilename(disW, disN, TRAVELCOSTPATH, TRAVELCOSTMAP,
                                  "NW", 100)
        try:
            newattrmap = costmap2attrmap(costmapfile)
        except IOError:
            print "file not found: ", outfilename
            continue
        print "\nstart adding...\n"
        start = time.time()
        attrmap = attrmap + (int)(weight) * newattrmap
        end = time.time()
        print "done map using time: "
        print(end - start)

    #normalizer = np.matrix(attrmap).max()
    #attrmap /= normalizer
    attrmap.round()  # round to integer
    outputmap(attrmap, header, ATTRACTIVEMAP)
def ascii2raster(layername):
    filename = './Data/' + layername + '.txt'
    grassheader = extractheader(GRASSHEADER)
    os.system('sed -i -e "1,6d" '+ filename) #delete first 6 lines
    lines = grassheader.rstrip().split('\n') #insert header line by line
    for line in reversed(lines):
        os.system("sed -i 1i\ '" + line+"' " +filename) #insert header to the 1st line
    if grass.run_command('r.in.ascii', input=filename, output=layername):
        raise RuntimeError('unable to read ascii map to raster map ' + layername )
def main():
    
    #convert road speed map to road class type matrix
    roadclass_matrix = roadspeed2class(ROAD, ROADSPEEDCHART, ROADCLASSMAP, HEADER)
    landcover_matrix = asciiMap2DataFrame(LANDCOVER)

    # generate landroadclassmap
    header= extractheader(HEADER)
    genlandroadclassmap(roadclass_matrix, landcover_matrix, header)

    # generate speedmap and dirprobmap
    speedmap = SpeedMap(landcover_matrix, roadclass_matrix, SPEEDCHART, SPEEDMAP, header)
    dirprobmap = SpeedMap(landcover_matrix, roadclass_matrix, DIRPROBCHART, DIRPROBMAP, header)
def main():

    #convert road speed map to road class type matrix
    roadclass_matrix = roadspeed2class(ROAD, ROADSPEEDCHART, ROADCLASSMAP,
                                       HEADER)
    landcover_matrix = asciiMap2DataFrame(LANDCOVER)

    # generate landroadclassmap
    header = extractheader(HEADER)
    genlandroadclassmap(roadclass_matrix, landcover_matrix, header)

    # generate speedmap and dirprobmap
    speedmap = SpeedMap(landcover_matrix, roadclass_matrix, SPEEDCHART,
                        SPEEDMAP, header)
    dirprobmap = SpeedMap(landcover_matrix, roadclass_matrix, DIRPROBCHART,
                          DIRPROBMAP, header)
Beispiel #6
0
    def __init__(self, cellx, celly, speedmap=SPEEDMAP, dirprobmap=DIRPROBMAP, 
        travelcostpath=TRAVELCOSTPATH, travelcostmap=TRAVELCOSTMAP, 
        maxcost=MAXCOST, maxmove=MAXMOVE, repeattimes=REPEATTIMES, cellsize=CELLSIZE, 
        dirP=DIRP, dirnearP = DIRNEARP, dirsideP=DIRSIDEP, diropP=DIROPP):
        """ Random Walk from one cell on a given map
        Update dirlist for walking in each direction.
        Update repeatcost and costaccumulated for each 2hrs move.
        @param: cellx and celly is the curretn position x and y indexies in speedmap.
        speedmap is a matrix with speed value meters/min in each cell and each cell is 30 meters.
                cellsize is the length of each cell.
                maxcost is the termiantion cost from current cell doing stocastic greedy random walk.
                maxmove is the maximum number of cells to move before termination.
                repeattimes is the times for each cell to conduct maxcost walks in each direction.
                dirP is the probabilty that goes for a pre-selected direction.
                dirsideP is the probabilty that goes for the two directions near pre-selected direction.
                diropP is the proabiltiy taht goes for the opposite direction of pre-selected direction.
                """
        # W: west, N: north, E: east, S:South
        #read in values
        self.speedmatrix=pd.read_csv(speedmap, skiprows=6, header=None, sep=r"\s+")
        self.dirprobmatrix=pd.read_csv(dirprobmap, skiprows=6, header=None, sep=r"\s+")
        self.cellx=cellx                           #initial starting cell x index
        self.celly=celly                           #initial starting cell y index
        self.distN = cellx                         #current cell x index
        self.distW = celly                         #current cell y index #(cellx, celly) = (0, 1) = (disN, disW)
        self.maxmove = maxmove
        self.distancetuple = self.speedmatrix.shape
        self.xmax = self.distancetuple[0]
        self.ymax = self.distancetuple[1]
        self.maxcost=maxcost
        self.cellsize=cellsize
        self.outfileheader = extractheader(HEADER)
        
        #initiliaze parameters
        self.costmap = pd.DataFrame(index=range(self.xmax), columns=range(self.ymax)) #initialize costmap with nan
        self.costmap = self.costmap.fillna(999)                                                               #initialize costmap with 999
        self.costmap.iloc[self.cellx, self.celly] = 0 # set the starting point cost to be 0
        self.costaccumulated = 0
        self.travelpathlist = []
        self.visited_dict = {}

        # select a seed for this cell to parallize the travelcost maps for each cell.
        # The seed of this cell is the product of the x and y axis positions of this cell.
        seedbase = self.cellx * self.celly
        np.random.seed(seedbase)

        self.walk8directions(travelcostpath, travelcostmap, repeattimes, dirP, dirnearP, dirsideP, diropP)
Beispiel #7
0
def main():
    
    header = extractheader(HEADER)
    speed_df = pd.read_csv(SPEEDMAP, sep=' ', skiprows=6, header=None, dtype=np.int)

    (nrows, ncols) = speed_df.shape
    travelcostmap  = gettravelcostmap(nrows, ncols, header)
    
    costmap_df = pd.read_csv(INPUT, sep=' ', skiprows=6, header=None, dtype=np.float)
    costmap = np.asarray(costmap_df).round()
    weightarray = np.fromfile(WEIGHTMAP, sep=' ', dtype=np.float)
    
    
    smoothcost = SmoothCost(costmap, weightarray, speed_df)
    costmap = smoothcost.smoothedmap

    
    outputmap(costmap, header, OUTPUT)
if ISEMP == 0:
    INPUT="./Data/attrmap-pop.txt"
    OUTPUT="./Data/attrmap-pop-interpolated.txt"
else:
    INPUT="./Data/attrmap-emp.txt"
    OUTPUT="./Data/attrmap-emp-interpolated.txt"
    
HEADER="./Input/arcGISheader.txt"
WEIGHTMAP = "./Input/weightmap.txt"
DIRPROBMAP = "./Data/dirprobmap.txt"
DIRPROBMAX = 200
#THREADNUM = 32
REPEATNUM = 5


header = extractheader(HEADER)

class SmoothAttr():
    def __init__(self, matrix, weightarray, dirprobmatrix, repeattimes=REPEATNUM, dirprobmax=DIRPROBMAX):
        start = time.time()
        self.weightarray = weightarray
        self.matrix = matrix
        (self.rows, self.cols) = matrix.shape
        self.maxrow = self.rows-2
        self.maxcol = self.cols-2
        self.dirprobmatrix = dirprobmatrix
        self.dirprobmax = dirprobmax
        self.smoothedmap = np.zeros((self.rows, self.cols), dtype=np.int)
        self.smooth2max(repeattimes)

    def smoothrow(self, rowidx):
Beispiel #9
0
ISEMP = 1
if ISEMP == 0:
    INPUT = "./Data/attrmap-pop.txt"
    OUTPUT = "./Data/attrmap-pop-interpolated.txt"
else:
    INPUT = "./Data/attrmap-emp.txt"
    OUTPUT = "./Data/attrmap-emp-interpolated.txt"

HEADER = "./Input/arcGISheader.txt"
WEIGHTMAP = "./Input/weightmap.txt"
DIRPROBMAP = "./Data/dirprobmap.txt"
DIRPROBMAX = 200
#THREADNUM = 32
REPEATNUM = 5

header = extractheader(HEADER)


class SmoothAttr():
    def __init__(self,
                 matrix,
                 weightarray,
                 dirprobmatrix,
                 repeattimes=REPEATNUM,
                 dirprobmax=DIRPROBMAX):
        start = time.time()
        self.weightarray = weightarray
        self.matrix = matrix
        (self.rows, self.cols) = matrix.shape
        self.maxrow = self.rows - 2
        self.maxcol = self.cols - 2