Skip to content

Commit

Permalink
Update dynamic_proj_covariates.R
Browse files Browse the repository at this point in the history
  • Loading branch information
r-a-dobson committed Jun 17, 2023
1 parent bb3b2df commit 1530706
Showing 1 changed file with 17 additions and 3 deletions.
20 changes: 17 additions & 3 deletions R/dynamic_proj_covariates.R
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
#'@param spatial.res.degrees optional; a numeric value, the spatial resolution in degrees for
#' projection rasters to be resampled to. Required if `spatial.ext` given.
#'@param resample.method a character string or vector length of varnames, specifying resampling
#' method to use. One of `ngb` and `bilinear`. See details for more information.
#' method to use. One of `near` and `bilinear`. See details for more information.
#'@param drive.folder optional; a character string or vector, Google Drive folder or folders to read
#' projection covariate rasters from. Folder must be uniquely named within Google Drive. Do not
#' provide path.
Expand All @@ -35,7 +35,7 @@
#'@param static.varnames a character string or vector, the unique names for each
#' explanatory variable in order of rasters in `static.raster` stack.
#'@param static.resample.method a character string or vector length of `static.varnames`, specifying resampling
#' method to use on static rasters provided. One of `ngb` and `bilinear`. See details for more information..
#' method to use on static rasters provided. One of `near` and `bilinear`. See details for more information..
#'@param static.moving.window.matrix optional; a matrix of weights with an odd number
#' of sides, representing the spatial neighbourhood of cells (“moving
#' window”) to calculate `GEE.math.fun` across from record co-ordinate. See
Expand Down Expand Up @@ -64,7 +64,7 @@
#'Note: if explanatory variable rasters are not of the same spatial resolution and extent, then the
#'function will error. Resample methods (`resample.method`) include:
#'
#'* `ngb`: Each cell acquires the value of its nearest neighbour cell in the original raster. This
#'* `near`: Each cell acquires the value of its nearest neighbour cell in the original raster. This
#'is typically used for categorical variables.
#'
#'* `bilinear`: the distance-weighted average of the four nearest cells are used to estimate a new
Expand Down Expand Up @@ -234,6 +234,19 @@ dynamic_proj_covariates <- function(dates,
}
}

if (!missing(resample.method)) {
if (length(resample.method) == 1) {
resample.method <- rep(resample.method, length(varnames))
}
}

if (!missing(static.resample.method)) {
if (length(static.resample.method) == 1) {
static.resample.method <-
rep(static.resample.method, length(static.varnames))
}
}

if (missing(local.directory) && missing(drive.folder)) {
stop("Provide local.directory or drive.folder to download rasters from.")
}
Expand Down Expand Up @@ -491,6 +504,7 @@ dynamic_proj_covariates <- function(dates,
start <- length(static.varnames)+1
end <- length(static.varnames) + length(varnames)
varnames <- c(static.varnames,varnames)
resample.method <- c(static.resample.method, resample.method)
}

for (v in start:end) {
Expand Down

0 comments on commit 1530706

Please sign in to comment.