hunzikp / velox

https://hunzikp.github.io/velox/
119 stars 23 forks source link

Velox Got A Lot Lot Lot Slower? #28

Closed nbarsch closed 6 years ago

nbarsch commented 6 years ago

After reviewing the issues (like I should have done first) I am definitly having an issue of velox 0.1.0 vs. 0.2.0 as here: https://github.com/hunzikp/velox/issues/25

I am working with a pretty big raster (nearly 1GB) and something is strange. Velox is a lot slower at extracting a huge raster than Raster. What is happening here????? (reproducible example below):

Reproduce DATA:

#To download a huge raster for a reproducible example, you can use my package spaceheater:
devtools::install_github("nbarsch/spaceheater")
library(spaceheater)
getWPdownload("Ethiopia", "Population", "adj", 2015) ###1GB file download, their server is also slow (sorry)
##Generate buffer
library(sf)
buff <- data.frame(lon=38.763, lat=9.005)
buff <- st_as_sf(buff,coords=c("lon","lat"),crs=4326)
buff <- st_transform(buff, crs=32637)
buff <- st_buffer(buff, 20000)
buff <- st_transform(buff, crs=4326)
buff$point <- "1"

Test velox2 v velox1:


library(raster)
library(velox)
vras <- velox("ETHIOPIA_Population_adj_2015.tif")
ras <- raster("ETHIOPIA_Population_adj_2015.tif")

##VELOX 0.2.0 version
velox_extracttime <- system.time(veloxval <- vras$extract(buff, fun=function(x){mean(x,na.rm=T)}))
> velox_extracttime
   user  system elapsed 
 12.019  48.024  88.293 

#Checking value
> veloxval
      [,1]
1 28.12575

###VELOX 0.1.0
> velox_extracttime <- system.time(veloxval <- vras$extract(as(buff,"Spatial"), fun=function(x){mean(x,na.rm=T)}))

> velox_extracttime
   user  system elapsed 
  0.052   0.004   0.056 

> veloxval
         [,1]
[1,] 28.12575
hunzikp commented 6 years ago

I'll subsume this under issue #25.