WorldPop — global mosaics (live URL resolution)¶
scope="global" fetches the per-year whole-world mosaic (via the hub's ?id= detail endpoint) and crops it to the AOI. Each 1 km global mosaic is ~1.1 GB (WorldPop has no server-side subsetting), so this notebook only resolves the download URL rather than pulling it.
What this notebook does¶
- Pick the sub-alias — ask the WorldPop catalog for the
global, 1 kmpopproduct key. - Resolve the URL — hit the hub's per-year detail endpoint to get the whole-world 2020 mosaic download URL.
No credentials are needed — WorldPop is an open hub. The full download (~1.1 GB) is left as a copy-paste snippet at the end.
Setup¶
Catalog resolves product aliases to concrete WorldPop keys, and global_files_for_year turns a resolved key into per-year download URLs. We import both up front.
from earthlens.worldpop import Catalog
from earthlens.worldpop.rest import global_files_for_year
1 · Pick the global sub-alias¶
The catalog maps a product family (pop) plus a resolution and scope onto a concrete WorldPop sub-alias. We instantiate the catalog first, then look up the global, 1 km population key.
cat = Catalog()
subalias = cat.pick_subalias('pop', resolution='1km', scope='global')
print('global pop 1km sub-alias ->', subalias)
2 · Resolve the whole-world mosaic URL¶
global_files_for_year returns the list of files for a given sub-alias and year. We take the first entry on its own line, then print the filename and the full URL — without downloading the ~1.1 GB raster.
files = global_files_for_year('pop', subalias, 2020)
url = files[0]
print('whole-world 2020 mosaic:', url.rsplit('/', 1)[-1])
print('full URL:', url)
Recap¶
Two catalog lookups resolve the live download URL for the whole-world 1 km population mosaic, without pulling the ~1.1 GB file.
Try it yourself¶
To actually download + crop it (a ~1.1 GB pull), construct the facade, then call download() on its own line:
earthlens = EarthLens(
data_source='worldpop',
variables=['pop'],
start='2020',
end='2020',
fmt='%Y',
scope='global',
resolution='1km',
lat_lim=[-4.7, 5.0],
lon_lim=[33.9, 41.9],
path='out/',
)
paths = earthlens.download()