WorldPop — constrained vs unconstrained (live)¶
Compare the 2020 unconstrained (wpgp) and constrained (cic2020_100m) 100 m population for Comoros over the same AOI.
In [ ]:
Copied!
import tempfile
import numpy as np
from pyramids.dataset import Dataset
from earthlens.earthlens import EarthLens
def total(constrained):
d = tempfile.mkdtemp()
p = 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=d,
constrained=constrained,
).download(progress_bar=False)
a = np.asarray(Dataset.read_file(str(p[0])).read_array(), dtype='float64')
return float(np.nansum(np.where(a < 0, np.nan, a)))
print('unconstrained total:', round(total(False)))
print('constrained total: ', round(total(True)))
import tempfile
import numpy as np
from pyramids.dataset import Dataset
from earthlens.earthlens import EarthLens
def total(constrained):
d = tempfile.mkdtemp()
p = 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=d,
constrained=constrained,
).download(progress_bar=False)
a = np.asarray(Dataset.read_file(str(p[0])).read_array(), dtype='float64')
return float(np.nansum(np.where(a < 0, np.nan, a)))
print('unconstrained total:', round(total(False)))
print('constrained total: ', round(total(True)))
The constrained product masks population to mapped settlements, so its spatial distribution differs from the unconstrained surface.