Skip to content

Commit

Permalink
trying to fix donttest rasterCVA and rasterPCA
Browse files Browse the repository at this point in the history
  • Loading branch information
KonstiDE committed Jan 16, 2024
1 parent 0c37a95 commit 1e20c50
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 18 deletions.
21 changes: 3 additions & 18 deletions R/rasterCVA.R
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,15 @@
#' Returns a SpatRaster with two layers: change vector angle and change vector magnitude
#' @export
#' @examples
#' \donttest{
#' library(terra)
#' pca <- rasterPCA(lsat)$map
#'
#' ## Do change vector analysis
#' cva <- rasterCVA(pca[[1:2]], pca[[3:4]])
#' cva
#' plot(cva)
#' }
rasterCVA <- function(x, y, tmf = NULL, nct = NULL, ...) {
x <- .toTerra(x)
y <- .toTerra(y)
Expand Down Expand Up @@ -96,28 +98,11 @@ rasterCVA <- function(x, y, tmf = NULL, nct = NULL, ...) {
nct <- tmf * medianEstimate
rm(RStoolbox_rasterCVAEnv)
}
out <- terra::clamp(out, lower = nct, ... = ellips)
out <- do.call(terra::clamp, c(list(x = out, lower=nct), ellips))

names(out) <- c("angle", "magnitude")
}

return(out)
}

test <- function(){
devtools::load_all()

r <- rast(val = 0, ncol = 2, nrow = 10)
r1 <- r2 <- c(r, r)
s <- 4
x <- c(0,s,s,s,0,-s,-s,-s, NA, 0)
y <- c(s,s,0,-s,-s,-s,0,s, 0, NA)
r2[[1]][] <- c(x, x + sign(x)*2)
r2[[2]][] <- c(y, y + sign(y)*2)

expectedDf <- as.matrix(data.frame(angle = c(0,45,90,135,180,225,270,315,NA,NA),
magnitude = c(rep(c(s, sqrt(2*s^2)), 4), NA,NA, rep(c((2+s), sqrt(2*(2+s)^2)), 4), NA,NA)))

rasterCVA(r1,r2, tmf = 0)

}
2 changes: 2 additions & 0 deletions R/rasterPCA.R
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
#' @return Returns a named list containing the PCA model object ($model) and a SpatRaster with the principal component layers ($object).
#' @export
#' @examples
#' \donttest{
#' library(ggplot2)
#' library(reshape2)
#' ggRGB(rlogo, 1,2,3)
Expand All @@ -42,6 +43,7 @@
#' plots <- lapply(1:3, function(x) ggR(rpc$map, x, geom_raster = TRUE))
#' grid.arrange(plots[[1]],plots[[2]], plots[[3]], ncol=2)
#' }
#' }
rasterPCA <- function(img, nSamples = NULL, nComp = nlyr(img), spca = FALSE, maskCheck = TRUE, ...){
img <- .toTerra(img)

Expand Down
2 changes: 2 additions & 0 deletions man/rasterCVA.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions man/rasterPCA.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 1e20c50

Please sign in to comment.