我正在尝试akima ::: interp的简单应用,但我只能得到分段错误。我试图将一个球体的半球投影到磁盘上,然后使用“图像”制作一个图。当nx和ny等于50时,代码工作正常,但我需要nx和ny为> 200。
library(plot3D)
library(akima)
# Define surface data for sphere
n<-100
az.matrix<-matrix(0,nrow=n,ncol=n)
# Simple function for sphere surface
d.function <- seq(0,0,length=n)+dnorm(1:n,mean=n/4,sd=n/10)+dnorm(1:n,mean=3*n/4,sd=n/10)*-1
for (i in 1:n){
for (j in 1:n){
az.matrix[i,j] <- sin(seq(0,pi,length=n))[j]*(d.function/max(d.function)*log(2))[i]
}
}
az.matrix.image <- az.matrix[1:(n/2),1:(n/2)]
# Define hemisphere
M <- mesh(seq(0, 2*pi, length.out = n/2), seq(0, pi, length.out = n/2))
u <- M$x ; v <- M$y
x <- cos(u)*sin(v)
y <- sin(u)*sin(v)
z <- az.matrix.image
# Define output grid
nx<-200
ny<-200
x.out <- seq(min(x),max(x),length=nx)
y.out <- seq(min(x),max(x),length=ny)
Interp <- akima:::interp(x = x, y = y, z = z,
xo = x.out, yo = y.out,
duplicate="strip", extrap = FALSE)
new.z <- Interp[[3]]
image(x = x.out, y = y.out, new.z , useRaster = TRUE, asp = 1, axes = FALSE, xlab = "", ylab = "",
col =jet.col(100))
当我尝试使用大型nx和ny时,此代码会产生
*** caught segfault ***
address 0x10f53d000, cause 'memory not mapped'
Traceback:
1: .Fortran("idsfft", as.integer(1), as.integer(ncp), as.integer(n), as.double(x), as.double(y), as.double(z), as.integer(nx), as.integer(ny), x = as.double(xo), y = as.double(yo), z = zo, integer((31 + ncp) * n + nx * ny), double(5 * n), misso = as.logical(misso), PACKAGE = "akima")
2: interp.old(x, y, z, xo, yo, ncp = 0, extrap = FALSE, duplicate = duplicate, dupfun = dupfun)
3: akima:::interp(x = x, y = y, z = z, duplicate = "strip")
我的RStudio会话已中止。 sessionInfo()的输出是
Platform: x86_64-apple-darwin13.4.0 (64-bit)
Running under: macOS Sierra 10.12.3
locale:
[1] en_NZ.UTF-8/en_NZ.UTF-8/en_NZ.UTF-8/C/en_NZ.UTF-8/en_NZ.UTF-8
attached base packages:
[1] stats graphics grDevices utils datasets methods base
loaded via a namespace (and not attached):
[1] tools_3.3.2 sp_1.2-4 grid_3.3.2 akima_0.6-2 lattice_0.20-34
任何帮助将不胜感激! 提前致谢