smooth_cube.Rd
This function is used to conduct a linear interpolation of missing values in the time series of vegetation indices on a pixel basis. By default a Savitzkiy-Golay filter is used to smooth the time series. A custom function for the interpolation and smoothing can be specified. It can be used on equally spaced data cubes in the time dimension where missing values, e.g. through clouds, are an issue. The result of the function is a dense time series where missing values are imputed and a smoothing function is applied to reduce the noise in the signal.
smooth_cube(
files = NULL,
bands = NULL,
times = NULL,
dx = NULL,
dy = NULL,
dt = NULL,
srs = NULL,
after = NULL,
before = NULL,
timeframe = "full",
bbox = NULL,
aggregation = "mean",
resampling = "bilinear",
smoothing_function = NULL,
chunking = c(1, 256, 256),
threads = 1,
outdir = ".",
overwrite = F,
label = "",
n = 100,
verbose = T,
...
)
A character vector with the filepaths to the raster files for which gap-filling and a smoothing function shall be applied.
A character vector indicating the names of the bands in each
of the raster files specified in the files
argument.
(see create_image_collection
)
A character vector indicating the date of each raster file specified
in the files
argument in the form of "
(see create_image_collection
)
The spatial resolution of the outcome raster files in the x
dimension
in the units of the coordinate reference system specified witht the srs
argument.
(see cube_view
)
The spatial resolution of the outcome raster files in the y
dimension
in the units of the coordinate reference system specified witht the srs
argument.
(see cube_view
)
The temporal resolution of the outcome raster files.
(see cube_view
)
Target spatial reference system as a string; can be a proj4 definition,
WKT, or in the form "EPSG:XXXX" (see cube_view
)
A length one character vector in the form " the earliest date (inclusive) included in the temporal extent.
A length one character vector in the form " the latest date (inclusive) included in the temporal extent.
A character of either "seasonal"
or "complete"
specifying
if the calculation should be applied for the complete time series or for
each year independently. Defaults to "complete"
. If "seasonal"
is specified
the years
variables cannot be left empty.
A numeric vector of lenght four indicating the spatial bounding
box of the query (xmin, ymin, xmax, ymax) in geographic coordinates. Defaults
to `NULL` which will set the spatial extent to global, i.e. c(-180, -90, 180, 90)
.
aggregation method as string, defining how to deal with pixels
containing data from multiple images, can be "min", "max", "mean", "median", or "first"
(see cube_view
)
resampling method used in gdalwarp when images are read, can be
"near", "bilinear", "bicubic" or others as supported by gdalwarp
(see https://gdal.org/programs/gdalwarp.html and cube_view
)
Defaults to NULL which means that a linear
interpolation coupled with sgolayfilt
` at its standard
parametrization is applied. Can be substituted by a function.
This function is applied across the time dimension of the data cube and imputes
NA's. The return vector must be of equal length to the time dimension, must
return one row for each band in the data cube and must not include any NA's.
See the example for the standard function which is applied when the smoothing_function
is omitted.
Vector of length 3 defining the size of data cube chunks in the
order time, y, x. (see raster_cube
)
Number of threads used to process data cubes
(see link[gdalcubes]{gdalcubes_options}
)
A character vector pointing to an existing directory where the output rasters are written to.
A logical indicating if existing files in outdir should be overwritten.
A character vector which is used as a prefix to the output filenames.
The ratio of pixels for which a custom smoothing_function
is tested
on randomly selected pixels to test if it is applicable. Defaults to 0.01
.
A logical indicating the verbosity.
additional arguments to write_tif
if (FALSE) {
smoothing_function = function(x){
results = lapply(1:nrow(x), function(i) {
y = x[i,]
lin = zoo::na.approx(y, na.rm = F, rule = 2)
svg = signal::sgolayfilt(lin)
svg
})
do.call(rbind, results)
}
}