4th Jun, 2021Gareth Simons

The cityseer Python package for pedestrian-scale network-based urban analysis

Online documentation is available from cityseer.benchmarkurbanism.com and the github repository is available at github.com/benchmark-urbanism/cityseer-api. See this blog post for some background reading on how the package came about.

Abstract

cityseer-api is a Python package consisting of computational tools for fine-grained street network and land-use analysis, helpful in assessing the morphological precursors to vibrant neighbourhoods. It is underpinned by network-based methods developed from the ground-up for localised urban analysis at the pedestrian scale to provide contextually specific metrics for any given street-front location. cityseer-api computes a variety of node or segment-based network centrality methods, land-use accessibility and mixed-use measures, and statistical aggregations. Aggregations are computed dynamically — directly over the street network while taking the direction of approach into account — and can optionally incorporate spatial impedances and network decomposition to accentuate spatial precision. The use of Python facilitates compatibility with popular computational tools for network manipulation (NetworkX), geospatial topology (shapely), and the numpy stack of scientific packages. The provision of graph cleaning tools aids the incorporation of Open Street Map derived network topologies. Underlying loop-intensive algorithms are implemented in NumbaJIT compiled code so that the methods scale efficiently to larger networks.

Overview

cityseer-api is a network-based spatial analysis package for contextually precise urban analytic workflows. The implemented methods are primarily intended for application at pedestrian walking tolerances, commonly up to 800m and infrequently exceeding 1600m. cityseer-api provides distance-weighted metrics that can — optionally — be combined with network ‘decomposition’ to generate observations at an exceptionally high spatial resolution. These forms of contextually sensitive urban analytic workflows aid the comparative analysis of urban development while providing a tool to gauge the impact of design decisions on considerations such as walkability or pedestrian accessibility to land-uses for a given location.

Computational methods for network-based centrality and land-use analysis rely extensively on shortest-path algorithms, presenting substantial computational complexity due to nested computational loops. Pure Python network-based measures, such as those implemented in NetworkX1, can consequently become prohibitively slow if applied to street networks for larger towns and cities. Computational speed improvements can be attained through the use of Python packages such as Graph-Tool2, which wrap underlying optimised C or C++ code libraries, and this was the approach adopted by the author before the development of cityseer-api. Nevertheless, whereas high-performance graph-analysis packages can be co-opted for generic forms of network analysis, they do not necessarily offer the degree of extensibility required for convenient experimentation with the underlying algorithmic considerations more specific to analytics from an urbanist’s perspective. Accordingly, attempts to co-opt existing off-the-shelf packages for unanticipated purposes incurs a sufficient degree of code complexity to create a bottleneck to furthered development while causing computational speed advantages to dissipate. This conundrum prompted the development of the codebase that has become formalised as the cityseer-api package, adopting an approach leveraging pure Python and NumPy3, but with computationally intensive algorithms optimised through use of NumbaJIT (just-in-time) compilation4. This strategy allows for wide-ranging experimentation and the ensuing customisation of underlying algorithms, thereby facilitating code abstraction, reducing duplicitous code, improving code maintenance through ongoing development and upgrade cycles, and adopting paradigms specifically suited to pedestrian-scale urban analysis. This approach has allowed for a range of particular issues to be addressed:

  • Localised analysis is based on network methods applied over the graph through means of a ‘moving-window’, whereby the graph is isolated at specified distance thresholds before localised analysis of the currently windowed node’s context. These thresholds are conventionally based on either crow-flies euclidean distances or actual network distances5. cityseer-api takes the position that true network distances are more representative when working at smaller pedestrian distance thresholds, particularly when applied to land-use accessibilities and mixed-use calculations;
  • It is common to use either shortest-distance or simplest-path (shortest angular ‘distance’) impedance heuristics. When using simplest-path heuristics, it is necessary to modify the underlying shortest-path algorithms to prevent side-stepping of sharp angular turns; otherwise, two smaller side-steps can be combined to ‘short-cut’ sharp corners6. It is also common for methods to be applied to either primal graph representations, generally used with shortest-path methods such as those applied by multiple centrality assessment analysis7, or dual graph representations, typically used with simplest-path methods in the tradition of space syntax8;
  • There is a range of possible centrality and mixed-use methods, many of which can be weighted by distances or street lengths. Some conventional methods, even if widely used, have not necessarily proved suitable for localised urban network analysis workflows: for example, conventional formulations of closeness centrality do not behave as anticipated on windowed graphs, and mixed-use analysis methods utilising larger-scale zoned or gridded aggregations are problematic if interpreted at the scale of streets. These methods and their implications are explored in detail in related papers on centrality methods and mixed-use methods;
  • Centrality methods are susceptible to topological distortions arising from ‘messy’ graph representations as well as due to the conflation of topological and geometrical properties of street networks. cityseer-api addresses these through the inclusion of graph cleaning functions; procedures for splitting geometrical properties from topological representations; and the inclusion of segmented centrality measures, which are less susceptible to distortions introduced by varying intensities of nodes;
  • Pedestrian-scale analysis requires approaches facilitating the evaluation of respective measures at finely-spaced intervals along street fronts. Further, granular evaluation of land-use accessibilities and mixed-uses requires that land-uses be assigned to the street network in a contextually precise manner. These are addressed in cityseer-api through the application of network decomposition combined with algorithms allowing for bidirectional assignment and aggregation of data points to network nodes based on the closest adjacent street edge and the direction of approach.

