Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
331 views
in Technique[技术] by (71.8m points)

r - Interp function in akima causing segmentation fault

I am trying a simple application of akima:::interp but I can only get a segmentation fault. I am trying to project a hemisphere of a sphere onto a disk, then use 'image' to make a plot. The code works fine when nx and ny equal 50, but I need nx and ny to be > 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))

When I try large nx and ny, this code yields

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

and my RStudio session is aborted. The output of sessionInfo() is

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

Any help would be greatly appreciated! Thanks in advance

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...