コード例 #1
0
    def radius_of_gyration(self):
        """ R_g based on edge distances
        """
        clon = np.average([coord[0] for coord in self.coordinates])
        clat = np.average([coord[1] for coord in self.coordinates])

        return np.average([greate_circle_distance(clon, clat, coord[0], coord[1]) for coord in self.coordinates])
コード例 #2
0
    def convert2graph(self, road_network=None, directed=True,
                      edge_weighted_by_distance=True,
                      node_weighted_by_dwelling=True):
        """ Return a graph representation of human mobility, one which
        is weighted by traveling distance for edge and dwelling time for node.

        **PerfStat** (PersonNum,Calls,AccTime): 100,1519,54.191s
        """
        graph = seq2graph(self.coordinates, directed)

        if edge_weighted_by_distance:
            for edge in graph.edges_iter():
                if road_network:
                    dist = road_network.shortest_path_distance(edge[0], edge[1])
                else:
                    dist = greate_circle_distance(edge[0][0], edge[0][1], edge[1][0], edge[1][1])

                graph.edge[edge[0]][edge[1]]['weight'] = dist
                if edge in self.freq:
                    graph.edge[edge[0]][edge[1]]['frequency'] = self.freq[edge]
                else:
                    graph.edge[edge[0]][edge[1]]['frequency'] = 1

        if node_weighted_by_dwelling:
            for node in graph.nodes_iter():
                graph.node[node]['weight'] = self.accdwelling.get(node)

        return graph
コード例 #3
0
def transtime(a, b):
    dist = greate_circle_distance(a[0], a[1], b[0], b[1])
    if dist <= 5: # km
        speed = 5
    elif dist <= 15:
        speed = 20
    else:
        speed = 30
    return 1.0 * dist / speed * 3600
コード例 #4
0
 def transtime(a, b):
     dist = greate_circle_distance(a[0], a[1], b[0], b[1])
     if dist <= 5: # km
         speed = 5
     elif dist <= 15:
         speed = 20
     else:
         speed = 30
     return 1.0 * dist / speed * 3600
コード例 #5
0
 def travel_dist(self):
     """ Calculate the travelling distance totally.
     """
     if len(self.coordinates) < 2:
         return 0
     total = 0
     for i in range(0, len(self.coordinates)-1):
         lon1, lat1 = self.coordinates[i]
         lon2, lat2 = self.coordinates[i+1]
         total += greate_circle_distance(lon1, lat1, lon2, lat2)
     return total
コード例 #6
0
 def __init__(self, shapefile, edge_weighted_by_distance=True):
     g = nx.read_shp(shapefile)
     mg = max(nx.connected_component_subgraphs(g.to_undirected()), key=len)
     if edge_weighted_by_distance:
         for n0, n1 in mg.edges_iter():
             path = np.array(json.loads(mg[n0][n1]['Json'])['coordinates'])
             distance = np.sum(
                 greate_circle_distance(path[1:, 0], path[1:, 1],
                                        path[:-1, 0], path[:-1, 1]))
             mg.edge[n0][n1]['distance'] = distance
     self.graph = mg
     self._cache = {}
     self._cache_nn = {}
コード例 #7
0
 def __init__(self, shapefile, edge_weighted_by_distance=True):
     g = nx.read_shp(shapefile)
     mg = max(nx.connected_component_subgraphs(g.to_undirected()), key=len)
     if edge_weighted_by_distance:
         for n0, n1 in mg.edges_iter():
             path = np.array(json.loads(mg[n0][n1]['Json'])['coordinates'])
             distance = np.sum(
                 greate_circle_distance(path[1:,0],path[1:,1], path[:-1,0], path[:-1,1])
             )
             mg.edge[n0][n1]['distance'] = distance
     self.graph = mg
     self._cache = {}
     self._cache_nn = {}