Smart City: Visualizing bike traffic in Münster

Inside.TechLabs
Apr 24 · 11 min read

Urban mobility and increasing traffic are major problems in German cities. This encompasses various forms of traffic like buses, trains, traffic light management and provision of additional parking spaces to name a few. Tracking traffic, predicting future flows and thus providing sufficient resources at an early stage are crucial to tackle those issues. With almost everything involved in traffic creating data and technology as well as software capable of processing that data, data science is the way to create the solutions.

With urban mobility just being one example of application, data science and other digital skills play a central role in the everyday work today and more important in the future. Some might say “coding is the new literacy” (Anna Hülemeier). Making sure students are ready for the tech-driven future is the ambitious goal of TechLabs.

TechLabs is a Münster-based, non-profit organization that enables students regardless of their field of study to develop digital skills and expand their knowledge in coding and tech trends. Participants can choose from three different learning tracks: Web Development, Data Science and Artificial Intelligence. A track consists of different online learning materials put together by experienced students in the respective fields. At the end of a TechLabs semester, the acquired skills and knowledge can be applied in a group project. This blog post is the outcome of such a project, tackling aspects of urban mobility.

Our Team

Our project team consists of five students. Three of us are specialized in Data Science via TechLabs and are studying economics in Münster. The other two expanded their knowledge in Artificial Intelligence and Information Systems students in Münster. This gives us diverse IT skills as some of us have already acquired programming or data science skills during their studies while others brought fresh ideas into the new field.

Traffic in Münster

In the future, trending concepts like e-mobility and car sharing are gaining significance on urban mobility. Currently, though, a growing number of cars, travelers and increasingly congested roads account for the majority of problems in urban mobility. As TechLabs was founded in Münster and our project team consists of students from Münster, our project will be initially focused on Münster.

