Last active
November 13, 2020 23:15
-
-
Save romunov/c9d1ca1628cfbca873679835a90cc395 to your computer and use it in GitHub Desktop.
calculating means for raster stacks, cell-wise
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
library(raster) | |
library(microbenchmark) | |
logo <- stack(system.file("external/rlogo.grd", package="raster")) | |
la <- as.array(logo) | |
microbenchmark(vanilla = mean(logo), | |
overlay = overlay(logo, fun = mean), times = 50, calc(logo, fun = mean), | |
rasterapply = {raster(apply(la, MARGIN = c(1,2), FUN = mean))}, | |
norasterapply = {apply(la, MARGIN = c(1,2), FUN = mean)}) | |
Unit: milliseconds | |
expr min lq mean median uq max neval cld | |
vanilla 19.60386 21.57217 23.4185 22.48069 23.87271 56.78282 50 a | |
overlay 188.79896 203.31245 220.2954 212.86435 227.59977 511.91230 50 d | |
calc 40.63554 42.48914 44.3292 43.67887 45.95958 52.97399 50 b | |
rasterapply 150.51631 160.30246 172.9886 171.31683 183.67126 231.59569 50 c | |
norasterapply 147.07012 157.48260 168.5057 166.99851 179.94597 217.33666 50 c |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment