interpolate_linear: Linear interpolation between pairs of rasters

Description Usage Arguments Details Value Examples

Description

Linearly interpolate cell values between pairs of raster grids, at specified locations (e.g. "times"). Extrapolation to times beyond the last raster in the series is also possible.

Usage

1
2
interpolate_linear(s, z_in, z_out, outdir, prefix, progress = TRUE,
  write_change = TRUE, return_stack = FALSE, ...)

Arguments

s

A RasterStack or RasterBrick containing the rasters between which interpolation will be performed.

z_in

A numeric vector indicating the positions (e.g., times) associated with layers in s (in the same order as the layers of s - see names(s)).

z_out

a numeric vector that indicates the times to be interpolated to (if z_out extends beyond the latest time slice in z_in, it will be extrapolated using the rate of change from the period between the last and second-to-last time in z_in).

outdir

The directory to which files will be written (recursively created if not already in existence) (character string).

prefix

The output files will have pattern prefix_x.tif, where x is the position (timestep) (potentially multiple digits), and prefix is a string that you specify here (character string).

progress

Logical. Show progress bar?

write_change

Logical. Should the change grids (which define the change in cells' values per timestep between each pair of time slices) be written to outdir.

return_stack

Logical. Should the interpolated grids (at timesteps z_out) be returned as a RasterStack?

...

Additional arguments passed to writeRaster.

Details

Extrapolation below the earliest grid in s is currently not implemented. Interpolation is linear between pairs of time slices existing in z_in, and extrapolation beyond the last slice in s, if requested, follows the trend observed between the last and second-to-last slice in z_in.

Value

Unless return_stack is TRUE, interpolate creates files in outdir, but returns NULL, invisibly, to R. If return_stack is TRUE, a RasterStack of interpolated Raster objects is returned to R.

Examples

1
2
3
4
5
6
7
library(raster)
r1 <- raster(matrix(rnorm(100), ncol=10))
r2 <- raster(matrix(rnorm(100, mean=11), ncol=10))
s <- stack(r1, r2)
s_interp <- interpolate_linear(s, c(2001, 2011), 2001:2020, tempdir(), 
                               'example', return_stack=TRUE)
plot(s_interp, zlim=range(values(s_interp)))

johnbaums/things documentation built on May 19, 2019, 3:03 p.m.