In comparison to the top jammed cities in Germany Münster is doing okay. Nevertheless, you get frustrated when you are among the 360,000 commuters that squeeze through the streets of Münster every day (https://www.stadt-muenster.de/verkehrsplanung/verkehr-in-zahlen.html). At peak times, there is no getting through at hotspots like the Ludgerikreisel or other main roads. Public transport is not really an option either because buses use the same roads as the commuters.

For people living in Münster, there is really just one option to get fast from A to B. And that is going by bike. Numbers proof that: 400,000 routes are covered by bike per day (https://www.stadtmuenster.de/verkehrsplanung/verkehr-in-zahlen.html). In 2016, 4,105,177 bicycles were recorded at the counting point at the central location Neutor in Münster, which corresponds to an average of 467 bicycles per hour. On Wolbecker Straße, fewer but still 3,589,382 bicycles were recorded in 2016. Münster has earned his name as bike capital of Germany. Bikes are especially popular among students. They are cheap, do not take up much space and you get to everywhere you want in Münster. Bikes are so popular in fact, that they cause traffic jams on bikeways. Approximately 60,500 students are living in Münster which corresponds to around 19 % of the overall population. University buildings and student residences being spread all over Münster, a huge traffic flow of students exists every day.

Our goal

With the bike being the most convenient (and also eco-friendly) alternative to car and bus, it must be assured that using it will remain convenient in the future. You have to get to your destination fast and safe. And with already so many bikes in use and no decrease in sight, that will remain a challenge.

The goal of our project is the identification of bottlenecks in the bike infrastructure in Münster. Therefore, we dealt with the following questions:

  • How are students and university buildings in Münster distributed?
  • Where are the main traffic flows between student residences and university buildings?
  • What are the bottlenecks in the bike infrastructure in Münster?

Inspiration

In our first meeting, we drew inspiration from a resource our mentor provided us with. It was Mark Padgham’s project in the field of planning the future of transport which he presented to the Münster UseR Meeting on November 20, 2018 (https://github.com/mpadge/ms-user-meetup-nov2018). He analyzes randomly distributed points and their traffic connection via bicycle and car. That project became the basis for our project.

As there are differences in the possibilities provided by R and Python, we were hoping to incorporate the specific advantages Python has over R like being able to handle larger datasets as well as the potential to be used beyond basic research analysis.

Project work

Our mentor helped us to find a starting point into the project by giving us advice and useful resources. However, the necessary steps were not obvious to us from the beginning, since neither of us has been involved in a project like this before. Through research and collaboration, we got to our goal step by step.

Getting ready

After setting our goal and getting familiar with the UseR Meeting presentation, we gathered ideas to realize the project. To get a first overview, we determined the main university locations on a Google Map. We then tried to identify where most students are living. Since they are literally everywhere in Münster, we decided to just predefine uni locations and set the starting points of the routes to those places randomly.

Open Street Maps

During the development phase, we heavily relied on Open Street Maps (OSM). It is the main platform we used to visualize Münster’s road network as it is “(…) the most comprehensive street atlas humanity has ever created” (Mark Padgham).

It represents roads and buildings using tags attached to its basic data structures (its nodes, ways, and relations). The tags itself contain a geographic attribute of the subject being shown by that specific node, way or relation.

Users can create their individual keys and locations that are relevant to their projects allowing OSM to be very versatile concerning the means of use. Most features can be described using only a small number of tags, such as a path with a classification tag such as “highway=footway”.

As there are constant updates regarding roads and buildings all over the world, OSM is a very precise and reliable source for the analysis as well as the visualization of projects like “Smart City”. Furthermore, OSM uses the standard ESPG 4326 which is commonly used in cartography. The main servers reside in the University College London (UCL) as well as the Imperial College London (ICL) allowing OSM to be classified as stable and effective.

In order to incorporate Python, the OSMnx package needed to be included as the “Python for street networks (…) [used to] retrieve, model, analyze, and visualize street networks and other spatial data from OpenStreetMap” (gboeing/osmnx). This package was used via the Jupyter Notebook option provided by Anaconda. OSMnx is to be used in combination with geopandas, networkx, and matplotlib in order to construct and analyze street networks. The OSMnx package proved to be rather difficult to install on certain laptops which slowed down the coding process for some of our team members but also resulting in an improved knowledge of the package via intense research on how to install this package as well as the causes for the previously mentioned failure.

Step by step to the solution

We started off the coding phase of the project rather simple with the task of visualizing Münster as a street network. We played around a bit to get familiar with OSM. Because drawing a graph of a whole city takes rather long, we sticked to the “Altstadt” over the next steps.

Next up, we wanted to integrate routes to our project. We took two random nodes of the graph and let Python compute the shortest path between those nodes. We got more specific by defining our own places. Those places not necessarily correlated to nodes of the graph. We had to find the closest nodes to the respective places in order to compute a route. Being able to compute a route between predefined places was the first big achievement of our project.

The next step was to create and display multiple routes in one graph. For the start, we let the routes be created manually. To be able to identify highly frequented streets, we turned down the opacity of the routes to 0.1 (route_alpha=0.1).

It became apparent rather soon that coding each flow individually was the easiest but also the most time consuming way. It was helpful for testing but for our application to be useful we have to create hundreds, or thousands of routes, and hence that has to be done automatically. In order to provide a more efficient solution, a for loop was created. In every iteration on route is created and saved to a list. After all routes have been created, that list was used as an argument in the visualization function of OSMnx.

Being able to efficiently create multiple routes, we then integrated the university locations we determined in the beginning. Therefore, we split up the work, so some of our team translated the places from the Google Map to usable data in Python via the ox.geocode() option while the others continue coding. Those places being the endpoints of our routes, we set the “Dom” in the center of Münster as starting point for testing purposes. Uni buildings being spread all over Münster, we also had to expand the area of the graph to the whole city.

That graph was showing us that we are on the right way to achieve our goal. The only thing missing were realistic starting points for the routes. As said in the beginning, we decided to not predefine those points but want to use random places.

We therefore changed the for loop to take a random point in the graph as starting point and pick one of the university locations randomly as end points. To get a meaningful visualization we played around with the number of routes being created. The for loop gets the number of random points as argument. This number represents the total number of routes which will be created. We ended up with 2000 routes. The resulting graph is the final result of this project.

The individual flows are shown in a rather transparent orange leading to certain streets being richer and darker in colour if several flows prefered the usage of this specific street creating a kind of layering-effect. We opted out of creating a heatmap which would require a specific explanation of the different colours and chose a more user-friendly and self-explaining solution.

At the end of our project we used another package for visualizing the routes. This package is called Folium. In contrast to the previous solution, Folium is an interactive graphic. The biggest problem is that this map can display only a few routes because of its performance.

The final python script can also be applied to other cities with a few changes. Additionally, we can visualize car traffic as well.

The TechLabs Curriculum was based on independent learning and the “hands-on” approach of e.g. the Data Camp courses. Because of this, each of our team members was already used to the general concept of coding in Python and using “trial and error” to determine whether their approach to a certain problem was effective or not. This being said, our problem solving techniques relied heavily on Google searches and the support of our mentors who were always very keen on helping us out while still giving us the freedom to make our own mistakes and learn from them.

The main reason for the Google searches was the specialized package OSMnx. The online courses help us to generate automatically routes.

Difficulties

Using the OSMnx package brought some problems with it. It created an at first unsolvable error that was dealt with in one of our meetings as the specific document in our github folders had to be properly traced back for each one of our team members in order for Jupyter Notebook to find and utilize the correct document. As soon as the proper document was traced back and the “os” package was imported, the code could finally be run properly without producing a “RunTime Error”.

In retrospective, setting up the environment and downloading and installing all the required packages was the most complicated part. That was annoying when we wanted to get going and get stuff done but some installation error or incompatibility kept us from doing so.

Conclusion

Initially our goals were to visualize the distribution of student residences and university buildings, create flows between them and hence identify the main traffic flows, so called bottlenecks in the bike infrastructure.

In the end we were able to achieve all these checkpoints: we’ve created a map of the city centre of Münster, displayed the university buildings and coded random student residences as well as flows between those points.

Our analysis confirmed bottlenecks in the bike infrastructure at places like the “Ludgerikreisel” and “Aegidiimarkt” — much as we expected. Interestingly, the “Promenade” — a street only allowed to be used by bike, is used very little according to our visualization — but empirically it is quite crowded as well.

What happened here — is there a mistake in our analysis? No, since the flows were meant to find the shortest routes. The “Promenade” is most of the time a circuitous way, but still bikers like to use it, because of its beauty and quietness. Thus, the possibility to weight certain routes more heavily would be one way to refine our visualisation and make it even more realistic. Furthermore, this project could be extended to identify bottlenecks in public transport.

Overall TechLabs provided a unique opportunity to strengthen or establish coding and tech skills. Regardless of whether it was ones first contact with coding, or participants already had a decent understanding — with the right amount of ambition everyone was able to make a big step in there Tech-career.

The idea to put the project teams together because of the general interest in the theme and not based on individual tech knowledge showed once more, that initiative and willingness actually decide whether the team succeeds or fails.

TechLabs is not only a great possibility to find a guided entrance into the coding world or efficiently improve ones skills with a hands on learning approach, but also an exceptional chance to experience the strength and drive resulting from a fully committed team.

Team:

Christoph Hoppe

Christopher Eßmann

Marie Landwehr

Ronja Köhling

Simon Röckinghausen (https://www.linkedin.com/simon-roeckinghausen/)

Betreuer: David Middelberg

TechLabs

We Build. Digital. Shapers.

Inside.TechLabs

Written by

Our community Members share their insights into the TechLabs Experience

TechLabs

TechLabs

We Build. Digital. Shapers.

Welcome to a place where words matter. On Medium, smart voices and original ideas take center stage - with no ads in sight. Watch
Follow all the topics you care about, and we’ll deliver the best stories for you to your homepage and inbox. Explore
Get unlimited access to the best stories on Medium — and support writers while you’re at it. Just $5/month. Upgrade