Description Usage Arguments Value Note Author(s) Examples
Interpolate the value of a GRF function in specified locations.
1 2 3 4 | evaluate.grf(locations, grf.object, function.number = 1,
function.name = NULL, periodic = TRUE,
interpolation.method = "bicubic", rescale.method = "minmax",
return.df = FALSE)
|
locations |
An N x 2 matrix containing the coordinates of the N locations of interest. |
grf.object |
The GRF object containing the function, generated by |
function.number |
The index of the function of interest. |
function.name |
The name of the function of interest. |
periodic |
If true, locations outside the rectangular domain of |
interpolation.method |
Specifies the method used for interpolation. Either |
rescale.method |
Specifies how the interpolated values are rescaled. Either |
return.df |
If true, the return value is a data frame containing 3 columns: The x- and y-coordinates from |
A numeric
of length N containing the interpolated values of the GRF in the specified locations.
Using interpolation.method = "bicubic"
can lead to interpolated values that are outside the range of the original grid values.
If this is combined with rescale.method = "minmax"
, then the resulting values are not guaranteed to be inside the interval [0, 1].
This can be fixed by mapping values greater than 1 to 1, and less than 0 to 0.
Mathias Isaksen mathiasleanderi@gmail.com
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 | # Comparison of different interpolation and rescaling methods
library(GRFics)
library(ggplot2)
# Create GRF object on a 20 x 20 grid
grf.object = generate.grf.object(-1, 1, -1, 1, 20, 20, num.functions = 1,
range.parameter = 1,
strength.parameter = 1, direction.parameter = pi/4,
initial.seed = 123)
# Create 500 x 500 grid for interpolation
interp.grid = generate.grid.centers(-1, 1, -1, 1, 500, 500)
rescale.method = c("minmax", "uniform")
comparison.df = data.frame()
for (i in 1:2) {
nearest.values = evaluate.grf(interp.grid, grf.object, interpolation.method = "nearest", rescale.method = rescale.method[i])
bilinear.values = evaluate.grf(interp.grid, grf.object, interpolation.method = "bilinear", rescale.method = rescale.method[i])
bicubic.values = evaluate.grf(interp.grid, grf.object, interpolation.method = "bicubic", rescale.method = rescale.method[i])
comparison.df = rbind(comparison.df,
data.frame(
x = interp.grid$x, y = interp.grid$y,
z = c(nearest.values, bilinear.values, bicubic.values),
interpolation.method = rep(c("1. nearest", "2. bilinear", "3. bicubic"), each = nrow(interp.grid)),
rescale.method = rescale.method[i]))
}
# Show comparison plot using facet_grid
ggplot()+
theme_bw()+
geom_raster(data = comparison.df, aes(x = x, y = y, fill = z))+
facet_grid(cols = vars(interpolation.method), rows = vars(rescale.method))+
scale_fill_gradientn(colours = c("black", "white"))+
coord_fixed()
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.