Subset-Predict {gapfill} | R Documentation |
Subset and Predict Functions
Description
The Subset
and Predict
function used in the default configuration of Gapfill
.
To predict a missing value, the two function are called sequentially as described the help page of Gapfill
.
Usage
Subset(data, mp, i, initialSize = c(10L, 10L, 1L, 5L))
Predict(
a,
i,
nTargetImage = 5,
nImages = 4,
nQuant = 2,
predictionInterval = FALSE,
qrErrorToNA = TRUE
)
Arguments
data |
Numeric array with four dimensions. The input (satellite) data to be gap-filled.
Missing values should be encoded as |
mp |
Integer vector of length 4 encoding the position of the missing value in |
i |
Integer vector of length 1. The number of tried subsets that lead to a |
initialSize |
Integer vector of length 4, that provides the size of the subset for |
a |
Return value of |
nTargetImage |
Integer vector of length 1. Minimum number of non-NA values in the image containing the missing value.
If the criterion is not met, |
nImages |
Integer vector of length 1. Minimum number of non-empty images.
If the criterion is not met, |
nQuant |
Integer vector of length 1. Parameter passed to |
predictionInterval |
Logical vector of length 1.
If |
qrErrorToNA |
Logical vector of length 1.
If |
Details
The Subset
function defines the search strategy to find a
relevant subset by calling the function ArrayAround
.
The size of the initial subset is given by the argument initialSize
.
Its default values is c(5L, 5L, 1L, 5L)
, which corresponds to a spatial extend of 5 pixels
in each direction from the missing value and includes time points having the previous, the same or the next seasonal index and
are not further apart than 5 years.
With an increase of the argument i
, the spatial extent of the subset increases.
The Predict
function decides whether the subset a
is suitable and
calculates the prediction (fill value) when a suitable subset is provided.
To formulate the conditions that are used to decide if a subset is suitable,
consider the subset a
as a collection of images.
More precisely, if dim(a)
=
c(d1, d2, d3, d4)
,
it can be seen as a collection of d3*d4
images with an extent of d1
by d2
pixels.
Using this terminology, we require the following conditions to be fulfilled
in order to predict the missing value:
-
a
contains at leastnTargetImage
non-NA values in the image containing the missing value, -
a
contains at leastnImages
non-empty images.
The prediction itself is based on sorting procedures (see Score
and
EstimateQuantile
) and the quantile regression function rq
.
If the argument predictionInterval
is TRUE
the Predict
functions returns
the predicted value together with the lower and upper bounds of an approximated 90% prediction interval.
The interval combines the uncertainties introduced by Score
and EstimateQuantile
.
Value
Subset
returns an array with 4 dimensions containing the missing value
at the position indicated by the attribute mp
.
Predict
returns a numeric vector containing the predicted value
(and if predictionInterval
is TRUE
, the lower and upper bounds of the prediction interval),
or NA
, if no prediction was feasible.
Note
The current implementation of Subset
does not take into account
that locations at the boundary of data
can be neighboring to each other.
For example, if global data (entire sphere) are considered, the location
data[1,1,,]
is a neighbor of data[dim(data)[1], dim(data)[2],,]
.
Similar considerations apply when data are available for an entire year.
To take this into account, the Subset
function can be redefined accordingly or
the data can be augmented.
Author(s)
Florian Gerber, flora.fauna.gerber@gmail.com.
References
F. Gerber, R. de Jong, M. E. Schaepman, G. Schaepman-Strub, and R. Furrer (2018) in IEEE Transactions on Geoscience and Remote Sensing, pp. 1-13, doi: 10.1109/TGRS.2017.2785240.
See Also
Gapfill
, Extend
,
EstimateQuantile
, Score
, ndvi
.
Examples
## Assume we choose c(5, 5, 1, 5) as initalSize of the subset
iS <- c(5, 5, 1, 5)
## case 1: initial subset leads to prediction -------
i <- 0
a <- Subset(data = ndvi, mp = c(1, 3, 1, 2), i = i, initialSize = iS)
p <- Predict(a = a, i = i)
p
stopifnot(identical(a, ArrayAround(data = ndvi, mp = c(1, 3, 1, 2),
size = c(5 + i, 5 + i, 1, 5))))
stopifnot(identical(p, Gapfill(data = ndvi, subset = 1807,
initialSize = iS, verbose = FALSE)$fill[1807]))
## case 2: two tries are necessary ------------------
i <- 0
a <- Subset(data = ndvi, mp = c(20, 1, 1, 2), i = i, initialSize = iS)
p <- Predict(a = a, i = i)
p
## Increase i and try again.
i <- i + 1
a <- Subset(data = ndvi, mp = c(20, 1, 1, 2), i = i, initialSize = iS)
p <- Predict(a = a, i = i)
p
stopifnot(identical(a, ArrayAround(data = ndvi, mp = c(20, 1, 1, 2),
size = c(5 + i, 5 + i, 1, 6))))
stopifnot(identical(p, Gapfill(data = ndvi, subset = 1784,
initialSize = iS, verbose = FALSE)$fill[1784]))