WorldPop — population quickstart (live)¶
Download Comoros (COM) 2020 population at 100 m, mosaicked + cropped to a small bbox. Small live download; no credentials.
In [ ]:
Copied!
import tempfile
from earthlens.earthlens import EarthLens
out_dir = tempfile.mkdtemp()
paths = EarthLens(
data_source='worldpop',
variables=['pop'],
aoi='COM',
start='2020',
end='2020',
fmt='%Y',
lat_lim=[-12.5, -11.3],
lon_lim=[43.2, 44.6],
path=out_dir,
).download(progress_bar=False)
paths
import tempfile
from earthlens.earthlens import EarthLens
out_dir = tempfile.mkdtemp()
paths = EarthLens(
data_source='worldpop',
variables=['pop'],
aoi='COM',
start='2020',
end='2020',
fmt='%Y',
lat_lim=[-12.5, -11.3],
lon_lim=[43.2, 44.6],
path=out_dir,
).download(progress_bar=False)
paths
Open the cropped GeoTIFF with pyramids and report the AOI population total:
In [ ]:
Copied!
import numpy as np
from pyramids.dataset import Dataset
ds = Dataset.read_file(str(paths[0]))
arr = np.asarray(ds.read_array(), dtype='float64')
nd = ds.no_data_value
nd = nd[0] if isinstance(nd, (tuple, list)) else nd
arr = np.where(arr == nd, np.nan, arr)
print('EPSG:', ds.epsg, 'shape:', arr.shape)
print('AOI population total:', round(float(np.nansum(arr))))
import numpy as np
from pyramids.dataset import Dataset
ds = Dataset.read_file(str(paths[0]))
arr = np.asarray(ds.read_array(), dtype='float64')
nd = ds.no_data_value
nd = nd[0] if isinstance(nd, (tuple, list)) else nd
arr = np.where(arr == nd, np.nan, arr)
print('EPSG:', ds.epsg, 'shape:', arr.shape)
print('AOI population total:', round(float(np.nansum(arr))))