Commit 1db7539c authored by Florian Gerber's avatar Florian Gerber

CRAN version 0.9.6

parent 2fd26265
......@@ -2,4 +2,4 @@
^\.Rproj\.user$
^\.git/*$
^.gitignore$
*.tar.gz$
\ No newline at end of file
^.*\.tar\.gz$
\ No newline at end of file
Package: gapfill
Type: Package
Title: Fill Missing Values in Satellite Data
Version: 0.9.5-3
Date: 2017-06-08
Version: 0.9.6
Date: 2018-04-09
Author: Florian Gerber
Maintainer: Florian Gerber <florian.gerber@math.uzh.ch>
Description: Tools to fill missing values in satellite data and to develop new
......
......@@ -22,4 +22,4 @@ importFrom(quantreg,predict.rq)
importFrom(quantreg,rq)
importFrom(stats,ecdf)
importFrom(stats,quantile)
useDynLib(gapfill)
useDynLib(gapfill, .registration = TRUE)
version 0.9.6
- updated citation information.
- bug fix: in former versions of Gapfill the error
'Error in rq.fit.br(x, y, tau = tau, ...) : Singular design matrix'
occurred if a subset used for the prediction contained very few
observed values. This error does no longer stop the gap-filling.
See the new argument 'qrErrorToNA' in ?Predict.
- it is now also possible to predict observed values.
See the description of the 'subset' argument in ?Gapfill.
version 0.9.5-3
- new case-sensitifity of message test with testthat is now respected.
......
......@@ -2,6 +2,6 @@
# Generator token: 10BE3573-1514-4C36-9D1C-5A225CD40393
Score_cpp <- function(mat) {
.Call('gapfill_Score_cpp', PACKAGE = 'gapfill', mat)
.Call(`_gapfill_Score_cpp`, mat)
}
This diff is collapsed.
.onAttach <- function(...) {
packageStartupMessage("--> See ?Gapfill and https://doi.org/10.1109/TGRS.2017.2785240 <--")
}
......@@ -25,7 +25,7 @@ The package can be installed with
R> install.packages("gapfill")
To get started the help pages
To get started see the example in
R> ?Gapfill
......
citHeader("To cite gapfill in publications use:")
citEntry(entry = "Article",
title = "Predicting missing values in spatio-temporal satellite data",
title = "Predicting Missing Values in Spatio-Temporal Remote Sensing Data",
author = personList(as.person("Florian Gerber"),
as.person("Reinhard Furrer"),
as.person("Gabriela Schaepman-Strub"),
as.person("Rogier de Jong"),
as.person("Micheal E. Schaepman")),
journal = "ArXiv e-prints",
year = "2016",
as.person("Micheal E. Schaepman"),
as.person("Gabriela Schaepman-Strub"),
as.person("Reinhard Furrer")
),
journal = "IEEE Transactions on Geoscience and Remote Sensing",
year = "2018",
volume = "",
number = "",
pages = "",
url = "http://arxiv.org/abs/1605.01038",
pages = "1--13",
url = "https://doi.org/10.1109/TGRS.2017.2785240",
doi = "10.1109/TGRS.2017.2785240",
textVersion =
paste("F. Gerber, R. Furrer, G. Schaepman-Strub, R. de Jong, and M.E. Schaepman (2016).",
"Predicting missing values in spatio-temporal satellite data.",
"http://arxiv.org/abs/1605.01038")
paste("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, https://doi.org/10.1109/TGRS.2017.2785240")
)
......@@ -36,9 +36,8 @@ EstimateQuantile(a = a, mp = attr(a, "mp"), nQuant = 2)
}
\references{
F. Gerber, R. Furrer, G. Schaepman-Strub, R. de Jong, M. E. Schaepman, 2016,
Predicting missing values in spatio-temporal satellite data.
\url{http://arxiv.org/abs/1605.01038}.
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, \url{https://doi.org/10.1109/TGRS.2017.2785240}.
}
\seealso{
\code{\link{Predict}}.
......
......@@ -100,9 +100,8 @@ Image(out5$fill)
}
}
\references{
F. Gerber, R. Furrer, G. Schaepman-Strub, R. de Jong, M. E. Schaepman, 2016,
Predicting missing values in spatio-temporal satellite data.
\url{http://arxiv.org/abs/1605.01038}.
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, \url{https://doi.org/10.1109/TGRS.2017.2785240}.
}
\seealso{
\code{\link{Gapfill}}, \code{\link{Subset-Predict}}, \code{\link{Score}}, \code{\link[stats]{lm}}.
......
......@@ -8,7 +8,7 @@
\title{Main Function for Gap-Filling}
\usage{
Gapfill(data, fnSubset = Subset, fnPredict = Predict, iMax = Inf,
nPredict = 1L, subset = "missings", clipRange = c(-Inf, Inf),
nPredict = 1L, subset = "missing", clipRange = c(-Inf, Inf),
dopar = FALSE, verbose = TRUE, ...)
}
\arguments{
......@@ -29,11 +29,11 @@ The maximum number of iterations until \code{NA} is returned as predicted value.
\item{nPredict}{Integer vector of length 1. Specifies the length of the vector returned from \code{fnPredict}.
Values larger than 1 may increase memory usage considerably.}
\item{subset}{If \code{"missing"}, all missing values in \code{data} are filled.
If a logical array of the same dimensions as \code{data} or
a vector with positive integers, only the missing elements of \code{data[subset]} are filled.
Note that this does not the same effect as selecting a subset of the input data, since
independent of the specified subset, all values in \code{data} are used to inform the predictions.}
\item{subset}{If \code{"missing"} (default), all missing values of \code{data} are replaced by predictions.
If \code{"observed"}, all observed values of \code{data} are replaced by predictions.
If a logical array of dimension \code{dim(data)} or
a vector with positive integers, the elements \code{data[subset]} are replaced by predictions.
Note that independently of the specified subset all provided values in \code{data} are used to inform the predictions.}
\item{clipRange}{Numeric vector of length 2.
Specifies the lower and the upper bound of the filled data.
......@@ -47,7 +47,7 @@ if a parallel back-end (e.g., from the R package doParallel or doMpi) is availab
See the example below and \code{\link[foreach]{foreach}} for more information.}
\item{verbose}{Logical vector of length 1.
If \code{TRUE}, messages are printed.}
If \code{TRUE} (default), messages are printed.}
\item{...}{Additional arguments passed to \code{fnSubset} and \code{fnPredict}.}
}
......@@ -139,7 +139,7 @@ Note that there exist other parallel back-ends implemented in other packages; su
Some parallel back-ends are platform dependent.
While this approach shortens the process time by distributing the computational workload,
it does not reduce the memory footprint of the procedure.
The second strategy, which also reduces memory usage, is to split the \code{data} into several independent chunks.
The second strategy, which also reduces memory usage, is to split the \code{data} into several independent chunks.
Whether data chunks are independent or not depends on the function provided to \code{fnSubset}.
For example, the default \code{\link{Subset}} function never includes data that
is further apart from the missing value than 1 seasonal index.
......@@ -184,9 +184,8 @@ Image(out$fill[,,,,3] - out$fill[,,,,2])
}
}
\references{
F. Gerber, R. Furrer, G. Schaepman-Strub, R. de Jong, M. E. Schaepman, 2016,
Predicting missing values in spatio-temporal satellite data.
\url{http://arxiv.org/abs/1605.01038}.
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, \url{https://doi.org/10.1109/TGRS.2017.2785240}.
}
\seealso{
\code{\link{Extend}}, \code{\link{Subset-Predict}}, \code{\link{Image}}.
......
......@@ -43,9 +43,8 @@ stopifnot(identical(s, sByHand))
}
\references{
F. Gerber, R. Furrer, G. Schaepman-Strub, R. de Jong, M. E. Schaepman, 2016,
Predicting missing values in spatio-temporal satellite data.
\url{http://arxiv.org/abs/1605.01038}.
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, \url{https://doi.org/10.1109/TGRS.2017.2785240}.
}
\author{
Florian Gerber, \email{florian.gerber@math.uzh.ch}.
......
......@@ -12,7 +12,7 @@
Subset(data, mp, i, initialSize = c(10L, 10L, 1L, 5L))
Predict(a, i, nTargetImage = 5, nImages = 4, nQuant = 2,
predictionInterval = FALSE)
predictionInterval = FALSE, qrErrorToNA = TRUE)
}
\arguments{
\item{data}{Numeric array with four dimensions. The input (satellite) data to be gap-filled.
......@@ -37,10 +37,15 @@ If the criterion is not met, \code{NA} is returned.}
\item{nQuant}{Integer vector of length 1. Parameter passed to \code{\link{EstimateQuantile}}.}
\item{predictionInterval}{Logical vector of length 1.
If \code{FALSE} (default), no prediction interval is returned.
If \code{TRUE}, the predicted value together with the lower and upper bounds
of an approximated 90\% prediction interval are returned.
When \code{predictionInterval} \code{= TRUE}, the function returns 3 values, and hence,
In that case, the function returns 3 values, and hence,
the argument \code{nPredict} of \code{\link{gapfill}} has to be set to 3 in order to store all returned values.}
\item{qrErrorToNA}{Logical vector of length 1.
If \code{TRUE} (default), an error in the quentile regression fitting leads to a \code{NA} return value.
If \code{FALSE}, an error in the quentile regression fitting leads to an error and stops the prediction.}
}
\value{
\code{Subset} returns an array with 4 dimensions containing the missing value
......@@ -122,9 +127,8 @@ stopifnot(identical(p, Gapfill(data = ndvi, subset = 1784,
initialSize = iS, verbose = FALSE)$fill[1784]))
}
\references{
F. Gerber, R. Furrer, G. Schaepman-Strub, R. de Jong, M. E. Schaepman, 2016,
Predicting missing values in spatio-temporal satellite data.
\url{http://arxiv.org/abs/1605.01038}.
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, \url{https://doi.org/10.1109/TGRS.2017.2785240}.
}
\seealso{
\code{\link{Gapfill}}, \code{\link{Extend}},
......
......@@ -34,9 +34,8 @@ function \code{\link{Image}}.
}
\references{
F. Gerber, R. Furrer, G. Schaepman-Strub, R. de Jong, M. E. Schaepman, 2016,
Predicting missing values in spatio-temporal satellite data.
\url{http://arxiv.org/abs/1605.01038}.
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, \url{https://doi.org/10.1109/TGRS.2017.2785240}.
}
\seealso{
\code{\link{Gapfill}}, \code{\link{Subset-Predict}}, \code{\link{Extend}}, \code{\link{Image}}.
......
......@@ -7,7 +7,7 @@ using namespace Rcpp;
// Score_cpp
NumericVector Score_cpp(NumericMatrix mat);
RcppExport SEXP gapfill_Score_cpp(SEXP matSEXP) {
RcppExport SEXP _gapfill_Score_cpp(SEXP matSEXP) {
BEGIN_RCPP
Rcpp::RObject rcpp_result_gen;
Rcpp::RNGScope rcpp_rngScope_gen;
......@@ -18,7 +18,7 @@ END_RCPP
}
static const R_CallMethodDef CallEntries[] = {
{"gapfill_Score_cpp", (DL_FUNC) &gapfill_Score_cpp, 1},
{"_gapfill_Score_cpp", (DL_FUNC) &_gapfill_Score_cpp, 1},
{NULL, NULL, 0}
};
......
......@@ -3,7 +3,7 @@ using namespace Rcpp;
double MeanNA_cpp(NumericVector x) {
int n = x.size() ;
double s = 0;
double s = 0 ;
int notNA = 0 ;
for( int i=0; i<n; i++){
......
#require(testthat); library("gapfill", lib.loc = "../../../lib/")
# library("testthat"); library("gapfill", lib.loc = "../../../lib/")
context("test-Gapfill")
test_that("Gapfill demo",{
......@@ -6,7 +6,7 @@ test_that("Gapfill demo",{
expect_message(fill <- Gapfill(data)$fill,
"data has 3969 values: 3301 \\(83.2%\\) observed,\n 668 \\(16.8%\\) missing,\n 668 \\(16.8%\\) to predict.\n")
"data has 3969 values: 3301 \\(83%\\) observed\n 668 \\(17%\\) missing\n 668 \\(17%\\) to predict\n")
ref <- c(0.5174, 0.4835, 0.4992, 0.4933, 0.5401, 0.5348, 0.5484, 0.5189,
0.5161, 0.5044, 0.5449, 0.5391, 0.5376, 0.5401, 0.5599, 0.5784,
......@@ -143,6 +143,84 @@ test_that("Gapfill prediction interval",{
})
test_that("Gapfill subset",{
data <- ndvi[,,2:3,2:3]
PredictMean <- function (a, i) mean(a, na.rm = TRUE)
ref <- structure(c(0.6279, 0.6241, 0.6228, 0.6215, 0.6211, 0.619, 0.6173,
0.6159, 0.6152, 0.6142, 0.615, 0.6134, 0.6125, 0.6096, 0.6072,
0.6063, 0.6061, 0.6045, 0.6039, 0.602, 0.6009, 0.6273, 0.6237,
0.6227, 0.6216, 0.6212, 0.6192, 0.6175, 0.6161, 0.6154, 0.6144,
0.6151, 0.6137, 0.6128, 0.6098, 0.6075, 0.6067, 0.6065, 0.605,
0.6044, 0.6026, 0.6016, 0.6284, 0.625, 0.624, 0.6228, 0.6223,
0.6203, 0.6187, 0.6173, 0.6166, 0.6156, 0.6163, 0.6151, 0.6143,
0.6115, 0.6093, 0.6084, 0.6082, 0.6065, 0.6057, 0.6039, 0.6028,
0.6282, 0.6251, 0.6242, 0.6231, 0.6226, 0.6206, 0.6191, 0.6178,
0.617, 0.6162, 0.6168, 0.6157, 0.615, 0.6123, 0.6102, 0.6095,
0.6094, 0.6076, 0.6068, 0.6051, 0.6041, 0.6266, 0.6239, 0.6232,
0.6223, 0.6221, 0.6203, 0.6189, 0.6176, 0.617, 0.6164, 0.6172,
0.6164, 0.6159, 0.6135, 0.6117, 0.611, 0.611, 0.6095, 0.6089,
0.6073, 0.6067, 0.6255, 0.623, 0.6225, 0.6216, 0.6211, 0.6195,
0.6182, 0.6172, 0.6168, 0.6163, 0.617, 0.6163, 0.616, 0.6139,
0.6122, 0.6117, 0.6117, 0.6103, 0.6097, 0.6083, 0.6077, 0.6244,
0.6221, 0.6215, 0.6206, 0.6199, 0.6183, 0.6172, 0.6163, 0.6159,
0.6156, 0.6165, 0.6159, 0.6157, 0.6138, 0.6123, 0.6118, 0.6119,
0.6103, 0.6098, 0.6083, 0.6078, 0.623, 0.621, 0.6203, 0.6194,
0.6189, 0.6174, 0.6164, 0.6157, 0.6153, 0.6153, 0.6161, 0.6158,
0.616, 0.6143, 0.6129, 0.6126, 0.6126, 0.6113, 0.6108, 0.6094,
0.6086, 0.6233, 0.6213, 0.6208, 0.6198, 0.6194, 0.618, 0.617,
0.6162, 0.6159, 0.6158, 0.6165, 0.6162, 0.6165, 0.6148, 0.6136,
0.6133, 0.6133, 0.6119, 0.6114, 0.6102, 0.6094, 0.6225, 0.6207,
0.6201, 0.6192, 0.6188, 0.6176, 0.6167, 0.6161, 0.6158, 0.6158,
0.6165, 0.6163, 0.6165, 0.615, 0.6139, 0.6136, 0.6136, 0.6123,
0.6118, 0.6109, 0.6103, 0.621, 0.6193, 0.6189, 0.6182, 0.6179,
0.617, 0.6162, 0.6157, 0.6155, 0.6155, 0.6163, 0.6161, 0.6163,
0.6149, 0.6138, 0.6136, 0.6136, 0.6124, 0.6122, 0.6116, 0.6113,
0.6211, 0.6192, 0.6187, 0.6179, 0.6175, 0.6165, 0.6158, 0.6152,
0.6149, 0.6149, 0.6156, 0.6154, 0.6157, 0.6143, 0.6132, 0.6128,
0.6128, 0.6114, 0.6113, 0.6104, 0.61, 0.6179, 0.6159, 0.6154,
0.6147, 0.6144, 0.6134, 0.6128, 0.6122, 0.6121, 0.6123, 0.6133,
0.6133, 0.6136, 0.6123, 0.6112, 0.6109, 0.6109, 0.6096, 0.6097,
0.6091, 0.6087, 0.6155, 0.6134, 0.6129, 0.6122, 0.6119, 0.6108,
0.6103, 0.6098, 0.6098, 0.6102, 0.6113, 0.6116, 0.6123, 0.611,
0.6096, 0.6093, 0.6093, 0.6081, 0.6083, 0.6076, 0.6072, 0.6131,
0.6108, 0.6103, 0.6095, 0.6092, 0.6081, 0.6076, 0.6073, 0.6074,
0.6079, 0.6093, 0.6098, 0.6107, 0.6093, 0.6079, 0.6075, 0.6076,
0.6064, 0.6066, 0.6059, 0.6057, 0.6123, 0.6101, 0.6099, 0.6093,
0.6091, 0.6079, 0.6074, 0.6071, 0.6071, 0.6077, 0.6092, 0.61,
0.6114, 0.6102, 0.609, 0.6085, 0.6087, 0.6073, 0.6076, 0.607,
0.6067, 0.6122, 0.6101, 0.6101, 0.6096, 0.6094, 0.6081, 0.6075,
0.6072, 0.6071, 0.6075, 0.6092, 0.6096, 0.6098, 0.609, 0.6083,
0.6081, 0.6088, 0.6077, 0.6081, 0.6076, 0.6069, 0.6154, 0.6129,
0.6126, 0.6121, 0.6117, 0.6103, 0.6093, 0.6083, 0.6081, 0.6085,
0.6098, 0.6107, 0.6113, 0.6107, 0.6102, 0.6092, 0.6078, 0.6058,
0.6065, 0.6056, 0.6046, 0.6158, 0.6167, 0.6176, 0.617, 0.6164,
0.6146, 0.6135, 0.6123, 0.6117, 0.6116, 0.6125, 0.6138, 0.6147,
0.6146, 0.6145, 0.6142, 0.6135, 0.6118, 0.6108, 0.6103, 0.6098,
0.6125, 0.6133, 0.6139, 0.6141, 0.614, 0.6143, 0.6148, 0.6151,
0.6154, 0.6167, 0.6172, 0.6189, 0.6203, 0.6206, 0.6209, 0.6211,
0.6211, 0.6204, 0.6206, 0.6214, 0.6226, 0.6109, 0.612, 0.6129,
0.6132, 0.6132, 0.6136, 0.6142, 0.6149, 0.6155, 0.6168, 0.6173,
0.6193, 0.6211, 0.6217, 0.6225, 0.6231, 0.6232, 0.6226, 0.6229,
0.6239, 0.6251), .Dim = c(21L, 21L))
ref <- abind::abind(ref, ref, along=3); ref <- abind::abind(ref, ref, along=4)
expect_equal(Gapfill(data, fnPredict=PredictMean, subset="all")$fill, ref,
check.attributes = FALSE, tolerance=1e-4)
ref_m <- data; ref_m[is.na(data)] <- ref[is.na(data)]
expect_equal(Gapfill(data, fnPredict=PredictMean, subset="missings")$fill, ref_m,
check.attributes = FALSE, tolerance=1e-4)
ref_o <- ref; ref_o[is.na(data)] <- NA
expect_equal(Gapfill(data, fnPredict=PredictMean, subset="observed")$fill, ref_o,
check.attributes = FALSE, tolerance=1e-4)
sub1 <- sample(seq_along(data), 100)
ref_sub1 <- data; ref_sub1[sub1] <- ref[sub1]
expect_equal(Gapfill(data, fnPredict=PredictMean, subset=sub1)$fill, ref_sub1,
check.attributes = FALSE, tolerance=1e-4)
sub2 <- array(FALSE, dim(data)); sub2[sample(seq_along(data), 100)] <- TRUE
ref_sub2 <- data; ref_sub2[sub2] <- ref[sub2]
expect_equal(Gapfill(data, fnPredict=PredictMean, subset=sub2)$fill, ref_sub2,
check.attributes = FALSE, tolerance=1e-4)
})
test_that("Gapfill args",{
expect_error(Gapfill(),
"argument \"data\" is missing, with no default")
......@@ -152,7 +230,6 @@ test_that("Gapfill args",{
"identical\\(length\\(dim\\(data\\)\\), 4L\\) is not TRUE")
expect_error(Gapfill(array(1, c(1,2,3,4,5))),
"identical\\(length\\(dim\\(data\\)\\), 4L\\) is not TRUE")
data <- ndvi[,,1:2,1:2]
expect_error(Gapfill(data = data, fnSubset = 1),
"is.function\\(fnSubset\\) is not TRUE")
......@@ -193,15 +270,19 @@ test_that("Gapfill args",{
expect_error(Gapfill(data = data, subset = c(1, 1)),
"subset\\[1\\] == \"missings\" || \\(identical\\(dim\\(subset\\), dim\\(data\\)\\) && .... is not TRUE")
expect_error(Gapfill(data = data,
subset = c(154, 155, 155.5)),
"The values\\(s\\) 154, 155.5 of argument \"subset\" do not match missing values of \"data\".")
expect_error(Gapfill(data = data,
subset = c(8, 8)),
"Argument \"subset\" contains duplicated values.")
expect_equal(Gapfill(data = data, subset = 155)$fill[155],
0.1527, tolerance = 1e-3)
data2 <- data[1:5,1:5,,]
fill2_obs <- Gapfill(data = data2, fnPredict=function(a, i) mean(a, na.rm=TRUE),
subset = "observed")$fill
expect_equal(fill2_obs[!is.na(fill2_obs)], rep(mean(data2, na.rm=TRUE), sum(!is.na(data2))))
expect_equal(!is.na(fill2_obs), !is.na(data2))
fill2_all <- Gapfill(data = data2, fnPredict=function(a, i) mean(a, na.rm=TRUE),
subset = "all")$fill
expect_true(all(!is.na(fill2_all)))
expect_equal(fill2_all, array(mean(data2, na.rm=TRUE), dim(data2), dimnames=dimnames(data2)))
expect_error(Gapfill(data = data, clipRange = TRUE),
"is.numeric\\(clipRange\\) is not TRUE")
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment