rtsa.gapfill: Raster time series gap-filling

Description Usage Arguments Value Author(s) See Also Examples

View source: R/rtsa_gapfill.R

Description

This function perform gap-filling of gappy raster time series

Usage

1
rtsa.gapfill(x, rastermask = NULL, method, cores = 1L, verbose = FALSE)

Arguments

x

Input raster time series as RasterStackTS or RasterBrickTS object

rastermask

A RasterLayer to use as a mask. If not set a raster mask is computed to remove all pixels with less than two values in temporal profiles

method

Character. Defines the algorithm to be used to interpolate pixels with incomplete temporal profiles. Accepts the following input:

"linear" for linear interpolation in na.interpolation using approxfun
"spline" for spline interpolation in na.interpolation using splinefun
"stine" for stine interpolation in na.interpolation using stinterp
"dineof" for dineof interpolation using dineof
cores

Integer. Defines the number of CPU to be used for multicore processing. Default to "1" core for singlecore processing.

...

Additional arguments

Value

Object of class RasterBrickTS with gap-filled pixels

Author(s)

Federico Filipponi

See Also

na.interpolation, dineof, approxfun, splinefun, stinterp

Examples

 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
34
35
36
37
38
## Not run: 
## create raster time series using the 'pacificSST' data from 'remote' package
require(remote)

data(pacificSST)
pacificSST[which(getValues(pacificSST == 0))] <- NA # set NA values
# create rts object
rasterts <- rts(pacificSST, seq(as.Date('1982-01-15'), as.Date('2010-12-15'), 'months'))

## generate raster mask
raster_mask <- pacificSST[[1]] # create raster mask
values(raster_mask) <- 1 # set raster mask values
raster_mask[which(is.na(getValues(pacificSST[[1]])))] <- 0 # set raster mask values

## randomly remove values from cells in rts object
frac_gaps <- 0.5 # the fraction of data with NaNs
temporal_cells <- as.integer(ncell(rasterts) * nlayers(rasterts)) # number of total cells in rts
# define random position of cells to be set to NaN
na_cells <- sort(unique(sample.int(temporal_cells, (temporal_cells * frac_gaps))))
gappy_values <- as.vector(getValues(rasterts)) # extract raster values
gappy_values[na_cells] <- NA # set NA to random positions
rasterts_gappy <- setValues(rasterts, values=gappy_values) # set NA to pixels

## perform gap-filling on the gappy dataset

# using linear interpolation
rasterts_linear <- rtsa.gapfill(rasterts_gappy, method="linear")

# using spline interpolation and multiple cores
rasterts_spline <- rtsa.gapfill(rasterts_gappy, method="spline", cores=4)

# using stine interpolation and raster mask
rasterts_stine <- rtsa.gapfill(rasterts_gappy, rastermask=raster_mask, method="stine")

# using dineof interpolation and raster mask
rasterts_dineof <- rtsa.gapfill(rasterts_gappy, rastermask=raster_mask, method="dineof")

## End(Not run)

ffilipponi/rtsa documentation built on Oct. 18, 2019, 12:37 a.m.