Commit 4ec7cb75 by agebhard

### add last changes from Martin Maechler

ready for release as 0.5-1
 ... @@ -56,7 +56,7 @@ interp.new(x, y, z, xo = seq(min(x), max(x), length = 40), ... @@ -56,7 +56,7 @@ interp.new(x, y, z, xo = seq(min(x), max(x), length = 40), \item{linear}{logical -- indicating wether linear or spline \item{linear}{logical -- indicating wether linear or spline interpolation should be used. supersedes old \code{ncp} parameter} interpolation should be used. supersedes old \code{ncp} parameter} \item{ncp}{ \item{ncp}{ deprecated, use parameter \code{linear}. Now only used by deprecated, use parameter \code{linear}. Now only used by \code{interp.old()}. \code{interp.old()}. meaning was: meaning was: ... @@ -101,14 +101,15 @@ interp.new(x, y, z, xo = seq(min(x), max(x), length = 40), ... @@ -101,14 +101,15 @@ interp.new(x, y, z, xo = seq(min(x), max(x), length = 40), interpolation the old version is choosen, but spline interpolation is interpolation the old version is choosen, but spline interpolation is done by the new version. done by the new version. Earlier versions (pre 0.5-1) of \code{interp} used the parameter Earlier versions (pre 0.5-1) of \code{interp} used the parameter \code{ncp} to choose between linear and cubic interpolation, this is now done \code{ncp} to choose between linear and cubic interpolation, this is now done by setting the logical parameter \code{linear}. Use of \code{ncp} is still by setting the logical parameter \code{linear}. Use of \code{ncp} is still possible, but is deprecated. possible, but is deprecated. The resulting structure is suitable for input to the The resulting structure is suitable for input to the functions \code{contour} and \code{image}. Check the requirements of functions \code{\link{contour}} and \code{\link{image}}. Check these functions when choosing values for \code{xo} and \code{yo}. the requirements of these functions when choosing values for \code{xo} and \code{yo}. } } \details{ \details{ If \code{linear} is \code{TRUE} (default), linear If \code{linear} is \code{TRUE} (default), linear ... @@ -125,26 +126,23 @@ interp.new(x, y, z, xo = seq(min(x), max(x), length = 40), ... @@ -125,26 +126,23 @@ interp.new(x, y, z, xo = seq(min(x), max(x), length = 40), user defined function). user defined function). The triangulation scheme used by \code{interp} works well if \code{x} The triangulation scheme used by \code{interp} works well if \code{x} and \code{y} have and \code{y} have similar scales but will appear stretched if they have similar scales but will appear stretched if they have very different very different scales. The spreads of \code{x} and \code{y} must be scales. The spreads of \code{x} and \code{y} must be within four within four orders of magnitude of each other for \code{interp} to work. orders of magnitude of each other for \code{interp} to work. } } \references{ \references{ Akima, H. (1978). A Method of Bivariate Interpolation and Akima, H. (1978). A Method of Bivariate Interpolation and Smooth Surface Fitting for Irregularly Distributed Data Points. Smooth Surface Fitting for Irregularly Distributed Data Points. ACM Transactions on Mathematical Software, ACM Transactions on Mathematical Software \bold{4}, 148-164. \bold{4}, 148-164. Akima, H. (1996). Algorithm 761: scattered-data surface fitting that has Akima, H. (1996). Algorithm 761: scattered-data surface fitting that has the accuracy of a cubic polynomial. the accuracy of a cubic polynomial. ACM Transactions on Mathematical Software, ACM Transactions on Mathematical Software \bold{22}, 362--371. \bold{22}, 362--371 } } \seealso{ \seealso{ \code{\link{contour}}, \code{\link{image}}, \code{\link{contour}}, \code{\link{image}}, \code{\link{approx}}, \code{\link{spline}}, \code{\link{approx}}, \code{\link{spline}}, \code{\link{aspline}}, \code{\link{outer}}, \code{\link{expand.grid}}. \code{\link{outer}}, \code{\link{expand.grid}}. } } \examples{ \examples{ ... @@ -162,8 +160,8 @@ points (akima, pch = 3) ... @@ -162,8 +160,8 @@ points (akima, pch = 3) akima.smooth <- akima.smooth <- with(akima, interp(x, y, z, xo=seq(0,25, length=100), with(akima, interp(x, y, z, xo=seq(0,25, length=100), yo=seq(0,20, length=100))) yo=seq(0,20, length=100))) image (akima.smooth) image (akima.smooth, main = "interp(, *) on finer grid") contour(akima.smooth, add=TRUE) contour(akima.smooth, add = TRUE, col = "thistle") points(akima, pch = 3, cex = 2, col = "blue") points(akima, pch = 3, cex = 2, col = "blue") # use triangulation package to show underlying triangulation: # use triangulation package to show underlying triangulation: if(library(tripack, logical.return=TRUE)) if(library(tripack, logical.return=TRUE)) ... @@ -171,9 +169,9 @@ if(library(tripack, logical.return=TRUE)) ... @@ -171,9 +169,9 @@ if(library(tripack, logical.return=TRUE)) # use only 15 points (interpolation only within convex hull!) # use only 15 points (interpolation only within convex hull!) akima.part <- with(akima, interp(x[1:15], y[1:15], z[1:15])) akima.part <- with(akima, interp(x[1:15], y[1:15], z[1:15])) image (akima.part) image (akima.part, "interp() on subset of only 15 points") contour(akima.part, add=TRUE) contour(akima.part, add=TRUE) points(akima$x[1:15],akima$y[1:15]) points(akima$x[1:15],akima$y[1:15], col = "blue") ## spline interpolation, two variants (AMS 526 "Old", AMS 761 "New") ## spline interpolation, two variants (AMS 526 "Old", AMS 761 "New") ## ----------------------------------------------------------------- ## ----------------------------------------------------------------- ... @@ -184,7 +182,7 @@ table(is.na(akima.sO$z)) ## 3990 NA's; = 40 \% ... @@ -184,7 +182,7 @@ table(is.na(akima.sO$z)) ## 3990 NA's; = 40 \% akima.sO <- with(akima, akima.sO <- with(akima, interp.old(x,y,z, xo=seq(0,25, length=100), yo=seq(0,20, len=100), ncp = 4)) interp.old(x,y,z, xo=seq(0,25, length=100), yo=seq(0,20, len=100), ncp = 4)) sum(is.na(akima.sO$z)) ## still 3429 sum(is.na(akima.sO$z)) ## still 3429 image (akima.sO) # almost useless image (akima.sO, main = "interp.old(*, ncp = 4) [almost useless]") contour(akima.sO, add = TRUE) contour(akima.sO, add = TRUE) ## "New:" ## "New:" ... @@ -195,7 +193,8 @@ akima.spl <- with(akima, interp(x,y,z, xo=seq(0,25, length=100), ... @@ -195,7 +193,8 @@ akima.spl <- with(akima, interp(x,y,z, xo=seq(0,25, length=100), yo=seq(0,20, length=100), yo=seq(0,20, length=100), linear=FALSE)) linear=FALSE)) contour(akima.spl) ; points(akima) contour(akima.spl, main = "smooth interp(*, linear = FALSE)") points(akima) full.pal <- function(n) hcl(h = seq(340, 20, length = n)) full.pal <- function(n) hcl(h = seq(340, 20, length = n)) cool.pal <- function(n) hcl(h = seq(120, 0, length = n) + 150) cool.pal <- function(n) hcl(h = seq(120, 0, length = n) + 150) ... @@ -203,6 +202,7 @@ warm.pal <- function(n) hcl(h = seq(120, 0, length = n) - 30) ... @@ -203,6 +202,7 @@ warm.pal <- function(n) hcl(h = seq(120, 0, length = n) - 30) filled.contour(akima.spl, color.palette = full.pal, filled.contour(akima.spl, color.palette = full.pal, plot.axes = { axis(1); axis(2); plot.axes = { axis(1); axis(2); title("smooth interp(*, linear = FALSE"); points(akima, pch = 3, col= hcl(c=100, l = 20))}) points(akima, pch = 3, col= hcl(c=100, l = 20))}) # no extrapolation! # no extrapolation! ... ...