In this notebook we will use dhis2eo to download yearly population count data from WorldPop for a given country.
import dhis2eo
from dhis2eo.data.worldpop import pop_totalIn the case of WorldPop, data downloads are organized by country, so the only other information we need is the ISO3 code of the country you want to download data for.
Downloading WorldPop total population data¶
The dhis2eo.data.worldpop.pop_total module allows you do easily download yearly historical and projected population data for individual countries from the WorldPop Global v2 dataset between 2015 and 2030. Downloading population data for a country and range of years can be achieved with a simple yearly loop and the country’s ISO3-code:
country_code = 'SLE'
start_year = 2015
end_year = 2030
for year in range(start_year, end_year+1):
print(f'Year: {year}')
# Download data...
data = pop_total.get(year, country_code)
# do something with the data
# e.g. save to disk, aggregate, or import to DHIS2
# ...Year: 2015
dhis2eo.data.utils - INFO - Loading from cache: /tmp/dhis2eo_data_worldpop_population_get_d8a7fc84b0.nc
Year: 2016
dhis2eo.data.utils - INFO - Loading from cache: /tmp/dhis2eo_data_worldpop_population_get_0371e022b1.nc
Year: 2017
dhis2eo.data.utils - INFO - Loading from cache: /tmp/dhis2eo_data_worldpop_population_get_a0f470ae2b.nc
Year: 2018
dhis2eo.data.utils - INFO - Loading from cache: /tmp/dhis2eo_data_worldpop_population_get_8c8d7e55e7.nc
Year: 2019
dhis2eo.data.utils - INFO - Loading from cache: /tmp/dhis2eo_data_worldpop_population_get_d7a7024821.nc
Year: 2020
dhis2eo.data.utils - INFO - Loading from cache: /tmp/dhis2eo_data_worldpop_population_get_7e627a6cd4.nc
Year: 2021
dhis2eo.data.utils - INFO - Loading from cache: /tmp/dhis2eo_data_worldpop_population_get_fee2865e70.nc
Year: 2022
dhis2eo.data.utils - INFO - Loading from cache: /tmp/dhis2eo_data_worldpop_population_get_a2258f364a.nc
Year: 2023
dhis2eo.data.utils - INFO - Loading from cache: /tmp/dhis2eo_data_worldpop_population_get_0a18c8815a.nc
Year: 2024
dhis2eo.data.utils - INFO - Loading from cache: /tmp/dhis2eo_data_worldpop_population_get_ced59883a5.nc
Year: 2025
dhis2eo.data.utils - INFO - Loading from cache: /tmp/dhis2eo_data_worldpop_population_get_44f9ae2458.nc
Year: 2026
dhis2eo.data.utils - INFO - Loading from cache: /tmp/dhis2eo_data_worldpop_population_get_8756087dd5.nc
Year: 2027
dhis2eo.data.utils - INFO - Loading from cache: /tmp/dhis2eo_data_worldpop_population_get_71cf4f875f.nc
Year: 2028
dhis2eo.data.utils - INFO - Loading from cache: /tmp/dhis2eo_data_worldpop_population_get_4b47c121bb.nc
Year: 2029
dhis2eo.data.utils - INFO - Loading from cache: /tmp/dhis2eo_data_worldpop_population_get_e91e6df4b2.nc
Year: 2030
dhis2eo.data.utils - INFO - Loading from cache: /tmp/dhis2eo_data_worldpop_population_get_e876b47b23.nc
To inspect the contents of the downloaded data, let’s view the data of the last element of the loop:
dataWe see that this is data for the last available year, 2030, and contains data variables total_pop (Total population).
Next steps¶
This notebook has showed how to download and potentially process the WorldPop population count data. For guidance on how to further process the downloaded data, see:
As these are yearly data that includes future projections, the script likely only needs to be run once.