Commit 4ec7cb75 authored by agebhard's avatar agebhard
Browse files

add last changes from Martin Maechler

ready for release as 0.5-1
parent 840a8ad1
...@@ -3,5 +3,5 @@ akima Waveform Distortion Data for Bivariate ...@@ -3,5 +3,5 @@ akima Waveform Distortion Data for Bivariate
aspline Univariate Akima interpolation aspline Univariate Akima interpolation
interp Gridded Bivariate Interpolation for Irregular interp Gridded Bivariate Interpolation for Irregular
Data Data
interpp Pointwise Bivariate Interpolation for Irregular interpp Pointwise Bivariate Interpolation for
Data Irregular Data
...@@ -7,18 +7,14 @@ interp.new <- ...@@ -7,18 +7,14 @@ interp.new <-
if(!(all(is.finite(x)) && all(is.finite(y)) && all(is.finite(z)))) if(!(all(is.finite(x)) && all(is.finite(y)) && all(is.finite(z))))
stop("missing values and Infs not allowed") stop("missing values and Infs not allowed")
if(!is.null(ncp)) { if(!is.null(ncp)) {
if(ncp != 0) { if(ncp != 0)
cat("ncp not supported, it is automatically choosen by Fortran code\n") warning("'ncp' not supported, it is automatically choosen by Fortran code\n")
} else
else { linear <- TRUE
cat("linear interpolation not yet implemented with interp.new().\n")
stop("use interp.old().")
}
}
if(linear) {
cat("linear interpolation not yet implemented with interp.new().\n")
stop("use interp.old().")
} }
if(linear)
stop("linear interpolation not implemented in interp.new().\n",
"use 'interp()' (or 'interp.old()').")
drx <- diff(range(x)) drx <- diff(range(x))
dry <- diff(range(y)) dry <- diff(range(y))
......
...@@ -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(<akima data>, *) 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!
......
...@@ -120,7 +120,10 @@ dupfun = NULL, ncp) ...@@ -120,7 +120,10 @@ dupfun = NULL, ncp)
\bold{22}, 362-371. \bold{22}, 362-371.
} }
\seealso{ \seealso{
\code{\link[base]{contour}}, \code{\link[base]{image}}, \code{\link[base]{approx}}, \code{\link[base]{spline}}, \code{\link[base]{outer}}, \code{\link[base]{expand.grid}},\code{\link{interp}}. \code{\link[base]{contour}}, \code{\link[base]{image}},
\code{\link[base]{approx}}, \code{\link[base]{spline}},
\code{\link[base]{outer}}, \code{\link[base]{expand.grid}},
\code{\link{interp}}, \code{\link{aspline}}.
} }
\examples{ \examples{
data(akima) data(akima)
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment