terra
terra copied to clipboard
distance and boundary functions run slower
Hi, was there updates to these functions? They seem to run considerably slower compared to older version of terra. Thanks!
Not on purpose, but I can look into it. Do you have an example where you observed this, or can you show(x)
where x is a SpatRaster? Is this a SpatRaster with a longlat crs?
Thanks of the response Robert. Attached is the .tif I use in the following code chunk to generate distance to edge:
library(terra)
library(raster)
# Input binary raster
cb <-rast("./cb.tif")
# Reclassify
m <- c(0,NA, 1,1)
rclmat <- matrix(m, ncol=2, byrow=TRUE)
na_1 <- terra::classify(cb,rclmat)
# Aggregate 30m to 150m cell size
cb150m_terra <- terra::aggregate(na_1,5, fun='max')
cb150m_raster <- raster(cb150m_terra)
# Terra::Distance
start.time <- Sys.time()
d2cb <- terra::distance(cb150m_terra)
end.time <- Sys.time()
time.taken <- end.time - start.time
time.taken
# Time difference of 2.53582 mins
# Raster::Distance
start.time <- Sys.time()
d2cb <- terra::distance(cb150m_raster)
end.time <- Sys.time()
time.taken <- end.time - start.time
time.taken
# Time difference of 2.002817 mins
I appreciate you looking into this. Terra is a great package and I have begun converting my code base to replacing raster with it.
Dan
Can you upload the file to github (or a file share and provide a link?). Attaching by email does not work (and github generally works much if you avoid email responses)
For sure. It is a .tif however and it won't let me upload. Here is a link you can download though: https://portal.onefilesync.ca/shares/file/b2gLr1ctxKJ/
I have (at long last) been working on speeding these things up, but I no longer have the file to compare with your benchmark,
I am closing this as I do not have the file for comparison. But it would be great if you could share it again.