【发布时间】:2016-03-14 14:48:15
【问题描述】:
真的希望你能帮助我。提前感谢您,到目前为止,我从这些页面中学到的一切。很抱歉,我的专业知识受到我试图学习 R 中所有内容的兼职性质的限制。
我的目标: 使用(大)栅格查找表反演。
我现在拥有的:
#Observed data (in this case just as a dataframe)
obs <- data.frame(runif(100,0,1))
#Two sets of simulated data (often n >10 000)
sim.A <- data.frame(runif(1000,0,1))
sim.B <- data.frame(runif(1000,0,1))
#Calculate the error [cost] for each observed value and every simulated(A) value
error.fun <- function(x){sqrt((x-sim.A)^2)}
error <- apply(obs,1,error.fun)
#Find the position of the min [error] value
min.func <- function(x){which(x == min(x),arr.ind = F)}
cost.min <- apply(error,2,min.func)
#Subset the simulated (B) dataset at the position of the least error[cost.min]
LUT.values = data.frame(sim.B[cost.min,])
我的问题:
1) 上面的代码适用于从栅格中提取的样本。但是,我需要用整个(ncell > 1Mil)栅格替换采样观察。我显然需要优化上述两个函数(合二为一?),但我得到的最接近的函数让我怀疑,因为与采样数据尝试相比,结果很差。
我对大型栅格的尝试:
#This runs, but I dont think it's working correctly
crs.UTM <- CRS("+proj=utm +zone=36 +south +datum=WGS84 +units=m +no_defs+ellps=WGS84 +towgs84=0,0,0")
r <- raster( crs=crs.UTM)
extent(r) <- extent(0, 100, 0, 100)
res(r) <- c(1, 1)
values(r) <- runif(ncell(r), 0, 1)
#Simulated data (often n >10 000)
sim.A <- data.frame(runif(1000,0,1))
sim.B <- data.frame(runif(1000,0,1))
cost.min.func <- function(x){
cost <- sqrt((x-sim.A)^2)
c.min <- sim.B[which(cost == min(cost),arr.ind = FALSE),]}
LUT.rst <- calc(r,cost.min.func)
非常感谢
【问题讨论】:
标签: r function spatial r-raster bigdata