R akima包中的Interp函数 - 未映射的内存

问题描述 投票:0回答:1

我正在尝试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<-50
ny<-50
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))

这段代码产生this plot,但我需要绘图具有更高的分辨率。

当我尝试大的nx和ny(例如200)时,此代码会产生

*** 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

任何帮助将不胜感激!提前致谢。这是几天前的一个问题的重复,我不小心发布在错误的论坛上,它在噪音中丢失了。 Interp function in akima causing segmentation fault

r interpolation surface
1个回答
0
投票

我只是有同样的问题,我在同一个域内有两个集合(range(x)range(y)),一个包含50k点,另一个30k点,具有相同的输出矩阵(xoyo)。 50k的积分很好,30k的积分让R崩溃了。 (与论据linear=TRUE

通过在我的脚本中处理函数akima::interpakima::interp.old并使用“复制”函数运行我的代码(不更改代码中的任何内容),我意外地找到了“解决方案”。我的意图是放置browser()并找到错误的来源。然而,崩溃不再发生......

sessionInfo():

R version 3.5.0 (2018-04-23)
Platform: x86_64-pc-linux-gnu (64-bit)
Running under: Progress Linux 4+ (dschinn-backports)

Matrix products: default
BLAS: /usr/lib/libblas/libblas.so.3.7.0
LAPACK: /usr/lib/lapack/liblapack.so.3.7.0

locale:
 [1] LC_CTYPE=en_US.UTF-8       LC_NUMERIC=C               LC_TIME=en_US.UTF-8        LC_COLLATE=en_US.UTF-8     LC_MONETARY=en_US.UTF-8   
 [6] LC_MESSAGES=en_US.UTF-8    LC_PAPER=en_US.UTF-8       LC_NAME=C                  LC_ADDRESS=C               LC_TELEPHONE=C            
[11] LC_MEASUREMENT=en_US.UTF-8 LC_IDENTIFICATION=C       

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base     

other attached packages:
[1] akima_0.6-2       polyclip_1.9-1    data.table_1.11.4 colorout_1.2-0   

loaded via a namespace (and not attached):
[1] compiler_3.5.0    sp_1.3-1          R.methodsS3_1.7.1 grid_3.5.0        R.utils_2.6.0     SDMTools_1.1-221  lattice_0.20-35  
[8] R.oo_1.22.0   
© www.soinside.com 2019 - 2024. All rights reserved.