def genlandroadclassmap(roadclassmap, landclassmap, header): # make the default class value to be a large number and then take # the minimum value of the maps. roadclassmap = roadclassmap.replace(to_replace=-1, value=999) landroadclassmap = np.minimum(roadclassmap, landclassmap) outputmap(landroadclassmap, header, LANDROADCLASSMAP)
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 __init__(self, landcover_matrix, road_matrix, speedchart, speedmap, header): self.cat_list = [] self.speed_list = [] self.projectioninfo_list = [] # read the speedchart to be a speed dictionary self.speedchart2dict(speedchart) # replace the landcover catogory values with speed values self.landcoverspeed_matrix = self.cat2speedmap(landcover_matrix) self.roadspeed_matrix = self.cat2speedmap(road_matrix) self.finalspeed_matrix = self.overlapspeedmap( self.landcoverspeed_matrix, self.roadspeed_matrix) #self.landcoverspeed_matrix = self.landcoverspeed_matrix.apply(np.sqrt) outputmap(self.landcoverspeed_matrix, header, "./Data/landcoverspeedmap.txt")
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 __init__(self, landcover_matrix, road_matrix, speedchart, speedmap, header): self.cat_list = [] self.speed_list = [] self.projectioninfo_list = [] # read the speedchart to be a speed dictionary self.speedchart2dict(speedchart) # replace the landcover catogory values with speed values self.landcoverspeed_matrix = self.cat2speedmap(landcover_matrix) self.roadspeed_matrix = self.cat2speedmap(road_matrix) self.finalspeed_matrix = self.overlapspeedmap(self.landcoverspeed_matrix, self.roadspeed_matrix) #self.landcoverspeed_matrix = self.landcoverspeed_matrix.apply(np.sqrt) outputmap(self.landcoverspeed_matrix, header, "./Data/landcoverspeedmap.txt") outputmap(self.roadspeed_matrix, header, "./Data/roadspeedmap.txt") outputmap(self.finalspeed_matrix, header, speedmap)