<jupyter_start><jupyter_text>HammThis [Jupyter Notebook](https://jupyter.org/) file is part of the master thesis’ project of [<NAME>](https://www.lucyhenriques.com), which aims to analyse walkability in Hamburg. It uses the [OSMNx](https://github.com/gboeing/osmnx) Python package.The complete research is available at [ResearchGate](https://www.researchgate.net/publication/332496058_The_influence_of_the_built_environment_on_walking_The_further_development_and_application_of_a_walkability_tool_in_a_comparison_study_of_two_selected_neighborhoods_and_the_proposal_of_guidelines_to_fo). Connectivity analysis1. Import the OSMnx and Pandas packages<jupyter_code>import osmnx as ox, pandas as pd

G = ox.graph_from_place('Hamm, Hamburg', network_type='all')
ox.plot_graph(G, save=True, file_format='svg', filename='Hamm')
stats = ox.basic_stats(G, area=3900000)
extended_stats = ox.extended_stats(G, ecc=True, bc=True, cc=True)
for key, value in extended_stats.items():
    stats[key] = value
series = pd.Series(stats)
series.to_csv(path="stats_series.csv")
series<jupyter_output><empty_output><jupyter_text>Street network centrality analysis<jupyter_code>import osmnx as ox
import networkx as nx
import matplotlib.cm as cm
import matplotlib.colors as colors
import pandas as pd
%matplotlib inline
ox.config(log_console=True, use_cache=True)
# download and project a street network
G = ox.graph_from_place('Hamm, Hamburg', network_type='all')
G = ox.project_graph(G)
fig, ax = ox.plot_graph(G, bgcolor='k', node_size=30, node_color='#999999', node_edgecolor='none', node_zorder=2,
                        edge_color='#555555', edge_linewidth=1.5, edge_alpha=1)<jupyter_output><empty_output><jupyter_text>Calculate and visualize node centrality<jupyter_code># node closeness centrality
node_centrality = nx.closeness_centrality(G)
# plot it
df = pd.DataFrame(data=pd.Series(node_centrality).sort_values(), columns=['cc'])
df['colors'] = ox.get_colors(n=len(df), cmap='inferno', start=0.2)
df = df.reindex(G.nodes())
nc = df['colors'].tolist()
fig, ax = ox.plot_graph(G, bgcolor='k', node_size=30, node_color=nc, node_edgecolor='none', node_zorder=2,
                        edge_color='#555555', edge_linewidth=1.5, edge_alpha=1)<jupyter_output><empty_output><jupyter_text>Calculate and visualize edge centrality<jupyter_code># 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 orginal 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]

# color the edges in the original graph with closeness 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, file_format='png', filename='hamm02', save=True)<jupyter_output><empty_output><jupyter_text>Building footprint (plus street network) figure-ground diagrams<jupyter_code>import osmnx as ox
from IPython.display import Image
%matplotlib inline
ox.config(log_file=True, log_console=True, use_cache=True)
# configure the inline image display
img_folder = 'images'
extension = 'svg'
size = 2000<jupyter_output><empty_output><jupyter_text>Building footprints within the boundaries of Hamm, Hamburg<jupyter_code>gdf = ox.buildings_from_place(place='Hamm, Hamburg')
gdf_proj = ox.project_gdf(gdf)
fig, ax = ox.plot_buildings(gdf_proj, bgcolor='#333333', color='w', 
                            save=True, show=False, close=True, filename='hamm_bldgs', dpi=300)
Image('{}/{}.{}'.format(img_folder, 'hamm_bldgs', extension), height=size, width=size)
# calculate the area in projected units (meters) of each building footprint, then display first five
areas = gdf_proj.area
areas.head()
# total area (sq m) covered by building footprints
sum(areas)
# get the total area within hamm's admin boundary in sq meters
place = ox.gdf_from_place('Hamm, Hamburg')
place_proj = ox.project_gdf(place)
place_proj.area.iloc[0]
# what proportion of Hamm is covered by building footprints?
sum(areas) / place_proj.area.iloc[0]<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.11664392905866303, 'fraction_numerical': 0.01682582992269213, 'mean_word_length': 6.5975820379965455, 'pattern_counts': {'":': 0, '<': 26, '<?xml version=': 0, '>': 26, 'https://': 4, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 1, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '6', 'dir': 'jupyter-structured-clean-dedup', 'id': '487120', 'license': 'MIT', 'n_tokens_mistral': 1578, 'n_tokens_neox': 1490, 'n_words': 353, 'path': 'Hamm.ipynb', 'repo_name': 'lucyhenriques/connectivityanalysis', 'size': '4406'}