Zones

class pyspainmobility.zones.zones.Zones(zones: str = None, version: int = 1, output_directory: str = None)[source]
__init__(zones: str = None, version: int = 1, 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]

TODO

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