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.)

If the link does not work, please report it and use the backup:

  1. Load KEN_population_v2_0_gridded.tif and KEN_building_class_metrics_v1_0_residential_count.tif files.
  2. Plot at least one of them in their full extent.
  3. Clip them both to the extent of the "Mombasa" functional urban area from GHSL.
  4. What is the maximum population per hectare in Mombasa?
  5. 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.

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!

rioxarray has the functionality to do this as one line of code. Have you checked their (not so great, I admin) documentation?

You are looking for .rio.reproject_match() method.

This is how the aligning should look.

aligned_b = b.rio.reproject_match(a)
  1. Normalise the population with the building count.
  2. Save the result as a GeoTIFF.
Optional extension
  1. If you have time, you can also figure out how many buildings are per district in Mombasa. Those are in OpenStreetMap as admin_level==6.
  2. Extract values for 100 random points from each Mombasa district.
  3. Generate zonal statistics for each district. Think about the proper aggregation method.