cityseer-api includes a variety of convenience methods for the general preparation of networks and their conversion into (and out of) the lower-level data structures used by the underlying algorithms. These graph utility methods are designed to work with NetworkX to facilitate ease of use. Broad overviews of these methods and how they can be used as part of typical workflows are provided in the paper, and in the detailed package documentation directly available at cityseer.benchmarkurbanism.com.

A complement of code tests maintains the integrity of the code-base through general package maintenance and upgrade cycles and, as of the time of writing, is based on Python 3.9. Shortest-path algorithms, harmonic closeness, and betweenness algorithms are tested against NetworkX. Mock data and test plots have been used to visually confirm the intended behaviour for divergent simplest and shortest-path heuristics and for testing the assignment of data points to nearby network nodes given various scenarios.

Please see the linked preprint paper for additional information.


  1. 1. Hagberg AA, Schult DA, Swart PJ. Exploring Network Structure, Dynamics, and Function using NetworkX. In: Varoquaux G, Vaught T, Millman J, editors. Proceedings of the 7th Python in Science Conference. Pasadena, CA USA; 2008. p. 11–5.
  2. 2. Peixoto TP. The graph-tool python library. figshare [Internet]. 2014; Available from: http://figshare.com/articles/graph%7B%5C_%7Dtool/1164194
  3. 3. Harris CR, Millman KJ, van der Walt SJ, Gommers R, Virtanen P, Cournapeau D, et al. Array programming with NumPy. Nature [Internet]. 2020 Sep;585(7825):357–62. Available from: http://www.nature.com/articles/s41586-020-2649-2
  4. 4. Lam SK, Pitrou A, Seibert S. Numba: a LLVM-based Python JIT compiler. In: Proceedings of the Second Workshop on the LLVM Compiler Infrastructure in HPC [Internet]. Austin Texas: ACM Press; 2015. p. 1–6. Available from: http://dl.acm.org/citation.cfm?doid=2833157.2833162
  5. 5. Cooper CHV. Spatial localization of closeness and betweenness measures: a self-contradictory but useful form of network analysis. International Journal of Geographical Information Science [Internet]. 2015;29(8):1293–309. Available from: https://www.tandfonline.com/doi/pdf/10.1080/13658816.2015.1018834?needAccess=true
  6. 6. Turner A. From axial to road-centre lines: a new representation for space syntax and a new model of route choice for transport network analysis. Environment and Planning B: Planning and Design [Internet]. 2007;34:539–55. Available from: http://journals.sagepub.com/doi/pdf/10.1068/b32067
  7. 7. Porta S, Crucitti P, Latora V. The Network Analysis of Urban Streets: A Primal Approach. Environment and Planning B: Planning and Design [Internet]. 2006;33:705–25. Available from: http://journals.sagepub.com/doi/pdf/10.1068/b32045
  8. 8. Hillier B, Hanson J. The Social Logic of Space. Cambridge: Cambridge University Press; 1984.