2

So I was wandering if there is a way to simplify a couple of Sentinel's rasters so I can apply raster analysis on them. Problem is that whenever I try to aggregate the data my RAM, CPU and storage overload (see the following line). And that is by using parallel processing.

r2=aggregate(ras,fact=10,fun=mean, expand=TRUE, na.rm=TRUE)

Now I am wandering, if there is a faster way to transform my data, faster, using another method or function. Now, I have also thought of resample and splitting but I wanted to ask you people if you knew a faster way to aggregate my data.

2

You can try with velox:

library(raster)
library(velox)
library(microbenchmark)
library(RStoolbox) # FOR DATA

data('lsat')

test_data <- lsat[[1]]

microbenchmark(a = raster::aggregate(x = test_data, fact = 10, fun = mean, expand = T, na.rm = T),
               b = {v <- velox(test_data); v$aggregate(factor = c(10,10), aggtype = 'mean')})

## Unit: milliseconds
## expr       min        lq      mean    median        uq        max neval cld
## a 36.975760 40.361677 46.470796 42.326149 46.097733 327.624192   100   b
## b  1.070906  1.462487  1.982737  1.772933  2.037216   7.178011   100  a 
  • ok, I missed something here. Velox works, but I can't even plot my aggregated raster. For example: here is my line (based on your example) v <- velox("path/to/raster.tif") v$aggregate(factor = c(10,10), aggtype = 'mean') Am I doing something wrong? How do I call the aggregated result? – George Nostradamos May 11 '18 at 18:29
  • A velox object is not suitable with raster methods. Convert it to raster r <- v$as.RasterLayer() and you can plot and do anything as a normal raster. Also, there are $as.RasterStack() and $as.RasterBrick() – aldo_tapia May 11 '18 at 18:39

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.