I followed what gboeing posted on this thread OSMnx : normalised measure of orientation order I got a " KeyError: 'bearing' " as a result when I ran it for my query. Below is the code
#CODE#
`ox.config(use_cache=True, log_console=True)
query = 'Khalifa City'
entropy_bins = 36
def reverse_bearing(x):
return x + 180 if x < 180 else x - 180
def count_and_merge(n, bearings):
n = n * 2
bins = np.arange(n + 1) * 360 / n
count, _ = np.histogram(bearings, bins=bins)
count = np.roll(count, 1)
return count[::2] + count[1::2]
Gu = ox.add_edge_bearings(ox.get_undirected(ox.graph_from_place(query, network_type='drive', simplify=True)))
b = pd.Series([d['bearing'] for u, v, k, d in Gu.edges(keys=True, data=True)])
bearings = pd.concat([b, b.map(reverse_bearing)]).reset_index(drop='True')
bin_counts = count_and_merge(entropy_bins, bearings)
orientation_entropy = stats.entropy(bin_counts)
perfect_grid = [1] * 4 + [0] * (entropy_bins - 4)
min_entropy = stats.entropy(perfect_grid)
max_entropy = np.log(entropy_bins)
orientation_order = 1 - ((orientation_entropy - min_entropy) / (max_entropy - min_entropy)) ** 2
print(orientation_order)
`
#ERROR#
`C:\Anaconda\envs\ox\Lib\site-packages\osmnx\utils.py:192: UserWarning: The `utils.config` function is deprecated and will be removed in a future release. Instead, use the `settings` module directly to configure a global setting's value. For example, `ox.settings.log_console=True`.
warnings.warn(
---------------------------------------------------------------------------
KeyError Traceback (most recent call last)
Cell In[62], line 17
14 return count[::2] + count[1::2]
16 Gu = ox.add_edge_bearings(ox.get_undirected(ox.graph_from_place(query, network_type='drive', simplify=True)))
---> 17 b = pd.Series([d['bearing'] for u, v, k, d in Gu.edges(keys=True, data=True)])
18 bearings = pd.concat([b, b.map(reverse_bearing)]).reset_index(drop='True')
19 bin_counts = count_and_merge(entropy_bins, bearings)
Cell In[62], line 17, in <listcomp>(.0)
14 return count[::2] + count[1::2]
16 Gu = ox.add_edge_bearings(ox.get_undirected(ox.graph_from_place(query, network_type='drive', simplify=True)))
---> 17 b = pd.Series([d['bearing'] for u, v, k, d in Gu.edges(keys=True, data=True)])
18 bearings = pd.concat([b, b.map(reverse_bearing)]).reset_index(drop='True')
19 bin_counts = count_and_merge(entropy_bins, bearings)
KeyError: 'bearing'`