jmsigner / amt

37 stars 13 forks source link

support for terra package in extract_covariates #32

Closed bniebuhr closed 2 years ago

bniebuhr commented 3 years ago

Hi!

I was wondering that it could be desirable to have a support for SpatRast objects from the terra package in the function amt::extract_covariates. terra is equivalent but faster than raster, so it would be nice to be able to use it for the same purpose here.

The function in terra seems to be the same, terra::extract, even though maybe the input must be a SpatVect object. In any way, I think it may be easy to implement the extract_covarieates for it.

Do you think about an improvement in this direction?

jmsigner commented 3 years ago

Yes, this is on my to-do list for a while. Did you experience significant speed increases?

bniebuhr commented 3 years ago

I haven't used it enough to test the difference in speed, my comment is more based on the authors (@rhijmans) comments on that... But I am currently trying this, I guess soon I may make some tests and I come back here to comment.

bniebuhr commented 3 years ago

Here are some tests on that by anyone else: https://tmieno2.github.io/R-as-GIS-for-Economists/extract-speed.html Maybe it is worth also thinking about the possibility of using exact_extract()?

In any case, I'll try implementing this (at least the terra approach) in some way and we can work on that. I have just forked and cloned the repo, but I cannot read the raster sh_forest to transform it into a terra::rast object. Is it hidden in the package building? The file data/sh_forest.rda makes reference to the raster data/sh_forest.tif, but I guess it is probably not uploaded to the Github repo because it is a large file. I'll need it to have a terra version of the object. What would be the best way to proceed with this?

bniebuhr commented 3 years ago

I made an implementation for this, maybe it could be tested? I am not sure what would be the best way to test the speed of the approaches with the data we have in hands...

PS: the issue with the tif file above is not important. There was a warning raised but I could successfully transform the raster into a SpatRast object from the terra package.