Abstract
pySpainMobility is an open-source Python package designed to streamline access to high-resolution human mobility datasets from the Spanish government. By providing a standardized API for downloading and processing data from over 13 million users, the tool facilitates reproducible research in urban planning, epidemiology, and transportation by automating data retrieval, preprocessing, and spatial hierarchy management.
Introduction
Understanding human mobility is essential for addressing societal challenges like disease modeling and transit optimization. However, high-quality mobility data is often proprietary or difficult to process. The Spanish Ministry of Transport and Sustainable Mobility has released detailed daily mobility data, but the raw data is technically challenging to handle across various scales. pySpainMobility addresses this by offering a Python library that simplifies fetching, standardizing, and analyzing this national dataset.
System Architecture and Methodology
Rather than introducing a new algorithm, pySpainMobility provides a software engineering solution to data fragmentation. The package utilizes a modular API to abstract data collection and harmonization. Key features include automated retrieval and preprocessing, converting raw government data into compressed Parquet files optimized for scalable analysis.
Data Management and Spatial Hierarchy
The library interfaces with the official open data portal of the Spanish Ministry of Transport and Sustainable Mobility, accessing data representing over 13 million users. A core strength of the package is its spatial hierarchy management. It fetches official geographic boundaries for three levels of granularity: districts, municipalities, and larger urban areas. Built-in mapping tables allow researchers to translate identifiers across these schemes, facilitating the integration of mobility data with external census or economic datasets.
Key Insights and Results
The authors demonstrate the library's utility through several use cases:
- Temporal Rhythms: Weekday flows from Madrid average ~11,600 trips to ~1,970 destinations, while weekends see higher volume (~14,300 trips) but fewer unique destinations (~1,500).
- Demographic Disparities: In Barcelona, high-income earners (>€15k) take substantially more trips than lower-income earners (<€7k), highlighting socioeconomic mobility gaps.
- Tourism Mapping: Overnight stay data from August accurately maps the saturation of the Spanish coast and Canary Islands, providing a proxy for seasonal population shifts.
Conclusion and Future Work
While the data relies on mobile phone traces—which may underrepresent children, the elderly, or international tourists—pySpainMobility significantly lowers the barrier to entry for large-scale mobility research. Future development will focus on integrating contextual data layers, such as land use and public transit infrastructure, and adding support for interactive spatial visualizations and advanced modeling frameworks.
Summary updated