def traj_visual(trajectory, ax): X = [] Y = [] Z = [] for i in range(12, 47): if i in trajectory.keys(): x, y = tools.parse_MeshCode(trajectory[i][0]) X.append(x) Y.append(y) Z.append(i - 12) ax.plot(X, Y, Z, color="red")
def traj_visual(trajectories): fig = plt.figure() ax = fig.add_subplot(111, projection='3d') for uid in trajectories.keys(): X = [] Y = [] Z = [] trajectory = trajectories[uid] print trajectory for i in range(12, 47): if i in trajectory.keys(): x, y = tools.parse_MeshCode(trajectory[i][0]) X.append(x) Y.append(y) Z.append(i - 12) ax.plot(X, Y, Z) plt.show()
def main(): path_sim = "D:/ClosePFLOW/53393574/sim/" path_validation = "D:/ClosePFLOW/53393574/validation/" path_observed = "D:/PT_Result/commuter/sim/" if not os.path.exists("D:/ClosePFLOW/53393574/comparison/"): os.mkdir("D:/ClosePFLOW/53393574/comparison/") observed_id_traj = load.load_directory_trajectory(path_observed) sim_id_traj = load.load_directory_trajectory(path_sim) validation_id_traj = load.load_directory_trajectory(path_validation) markov_id_traj = load_markovchain("D:/ClosePFLOW/53393574/markovchain/") print len(markov_id_traj) # diff_list = [] # min_id = None # trajectories = random.sample(observed_id_traj.values(), 10) # for validation_id in validation_id_traj.keys(): # # min_dist = sys.maxint # dist = traj_dist((random.choice(trajectories), validation_id_traj[validation_id])) # for trajectory in trajectories: # dist = traj_dist((trajectory, validation_id_traj[validation_id])) # if dist < min_dist: # min_dist = dist # min_id = validation_id # # diff_list.append(dist) # # validation_id_traj.pop(min_id) # # diff_list.sort() # # print diff_list # print np.average(diff_list) fig = plt.figure() ax = fig.add_subplot(111, projection='3d') count = 0 for uid in observed_id_traj.keys(): count += 1 if count > 80: break X = [] Y = [] Z = [] trajectory = observed_id_traj[uid] # print "trajectory", trajectory # print "adjusted trajectory", adjust_traj(trajectory) for i in range(12, 47): if i in trajectory.keys(): x, y = tools.parse_MeshCode(trajectory[i][0]) X.append(x) Y.append(y) Z.append(i-12) ax.plot(X, Y, Z) ax.set_zlabel('Hour') ax.set_ylabel('Lat') ax.set_xlabel('Lon') plt.show() # for uid in validation_id_traj.keys(): # X = [] # Y = [] # Z = [] # # # trajectory = validation_id_traj[uid] # # print "trajectory", trajectory # # print "adjusted trajectory", adjust_traj(trajectory) # for i in range(12, 47): # if i in trajectory.keys(): # x, y = tools.parse_MeshCode(trajectory[i][0]) # X.append(x) # Y.append(y) # Z.append(i-12) # ax.plot(X, Y, Z) # # plt.show() # # for uid in sim_id_traj.keys(): # X = [] # Y = [] # Z = [] # trajectory = sim_id_traj[uid] # for i in range(12, 46): # if i in trajectory.keys(): # x, y = tools.parse_MeshCode(trajectory[i][0]) # X.append(x) # Y.append(y) # Z.append(i-12) # ax.plot(X, Y, Z, color="blue") # # plt.show() diff_list = [] # # for ob_id in observed_id_traj: # fig = plt.figure() # # ax = fig.add_subplot(111, projection='3d') # # min_dist = sys.maxint # for validation_id in validation_id_traj.keys(): # dist = traj_dist((observed_id_traj[ob_id], validation_id_traj[validation_id])) # if dist < min_dist: # min_dist = dist # min_id = validation_id # # diff_list.append(min_dist) # if min_id in validation_id_traj.keys(): # X = [] # Y = [] # Z = [] # trajectory = validation_id_traj[min_id] # # print "trajectory", trajectory # # print "adjusted trajectory", adjust_traj(trajectory) # for i in range(12, 47): # if i in trajectory.keys(): # x, y = tools.parse_MeshCode(trajectory[i][0]) # print x, y # X.append(x) # Y.append(y) # Z.append(i - 12) # ax.plot(X, Y, Z, color="red") # # X = [] # Y = [] # Z = [] # trajectory = observed_id_traj[ob_id] # for i in range(12, 46): # if i in trajectory.keys(): # x, y = tools.parse_MeshCode(trajectory[i][0]) # X.append(x) # Y.append(y) # Z.append(i - 12) # ax.plot(X, Y, Z, color="blue") # # ax.set_zlabel('time') # ax.set_ylabel('lat') # ax.set_xlabel('lon') # plt.show() # # validation_id_traj.pop(min_id) # # diff_list.sort() # # print len(diff_list) # # x = range(len(diff_list)) # plt.plot(x, diff_list) # plt.show() diff_list = [] for sim_id in sim_id_traj: fig = plt.figure() ax = fig.add_subplot(111, projection='3d') min_dist = sys.maxint for validation_id in validation_id_traj.keys(): dist = traj_dist((sim_id_traj[sim_id], validation_id_traj[validation_id])) if dist < min_dist: min_dist = dist min_id = validation_id diff_list.append(min_dist) print min_id if min_id in validation_id_traj.keys(): X = [] Y = [] Z = [] trajectory = validation_id_traj[min_id] # print "trajectory", trajectory # print "adjusted trajectory", adjust_traj(trajectory) for i in range(12, 47): if i in trajectory.keys(): x, y = tools.parse_MeshCode(trajectory[i][0]) X.append(x) Y.append(y) Z.append(i - 12) ax.plot(X, Y, Z, color="red", linewidth=3.5) X = [] Y = [] Z = [] trajectory = sim_id_traj[sim_id] for i in range(12, 46): print trajectory.keys() if i in trajectory.keys(): x, y = tools.parse_MeshCode(trajectory[i][0]) print i,";;;;;;;;;;;;;;;" print trajectory[i] X.append(x) Y.append(y) Z.append(i - 12) ax.plot(X, Y, Z, color="blue", linewidth=3.5) ax.set_zlabel('time') ax.set_ylabel('lat') ax.set_xlabel('lon') for tick in ax.xaxis.get_major_ticks(): tick.label1.set_fontsize(6) for tick in ax.yaxis.get_major_ticks(): tick.label1.set_fontsize(6) for tick in ax.zaxis.get_major_ticks(): tick.label1.set_fontsize(6) ax.xaxis.set_ticks_position('none') plt.xlim((139, 140)) plt.ylim((35.3, 36)) plt.title(min_dist) plt.savefig("D:/ClosePFLOW/53393574/comparison/traj_compare"+sim_id+"_"+".png") plt.show() validation_id_traj.pop(min_id) diff_list.sort() print np.average(diff_list)
def __init__(self, bottomleft, upperright): self.min_lon, self.min_lat = tools.parse_MeshCode(bottomleft) self.max_lon, self.max_lat = tools.parse_MeshCode(upperright) self.x_unit = (self.max_lon - self.min_lon) / 80.0 self.y_unit = (self.max_lat - self.min_lat) / 120.0 print self.x_unit, self.y_unit
def get_coor(self, mesh): x, y = tools.parse_MeshCode(mesh) return int((x - self.min_lon) / self.x_unit), int( (y - self.min_lat) / self.y_unit)