diff --git a/DESCRIPTION b/DESCRIPTION index 488c95dd1..65458712c 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,6 +1,6 @@ Package: wallace -Version: 2.1.3 -Date: 2024-07-18 +Version: 2.2.0 +Date: 2025-03-06 Title: A Modular Platform for Reproducible Modeling of Species Niches and Distributions Description: The 'shiny' application Wallace is a modular platform for @@ -13,6 +13,7 @@ Description: The 'shiny' application Wallace is a modular platform for website: . Authors@R: c(person("Bethany A.", "Johnson", email = "bjohnso005@citymail.cuny.edu", role = "aut"), + person("Daniel F.", "Lopez-Lozano", email = "dlopezlozano@amnh.org", role = "aut"), person("Jamie M.", "Kass", email = "jamie.m.kass@gmail.com", role = "aut"), person("Gonzalo E.", "Pinilla-Buitrago", email = "gepinillab@gmail.com", role = "aut"), person("Andrea", "Paz", email = "paz.andreita@gmail.com", role = "aut"), @@ -38,7 +39,7 @@ Imports: dplyr (>= 1.0.2), DT (>= 0.5), ecospat (>= 4.0.0), - ENMeval (>= 2.0.3), + ENMeval (>= 2.0.5), geodata, knitcitations, leafem, @@ -67,6 +68,7 @@ Suggests: mapview, maxnet, occCite, + predicts, rangeModelMetadata, raster, rgbif (>= 3.3.0), diff --git a/NEWS.md b/NEWS.md index 3737810cf..4a3adb342 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,3 +1,9 @@ +wallace 2.2.0 +============= +- updated for ENMeval v2.0.5 functionality +- updated module skeleton & module addition vignette to include `knitcitations` for References +- RPA edits to guidance texts + wallace 2.1.3 ============= - Fixed NULL error in poccs_selectOccs Rmd code diff --git a/R/model_bioclim.R b/R/model_bioclim.R index 84f9b35e7..855830849 100644 --- a/R/model_bioclim.R +++ b/R/model_bioclim.R @@ -63,6 +63,7 @@ #' @author Jamie M. Kass #' @author Gonzalo E. Pinilla-Buitrago +#' @author Bethany A. Johnson # @note #' @seealso \code{\link[ENMeval]{ENMevaluate}} @@ -79,7 +80,7 @@ model_bioclim <- function(occs, bg, user.grp, bgMsk, logger = NULL, smartProgress(logger, message = paste0("Building/Evaluating BIOCLIM model for ", spName(spN), "..."), { - e <- ENMeval::ENMevaluate(occs = occs.xy, envs = bgMsk, bg = bg.xy, + e <- ENMeval::ENMevaluate(occs = occs.xy, envs = terra::rast(bgMsk), bg = bg.xy, algorithm = "bioclim", partitions = "user", user.grp = user.grp) }) diff --git a/R/model_maxent.R b/R/model_maxent.R index 82a53b069..a1365dba6 100644 --- a/R/model_maxent.R +++ b/R/model_maxent.R @@ -85,6 +85,7 @@ #' and a selection of appropriate fields. #' @author Jamie M. Kass #' @author Gonzalo E. Pinilla-Buitrago +#' @author Bethany A. Johnson # @note #' @seealso \code{\link[ENMeval]{ENMevaluate}} @@ -196,14 +197,14 @@ model_maxent <- function(occs, bg, user.grp, bgMsk, rms, rmsStep, fcs, bg = as.data.frame(bg.xy), partitions = 'user', user.grp = user.grp, - envs = bgMsk, + envs = terra::rast(bgMsk), tune.args = tune.args, doClamp = clampSel, algorithm = algMaxent, categoricals = catEnvs, parallel = parallel, numCores = numCores, - parallelType = "doSNOW", + # parallelType = "doSNOW", # taxon.name = NULL, # user.enm = NULL, # occs.ind = NULL, diff --git a/R/part_partitionOccs.R b/R/part_partitionOccs.R index 17fff7961..2863609bf 100644 --- a/R/part_partitionOccs.R +++ b/R/part_partitionOccs.R @@ -40,8 +40,8 @@ #' (1) 'jack' Non-spatial Partition - jackknife \cr #' (2) 'rand' Non-spatial Partition - random k-fold \cr #' (3) 'block' spatial Partition - block \cr -#' (4) 'cb1' spatial Partition - checkerboard 1 (K=2) \cr -#' (5) 'cb2' spatial Partition - checkerboard 2 (K=4) \cr +#' (4) 'cb1' spatial Partition - checkerboard (k=2) \cr +#' (5) 'cb2' spatial Partition - hierarchical checkerboard (k=4) \cr #' @param kfolds numeric. Number of partitions to create if selected method is #' random k-fold (must be >=2). If other method then keep default of NULL. #' @param bgMask a RasterStack or a RasterBrick of environmental layers cropped @@ -75,6 +75,7 @@ #' @author Jamie Kass #' @author Gonzalo E. Pinilla-Buitrago #' @author Andrea Paz +#' @author Bethany A Johnson # @note #' @seealso \code{\link[ENMeval]{partitions}} # @references @@ -163,22 +164,23 @@ part_partitionOccs <- function(occs, bg, method, kfolds = NULL, bgMask = NULL, if(method == 'cb1') { smartProgress(logger, message = "Aggregating rasters...", { - group.data <- ENMeval::get.checkerboard1(occs.xy, bgMask, bg.xy, aggFact) + group.data <- ENMeval::get.checkerboard(occs.xy, terra::rast(bgMask), bg.xy, aggFact) }) logger %>% writeLog(hlSpp(spN), - "Occurrences partitioned by checkerboard 1 method with ", - "aggregation factor ", aggFact, ".") + "Occurrences partitioned by checkerboard method with ", + "aggregation factor of ", aggFact, ".") } if(method == 'cb2') { smartProgress(logger, message = "Aggregating rasters...", { - group.data <- ENMeval::get.checkerboard2(occs.xy, bgMask, bg.xy, aggFact) + group.data <- ENMeval::get.checkerboard(occs.xy, terra::rast(bgMask), + bg.xy, c(aggFact, aggFact)) }) logger %>% writeLog(hlSpp(spN), - "Occurrences partitioned by checkerboard 2 method with ", - "aggregation factor ", aggFact, ".") + "Occurrences partitioned by hierarchical checkerboard method with ", + "aggregation factor of ", aggFact, ".") } return(group.data) } diff --git a/R/vis_bioclimPlot.R b/R/vis_bioclimPlot.R index d979c50f2..d20a9479f 100644 --- a/R/vis_bioclimPlot.R +++ b/R/vis_bioclimPlot.R @@ -68,6 +68,7 @@ #' more variables are plotted as orange triangles. #' @author Jamie Kass #' @author Gonzalo E. Pinilla-Buitrago +#' @author Bethany A. Johnson # @note #' @seealso #'\code{\link{model_bioclim}} \code{\link[ENMeval]{ENMevaluate}} diff --git a/R/xfer_area.R b/R/xfer_area.R index f0c2e9cd3..4821aa61a 100644 --- a/R/xfer_area.R +++ b/R/xfer_area.R @@ -69,11 +69,22 @@ #' polyExt <- #' sp::SpatialPolygons(list(sp::Polygons(list(sp::Polygon(selCoords)), #' ID = 1))) -#' # load model -#' m <- readRDS(system.file("extdata/model.RDS", -#' package = "wallace")) +#' # build model +#' occs <- read.csv(system.file("extdata/Bassaricyon_alleni.csv", +#' package = "wallace")) +#' bg <- read.csv(system.file("extdata/Bassaricyon_alleni_bgPoints.csv", +#' package = "wallace")) +#' partblock <- part_partitionOccs(occs, bg, method = 'block') +#' m <- model_maxent(occs, bg, +#' user.grp = partblock, +#' bgMsk = envs, rms = c(1:2), +#' rmsStep = 1, fcs = c('L', 'LQ'), +#' clampSel = TRUE, +#' algMaxent = "maxnet", +#' parallel = FALSE) +#' ### run function #' modXfer <- xfer_area(evalOut = m, curModel = 1, envs, -#' outputType = 'cloglog', alg = 'maxent.jar', +#' outputType = 'cloglog', alg = 'maxnet', #' clamp = TRUE, xfExt = polyExt) #' } #' @@ -117,18 +128,16 @@ xfer_area <- function(evalOut, curModel, envs, xfExt, alg, outputType = NULL, smartProgress(logger, message = 'Transferring model to new area...', { if (alg == 'BIOCLIM') { - modXferArea <- dismo::predict(evalOut@models[[curModel]], xferMsk, - useC = FALSE) + modXferArea <- dismo::predict(evalOut@models[[curModel]], terra::rast(xferMsk)) } else if (alg == 'maxnet') { if (outputType == "raw") outputType <- "exponential" modXferArea <- predictMaxnet(evalOut@models[[curModel]], xferMsk, type = outputType, clamp = clamp) } else if (alg == 'maxent.jar') { modXferArea <- dismo::predict( - evalOut@models[[curModel]], xferMsk, + evalOut@models[[curModel]], terra::rast(xferMsk), args = c(paste0("outputformat=", outputType), - paste0("doclamp=", tolower(as.character(clamp)))), - na.rm = TRUE) + paste0("doclamp=", tolower(as.character(clamp))))) } }) diff --git a/R/xfer_time.R b/R/xfer_time.R index 832f4fcd8..d6f69121e 100644 --- a/R/xfer_time.R +++ b/R/xfer_time.R @@ -74,9 +74,13 @@ #' selCoords <- matrix(c(longitude, latitude), byrow = FALSE, ncol = 2) #' polyExt <- sp::SpatialPolygons(list(sp::Polygons(list(sp::Polygon(selCoords)), #' ID = 1))) -#' # load model -#' m <- readRDS(system.file("extdata/model.RDS", -#' package = "wallace")) +#' # build model +#' occs <- read.csv(system.file("extdata/Bassaricyon_alleni.csv",package = "wallace")) +#' bg <- read.csv(system.file("extdata/Bassaricyon_alleni_bgPoints.csv", package = "wallace")) +#' partblock <- part_partitionOccs(occs, bg, method = 'block') +#' m <- model_maxent(occs, bg, user.grp = partblock, bgMsk = envs, rms = c(1:2), +#' rmsStep = 1, fcs = c('L', 'LQ'), +#' clampSel = TRUE, algMaxent = "maxnet", parallel = FALSE) #' occsEnvs <- m@@occs #' bgEnvs <- m@@bg #' envsFut <- list.files(path = system.file('extdata/wc/future', @@ -84,7 +88,7 @@ #' full.names = TRUE) #' envsFut <- raster::stack(envsFut) #' modXfer <- xfer_time(evalOut = m, curModel = 1, -#' envs = envsFut, alg = 'maxent.jar', +#' envs = envsFut, alg = 'maxnet', #' xfExt = polyExt, clamp = FALSE, outputType = 'cloglog') #' } @@ -129,18 +133,16 @@ xfer_time <- function(evalOut, curModel, envs, xfExt, alg, outputType = NULL, logger, message = ("Transferring to new time..."), { if (alg == 'BIOCLIM') { - modXferTime <- dismo::predict(evalOut@models[[curModel]], xftMsk, - useC = FALSE) + modXferTime <- dismo::predict(evalOut@models[[curModel]], terra::rast(xftMsk)) } else if (alg == 'maxnet') { if (outputType == "raw") outputType <- "exponential" modXferTime <- predictMaxnet(evalOut@models[[curModel]], xftMsk, type = outputType, clamp = clamp) } else if (alg == 'maxent.jar') { modXferTime <- dismo::predict( - evalOut@models[[curModel]], xftMsk, + evalOut@models[[curModel]], terra::rast(xftMsk), args = c(paste0("outputformat=", outputType), - paste0("doclamp=", tolower(as.character(clamp)))), - na.rm = TRUE) + paste0("doclamp=", tolower(as.character(clamp))))) } }) return(list(xferExt = xftMsk, xferTime = modXferTime)) diff --git a/R/xfer_userEnvs.R b/R/xfer_userEnvs.R index 8d87f0c71..3e361998d 100644 --- a/R/xfer_userEnvs.R +++ b/R/xfer_userEnvs.R @@ -63,16 +63,24 @@ #' selCoords <- matrix(c(longitude, latitude), byrow = FALSE, ncol = 2) #' polyExt <- sp::SpatialPolygons(list(sp::Polygons(list(sp::Polygon(selCoords)), #' ID = 1))) -#' # load model -#' m <- readRDS(system.file("extdata/model.RDS", -#' package = "wallace")) +#' # build model +#' occs <- read.csv(system.file("extdata/Bassaricyon_alleni.csv",package = "wallace")) +#' bg <- read.csv(system.file("extdata/Bassaricyon_alleni_bgPoints.csv", +#' package = "wallace")) +#' envs <- envs_userEnvs(rasPath = list.files(system.file("extdata/wc", +#' package = "wallace"), pattern = ".tif$", full.names = TRUE), +#' rasName = list.files(system.file("extdata/wc",package = "wallace"), +#' pattern = ".tif$", full.names = FALSE)) +#' partblock <- part_partitionOccs(occs, bg, method = 'block') +#' m <- model_maxent(occs, bg, user.grp = partblock, bgMsk = envs, rms = c(1:2), +#' rmsStep = 1, fcs = c('L', 'LQ'), clampSel = TRUE, algMaxent = "maxnet", parallel = FALSE) #' envsFut <- list.files(path = system.file('extdata/wc/future', #' package = "wallace"), #' full.names = TRUE) #' envsFut <- raster::stack(envsFut) #' ### run function #' modXfer <- xfer_userEnvs(evalOut = m, curModel = 1, envs = envsFut, -#' outputType = "cloglog", alg = "maxent.jar", +#' outputType = "cloglog", alg = "maxnet", #' clamp = FALSE, xfExt = polyExt) #' } #' @@ -114,18 +122,16 @@ xfer_userEnvs <- function(evalOut, curModel, envs, xfExt, alg, outputType = NULL logger, message = 'Transferring model to user uploaded environmental variables & area', { if (alg == 'BIOCLIM') { - modXferUser <- dismo::predict(evalOut@models[[curModel]], xferMsk, - useC = FALSE) + modXferUser <- dismo::predict(evalOut@models[[curModel]], terra::rast(xferMsk)) } else if (alg == 'maxnet') { if (outputType == "raw") outputType <- "exponential" modXferUser <- predictMaxnet(evalOut@models[[curModel]], xferMsk, type = outputType, clamp = clamp) } else if (alg == 'maxent.jar') { modXferUser <- dismo::predict( - evalOut@models[[curModel]], xferMsk, + evalOut@models[[curModel]], terra::rast(xferMsk), args = c(paste0("outputformat=", outputType), - paste0("doclamp=", tolower(as.character(clamp)))), - na.rm = TRUE) + paste0("doclamp=", tolower(as.character(clamp))))) } }) diff --git a/README.md b/README.md index dd5694ac9..44b288803 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ [![R-CMD-check](https://github.com/wallaceEcoMod/wallace/workflows/R-CMD-check/badge.svg)](https://github.com/wallaceEcoMod/wallace/actions) [![License: GPL v3](https://img.shields.io/badge/License-GPL%20v3-blue.svg)](https://www.gnu.org/licenses/gpl-3.0) [![CRAN version](http://www.r-pkg.org/badges/version/wallace)](https://CRAN.R-project.org/package=wallace) [![downloads](https://cranlogs.r-pkg.org:443/badges/grand-total/wallace?color=orange)](https://cranlogs.r-pkg.org:443/badges/grand-total/wallace?color=orange) -# Wallace (v2.1.3) +# Wallace (v2.2.0) *Wallace* is a modular platform for reproducible modeling of species niches and distributions, written in R. The application guides users through a complete analysis, from the acquisition of data to visualizing model predictions on an interactive map, thus bundling complex workflows into a single, streamlined interface. @@ -27,7 +27,7 @@ run_wallace() Please make sure you have installed the latest versions of both R (Mac OS, Windows) and RStudio (Mac OS / Windows: choose the free version). #### How to run Maxent with maxent.jar -*Wallace* v2.1.3 includes two options to run Maxent models: maxnet and maxent.jar. The former, which is an R implementation and fits the model with the package `glmnet`, is now the default and does not require the package `rJava` (see Phillips et al. 2017). The latter, which is the Java implementation, runs the `maxent()` function in the package `dismo`. This function requires the user to place the `maxent.jar` file in the `/java` directory of the `dismo` package root folder. You can download Maxent here, and locate `maxent.jar`, which is the Maxent program itself, in the downloaded folder. You can find the directory path to `dismo/java` by running `system.file('java', package="dismo")` at the R console. Simply copy `maxent.jar` and paste it into this folder. If you try to run Maxent in *Wallace* without the file in place, you will get a warning message in the log window and Maxent will not run. +*Wallace* v2.2.0 includes two options to run Maxent models: maxnet and maxent.jar. The former, which is an R implementation and fits the model with the package `glmnet`, is now the default and does not require the package `rJava` (see Phillips et al. 2017). The latter, which is the Java implementation, runs the `maxent()` function in the package `dismo`. This function requires the user to place the `maxent.jar` file in the `/java` directory of the `dismo` package root folder. You can download Maxent here, and locate `maxent.jar`, which is the Maxent program itself, in the downloaded folder. You can find the directory path to `dismo/java` by running `system.file('java', package="dismo")` at the R console. Simply copy `maxent.jar` and paste it into this folder. If you try to run Maxent in *Wallace* without the file in place, you will get a warning message in the log window and Maxent will not run. ### Potential Issues diff --git a/inst/module_skeleton/skeleton.R b/inst/module_skeleton/skeleton.R index 9f2333c6b..e88602adf 100644 --- a/inst/module_skeleton/skeleton.R +++ b/inst/module_skeleton/skeleton.R @@ -15,6 +15,8 @@ # LOAD INTO SPP #### + # REFERENCES #### + # METADATA #### }) diff --git a/inst/shiny/Rmd/text_about.Rmd b/inst/shiny/Rmd/text_about.Rmd index c68aabda6..4d8be8768 100644 --- a/inst/shiny/Rmd/text_about.Rmd +++ b/inst/shiny/Rmd/text_about.Rmd @@ -7,7 +7,7 @@ output: html_document logo -Welcome to *Wallace*, a flexible application for reproducible ecological modeling, built for community expansion. The current version of *Wallace* (v2.1.3) steps the user through a full niche/distribution modeling analysis, from data acquisition to visualizing results. +Welcome to *Wallace*, a flexible application for reproducible ecological modeling, built for community expansion. The current version of *Wallace* (v2.2.0) steps the user through a full niche/distribution modeling analysis, from data acquisition to visualizing results. The application is written in `R` with the web app development package `shiny`. Please find the stable version of *Wallace* on CRAN, and the development version on Github. We also maintain a *Wallace* website that has some basic info, links, and will be updated with tutorial materials in the near future. diff --git a/inst/shiny/Rmd/text_intro_tab.Rmd b/inst/shiny/Rmd/text_intro_tab.Rmd index 1e8dedddd..554b7fba0 100644 --- a/inst/shiny/Rmd/text_intro_tab.Rmd +++ b/inst/shiny/Rmd/text_intro_tab.Rmd @@ -5,7 +5,7 @@ output: html_document #### WORKFLOW -*Wallace* (v2.1.3) currently includes ten components, or steps of a possible workflow. Each component includes two or more modules, which are possible analyses for that step. +*Wallace* (v2.2.0) currently includes ten components, or steps of a possible workflow. Each component includes two or more modules, which are possible analyses for that step. **Components:** diff --git a/inst/shiny/Rmd/userReport_intro.Rmd b/inst/shiny/Rmd/userReport_intro.Rmd index 345a8e569..47b20b550 100644 --- a/inst/shiny/Rmd/userReport_intro.Rmd +++ b/inst/shiny/Rmd/userReport_intro.Rmd @@ -10,7 +10,7 @@ knit_engines$set(asis = function(options) { knitr::opts_chunk$set(message = FALSE, warning = FALSE, eval = FALSE) ``` -Please find below the R code history from your *Wallace* v2.1.3 session. +Please find below the R code history from your *Wallace* v2.2.0 session. You can reproduce your session results by running this R Markdown file in RStudio. diff --git a/inst/shiny/modules/envs_userEnvs.md b/inst/shiny/modules/envs_userEnvs.md index 5e2165f82..473855915 100644 --- a/inst/shiny/modules/envs_userEnvs.md +++ b/inst/shiny/modules/envs_userEnvs.md @@ -26,6 +26,6 @@ Users will need to know what the original CRS of their rasters is, then look up *NOTE: A reminder that some file types like .asc cannot embed CRS information in the file, so please avoid these types -- instead use types such as .tif that retain the CRS.* -A warning message will appear if your layers have NA values falling in pixels that are not consistent among each layer. You can continue using them, but some downstream steps of analyses may not be functional. Alternatively, you can assign values in a GIS program or mask the layers to have matching NA values outside of Wallace in R. +A warning message will appear if your layers have NA values for pixels that are not consistent among all of the layers. You can continue using them, but some downstream analyses may not be functional. Alternatively, before uploading rasters to Wallace, you can assign values in a GIS program or mask the rasters in R to have matching NA values. -Using your own environmental data will disable the Module: *Transfer to New Time*, as this module requires WorldClim bioclimatic variables. The Module: *Transfer to User Environments* is still available. +Using your own environmental data here will disable the later *Transfer to New Time* module, as it requires WorldClim bioclimatic variables. The later Module: *Transfer to User Environments* is still available. diff --git a/inst/shiny/modules/model_bioclim.yml b/inst/shiny/modules/model_bioclim.yml index 6eab48bcd..6ab99a6ad 100644 --- a/inst/shiny/modules/model_bioclim.yml +++ b/inst/shiny/modules/model_bioclim.yml @@ -1,5 +1,5 @@ component: "model" short_name: "BIOCLIM" long_name: "BIOCLIM" -authors: "Jamie M. Kass, Robert Muscarella, Bruno Vilela, Robert P. Anderson" +authors: "Jamie M. Kass, Robert Muscarella, Bruno Vilela, Bethany A. Johnson, Robert P. Anderson" package: [ENMeval, dismo] diff --git a/inst/shiny/modules/model_maxent.yml b/inst/shiny/modules/model_maxent.yml index b3b2b116d..b2fc33600 100644 --- a/inst/shiny/modules/model_maxent.yml +++ b/inst/shiny/modules/model_maxent.yml @@ -1,5 +1,5 @@ component: "model" short_name: "Maxent" long_name: "Maxent" -authors: "Jamie M. Kass, Robert Muscarella, Bruno Vilela, Gonzalo E. Pinilla-Buitrago, Robert P. Anderson" +authors: "Jamie M. Kass, Robert Muscarella, Bruno Vilela, Gonzalo E. Pinilla-Buitrago, Bethany A. Johnson, Robert P. Anderson" package: [ENMeval, dismo, maxnet] diff --git a/inst/shiny/modules/part_nonSpat.yml b/inst/shiny/modules/part_nonSpat.yml index b645800c1..766854044 100644 --- a/inst/shiny/modules/part_nonSpat.yml +++ b/inst/shiny/modules/part_nonSpat.yml @@ -1,5 +1,5 @@ component: "part" short_name: "Non-spatial Partition" long_name: "Non-spatial Partition" -authors: "Jamie M. Kass, Bruno Vilela, Robert P. Anderson" +authors: "Jamie M. Kass, Bruno Vilela, Bethany A. Johnson, Robert P. Anderson" package: [ENMeval] diff --git a/inst/shiny/modules/part_spat.yml b/inst/shiny/modules/part_spat.yml index 61060ec6d..ef65e99ec 100644 --- a/inst/shiny/modules/part_spat.yml +++ b/inst/shiny/modules/part_spat.yml @@ -1,5 +1,5 @@ component: "part" short_name: "Spatial Partition" long_name: "Spatial Partition" -authors: "Jamie M. Kass, Bruno Vilela, Robert P. Anderson" +authors: "Jamie M. Kass, Bruno Vilela, Bethany A. Johnson, Robert P. Anderson" package: [ENMeval] diff --git a/inst/shiny/modules/vis_bioclimPlot.yml b/inst/shiny/modules/vis_bioclimPlot.yml index 1ed41c4e6..01ed69749 100644 --- a/inst/shiny/modules/vis_bioclimPlot.yml +++ b/inst/shiny/modules/vis_bioclimPlot.yml @@ -1,5 +1,5 @@ component: "vis" short_name: "BIOCLIM Envelope Plots" long_name: "BIOCLIM Envelope Plots" -authors: "Jamie M. Kass, Robert Muscarella, Bruno Vilela, Robert P. Anderson" +authors: "Jamie M. Kass, Robert Muscarella, Bruno Vilela, Bethany A. Johnson, Robert P. Anderson" package: [dismo] diff --git a/inst/shiny/modules/vis_mapPreds.R b/inst/shiny/modules/vis_mapPreds.R index 9b73cb69d..99e379e70 100644 --- a/inst/shiny/modules/vis_mapPreds.R +++ b/inst/shiny/modules/vis_mapPreds.R @@ -1,6 +1,6 @@ # Wallace EcoMod: a flexible platform for reproducible modeling of # species niches and distributions. -# +# # vis_mapPreds.R # File author: Wallace EcoMod Dev Team. 2023. # -------------------------------------------------------------------------- @@ -86,6 +86,7 @@ vis_mapPreds_module_server <- function(input, output, session, common) { # pick the prediction that matches the model selected predSel <- evalOut()@predictions[[curModel()]] + predSel <- raster::raster(predSel) raster::crs(predSel) <- raster::crs(bgMask()) if(is.na(raster::crs(predSel))) { logger %>% writeLog( @@ -102,7 +103,8 @@ vis_mapPreds_module_server <- function(input, output, session, common) { if (spp[[curSp()]]$rmm$model$algorithms == "BIOCLIM") { predType <- "BIOCLIM" m <- evalOut()@models[[curModel()]] - predSel <- dismo::predict(m, bgMask(), useC = FALSE) + predSel <- dismo::predict(m, terra::rast(bgMask())) + predSel <- raster::raster(predSel) # define crs raster::crs(predSel) <- raster::crs(bgMask()) # define predSel name @@ -133,9 +135,11 @@ vis_mapPreds_module_server <- function(input, output, session, common) { } else { doClamp <- "doclamp=false" } - predSel <- dismo::predict(m, bgMask(), + predSel <- dismo::predict(m, terra::rast(bgMask()), args = c(outputFormat, doClamp), - na.rm = TRUE) + #na.rm = TRUE + ) + predSel <- raster::raster(predSel) } }) # define crs diff --git a/inst/shiny/modules/vis_mapPreds.Rmd b/inst/shiny/modules/vis_mapPreds.Rmd index 0ae91340a..5f67b8627 100644 --- a/inst/shiny/modules/vis_mapPreds.Rmd +++ b/inst/shiny/modules/vis_mapPreds.Rmd @@ -7,7 +7,8 @@ Generate a map of the Bioclim generated model with no threshold # Select current model and obtain raster prediction m_{{spAbr}} <- model_{{spAbr}}@models[["{{curModel_rmd}}"]] -predSel_{{spAbr}} <- dismo::predict(m_{{spAbr}}, bgMask_{{spAbr}}, useC = FALSE) +predSel_{{spAbr}} <- dismo::predict(m_{{spAbr}}, terra::rast(bgMask_{{spAbr}})) +predSel_{{spAbr}} <- raster::raster(predSel_{{spAbr}}) #Get values of prediction mapPredVals_{{spAbr}} <- getRasterVals(predSel_{{spAbr}}, "{{predType_rmd}}") #Define colors and legend @@ -42,7 +43,8 @@ Generate a map of the Bioclim generated model with a "{{thresholdRule_rmd}}" thr ```{r, echo = {{vis_mapPreds_knit & vis_map_bioclim_knit & vis_map_threshold_knit}}, include = {{vis_mapPreds_knit & vis_map_bioclim_knit & vis_map_threshold_knit}}} # Select current model and obtain raster prediction m_{{spAbr}} <- model_{{spAbr}}@models[["{{curModel_rmd}}"]] -predSel_{{spAbr}} <- dismo::predict(m_{{spAbr}}, bgMask_{{spAbr}}, useC = FALSE) +predSel_{{spAbr}} <- dismo::predict(m_{{spAbr}}, terra::rast(bgMask_{{spAbr}})) +predSel_{{spAbr}} <- raster::raster(predSel_{{spAbr}}) # extract the suitability values for all occurrences occs_xy_{{spAbr}} <- occs_{{spAbr}}[c('longitude', 'latitude')] # determine the threshold based on the current prediction @@ -91,10 +93,10 @@ Generate a map of the Maxent generated model with no threshold # Select current model and obtain raster prediction m_{{spAbr}} <- model_{{spAbr}}@models[["{{curModel_rmd}}"]] predSel_{{spAbr}} <- dismo::predict( - m_{{spAbr}}, bgMask_{{spAbr}}, + m_{{spAbr}}, terra::rast(bgMask_{{spAbr}}), args = c(paste0("outputformat=", "{{predType_rmd}}"), - paste0("doclamp=", tolower(as.character({{clamp_rmd}})))), - na.rm = TRUE) + paste0("doclamp=", tolower(as.character({{clamp_rmd}}))))) +predSel_{{spAbr}} <- raster::raster(predSel_{{spAbr}}) #Get values of prediction mapPredVals_{{spAbr}} <- getRasterVals(predSel_{{spAbr}}, "{{predType_rmd}}") #Define colors and legend @@ -130,10 +132,10 @@ Generate a map of the Maxent generated model with a "{{thresholdRule_rmd}}" thre # Select current model and obtain raster prediction m_{{spAbr}} <- model_{{spAbr}}@models[["{{curModel_rmd}}"]] predSel_{{spAbr}} <- dismo::predict( - m_{{spAbr}}, bgMask_{{spAbr}}, + m_{{spAbr}}, terra::rast(bgMask_{{spAbr}}), args = c(paste0("outputformat=", "{{predType_rmd}}"), - paste0("doclamp=", tolower(as.character({{clamp_rmd}})))), - na.rm = TRUE) + paste0("doclamp=", tolower(as.character({{clamp_rmd}}))))) +predSel_{{spAbr}} <- raster::raster(predSel_{{spAbr}}) # extract the suitability values for all occurrences occs_xy_{{spAbr}} <- occs_{{spAbr}}[c('longitude', 'latitude')] # determine the threshold based on the current prediction diff --git a/inst/shiny/modules/vis_mapPreds.yml b/inst/shiny/modules/vis_mapPreds.yml index 92839bc03..b76a04aaa 100644 --- a/inst/shiny/modules/vis_mapPreds.yml +++ b/inst/shiny/modules/vis_mapPreds.yml @@ -1,5 +1,5 @@ component: "vis" short_name: "Map Prediction" long_name: "Map Prediction" -authors: "Jamie M. Kass, Robert Muscarella, Bruno Vilela, Gonzalo E. Pinilla-Buitrago, Robert P. Anderson" +authors: "Jamie M. Kass, Robert Muscarella, Bruno Vilela, Gonzalo E. Pinilla-Buitrago, Bethany A. Johnson, Robert P. Anderson" package: [dismo] diff --git a/inst/shiny/modules/vis_maxentEvalPlot.yml b/inst/shiny/modules/vis_maxentEvalPlot.yml index 918001b7d..0cb53999c 100644 --- a/inst/shiny/modules/vis_maxentEvalPlot.yml +++ b/inst/shiny/modules/vis_maxentEvalPlot.yml @@ -1,5 +1,5 @@ component: "vis" short_name: "Maxent Evaluation Plots" long_name: "Maxent Evaluation Plots" -authors: "Jamie M. Kass, Robert Muscarella, Bruno Vilela, Gonzalo E. Pinilla-Buitrago, Robert P. Anderson" +authors: "Jamie M. Kass, Robert Muscarella, Bruno Vilela, Gonzalo E. Pinilla-Buitrago, Bethany A. Johnson, Robert P. Anderson" package: [ENMeval] diff --git a/inst/shiny/modules/vis_responsePlot.R b/inst/shiny/modules/vis_responsePlot.R index c180303a3..39828f494 100644 --- a/inst/shiny/modules/vis_responsePlot.R +++ b/inst/shiny/modules/vis_responsePlot.R @@ -82,7 +82,7 @@ vis_responsePlot_module_server <- function(input, output, session, common) { maxnet::response.plot(evalOut()@models[[curModel()]], v = curEnv(), type = "cloglog") ) } else if (spp[[curSp()]]$rmm$model$algorithms == "maxent.jar") { - dismo::response(evalOut()@models[[curModel()]], var = curEnv()) + predicts::partialResponse(evalOut()@models[[curModel()]], var = curEnv()) } }, width = 700, height = 700) diff --git a/inst/shiny/modules/vis_responsePlot.Rmd b/inst/shiny/modules/vis_responsePlot.Rmd index 82cecbd9c..ba948c919 100644 --- a/inst/shiny/modules/vis_responsePlot.Rmd +++ b/inst/shiny/modules/vis_responsePlot.Rmd @@ -27,7 +27,7 @@ n <- mxNonzeroCoefs(model_{{spAbr}}@models[["{{curModel_rmd}}"]], "maxent.jar") # Create response curves for (i in n) { -dismo::response( +predicts::partialResponse( model_{{spAbr}}@models[["{{curModel_rmd}}"]], var = i) } diff --git a/inst/shiny/modules/vis_responsePlot.yml b/inst/shiny/modules/vis_responsePlot.yml index 31287809d..1da1a5ab7 100644 --- a/inst/shiny/modules/vis_responsePlot.yml +++ b/inst/shiny/modules/vis_responsePlot.yml @@ -1,5 +1,5 @@ component: "vis" short_name: "Response Curves" long_name: "Plot Response Curves" -authors: "Jamie M. Kass, Robert Muscarella, Bruno Vilela, Gonzalo E. Pinilla-Buitrago, Robert P. Anderson" +authors: "Jamie M. Kass, Robert Muscarella, Bruno Vilela, Gonzalo E. Pinilla-Buitrago, Bethany A. Johnson, Robert P. Anderson" package: [dismo, maxnet] diff --git a/inst/shiny/modules/xfer_area.R b/inst/shiny/modules/xfer_area.R index 059753325..3f9ecedda 100644 --- a/inst/shiny/modules/xfer_area.R +++ b/inst/shiny/modules/xfer_area.R @@ -273,6 +273,8 @@ xfer_area_module_server <- function(input, output, session, common) { logger %>% writeLog(hlSpp(curSp()), "Transfer of model to new area with ", predType, ' output.') } + if(spp[[curSp()]]$rmm$model$algorithms == 'maxent.jar') + xferAreaThr <- raster::raster(xferAreaThr) raster::crs(xferAreaThr) <- raster::crs(envs()) # rename names(xferAreaThr) <- paste0(curModel(), '_thresh_', predType) diff --git a/inst/shiny/modules/xfer_time.md b/inst/shiny/modules/xfer_time.md index 9a16bbe51..2770775dd 100644 --- a/inst/shiny/modules/xfer_time.md +++ b/inst/shiny/modules/xfer_time.md @@ -4,7 +4,7 @@ In simple terms, applying or “transferring” a niche/distributional model to a region or time period different from the ones used to make the model involves making a prediction based on the model and the new values of the predictor variables. In reality, however, researchers should be cognizant of many possible pitfalls, including non-analog conditions (e.g., requiring extrapolation in environmental space; see **Component: Build and Evaluate Niche Model**) and heterogeneity in the effects of species interactions (Fitzpatrick and Hargrove 2009; Anderson 2013). -To predict to different times, datasets describing environmental variables in these times are needed. Global circulation models (GCMs) provide estimates for climate for both the past and future. Various GCMs may have disparate estimates because they are based on different assumptions. Wallace currently uses future climate data based on the user’s selection of WorldClim or ecoClimate source variables. For WorldClim, CMIP6 downscaled future climate projections are available via WorldClim v2.1. Some climate projections use the four Representative Concentration Pathways (RCPs) available (RCP2.6, RCP4.5, RCP6.0, and RCP8.5), which span a range of climate change scenarios from different greenhouse gas emission outcomes. Others use Shared Socio-economic Pathways (SSPs; 126, 245, 370 and 585). More information on climate change models can be found here (Hausfather 2019). +To predict to different times, datasets describing environmental variables in these times are needed. Global circulation models (GCMs) provide estimates for climate for both the past and future. Various GCMs may have disparate estimates because they are based on different assumptions. Wallace currently uses future climate data based on the user’s selection of WorldClim or ecoClimate source variables. For WorldClim, downscaled future climate projections from the CMIP6 model are available via WorldClim v2.1. Some climate projections use the four Representative Concentration Pathways (RCPs) available (RCP2.6, RCP4.5, RCP6.0, and RCP8.5), which span a range of climate change scenarios from different greenhouse gas emission outcomes. Others use Shared Socio-economic Pathways (SSPs; 126, 245, 370 and 585). More information on climate change models can be found here (Hausfather 2019). **IMPLEMENTATION** diff --git a/inst/shiny/server.R b/inst/shiny/server.R index 7439c0cd8..b274e2ac6 100644 --- a/inst/shiny/server.R +++ b/inst/shiny/server.R @@ -768,7 +768,7 @@ function(input, output, session) { namesEnvs <- mxNonzeroCoefs(evalOut()@models[[curModel()]], "maxent.jar") for (i in namesEnvs) { png(paste0( i, ".png")) - dismo::response(evalOut()@models[[curModel()]], var = i) + predicts::partialResponse(evalOut()@models[[curModel()]], var = i) dev.off() } } diff --git a/man/model_bioclim.Rd b/man/model_bioclim.Rd index ef316188c..9147402af 100644 --- a/man/model_bioclim.Rd +++ b/man/model_bioclim.Rd @@ -60,4 +60,6 @@ m <- model_bioclim(occs, bg, partblock, envs) Jamie M. Kass Gonzalo E. Pinilla-Buitrago + +Bethany A. Johnson } diff --git a/man/model_maxent.Rd b/man/model_maxent.Rd index 5a443d9a3..0f5ad1e56 100644 --- a/man/model_maxent.Rd +++ b/man/model_maxent.Rd @@ -104,4 +104,6 @@ m <- model_maxent(occs = occs, bg = bg, user.grp = partblock, Jamie M. Kass Gonzalo E. Pinilla-Buitrago + +Bethany A. Johnson } diff --git a/man/part_partitionOccs.Rd b/man/part_partitionOccs.Rd index 3e311bedd..18141cdbe 100644 --- a/man/part_partitionOccs.Rd +++ b/man/part_partitionOccs.Rd @@ -25,8 +25,8 @@ components occs: Obtain occurrence data or, poccs: Process occurrence data.} (1) 'jack' Non-spatial Partition - jackknife \cr (2) 'rand' Non-spatial Partition - random k-fold \cr (3) 'block' spatial Partition - block \cr -(4) 'cb1' spatial Partition - checkerboard 1 (K=2) \cr -(5) 'cb2' spatial Partition - checkerboard 2 (K=4) \cr} +(4) 'cb1' spatial Partition - checkerboard (k=2) \cr +(5) 'cb2' spatial Partition - hierarchical checkerboard (k=4) \cr} \item{kfolds}{numeric. Number of partitions to create if selected method is random k-fold (must be >=2). If other method then keep default of NULL.} @@ -85,4 +85,6 @@ Jamie Kass Gonzalo E. Pinilla-Buitrago Andrea Paz + +Bethany A Johnson } diff --git a/man/vis_bioclimPlot.Rd b/man/vis_bioclimPlot.Rd index 51f557faf..2e055e1a5 100644 --- a/man/vis_bioclimPlot.Rd +++ b/man/vis_bioclimPlot.Rd @@ -64,4 +64,6 @@ bioclimPlot <- vis_bioclimPlot(x = m@models$bioclim, Jamie Kass Gonzalo E. Pinilla-Buitrago + +Bethany A. Johnson } diff --git a/man/xfer_area.Rd b/man/xfer_area.Rd index 2b6513592..b58e97fda 100644 --- a/man/xfer_area.Rd +++ b/man/xfer_area.Rd @@ -80,11 +80,22 @@ selCoords <- matrix(c(longitude, latitude), byrow = FALSE, ncol = 2) polyExt <- sp::SpatialPolygons(list(sp::Polygons(list(sp::Polygon(selCoords)), ID = 1))) -# load model -m <- readRDS(system.file("extdata/model.RDS", - package = "wallace")) +# build model +occs <- read.csv(system.file("extdata/Bassaricyon_alleni.csv", + package = "wallace")) +bg <- read.csv(system.file("extdata/Bassaricyon_alleni_bgPoints.csv", + package = "wallace")) +partblock <- part_partitionOccs(occs, bg, method = 'block') +m <- model_maxent(occs, bg, + user.grp = partblock, + bgMsk = envs, rms = c(1:2), + rmsStep = 1, fcs = c('L', 'LQ'), + clampSel = TRUE, + algMaxent = "maxnet", + parallel = FALSE) +### run function modXfer <- xfer_area(evalOut = m, curModel = 1, envs, - outputType = 'cloglog', alg = 'maxent.jar', + outputType = 'cloglog', alg = 'maxnet', clamp = TRUE, xfExt = polyExt) } diff --git a/man/xfer_time.Rd b/man/xfer_time.Rd index 2f187e211..62434ae8d 100644 --- a/man/xfer_time.Rd +++ b/man/xfer_time.Rd @@ -84,9 +84,13 @@ latitude <- c(13.18379, 7.52315, 0.93105, -1.70167, 0.98391, 6.09208, 12.74980) selCoords <- matrix(c(longitude, latitude), byrow = FALSE, ncol = 2) polyExt <- sp::SpatialPolygons(list(sp::Polygons(list(sp::Polygon(selCoords)), ID = 1))) -# load model -m <- readRDS(system.file("extdata/model.RDS", - package = "wallace")) +# build model +occs <- read.csv(system.file("extdata/Bassaricyon_alleni.csv",package = "wallace")) +bg <- read.csv(system.file("extdata/Bassaricyon_alleni_bgPoints.csv", package = "wallace")) +partblock <- part_partitionOccs(occs, bg, method = 'block') +m <- model_maxent(occs, bg, user.grp = partblock, bgMsk = envs, rms = c(1:2), +rmsStep = 1, fcs = c('L', 'LQ'), +clampSel = TRUE, algMaxent = "maxnet", parallel = FALSE) occsEnvs <- m@occs bgEnvs <- m@bg envsFut <- list.files(path = system.file('extdata/wc/future', @@ -94,7 +98,7 @@ envsFut <- list.files(path = system.file('extdata/wc/future', full.names = TRUE) envsFut <- raster::stack(envsFut) modXfer <- xfer_time(evalOut = m, curModel = 1, - envs = envsFut, alg = 'maxent.jar', + envs = envsFut, alg = 'maxnet', xfExt = polyExt, clamp = FALSE, outputType = 'cloglog') } } diff --git a/man/xfer_userEnvs.Rd b/man/xfer_userEnvs.Rd index 7f43385bb..5e4930591 100644 --- a/man/xfer_userEnvs.Rd +++ b/man/xfer_userEnvs.Rd @@ -69,16 +69,24 @@ latitude <- c(13.18379, 7.52315, 0.93105, -1.70167, 0.98391, 6.09208, 12.74980) selCoords <- matrix(c(longitude, latitude), byrow = FALSE, ncol = 2) polyExt <- sp::SpatialPolygons(list(sp::Polygons(list(sp::Polygon(selCoords)), ID = 1))) -# load model -m <- readRDS(system.file("extdata/model.RDS", - package = "wallace")) +# build model +occs <- read.csv(system.file("extdata/Bassaricyon_alleni.csv",package = "wallace")) +bg <- read.csv(system.file("extdata/Bassaricyon_alleni_bgPoints.csv", +package = "wallace")) +envs <- envs_userEnvs(rasPath = list.files(system.file("extdata/wc", +package = "wallace"), pattern = ".tif$", full.names = TRUE), +rasName = list.files(system.file("extdata/wc",package = "wallace"), +pattern = ".tif$", full.names = FALSE)) +partblock <- part_partitionOccs(occs, bg, method = 'block') +m <- model_maxent(occs, bg, user.grp = partblock, bgMsk = envs, rms = c(1:2), +rmsStep = 1, fcs = c('L', 'LQ'), clampSel = TRUE, algMaxent = "maxnet", parallel = FALSE) envsFut <- list.files(path = system.file('extdata/wc/future', package = "wallace"), full.names = TRUE) envsFut <- raster::stack(envsFut) ### run function modXfer <- xfer_userEnvs(evalOut = m, curModel = 1, envs = envsFut, - outputType = "cloglog", alg = "maxent.jar", + outputType = "cloglog", alg = "maxnet", clamp = FALSE, xfExt = polyExt) } diff --git a/tests/testthat/test_model_bioclim.R b/tests/testthat/test_model_bioclim.R index 48c0adaaf..e1d546e53 100644 --- a/tests/testthat/test_model_bioclim.R +++ b/tests/testthat/test_model_bioclim.R @@ -44,14 +44,14 @@ test_that("output type checks", { expect_is(bioclimAlg@other.settings, "list") expect_is(bioclimAlg@models, "list") # a raster Stack - expect_is(bioclimAlg@predictions, "RasterStack") + expect_is(bioclimAlg@predictions, "SpatRaster") # factor expect_is(bioclimAlg@occs.grp, "factor") expect_is(bioclimAlg@bg.grp, "factor") # there is 1 model expect_equal(length(bioclimAlg@models), 1) # there is 1 prediction - expect_equal(raster::nlayers(bioclimAlg@predictions), 1) + expect_equal(terra::nlyr(bioclimAlg@predictions), 1) # there is 1 model in the evaluation table expect_equal(nrow(bioclimAlg@results), 1) # columns name in the evaluation table are right @@ -71,12 +71,12 @@ test_that("output type checks", { "or.mtp", "or.10p")) }) -### test function stepts +### test function steps test_that("output data checks", { # the AUC values are between 0 and 1 expect_false(FALSE %in% (( bioclimAlg@results[, c("auc.val.avg", "auc.val.sd", "auc.diff.avg", "auc.diff.sd")]) <= 1 | (bioclimAlg@results[, c("auc.val.avg", "auc.val.sd", "auc.diff.avg", "auc.diff.sd")]) <= 0)) # the predictions generated are within the background mask - expect_equal(raster::extent(envs), raster::extent(bioclimAlg@predictions)) + expect_equal(raster::extent(envs), raster::extent(raster::raster(bioclimAlg@predictions))) }) diff --git a/tests/testthat/test_model_maxent.R b/tests/testthat/test_model_maxent.R index 16e52c190..e9be364eb 100644 --- a/tests/testthat/test_model_maxent.R +++ b/tests/testthat/test_model_maxent.R @@ -78,7 +78,7 @@ for (i in algorithm) { expect_is(maxentAlg@models, "list") expect_is(maxentAlg@variable.importance,"list") # a raster Stack - expect_is(maxentAlg@predictions, "RasterStack") + expect_is(maxentAlg@predictions, "SpatRaster") # factor expect_is(maxentAlg@occs.grp, "factor") expect_is(maxentAlg@bg.grp, "factor") @@ -86,7 +86,7 @@ for (i in algorithm) { # there are as much models as feature classes * rms/rmsStep expect_equal(length(maxentAlg@models), (length(rms)/rmsStep)*length(fcs)) # as many rasters as models are generated - expect_equal(length(maxentAlg@models), raster::nlayers(maxentAlg@predictions)) + expect_equal(length(maxentAlg@models), terra::nlyr(maxentAlg@predictions)) # there is a model for each combination of feature classes and # regularization multiplier expect_equal(sort(as.character(maxentAlg@results$tune.args)), diff --git a/tests/testthat/test_xfer_area.R b/tests/testthat/test_xfer_area.R index 9cd9571df..71256bca4 100644 --- a/tests/testthat/test_xfer_area.R +++ b/tests/testthat/test_xfer_area.R @@ -20,11 +20,20 @@ latitude <- c(13.18379, 7.52315, 0.93105, -1.70167, 0.98391, 6.09208, 12.74980) selCoords <- matrix(c(longitude, latitude), byrow = FALSE, ncol = 2) polyExt <- sp::SpatialPolygons(list(sp::Polygons(list(sp::Polygon(selCoords)), ID = 1))) -# load model -m <- readRDS(system.file("extdata/model.RDS", - package = "wallace")) + +# build model +occs <- read.csv(system.file("extdata/Bassaricyon_alleni.csv",package = "wallace")) +bg <- read.csv(system.file("extdata/Bassaricyon_alleni_bgPoints.csv", + package = "wallace")) +partblock <- part_partitionOccs(occs, bg, method = 'block') +m <- model_maxent(occs, bg, user.grp = partblock, + bgMsk = envs, rms = c(1:2), rmsStep = 1, fcs = c('L', 'LQ'), + clampSel = TRUE, algMaxent = "maxnet", + parallel = FALSE) + +### run function modXfer <- xfer_area(evalOut = m, curModel = 1, envs, - outputType = 'cloglog', alg = 'maxent.jar', + outputType = 'cloglog', alg = 'maxnet', clamp = TRUE, xfExt = polyExt) test_that("output type checks", { diff --git a/tests/testthat/test_xfer_time.R b/tests/testthat/test_xfer_time.R index 7c707e1f6..836ff6b22 100644 --- a/tests/testthat/test_xfer_time.R +++ b/tests/testthat/test_xfer_time.R @@ -17,9 +17,16 @@ latitude <- c(13.18379, 7.52315, 0.93105, -1.70167, 0.98391, 6.09208, 12.74980) selCoords <- matrix(c(longitude, latitude), byrow = FALSE, ncol = 2) polyExt <- sp::SpatialPolygons(list(sp::Polygons(list(sp::Polygon(selCoords)), ID = 1))) -# load model -m <- readRDS(system.file("extdata/model.RDS", - package = "wallace")) +# build model +occs <- read.csv(system.file("extdata/Bassaricyon_alleni.csv",package = "wallace")) +bg <- read.csv(system.file("extdata/Bassaricyon_alleni_bgPoints.csv", + package = "wallace")) +partblock <- part_partitionOccs(occs, bg, method = 'block') +m <- model_maxent(occs, bg, user.grp = partblock, + bgMsk = envs, rms = c(1:2), rmsStep = 1, fcs = c('L', 'LQ'), + clampSel = TRUE, algMaxent = "maxnet", + parallel = FALSE) + occsEnvs <- m@occs bgEnvs <- m@bg envsFut <- list.files(path = system.file('extdata/wc/future', @@ -27,7 +34,7 @@ envsFut <- list.files(path = system.file('extdata/wc/future', full.names = TRUE) envsFut <- raster::stack(envsFut) modXfer <- xfer_time(evalOut = m, curModel = 1, - envs = envsFut, alg = 'maxent.jar', + envs = envsFut, alg = 'maxnet', xfExt = polyExt, clamp = FALSE, outputType = 'cloglog') # build model and test for both algorithms diff --git a/tests/testthat/test_xfer_userEnvs.R b/tests/testthat/test_xfer_userEnvs.R index 496255a7b..675b739ae 100644 --- a/tests/testthat/test_xfer_userEnvs.R +++ b/tests/testthat/test_xfer_userEnvs.R @@ -11,16 +11,28 @@ latitude <- c(13.18379, 7.52315, 0.93105, -1.70167, 0.98391, 6.09208, 12.74980) selCoords <- matrix(c(longitude, latitude), byrow = FALSE, ncol = 2) polyExt <- sp::SpatialPolygons(list(sp::Polygons(list(sp::Polygon(selCoords)), ID = 1))) -# load model -m <- readRDS(system.file("extdata/model.RDS", - package = "wallace")) +# build model +occs <- read.csv(system.file("extdata/Bassaricyon_alleni.csv",package = "wallace")) +bg <- read.csv(system.file("extdata/Bassaricyon_alleni_bgPoints.csv", + package = "wallace")) +envs <- envs_userEnvs(rasPath = list.files(system.file("extdata/wc", + package = "wallace"), + pattern = ".tif$", full.names = TRUE), + rasName = list.files(system.file("extdata/wc", + package = "wallace"), + pattern = ".tif$", full.names = FALSE)) +partblock <- part_partitionOccs(occs, bg, method = 'block') +m <- model_maxent(occs, bg, user.grp = partblock, + bgMsk = envs, rms = c(1:2), rmsStep = 1, fcs = c('L', 'LQ'), + clampSel = TRUE, algMaxent = "maxnet", + parallel = FALSE) envsFut <- list.files(path = system.file('extdata/wc/future', package = "wallace"), full.names = TRUE) envsFut <- raster::stack(envsFut) ### run function modXfer <- xfer_userEnvs(evalOut = m, curModel = 1, envs = envsFut, - outputType = "cloglog", alg = "maxent.jar", + outputType = "cloglog", alg = "maxnet", clamp = FALSE, xfExt = polyExt) ### test output features diff --git a/vignettes/module-addition.Rmd b/vignettes/module-addition.Rmd index 412cb2ea3..0477ec771 100644 --- a/vignettes/module-addition.Rmd +++ b/vignettes/module-addition.Rmd @@ -1,7 +1,7 @@ --- title: "How to write a module in Wallace" author: "Gonzalo Pinilla-Buitrago, Jamie M. Kass, Siew Fong Chen, Peter Galante, Bethany A. Johnson, Dean Attali" -date: "April 19, 2022" +date: "April 19, 2022; updated August 26, 2024" output: rmarkdown::html_vignette vignette: > %\VignetteIndexEntry{Wallace Ecological Modeling Application v2.0 Vignette} @@ -285,7 +285,7 @@ The following reactive variables that can be used by the module: logger, spp, cu The following reactives that are shortcuts to reactives inside spp: occs, envs, bg, bgExt, bgMask, evalOut, mapPred, mapXfer, rmm. A function `update_component(tab)` that allows you to switch to a new tab within the component. -This function `penvs_correlations_module_server()` is a wrapper for a shiny reactive expression. Inside, there is a template for the essential parts needed in a *Wallace* module. First, we specify shorter names for the shortcut variables inside the “common” list. Next, we specify a UI function that can use reactive values inside of this server function—in this case, we want to know the names of the environmental variables input so they can be printed to the UI control (see Creating a reactive shortcut in the next section for more details). After this, we specify when the module function gets run. The function `observeEvent()` performs an action in response to an event (e.g., clicking a button created by `penvs_correlations_module_ui()`). Inside of each `observeEvent()`, you need to include the following code. The first, "WARNING", catches any possible errors before the module's core functionality is run. If there is an error, the function stops and a log error message is written. The user will need to define these errors in order to catch them and prevent the module from crashing unexpectedly. Next, under “FUNCTION CALL”, we call the function from `/wallace/R` and make sure it returns what we expect. Next, under “LOAD INTO SPP”, we load the model object into `spp`. Finally, under “METADATA”, we fill in appropriate metadata fields for the rangeModelMetadata object in `spp`. Ultimately, the module author decides what metadata to include, but we encourage authors to explore the rangeModelMetadata object, decide which fields best apply to your module, and enter information detailed enough to enable reproducibility. As shiny modules exist in their own namespaces, if we want to refer to any of the results from the module later (in other modules), we need to put them into the `spp` reactiveValues list. +This function `penvs_correlations_module_server()` is a wrapper for a shiny reactive expression. Inside, there is a template for the essential parts needed in a *Wallace* module. First, we specify shorter names for the shortcut variables inside the “common” list. Next, we specify a UI function that can use reactive values inside of this server function—in this case, we want to know the names of the environmental variables input so they can be printed to the UI control (see Creating a reactive shortcut in the next section for more details). After this, we specify when the module function gets run. The function `observeEvent()` performs an action in response to an event (e.g., clicking a button created by `penvs_correlations_module_ui()`). Inside of each `observeEvent()`, you need to include the following code. The first, "WARNING", catches any possible errors before the module's core functionality is run. If there is an error, the function stops and a log error message is written. The user will need to define these errors in order to catch them and prevent the module from crashing unexpectedly. Next, under “FUNCTION CALL”, we call the function from `/wallace/R` and make sure it returns what we expect. Next, under “LOAD INTO SPP”, we load the model object into `spp`. In "REFERENCES", use the `knitcitations`package `citep` to include any packages to cite in the Reference Packages module in the Reproduce component. Finally, under “METADATA”, we fill in appropriate metadata fields for the rangeModelMetadata object in `spp`. Ultimately, the module author decides what metadata to include, but we encourage authors to explore the rangeModelMetadata object, decide which fields best apply to your module, and enter information detailed enough to enable reproducibility. As shiny modules exist in their own namespaces, if we want to refer to any of the results from the module later (in other modules), we need to put them into the `spp` reactiveValues list. ```{r, eval = F} penvs_correlations_module_server <- function(input, output, session, common) { @@ -335,6 +335,9 @@ penvs_correlations_module_server <- function(input, output, session, common) { # LOAD INTO SPP #### spp[[sp]]$procEnvs$envCorrs <- envCorrs$`pearson correlation coefficient` + # REFERENCES #### + knitcitations::citep(citation("raster", auto = TRUE)) + # METADATA #### }