Description Usage Arguments Value Author(s) See Also Examples
This function perform gap-filling of gappy raster time series
1 | rtsa.gapfill(x, rastermask = NULL, method, cores = 1L, verbose = FALSE)
|
x |
Input raster time series as | |||||||||||||
rastermask |
A | |||||||||||||
method |
Character. Defines the algorithm to be used to interpolate pixels with incomplete temporal profiles. Accepts the following input:
| |||||||||||||
cores |
Integer. Defines the number of CPU to be used for multicore processing. Default to "1" core for singlecore processing. | |||||||||||||
... |
Additional arguments |
Object of class RasterBrickTS
with gap-filled pixels
Federico Filipponi
na.interpolation
, dineof
, approxfun
, splinefun
, stinterp
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)
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.