afrimapr / afrilearndata

small african spatial datasets for learning & teaching mapping in R
https://afrimapr.github.io/afrilearndata
15 stars 11 forks source link

add a categorical raster dataset #2

Closed andysouth closed 3 years ago

andysouth commented 3 years ago

Be useful to have a categorical raster. Where cell values represent categories rather than a numeric scale.

Ideally : ~ covering the continent ~ low resolution, ~ 800 * 800 cells ~ not population

Doesn't have to be exactly the same grid, indeed if it isn't the data could be used with afripop2020 to show how to combine different datasets.

Options :

  1. Copernicus global landcover : https://lcviewer.vito.be/2015
  2. Köppen-Geiger climate classification : http://koeppen-geiger.vu-wien.ac.at/present.htm

I guess that we could aggregate and assign the the most frequent cell value by raster::aggregate(fun=modal)

Code to create the lowres data from publically available data could be put here. Pull requests welcome :-) https://github.com/afrimapr/afrilearndata/blob/28dab6394e6be7d96cc13185688b9c89390dc2bc/data-raw/afrilearndata-data-creation.R#L186

chrislittleboy commented 3 years ago

I've had a go at this for land cover! let me know what you think. I've used MODIS data as it's easier to automate the download in R. The reproducible script and final data is here!

andysouth commented 3 years ago

Many thanks @chrislittleboy this looks amazing. If you are OK with it I'm keen to put something like this in afrilearndata and credit you.

Two things first (and bear in mind I don't have much experience of dealing with rasters in R, so excuse anything I get wrong)

  1. resolution - for the one you created is around 2000x2000 cells which feels a bit big to me. e.g. mapview doesn't display that many cells by default & decreases the resolution. Ideally I was looking to have something ~800x800. But my approach is fairly arbitrary trying to have something that is big enough to be useful and interesting but not too big to be awkward. (As a side issue it may also be useful to make the higher resolution version available to R users somehow ?).

  2. method of decreasing the resolution. You use sampleRegular(), my understanding is that this might make a less representative map if sample points happen to fall in otherwise rare categories. africalowres <- sampleRegular(africalandcover, size = 5000000, asRaster = T) Might something like this produce a more representative result ? africalowres <- raster::aggregate(africalandcover, fun=modal, fact=10) I haven't thought about what the factor level would need to be.

Good to see that the data seem not to have restriction on re-use and redistribution : https://lpdaac.usgs.gov/data/data-citation-and-policies/ Once we get sorted I'll make sure to get the correct citation in.

chrislittleboy commented 3 years ago

Thanks Andy, I'm definitely okay with you using it.

On 1, you can either sort this by changing the template raster (I had imagined you might want the same size/resolution/projection as the population data that you use in the package). There is a lot of ocean in my template... Or you could reduce the size as desired when aggregating. I'll leave the decision regarding the trade-off between file size and usefulness to you!

On 2, this was my first instinct too, but I used fun = median originally and got irritated by non-integer returns. Using modal is a great fix.

On the side issue, it's relatively easy to download and process the MODIS using the R package MODIS. I was going to do a tutorial-style blog post so maybe that's another option for R users wanting to get high res land cover or other MODIS products...

andysouth commented 3 years ago

Hi @chrislittleboy categorical raster now in the package following your suggestion :-)

https://github.com/afrimapr/afrilearndata/blob/master/R/afrilandcover.r

I've mentioned you as a contributor in the package description If you want to send me your orcid number I can pop that in too. I hope to submit to CRAN next week. Any other suggestions welcome.

chrislittleboy commented 3 years ago

Thanks Andy, very glad it was helpful. My orcid is 0000-0002-3293-7987. Good luck with getting the package up!

Chris

On Fri, 8 Oct 2021 at 11:39, Andy South @.***> wrote:

Hi @chrislittleboy https://github.com/chrislittleboy categorical raster now in the package following your suggestion :-)

https://github.com/afrimapr/afrilearndata/blob/master/R/afrilandcover.r

I've mentioned you as a contributor in the package description If you want to send me your orcid number I can pop that in too. I hope to submit to CRAN next week. Any other suggestions welcome.

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/afrimapr/afrilearndata/issues/2#issuecomment-938538023, or unsubscribe https://github.com/notifications/unsubscribe-auth/AOHZM2F7QCJHSKYJOJZ7VX3UF3C7DANCNFSM4UHTC2WA . Triage notifications on the go with GitHub Mobile for iOS https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675 or Android https://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub.