有哪些方法可以更快地处理栅格堆栈

问题描述 投票:0回答:1

我一直在尝试计算8天MODIS数据的月平均值,但计算平均值需要很长时间。有没有更快的方法来做到这一点。我使用以下代码在 R 中执行此操作:

library(doParallel)
library(foreach)
library(raster)
# Set the number of cores to use for parallel processing
ncores <- parallel::detectCores() - 1  # Use all available cores except one
registerDoParallel(cores = ncores)

m<-stack()

foreach (month_name = month.name) %dopar% {
  print(month_name)
  # Subset layers corresponding to the current month
  month_layers <- s[[which(months(getZ(s)) == month_name)]]
  print(month_layers)
  # Calculate mean for the month (exclude NA values)
  month_mean <- mean(month_layers, na.rm = TRUE)
  print(month_mean)
  # Store the monthly mean in the list with the month name as the list element name
  m<-stack(m,month_mean)
}
r qgis r-modis pymodis
1个回答
0
投票

我愿意

library(terra)
x <- rast(files)
r <- tapp(x, "months", mean, cores=ncores)
© www.soinside.com 2019 - 2024. All rights reserved.