【问题标题】:ClusterR with multiple raster stacks具有多个栅格堆栈的 ClusterR
【发布时间】:2016-02-12 17:52:16
【问题描述】:

以下是栅格库为使用 clusterR 和覆盖函数提供的示例:

library(raster)
beginCluster()
r <- raster()
r[] <- 1:ncell(r)
s <- stack(r, r*2, r*3)
f2 <- function(d,e,f) (d + e) / (f * param)
param <- 122
ov <- clusterR(s, overlay, args=list(fun=f2), export='param')

如果我有多个栅格堆栈,我想知道如何运行该函数:

s <- stack(r, r*2, r*3)
s2 <- stack(r*2, r*3, r*4)
s3 <- stack(r*3, r*4, r*5)

我想要这样的东西(函数f2中的d,e,fs, s2s3中的每一层):

ov <- clusterR(s,s2,s3, overlay, args=list(fun=f2), export='param')

【问题讨论】:

  • 列出堆栈并循环集群?

标签: r parallel-processing raster


【解决方案1】:

首先,我将在您的堆栈中创建一个虚拟栅格图层,其中包含param值。因此,操作可以向量化:

p <- 122
rp <- r
rp[] <- p
s <- stack(s, rp)
s2 <- stack(s2, rp)
s3 <- stack(s3, rp)

然后你像这样改变你的功能:

f2 <- function(x) (x[[1]] + x[[2]]) / (x[[3]] * x[[4]])

因此,单个堆栈x 的层被正确引用。第4层是param值(这里是p

然后你创建一个层堆栈列表:

stackList <- list(s, s2, s3)

然后你 lapply clusterR 函数。

ov <- lapply(stackList, function(x){clusterR(x, fun = f2, progress = "text")})

ov 将成为您覆盖层的列表。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-07-03
    • 1970-01-01
    相关资源
    最近更新 更多