0

I have a two part question related to Boeing's OSMnx Tutorial 8 - Street network centrality analysis. Firstly, I have a knowledge question regarding edge closeness centrality and then a code-based question regarding edge betweenness centrality. My purpose is to calculate edge closeness and betweenness centrality around stations in various locations.

1. Edge Closeness Centrality

The following code works well for me:

# edge closeness centrality: convert graph to a line graph so edges become nodes and vice versa
edge_centrality = nx.closeness_centrality(nx.line_graph(G))

# list of edge values for the original graph
ev = [edge_centrality[edge + (0,)] for edge in G.edges()]

# color scale converted to list of colors for graph edges
norm = colors.Normalize(vmin=min(ev)*0.8, vmax=max(ev))
cmap = cm.ScalarMappable(norm=norm, cmap=cm.inferno)
ec = [cmap.to_rgba(cl) for cl in ev]

Question: Can anyone explain why in the normalisation code the mininum edge value is multiplied by 0.8 and the the maximum value is set at the maximum edge value? I am not too familiar with the literature so any advice would be appreciated.

2. Edge Betweenness Centrality

I am trying to calculate edge betweenness centrality in a similar way to the above code for edge closeness centrality on the same graph in the example. I have tried this and get the following:

# edge betweenness centrality
edge_bcentrality = nx.edge_betweenness_centrality(G)

# list of edge values for the orginal graph
ev1 = [edge_bcentrality[edge + (0,)] for edge in G.edges()]

# color scale converted to list of colors for graph edges
norm = colors.Normalize(vmin=min(ev1)*0.8, vmax=max(ev1))
cmap = cm.ScalarMappable(norm=norm, cmap=cm.inferno)
ec = [cmap.to_rgba(cl) for cl in ev1]

# color the edges in the original graph with betweeness centralities in the line graph
fig, ax = ox.plot_graph(G, bgcolor='k', axis_off=True, node_size=0, node_color='w', node_edgecolor='gray', node_zorder=2,
                        edge_color=ec, edge_linewidth=1.5, edge_alpha=1)

---------------------------------------------------------------------------
KeyError                                  Traceback (most recent call last)
<ipython-input-14-6ee1d322067c> in <module>()
      1 # list of edge values for the orginal graph
----> 2 ev1 = [edge_bcentrality[edge + (0,)] for edge in G.edges()]
      3 
      4 # color scale converted to list of colors for graph edges
      5 norm = colors.Normalize(vmin=min(ev)*0.8, vmax=max(ev))

KeyError: (53090322, 53082634, 0)

If anyone advice on the the best way to calculate edge betweenness centrality I would be greatly appreciated, as I am still a novice. Also, it would be appreciated if someone could share the best way to proceed with normalisation.

Thank you for your time,

BC

1 Answers1

0

I applied this code and it works for me. Hope it helps.

#calculate betweenness
betweenness = nx.edge_betweenness(G=G, normalized=False)

# iterate over edges
edges = []
for i in betweenness.items():
    i = i[0] + (0,)
    edges.append(i)
for i,j in zip(edges,betweenness.keys()): 
    betweenness[i] = betweenness[j]
    del betweenness[j]

# color scale converted to list of colors for graph edges
norm = colors.Normalize(vmin=min(betweenness.values())*0.8, vmax=max(betweenness.values()))
cmap = cm.ScalarMappable(norm=norm, cmap=cm.viridis)
ec = [cmap.to_rgba(cl) for cl in betweenness.values()]

# color the edges in the original graph with betweeness centralities in the line graph
fig, ax = ox.plot_graph(G, bgcolor='w', axis_off=True, node_size=0, node_color='w', node_edgecolor='gray', node_zorder=2,
                        edge_color=ec, edge_linewidth=1.5, edge_alpha=1)
fig.show()