Get Even More Visitors To Your Blog, Upgrade To A Business Listing >>

Urban Accessibility — How to Reach Defibrillators on Time | by Milan Janosov | Oct, 2023

Sed ut perspiciatis unde. The root of urban Accessibility, or walkability, lies in a graph-based computation measuring the Euclidean distance (transforming it into walking minutes, assuming constant speed and no traffic jams and obstacles). The results of such analyses can tell us how easy it is to reach specific types of amenities from every single location within the city. To be more precise, from every single node within the city’s road network, but due to a large number of road crossings, this approximation is mostly negligible.In this current case study, I focus on one particular type of Point of Interest (POI): the location of defibrillator devices. While the Austrian Government’s Open Data Portal shares official records on this, in Hungary, I could only obtain a less-then-half coverage crowd-sourced data set — which, hopefully, will later grow both in absolute size and data coverage.In the first section of my article, I will create the accessibility map for each city, visualizing the time needed to reach the nearest defibrillator units within a range of 2.5km at a running speed of 15km/h. Then, I will split the cities into hexagon grids using Uber’s H3 library to compute the average defibrillator-accessibility time for each Grid cell. I also estimate the Population level at each hexagon cell following my previous article. Finally, I combine these and compute the fraction of the population reachable as a function of reachability (running) time.As a disclaimer, I want to emphasize that I am not a trained medical expert by any means — and I do not intend to take a stand on the importance of defibrillator devices compared to other means of life support. However, building on common sense and urban planning principles, I assume that the easier it is to reach such devices, the better.As always, I like to start by exploring the data types I use. First, I will collect the administrative boundaries of the cities I study in — Budapest, Hungary, and Vienna, Austria.Then, building on a previous article of mine on how to process rasterized population data, I add city-level population information from the WorldPop hub. Finally, I incorporate official governmental data on defibrillator devices in Vienna and my own web-scraped version of the same, though crowded sources and intrinsically incomplete, for Budapest.1.1. Administrative boundariesFirst, I query the admin boundaries of Budapest and Vienna from OpenStreetMap using the OSMNx library:admin = {}cities = ['Budapest', 'Vienna']f, ax = plt.subplots(1,2, figsize = (15,5))# visualize the admin boundariesfor idx, city in enumerate(cities):admin[city] = ox.geocode_to_gdf(city)admin[city].plot(ax=ax[idx],color='none',edgecolor= 'k', linewidth = 2) ax[idx].set_title(city, fontsize = 16)The result of this code block:1.2. Population dataSecond, following the steps in this article, I created the population grid in vector data format for both cities, building on the WorldPop online Demographic Database. Without repeating the steps, I just read in the output files of that process containing population information for these cities.Also, to make things look nice, I created a colormap from the color of 2022, Very Peri, using Matplotlib and a quick script from ChatGPT.very_peri = '#8C6BF3' second_color = '#6BAB55' colors = [second_color, very_peri ]n_bins = 100cmap_name = "VeryPeri"colormap = LinearSegmentedColormap.from_list(cmap_name, colors, N=n_bins)demographics = {}f, ax = plt.subplots(1,2, figsize = (15,5))for idx, city in enumerate(cities):demographics[city] = gpd.read_file(city.lower() + \'_population_grid.geojson')[['population', 'geometry']]admin[city].plot(ax=ax[idx], color = 'none', edgecolor = 'k', \linewidth = 3)demographics[city].plot(column = 'population', cmap = colormap, \ax=ax[idx], alpha = 0.9, markersize = 0.25)ax[idx].set_title(city)ax[idx].set_title('Population density\n in ' + city, fontsize = 16)ax[idx].axis('off')The result of this code block:1.3. Defibrillator locationsThird, I collected locational data on the available defibrillators in both cities.For Vienna, I downloaded this data set from the official open data portal of the Austrian government containing the point location of 1044 units:While such an official open data portal does not exist in Budapest/Hungary, the Hungarian National Heart Foundation runs a crowd-sourced website where operators can update the location of their defibrillator units. Their country-wide database consists of 677 units; however, their disclaimer says they know about at least one thousand units operating in the country — and are waiting for their owners to upload them. With a simple web crawler, I downloaded the location of each of the 677 registered units and filtered the data set down to those in Budapest, resulting in a set of 148 units.gdf_units['Vienna'] = gpd.read_file('DEFIBRILLATOROGD')gdf_units['Budapest'] = gpd.read_file('budapest_defibrillator.geojson')for city in cities:gdf_units[city] = gpd.overlay(gdf_units[city], admin[city])# visualize the unitsf, ax = plt.subplots(1,2, figsize = (15,5))for idx, city in enumerate(cities):admin[city].plot(ax=ax[idx],color='none',edgecolor= 'k', linewidth = 3)gdf_units[city].plot( ax=ax[idx], alpha = 0.9, color = very_peri, \markersize = 6.0)ax[idx].set_title('Locations of defibrillator\ndevices in ' + city, \fontsize = 16)ax[idx].axis('off')The result of this code block:Next, I wrapped up this great article written by Nick Jones in 2018 on how to compute pedestrian accessibility:def get_city_accessibility(admin, POIs):# walkability parameterswalkingspeed_kmh = 15walkingspeed_mm = walkingspeed_kmh * 1000 / 60distance = 2500# bounding box as a list of llcrnrlat, llcrnrlng, urcrnrlat, urcrnrlngminx, miny, maxx, maxy = admin.bounds.T[0].to_list()bbox = [miny, minx, maxy, maxx]# setting the input params, going for the nearest POInum_pois = 1num_categories = 1bbox_string = '_'.join([str(x) for x in bbox])net_filename = 'data/network_{}.h5'.format(bbox_string)if not os.path.exists('data'): os.makedirs('data')# precomputing nework distancesif os.path.isfile(net_filename):# if a street network file already exists, just load the dataset from thatnetwork = pandana.network.Network.from_hdf5(net_filename)method = 'loaded from HDF5'else:# otherwise, query the OSM API for the street network within the specified bounding boxnetwork = osm.pdna_network_from_bbox(bbox[0], bbox[1], bbox[2], bbox[3])method = 'downloaded from OSM'# identify nodes that are connected to fewer than some threshold of other nodes within a given distancelcn = network.low_connectivity_nodes(impedance=1000, count=10, imp_name='distance')network.save_hdf5(net_filename, rm_nodes=lcn) #remove low-connectivity nodes and save to h5# precomputes the range queries (the reachable nodes within this maximum distance)# so, as long as you use a smaller distance, cached results will be usednetwork.precompute(distance + 1)# compute accessibilities on POIspois = POIs.copy()pois['lon'] = pois.geometry.apply(lambda g: g.x)pois['lat'] = pois.geometry.apply(lambda g: g.y)pois = pois.drop(columns = ['geometry'])network.init_pois(num_categories=num_categories, max_dist=distance, max_pois=num_pois)network.set_pois(category='all', x_col=pois['lon'], y_col=pois['lat'])# searches for the n nearest amenities (of all types) to each node in the networkall_access = network.nearest_pois(distance=distance, category='all', num_pois=num_pois)# transform the results into a geodataframenodes = network.nodes_dfnodes_acc = nodes.merge(all_access[[1]], left_index = True, right_index = True).rename(columns = {1 : 'distance'})nodes_acc['time'] = nodes_acc.distance / walkingspeed_mmxs = list(nodes_acc.x)ys = list(nodes_acc.y)nodes_acc['geometry'] = [Point(xs[i], ys[i]) for i in range(len(xs))]nodes_acc = gpd.GeoDataFrame(nodes_acc)nodes_acc = gpd.overlay(nodes_acc, admin)nodes_acc[['time', 'geometry']].to_file(city + '_accessibility.geojson', driver = 'GeoJSON')return nodes_acc[['time', 'geometry']]accessibilities = {}for city in cities:accessibilities[city] = get_city_accessibility(admin[city], gdf_units[city])This code block outputs the number of road network nodes in Budapest (116,056) and in Vienna (148,212).Now visualize the accessibility maps:This code block outputs the following figures:At this point, I have both the population and the accessibility data; I just have to bring them together. The only trick is that their spatial units differ:While rehabilitating the original raster grid may be an option, in the hope of a more pronounced universality (and adding a bit of my personal taste), I now map these two types of point data sets into the H3 grid system of Uber for those who haven’t used it before, for now, its enough to know that it’s an elegant, efficient spacial indexing system using hexagon tiles. And for more reading, hit this link!3.1. Creating H3 cellsFirst, put together a function that splits a city into hexagons at any given resolution:def split_admin_boundary_to_hexagons(admin_gdf, resolution):coords = list(admin_gdf.geometry.to_list()[0].exterior.coords)admin_geojson = {"type": "Polygon", "coordinates": [coords]}hexagons = h3.polyfill(admin_geojson, resolution, \geo_json_conformant=True)hexagon_geometries = {hex_id : Polygon(h3.h3_to_geo_boundary(hex_id, \geo_json=True)) for hex_id in hexagons}return gpd.GeoDataFrame(hexagon_geometries.items(), columns = ['hex_id', 'geometry'])resolution = 8 hexagons_gdf = split_admin_boundary_to_hexagons(admin[city], resolution)hexagons_gdf.plot()The result of this code block:Now, see a few different resolutions:admin_h3 = {}for city in cities:admin_h3[city] = split_admin_boundary_to_hexagons(admin[city], resolution)f, ax = plt.subplots(1,2, figsize = (15,5))for idx, city in enumerate(cities):admin[city].plot(ax=ax[idx], color = 'none', edgecolor = 'k', \linewidth = 3)admin_h3[city].plot( ax=ax[idx], alpha = 0.8, edgecolor = 'k', \color = 'none')ax[idx].set_title(city + ' (resolution = '+str(resolution)+')', \fontsize = 14)ax[idx].axis('off')The result of this code block:Let’s keep resolution 9!3.2. Map values into h3 cellsNow, I have both our cities in a hexagon grid format. Next, I shall map the population and accessibility data into the hexagon cells based on which grid cells each point geometry falls into. For this, the sjoin function of GeoPandasa, doing a nice spatial joint, is a good choice.Additionally, as we have more than 100k road network nodes in each city and thousands of population grid centroids, most likely, there will be multiple POIs mapped into each hexagon grid cell. Therefore, aggregation will be needed. As the population is an additive quantity, I will aggregate population levels within the same hexagon by summing them up. However, accessibility is not extensive, so I would instead compute the average defibrillator accessibility time for each tile.for city in cities:# do the spatial join, aggregate on the population level of each \# hexagon, and then map these population values to the grid idsdemographics_dict = gpd.sjoin(admin_h3[city], demographics[city]).groupby(by = 'hex_id').sum('population').to_dict()['population']demographics_h3[city] = admin_h3[city].copy()demographics_h3[city]['population'] = demographics_h3[city].hex_id.map(demographics_dict)# do the spatial join, aggregate on the population level by averaging # accessiblity times within each hexagon, and then map these time score # to the grid idsaccessibility_dict = gpd.sjoin(admin_h3[city], accessibilities[city]).groupby(by = 'hex_id').mean('time').to_dict()['time']accessibility_h3[city] = admin_h3[city].copy()accessibility_h3[city]['time'] = \accessibility_h3[city].hex_id.map(accessibility_dict)# now show the resultsf, ax = plt.subplots(2,1,figsize = (15,15))demographics_h3[city].plot(column = 'population', legend = True, \cmap = colormap, ax=ax[0], alpha = 0.9, markersize = 0.25)accessibility_h3[city].plot(column = 'time', cmap = 'RdYlGn_r', \legend = True, ax = ax[1])ax[0].set_title('Population level\n in ' + city, fontsize = 16)ax[1].set_title('Defibrillator reachability time\n in ' + city, \fontsize = 16)for ax_i in ax: ax_i.axis('off')The results of this code block are the following figures:In this final step, I will estimate the fraction of the reachable population from the nearest defibrillator unit within a certain amount of time. Here, I still build on the relatively fast 15km/h running pace and the 2.5km distance limit.From the technical perspective, I merge the H3-level population and accessibility time data frames and then do a simple thresholding on the time dimension and a sum on the population dimension.for idx, city in enumerate(cities):total_pop = demographics_h3[city].population.sum()merged = demographics_h3[city].merge(accessibility_h3[city].drop(columns =\['geometry']), left_on = 'hex_id', right_on = 'hex_id')time_thresholds = range(10)population_reached = [100*merged[merged.time



This post first appeared on VedVyas Articles, please read the originial post: here

Share the post

Urban Accessibility — How to Reach Defibrillators on Time | by Milan Janosov | Oct, 2023

×

Subscribe to Vedvyas Articles

Get updates delivered right to your inbox!

Thank you for your subscription

×