Zones¶
- class pyspainmobility.zones.zones.Zones(zones: str = 'municipalities', version: int = 2, output_directory: str = None)[source]¶
- __init__(zones: str = 'municipalities', version: int = 2, output_directory: str = None)[source]¶
Class to handle the zoning related to the Spanish big mobility data. The class is used to download the data and process it. Selectable granularities are districts (distritos), municipalities (municipios) and large urban areas (grandes áreas urbanas). As a reminder, mobility data for the COVID-19 period (version 1) are not available for the large urban areas.
- Parameters:
zones (str) – The zones to download the data for. Default is municipalities. Zones must be one of the following: districts, dist, distr, distritos, municipalities, muni, municipal, municipios, lua, large_urban_areas, gau, gaus, grandes_areas_urbanas
version (int) – The version of the data to download. Default is 2. Version must be 1 or 2. Version 1 contains the data from 2020 to 2021. Version 2 contains the data from 2022 onwards.
output_directory (str) – The directory to save the raw data and the processed parquet. Default is None. If not specified, the data will be saved in a folder named ‘data’ in user’s home directory.
Examples
>>> from pyspainmobility import Zones >>> # instantiate the object >>> zones = Zones(zones='municipalities', version=2, output_directory='data') >>> # get the geodataframe with the zones >>> gdf = zones.get_zone_geodataframe() >>> print(gdf.head()) name population ID 01001 Alegría-Dulantzi 2925.0 01002 Amurrio 10307.0 01004_AM Artziniega agregacion de municipios 3005.0 01009_AM Asparrena agregacion de municipios 4599.0
- get_zone_geodataframe()[source]¶
Function that returns the geodataframe with the zones. The geodataframe contains the following columns: - id: the id of the zone - name: the name of the zone - population: the population of the zone (if available)
Examples
>>> from pyspainmobility import Zones >>> # instantiate the object >>> zones = Zones(zones='municipalities', version=2, output_directory='data') >>> # get the geodataframe with the zones >>> gdf = zones.get_zone_geodataframe() >>> print(gdf.head()) name population ID 01001 Alegría-Dulantzi 2925.0 01002 Amurrio 10307.0 01004_AM Artziniega agregacion de municipios 3005.0 01009_AM Asparrena agregacion de municipios 4599.0
- get_zone_relations()[source]¶
Return official mapping tables between INE administrative units and MITMA zoning identifiers.
For version 2, the returned table includes one row per relation entry with harmonized column names. For version 1, the method returns one row per MITMA zone id, where each relation column contains the set of linked INE identifiers.
- Parameters:
None
- Returns:
Relation table between census/municipality identifiers and MITMA zoning identifiers.
- Return type:
Examples
>>> from pyspainmobility import Zones >>> zones = Zones(zones='municipalities', version=2, output_directory='data') >>> rel = zones.get_zone_relations() >>> rel.columns.tolist() ['census_sections', 'census_districts', 'municipalities', 'municipalities_mitma', 'districts_mitma', 'luas_mitma']