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 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 walk8directions(self, travelcostpath, travelcostmap, repeattimes, dirP, dirnearP, dirsideP, diropP): """Walk in each of the 8 directions. """ self.walkeachdirection("N", travelcostpath, travelcostmap, repeattimes, dirP, dirnearP, dirsideP, diropP) self.walkeachdirection("NE", travelcostpath, travelcostmap, repeattimes, dirP, dirnearP, dirsideP, diropP) self.walkeachdirection("E", travelcostpath, travelcostmap, repeattimes, dirP, dirnearP, dirsideP, diropP) self.walkeachdirection("SE", travelcostpath, travelcostmap, repeattimes, dirP, dirnearP, dirsideP, diropP) self.walkeachdirection("S", travelcostpath, travelcostmap, repeattimes, dirP, dirnearP, dirsideP, diropP) self.walkeachdirection("SW", travelcostpath, travelcostmap, repeattimes, dirP, dirnearP, dirsideP, diropP) self.walkeachdirection("W", travelcostpath, travelcostmap, repeattimes, dirP, dirnearP, dirsideP, diropP) self.walkeachdirection("NW", travelcostpath, travelcostmap, repeattimes, dirP, dirnearP, dirsideP, diropP) #self.costmap[self.costmap < 20] = 20 outcostfilename = outfilename(self.cellx, self.celly, travelcostpath, travelcostmap, "NW", 100) outputmap(self.costmap, self.outfileheader, outcostfilename) for (x, y), val in self.visited_dict.iteritems(): print "(", x, ",", y, ")", val
def gettravelcostmap(nrows, ncols, header, CENTERLIST=CENTERLIST, COSTMAX=COSTMAX, TRAVELCOSTPATH=TRAVELCOSTPATH, TRAVELCOSTMAP=TRAVELCOSTMAP): """Generate travelcost map by overlapping the 100 pop/emp center travelcost maps and obtain the minimal value of each cell in these 100 maps. This process takes several minutes. @param: nrows is # rows and ncols is # columns of travelcostmaps. @output: the overlapped minimal value travelcostma Time consumption: 3.5min """ with open(CENTERLIST, 'r') as p: centerlist = p.readlines() trcostdf = pd.DataFrame(index=xrange(nrows), columns=xrange(ncols)) #initialize costmap with nan trcostdf = trcostdf.fillna(COSTMAX) #initialize costmap with 999 for i in xrange(99): (disW, disN, weight) = centerlist[i].strip('\n').split(',') costmapfile = outfilename(disW, disN, TRAVELCOSTPATH, TRAVELCOSTMAP, "NW", 100) try: newtrcostdf = pd.read_csv(costmapfile, skiprows=6, header=None, sep=r"\s+" ) #skip the 6 header lines print disW, disN, weight except IOError: print "file not found: ", costmapfile continue trcostdf = np.minimum(trcostdf, newtrcostdf) # header = extractheader(HEADER) with open(TRCOSTMAP, 'w') as w: w.writelines(header) trcostdf.round() # round to integer trcostdf.to_csv(path_or_buf=TRCOSTMAP, sep=' ', index=False, header=False, mode = 'a') # append return trcostdf
def walk8directions(self, travelcostpath, travelcostmap, repeattimes, dirP, dirnearP, dirsideP, diropP): """Walk in each of the 8 directions. """ self.walkeachdirection("N",travelcostpath, travelcostmap, repeattimes, dirP, dirnearP, dirsideP, diropP) self.walkeachdirection("NE",travelcostpath, travelcostmap, repeattimes, dirP, dirnearP, dirsideP, diropP) self.walkeachdirection("E",travelcostpath, travelcostmap, repeattimes, dirP, dirnearP, dirsideP, diropP) self.walkeachdirection("SE",travelcostpath, travelcostmap, repeattimes, dirP, dirnearP, dirsideP, diropP) self.walkeachdirection("S",travelcostpath, travelcostmap, repeattimes, dirP, dirnearP, dirsideP, diropP) self.walkeachdirection("SW",travelcostpath, travelcostmap, repeattimes, dirP, dirnearP, dirsideP, diropP) self.walkeachdirection("W",travelcostpath, travelcostmap, repeattimes, dirP, dirnearP, dirsideP, diropP) self.walkeachdirection("NW",travelcostpath, travelcostmap, repeattimes, dirP, dirnearP, dirsideP, diropP) #self.costmap[self.costmap < 20] = 20 outcostfilename = outfilename(self.cellx, self.celly, travelcostpath, travelcostmap, "NW", 100) outputmap(self.costmap, self.outfileheader, outcostfilename) for (x,y) , val in self.visited_dict.iteritems(): print "(" ,x, ",",y,")",val