sl.remap.array: Remap Array

sl.remap.arrayR Documentation

Remap Array

Description

Remap a numeric array along one of its dimensions from an old to a new dimension variable vector.

Usage

sl.remap(input.data, input.dimvals, new.dimvals, remap.dim = 1, method = "linear", extrapolate.method = "none", return.remapinfo = FALSE, verbose = TRUE)

Arguments

input.data

a numeric array (can also be a vector or matrix) with D <= 4 dimensions specifying the original data values. The dimension specified by remap.dim must have the same length as input.dimvals; the remapping is performed along this dimension while the other dimensions are kept.

input.dimvals

a numeric vector of length N > 1 specifying the original dimension variable values; must increase strict monotonously.

new.dimvals

a numeric vector of length M >= 1 specifying the new dimension variable values; must increase strict monotonously.

remap.dim

an integer for which 1 <= remap.dim <= D specifying the dimension along which the data is remapped.

method

a character specifying the interpolation method. Must be one of "linear" (default) and "nearestneighbour".

extrapolate.method

a character specifying the extrapolation method. Must be one of "none" (default), "linear", and "nearestneighbour". Default is "none" which implies that values outside the original dimension range will be NA.

return.remapinfo

a logical value specifying whether or not to return information on the remapping (nearest-neighbour-before indices and weights). Default is FALSE.

verbose

a logical value specifying whether to produce warnings, in particular when the new dimension variable axis reaches outside the original dimension variable axis. Default is TRUE.

Value

data

an array with D dimensions (like the input array input.data) where all expect the remapped dimension have the same length as in input.data, but the remapped dimension has the same length as new.dimvals instead of input.dimvals.

If return.remapinfo=TRUE, an additional list element remapinfo is returned, with the following sub-elements:

weights.left.ind

an integer vector of length M with the indices of the original points directly before the corresponding new points.

weights.left

an numeric vector of length M with the weights given to the points provided in weights.left.ind; the respective subsequent points were given the weights (1-weights.left).

Note

This function is similar to and was inspired by sl.trajectory.remaptime but works on arrays (including vectors) instead of 1-dimensional spatial line objects on spheres (such as trajectories).

Author(s)

Helge Goessling

See Also

sl.trajectory.remaptime

Examples

# Vector remapping
x = seq(-2, 3, by=0.5)
y = x^2
x.remap = seq(-1, 5, by=0.3)
y.remap.lin = as.vector(sl.remap.array(input.dat=y, input.dimvals=x, new.dimvals=x.remap,
                                       method="linear",extrapolate.method="linear")$data)
y.remap.nn = as.vector(sl.remap.array(input.dat=y, input.dimvals=x,new.dimvals=x.remap,
                                      method="nearestneighbour",extrapolate.method="nearestneighbour")$data)

plot(x,y,ylim=c(0,20),type="p",xlim=c(-2,5))
points(x.remap,y.remap.lin,col="red")
points(x.remap,y.remap.nn,col="blue")

# Matrix remapping
dat1 = matrix(seq(0.5,3,by=0.5),ncol=3)
dat2 = sl.remap.array(input.dat=dat1, input.dimvals=1:3, new.dimvals = seq(1.5,3.5,by=0.5),
                      remap.dim=2, method="linear",extrapolate.method="linear")

print(dat1)
print(dat2$data)

FESOM/spheRlab documentation built on April 6, 2024, 6:52 p.m.