私はraster
長い間 R パッケージを使用してきましたが、今ではこの clusterR の問題に頭を悩ませています。netCDF ラスターの SPI インデックスを計算する必要があります。これはセルごとに行われ、セルの時系列を取得し、そのセルの SPI インデックスの時系列を返します。
入力ファイルの例 (約 4MB) は、ここにあります。
以下のコードを参照してください。
library(raster)
library(SPEI)
calcspi <- function(pr) { #this function calculates the SPI index for each timeseries of values
pr <- as.numeric(pr)
if (all(is.na(pr[1:20]))) { #Check that this is not an NA cell
outspi <- rep(NA, length(pr))
} else {
outspi <- fitted(spi(pr, 12, na.rm=TRUE))
}
return(outspi)
}
b <- brick("input_crop.nc", varname="pr")
readAll(b) #As requested in the comments
###THIS WORKS BUT IS SLOW:
bc <- calc(b, calcspi)
###THIS DOES NOT:
beginCluster(n=4)
bc <- clusterR(b, calc, args=list(fun="calcspi"))
#[1] "argument is of length zero"
#attr(,"class")
#[1] "snow-try-error" "try-error"
#Error in clusterR(b, calc, args = list(fun = "calcspi")) : cluster error
endCluster()
###THIS DOESN'T EITHER:
beginCluster(n=4)
f <- function(x) calc(x, calcspi)
bc <- clusterR(b, f)
#[1] "argument is of length zero"
#attr(,"class")
#[1] "snow-try-error" "try-error"
#Error in clusterR(b, f) : cluster error
endCluster()
traceback()
この場合はまったく役に立ちません。なにが問題ですか?