Learning xarray
Try to reproduce the similar with different population grids.
WorldPop data of Kenya
Go to wopr.worldpop.org and download a Gridded population estimates (~100m) for Kenya and a Kenya 100m Building class. Each is an archive, so unzip (reading from the zipped archive doesn’t seem to work in this case.)
Backup data
If the link does not work, please report it and use the backup:
- Load
KEN_population_v2_0_gridded.tif
andKEN_building_class_metrics_v1_0_residential_count.tif
files. - Plot at least one of them in their full extent.
- Clip them both to the extent of the
"Mombasa"
functional urban area from GHSL. - What is the maximum population per hectare in Mombasa?
- Reproject one to match the other. These two grids are not perfectly aligned, so you need to align them. Check the tip below on how to do that.
Aligning rasters
When two rasters don’t perfectly match (i.e. their resolution and placement are exactly the same), you need to align them by projecting one to match the other.
Try figuring that out!
A hint, please!
rioxarray
has the functionality to do this as one line of code. Have you checked their (not so great, I admin) documentation?
Another hint
You are looking for .rio.reproject_match()
method.
Okay, here’s the code
This is how the aligning should look.
= b.rio.reproject_match(a) aligned_b
- Normalise the population with the building count.
- Save the result as a GeoTIFF.