Learn R Programming

ursa (version 3.11.1)

temporal_interpolate: Fill gaps across bands using moving mean window

Description

temporal_interpolate is applicable for multiband raster image, where bands are regular timestamps or period. For each cell (local operation of map algebra), NA value is replaced by averaging of two closest values (one value before, one value later) inside of moving window.

Usage

temporal_interpolate(obj, win = 7, cover = 0, verbose = FALSE)

Value

ursaRaster object, if obj is object of class ursaRaster.

matrix object, if obj is a matrix.

Arguments

obj

Object of class ursaRaster or matrix, where spatial locations are by rows and temporal observations are by columns.

win

Positive integer. Size of moving window. Required odd value; otherwise is coerced to the closest odd integer.

cover

Not applicable. For consistence call with temporal_mean.

verbose

Logical. TRUE provides some additional information on console. Default is FALSE.

Author

Nikita Platonov platonov@sevin.ru

Details

Function uses weighted averaging depending of proximity of found non-NA values. For example, if ind is temporal index of NA value in the center of movind window, indL=ind-2 is temporal index of the closest early value valL, and indR=ind+1 is temporal index of the closest late value valR, then result is val <- (1/3) * valL + (2/3) * valR.

See Also

temporal_mean

Examples

Run this code
session_grid(NULL)
n <- 45 # bands
m <- 3 # sample size
k <- median(seq(n))+seq(m)-(m %/% 2)-1 ## sample subset
s <- 5 # window size
a <- round(ursa_dummy(n,min=-60,max=60,elements=15,mul=1/8))
a[a<(-40)] <- NA
b <- temporal_interpolate(a,7)
p1 <- colorize(a,lazy=TRUE)
p2 <- colorize(b,lazy=TRUE,colortable=p1)
display(list('Source'=p1[k],'Gaps are filled'=p2[k]),layout=c(2,NA)
       ,legend=list(list(1,"right"),list(2,"right")),decor=FALSE)

Run the code above in your browser using DataLab