Skip to content

Functions

Table of the available datasets: name, description, source and whether it comes with the package or is downloaded the first time it is used.

Load a dataset by its name in popmex (R).

Parameters:

Name Type Description Default
dataset str

"pop2000", "pop2010", "pop2020", "conapop", "hdx_pop2021", "hdx_pop2022" or "hdx_pop2023" (see :func:datasets).

required
cve_edo (str, int or list)

INEGI state key(s) to keep only the municipalities of those states (municipal tables only).

None

Returns:

Type Description
DataFrame or GeoDataFrame

The municipal tables have the municipality key (CVEGEO; cvegeo in conapop) as text with its leading zero. The hexagons are a GeoDataFrame in EPSG:4326 with population (and h3 in 2022 and 2023).

Population of one or several localities in 400 m H3 hexagons.

Selects the hexagons of the Kontur/HDX population dataset of the year that intersect the localities. The boundaries of the localities (INEGI 2019) come from rgeomex <https://fdzul.github.io/rgeomex-py/>_, which must be installed (pip install git+https://github.com/fdzul/rgeomex-py).

Parameters:

Name Type Description Default
year (2021, 2022, 2023)
2021
cve_edo str or int

INEGI state key, e.g. "31" (Yucatán).

None
locality str or list of str

Name or names of the localities; the names do not need to be exact ("Merida" finds "Mérida").

None

Returns:

Type Description
GeoDataFrame

The hexagons (EPSG:4326) that intersect the localities, with their population.

Examples:

>>> import popmex
>>> merida = popmex.extract_pop(2023, cve_edo="31", locality=["Merida", "Uman", "Kanasin"])
>>> merida["population"].sum()

Rate per per inhabitants (100,000 by default): cases / population * per.

Works with numbers or with pandas columns (aligned by index); a population of 0 gives NaN instead of infinity.

Download (only the first time) the LandScan population raster of Mexico.

The GeoTIFF (about 41 MB, 1 km, EPSG:4326) is the same file used by popmex (R): one band per year (pop_2000 ... pop_2024, pop_2026) with the estimated population of each cell. It is downloaded from the data-v1 release, verified with its SHA-256 and kept in the local cache, so later calls read it from disk.

Parameters:

Name Type Description Default
refresh bool

Download the file again even if it is in the cache.

False

Returns:

Type Description
Path

Path of the GeoTIFF, to open with rasterio or rioxarray, e.g. rasterio.open(popmex.get_landscan()).

Notes

Cite the LandScan edition you use, e.g. Sims K, et al. (2023). LandScan Global 2022 [Data set]. Oak Ridge National Laboratory. https://doi.org/10.48690/1529167

Years of the bands of the LandScan raster.

Population of LandScan inside each polygon (sum of its 1 km cells).

A cell is counted in a polygon when its centre falls inside it, so small polygons (an AGEB, a block) can get 0; LandScan is meant for municipalities, localities or larger areas.

Parameters:

Name Type Description Default
gdf GeoDataFrame

Polygons, e.g. the municipalities of rgeomex.

required
year int

Year of the band (see :func:landscan_years).

required
id_col str

Column with the identifier of each polygon.

required

Returns:

Type Description
DataFrame

id_col and population (LandScan of the year).

Examples:

>>> import rgeomex, popmex
>>> mun = rgeomex.load("AGEM_inegi19_mx", cve_edo="31")
>>> popmex.landscan_population(mun, year=2020, id_col="CVEGEO")

Folder where the downloaded files are kept.

Delete the downloaded files (they are downloaded again when needed).