Skip to content

pycensus.census.worldwide.worldpop.loader

Loader for WorldPop gridded population/age-sex-structure rasters.

Downloads WorldPop rasters (https://www.worldpop.org/, REST API: https://www.worldpop.org/sdi/introapi) for a given area of interest and year. Unlike pyCensus' vector/tabular sources (e.g. :mod:pycensus.usa.acs), WorldPop ships gridded raster data, so every download_*/fetch_* function here returns a filesystem path to a downloaded/derived GeoTIFF rather than a GeoDataFrame -- callers that need a :class:geopandas.GeoDataFrame (e.g. for :meth:geohierarchy.GeoHierarchy.add_level) are expected to vectorize/sample the raster themselves and expose the result through the worldpop accessor registered in :mod:pycensus.census.worldwide.worldpop.schema.

Technical aspects

WorldPop publishes population data across several REST-queryable dataset families (https://hub.worldpop.org/rest/data). Two are wired up here, both real, verified live 2026-08-20:

  • pop (subset G2_CN_POP_R25A_{resolution}): a single total- population GeoTIFF per country/year, covering 2015-2030. This is :func:download_worldpop_population's default path.
  • age_structures (subset G2_CN_Age_R25A_{resolution}): the full age-and-sex-disaggregated breakdown per country/year, also covering 2015-2030 -- one GeoTIFF per (sex, 5-year age bin) plus two pre-aggregated total-by-sex files (T_M/T_F). Age bins are 00 (age 0), 01 (ages 1-4), then 5-year bins 05, 10, 15, ..., 90 (90+). :func:download_worldpop_layer builds :data:GLOBAL_SCHEMA_FEATURES from this family:

  • malePopulation/femalePopulation: the T_M/T_F files directly -- no band math, exact (not an approximation).

  • over65Population: sum of bins 65..90 -- exact, since WorldPop's bin boundaries happen to include 65.
  • under18Population: sum of bins 00,01,05,10 (ages 0-14) plus 0.6x of bin 15 (ages 15-19), the linear- within-bin share that falls under 18 (ages 15-17 = 3 of the bin's 5 years). WorldPop's per-year age-sex product has no dataset with an exact 18-year cutoff for years other than 2015 (a one-off, separately-published under_18/U18 subset exists, but only for 2015 -- verified live, its popyear is always "2015" regardless of the requested year). This is a documented linear- interpolation approximation, not an exact figure.
  • adultPopulation: total population (sum of all t_XX bins) minus under18Population -- inherits the same bin-15 approximation.

Note population (from the pop family) and malePopulation+femalePopulation (from age_structures) come from different WorldPop models and are not guaranteed to sum to identical totals -- both are real, independently verified WorldPop products, just not cross-consistent by construction.

Three more real WorldPop REST families are wired up as of 2026-08-25 (verified live via https://hub.worldpop.org/rest/data and its per-dataset/per-country endpoints):

  • births (subset bic = "Individual countries"): gridded estimated-live-births-per-pixel rasters, single .7z-compressed GeoTIFF per country. Unlike pop/age_structures, this is a 2015-only dataset (popyear is reported as null by the API; every file is a fixed *_births_pp_v{1,2}_2015.tif) and does not cover every country -- confirmed live: Israel (ISR), Chile (CHL) and Mexico (MEX) have real data, but Spain (ESP), the USA and Germany (DEU) return an empty data: [] (WorldPop only ever published this product for a subset of, largely lower/middle-income, countries). :func:download_worldpop_layer raises ValueError for an uncovered country rather than silently returning nothing. Live-verified real totals: Israel's 2015 raster sums to 166,214 estimated births (Israel's actual 2015 population was ~8.3M at a ~20/1000 crude birth rate -> ~166-174k expected, matching within ~5%); Chile's sums to 235,608 (2015 population ~17.9M at a ~13.7/1000 rate -> ~245k expected, matching within ~4%).
  • pregnancies (subset individual_countries): the sibling gridded-pregnancies-per-pixel product (live births plus estimated stillbirths/miscarriages/abortions per the Guttmacher Institute), same 2015-only/.7z/partial-coverage shape as births. Live-verified: Israel's 2015 raster sums to 245,337 pregnancies -- a pregnancies:births ratio of ~1.48, in the expected ~1.4-1.6 range for a country with Israel's real abortion/miscarriage rates.
  • dug (subset dug_g2_v1 = "Degree of Urbanisation 2015-2030 using WorldPop Global2 R2025A"): not a count raster -- verified live by downloading Israel's real 2015 _GRID_L1 GeoTIFF and inspecting its actual pixel values: it is a uint8 categorical settlement-grid classification with exactly the values {0 (nodata/water), 1 (rural grid cell), 2 (urban cluster grid cell), 3 (urban centre grid cell)} -- Israel's real 2015 L1 grid has 20,199 rural / 1,527 urban-cluster / 683 urban-centre land pixels, matching the published GHSL/DEGURBA Level-1 settlement classification standard (https://ghsl.jrc.ec.europa.eu/degurbaDefinitions.php), not a guess. A raw class code isn't itself a summable quantity like the rest of :data:GLOBAL_SCHEMA_FEATURES, so rather than exposing it as-is, :func:download_worldpop_layer's "urbanPopulation" feature multiplies this classification (reprojected/resampled nearest-neighbour onto the population raster's own grid -- DUG ships at 1km/Mollweide ESRI:54009, the population raster at the requested resolution/WGS84) against download_worldpop_population's real per-pixel population raster, keeping only pixels DUG classifies as urban cluster or urban centre (class 2 or 3). This is real, derived-but-not-fabricated population attributable to WorldPop's own real classification and real population products, both independently verified above.

Every downloaded/derived raster is cached on disk by (iso3, year, resolution, file/feature) -- re-running with the same arguments and overwrite=False reuses the cached file instead of re-downloading/re-deriving.

GLOBAL_SCHEMA_FEATURES = ('population', 'malePopulation', 'femalePopulation', 'under18Population', 'over65Population', 'adultPopulation', 'urbanPopulation') module-attribute

Feature names (matching global_schema.json) that :func:download_worldpop_layer supports.

births/pregnancies are deliberately NOT included here (2026-08-25): both are fixed at WorldPop's single 2015 vintage with no per-year files (see download_worldpop_layer's feature == "pregnancies" branch, which already warns and falls back to 2015 regardless of the requested year) -- real, live-verified data, but 11 years stale relative to this project's 2020-2026 data-recency requirement. download_worldpop_layer still implements them (harmless, real, dead code kept for a future project with a looser recency bar) but no caller should request them for this project. urbanPopulation (Degree of Urbanisation) stays: unlike births/ pregnancies, WorldPop genuinely publishes a real per-year DUG raster for 2015-2030 (live-verified 2026-08-25 -- Israel alone has 16 real per-year rows, ids 124025-124040, one per year 2015-2030), and _fetch_single_country_dataset_row's year-matching branch already selects the real row for whatever year is requested -- so a 2025 (or any 2020-2026) urbanPopulation fetch is real, current data, not a stale fallback.

download_worldpop_population(aoi, date, folder=None, overwrite=False, resolution='100m', dataset='pop', subset='wpgpunadj', chunk_size=1048576)

Download a WorldPop population (or age-structure) raster for an AOI and year.

Resolves the AOI's country via :func:get_country_region, queries the WorldPop REST API (https://hub.worldpop.org/rest/data/) for the matching dataset/subset/year, and streams the resulting GeoTIFF to disk. If the resolved file is a .zip (e.g. the age_structures/U18 subset), it is automatically extracted and the path to the .tif inside is returned -- callers never need to unzip it themselves.

For the global-schema-aligned features (population by sex, under-18, over-65, adult), prefer :func:download_worldpop_layer instead -- it's built on the same underlying data but returns exactly one of those logical features per call without the caller needing to know WorldPop's dataset/subset naming.

Parameters:

Name Type Description Default
aoi GeoDataFrame

Area of interest. Must have a CRS set (ideally EPSG:4326); its centroid is used to resolve the country via reverse geocoding.

required
date Union[date, datetime, int]

A :class:datetime.date/:class:datetime.datetime, or a bare year as int; only the year is used to query WorldPop.

required
folder Optional[str]

Directory to save the downloaded file to. If None (default), a system temporary directory is used. If "", the current working directory is used.

None
overwrite bool

If False (default) and the destination file already exists, skip the download and reuse it.

False
resolution str

Resolution of the WorldPop dataset, "100m" or "1km".

'100m'
dataset str

WorldPop dataset family: "pop" for population counts, or "age_structures" for age-structure rasters.

'pop'
subset str

WorldPop dataset subset code (e.g. "wpgpunadj"). If not applicable for the resolved year, it is overridden automatically (see WorldPop's dataset catalog at https://hub.worldpop.org/rest/data/ for all available datasets/subsets). For dataset="age_structures", pass "under_18"/"U18" to select the under-18 subset (only available for year 2015, see :func:download_worldpop_layer's docstring for a per-year alternative).

'wpgpunadj'
chunk_size int

Chunk size in bytes used when streaming the download.

1048576

Returns:

Type Description
str

Path to the downloaded (and, if applicable, extracted) GeoTIFF file.

Raises:

Type Description
ValueError

If the AOI has no CRS, its country cannot be resolved, or no matching WorldPop dataset exists for the requested year/dataset/subset combination.

HTTPError

If a WorldPop API or file-download request fails.

download_worldpop_layer(aoi, date, feature, folder=None, overwrite=False, resolution='100m')

Download (or derive) a single global-schema-aligned WorldPop raster for an AOI and year.

This is the recommended entry point for anything beyond plain total population -- it hides WorldPop's dataset/subset/file-naming details behind the same logical feature names used across every other pycensus country module (see :data:GLOBAL_SCHEMA_FEATURES), and handles multi-file downloads/zip extraction/band-math internally.

Parameters:

Name Type Description Default
aoi GeoDataFrame

Area of interest. Must have a CRS set; its centroid resolves the country via reverse geocoding (see :func:get_country_region).

required
date Union[date, datetime, int]

A date/datetime, or a bare year as int (2015-2030).

required
feature str

One of :data:GLOBAL_SCHEMA_FEATURES -- "population", "malePopulation", "femalePopulation", "under18Population", "over65Population", "adultPopulation", "births", "pregnancies", or "urbanPopulation". See the module docstring for exactly how each is derived, and which are exact vs. approximated. "births"/"pregnancies" are only available for a subset of countries and are always the real 2015 dataset regardless of date (WorldPop never published another year for these two products -- see the module docstring); both raise ValueError for a country WorldPop has no data for.

required
folder Optional[str]

Directory to save/derive files into. Defaults to a system temp directory.

None
overwrite bool

If True, re-download/re-derive even if a cached file already exists.

False
resolution str

"100m" or "1km".

'100m'

Returns:

Type Description
str

Path to a single-band GeoTIFF for the requested feature.

Raises:

Type Description
ValueError

If feature isn't in :data:GLOBAL_SCHEMA_FEATURES, the AOI's country/year has no matching WorldPop dataset, or (for population) the year is outside WorldPop's 2015-2030 pop coverage.