Image for post
Image for post

How to Quantify the Impact of COVID-19 Measures on Urban Density? A data-driven approach with Python and REST APIs

To slow down the spread of COVID-19, governments introduced public health strategies such as social distancing and mobility restrictions. Enforcing mobility restrictions is one of the top strategies because it has a direct impact on the evolution of number of cases: it flattens the peak of the curve and delays it.

In such conditions, it is more critical than ever to quickly have feedback from the field with the relevant data in time: what is the actual impact of these decisions on collective mobility ? Does it match the desired outcome, or should stricter measures be introduced?

In this article, we will show you how to Swisscom heatmaps REST API to quantify the urban density evolution for any time period and geographical region in Switzerland, with a focus on COVID-19 period. The Python code is available on GitHub.

Rail vs. Airline

  • We define the density variation for a given day as the percentage of variation with respect to the baseline. We define the baseline as the median density, for the corresponding day of the week, during the month of January 2020.
Image for post
Image for post
Density evolution for the postal code 8001 associated with the train station of Zurich
Image for post
Image for post
Density evolution for the postal code 1215 associated with Geneva airport
  • We observe an important decrease in density just after the federal measures of March 13 with a maximum decrease of ~80% for the train station of Zurich and of more than 90% for Geneva airport.
  • In the weeks following the measures, the density progressively increased but is still far from its usual level (~-25% for Zurich train station in August vs. ~-50% for Geneva airport for the same month).
  • This also confirms that the impact of the pandemic is more important on the airline industry than on the rail industry. Naturally, in order to measure more accurately this trend, we would need to run the same analysis for all train stations and all airports of Switzerland.

How to produce these plots for any region in Switzerland?

If you only register to the API demo plan we recommend one of these two options:

  • [Easiest] Start with this code that allows for getting the hourly density evolution for any postal code.
  • Modify the code below in order to focus your analysis of density evolution on the 24 hours associated with the available day (27 Jan. 2020).

If you register to the API standard plan the connection to the API is straighforward and is done with a few lines of code

The connection to the API is straighforward and is done with a few lines of code. The client_id and client_secret are obtained once you register to the heatmaps API

The function get_tile_ids_postal_code returns the tile ids associated with a given postal code. To increase code simplicity and redability, we choose to randomly sample from these tile ids the maximum number of tiles (100) we can query in only one API call.

The function build_api_query returns the API request needed to get the data associated with a given list of tiles for a given date. We use it in the function get_daily_density to query the API and get the sum of density scores associated with the given list of tiles.

We share in Github the code used to generate the plots shown in this article.

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store