我有一个网格化地图,我想使用 ECDF 对像元值进行偏差校正。我尝试使用 R 中 snow 包中的 clusterR。但我一直收到此错误。
[1] "cannot use this function"
attr(,"class")
[1] "snow-try-error" "try-error"
Error in clusterR(snodas_max_4km_2014, calc, args = list(fun = bias_correct_on_grid), :
cluster error
应用于每个单元格的功能。 in_ecdf_snodas 是逆 cdf,ecdf_ua 是 cdf 函数
#define the function to apply to each cell
bias_correct_on_grid = function(x, snodas_overlap, ua_overlap){
if (x <= max_ua_overlap) {
x_biased_correct <- in_ecdf_snodas(ecdf_ua(x))
} else if (x > max_ua_overlap) {
x_biased_correct <- max_snodas_overlap + (x - max_ua_overlap) * (sd_snodas_overlap / sd_ua_overlap)
} else if (is.na(x)){
x_biased_correct <- x
}
return(x_biased_correct)
}
其余代码如下:
load("data-raw/RObject/snodas_max_4km_2014.RData") #raster layer
# create a cluster with 6 workers
cl <- makeCluster(4)
# load required packages on each worker node
clusterEvalQ(cl, {
library(raster)
library(snow)
library(GoFKernel)
})
clusterExport(cl, list(
"bias_correct_on_grid", "max_ua_overlap", "min_snodas_overlap",
"max_snodas_overlap", "sd_snodas_overlap",
"sd_ua_overlap" , "in_ecdf_snodas", "ecdf_ua"
))
# apply the function to the raster using clusterR
raster_out <- clusterR(snodas_max_4km_2014, calc,
args = list(fun = bias_correct_on_grid), cl = cl)
# stop the cluster
stopCluster(cl)