From 954a2d4eb0596c01e86d4fe9941f46f2e54fcb7b Mon Sep 17 00:00:00 2001 From: Bethany Johnson Date: Mon, 26 Aug 2024 14:10:23 -0400 Subject: [PATCH 01/12] draft for v2.2.0 --- DESCRIPTION | 4 ++-- NEWS.md | 5 +++++ README.md | 4 ++-- inst/shiny/Rmd/text_about.Rmd | 2 +- inst/shiny/Rmd/text_intro_tab.Rmd | 2 +- inst/shiny/Rmd/userReport_intro.Rmd | 2 +- 6 files changed, 12 insertions(+), 7 deletions(-) diff --git a/DESCRIPTION b/DESCRIPTION index 488c95dd..119b4341 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,6 +1,6 @@ Package: wallace -Version: 2.1.3 -Date: 2024-07-18 +Version: 2.2.0 +Date: 2024-08-22 Title: A Modular Platform for Reproducible Modeling of Species Niches and Distributions Description: The 'shiny' application Wallace is a modular platform for diff --git a/NEWS.md b/NEWS.md index 3737810c..c5f7d0bd 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,3 +1,8 @@ +wallace 2.2.0 +============= +- +- + wallace 2.1.3 ============= - Fixed NULL error in poccs_selectOccs Rmd code diff --git a/README.md b/README.md index dd5694ac..44b28880 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/shiny/Rmd/text_about.Rmd b/inst/shiny/Rmd/text_about.Rmd index c68aabda..4d8be876 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 1e8deddd..554b7fba 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 345a8e56..47b20b55 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. From 9f170fd5bf44dd7d7e43fd906687ea07cfff1324 Mon Sep 17 00:00:00 2001 From: Bethany Johnson Date: Mon, 26 Aug 2024 14:32:44 -0400 Subject: [PATCH 02/12] RPA edits to gt --- NEWS.md | 2 +- inst/shiny/modules/envs_userEnvs.md | 4 ++-- inst/shiny/modules/xfer_time.md | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/NEWS.md b/NEWS.md index c5f7d0bd..6b3a1be7 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,7 +1,7 @@ wallace 2.2.0 ============= - -- +- RPA edits to guidance texts wallace 2.1.3 ============= diff --git a/inst/shiny/modules/envs_userEnvs.md b/inst/shiny/modules/envs_userEnvs.md index 5e2165f8..47385591 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/xfer_time.md b/inst/shiny/modules/xfer_time.md index 9a16bbe5..2770775d 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** From 5f3058f9b4ca5e921af7b3b4f7af72939a410cb5 Mon Sep 17 00:00:00 2001 From: Bethany Johnson Date: Mon, 26 Aug 2024 14:59:29 -0400 Subject: [PATCH 03/12] add REFERENCES to module skeleton & vignette --- NEWS.md | 1 + inst/module_skeleton/skeleton.R | 2 ++ vignettes/module-addition.Rmd | 7 +++++-- 3 files changed, 8 insertions(+), 2 deletions(-) diff --git a/NEWS.md b/NEWS.md index 6b3a1be7..cb954a64 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,6 +1,7 @@ wallace 2.2.0 ============= - +- updated module skeleton & module addition vignette to include `knitcitations` for References - RPA edits to guidance texts wallace 2.1.3 diff --git a/inst/module_skeleton/skeleton.R b/inst/module_skeleton/skeleton.R index 9f2333c6..e88602ad 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/vignettes/module-addition.Rmd b/vignettes/module-addition.Rmd index 412cb2ea..0477ec77 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 #### } From ade04134c0e9dcf35e8b36afd384058bff551afc Mon Sep 17 00:00:00 2001 From: Bethany Johnson Date: Thu, 5 Dec 2024 15:57:29 -0500 Subject: [PATCH 04/12] updates for ENMeval 2.0.5: partitioning --- DESCRIPTION | 4 ++-- R/part_partitionOccs.R | 18 ++++++++++-------- inst/shiny/modules/part_nonSpat.yml | 2 +- inst/shiny/modules/part_spat.yml | 2 +- man/part_partitionOccs.Rd | 6 ++++-- 5 files changed, 18 insertions(+), 14 deletions(-) diff --git a/DESCRIPTION b/DESCRIPTION index 119b4341..fd8ed947 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,6 +1,6 @@ Package: wallace Version: 2.2.0 -Date: 2024-08-22 +Date: 2024-12-05 Title: A Modular Platform for Reproducible Modeling of Species Niches and Distributions Description: The 'shiny' application Wallace is a modular platform for @@ -38,7 +38,7 @@ Imports: dplyr (>= 1.0.2), DT (>= 0.5), ecospat (>= 4.0.0), - ENMeval (>= 2.0.3), + ENMeval (>= 2.0.5), geodata, knitcitations, leafem, diff --git a/R/part_partitionOccs.R b/R/part_partitionOccs.R index 17fff796..2863609b 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/inst/shiny/modules/part_nonSpat.yml b/inst/shiny/modules/part_nonSpat.yml index b645800c..76685404 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 61060ec6..ef65e99e 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/man/part_partitionOccs.Rd b/man/part_partitionOccs.Rd index 3e311bed..18141cdb 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 } From 62f8e6eebfcb3b8965068fb21249a446eb624c4d Mon Sep 17 00:00:00 2001 From: Bethany Johnson Date: Thu, 5 Dec 2024 16:34:11 -0500 Subject: [PATCH 05/12] updates for ENMeval 2.0.5: modeling --- R/model_bioclim.R | 3 ++- R/model_maxent.R | 3 ++- inst/shiny/modules/model_bioclim.yml | 2 +- inst/shiny/modules/model_maxent.yml | 2 +- man/model_bioclim.Rd | 2 ++ man/model_maxent.Rd | 2 ++ tests/testthat/test_model_bioclim.R | 8 ++++---- tests/testthat/test_model_maxent.R | 4 ++-- 8 files changed, 16 insertions(+), 10 deletions(-) diff --git a/R/model_bioclim.R b/R/model_bioclim.R index 84f9b35e..85583084 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 82a53b06..31a8c25d 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,7 +197,7 @@ 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, diff --git a/inst/shiny/modules/model_bioclim.yml b/inst/shiny/modules/model_bioclim.yml index 6eab48bc..6ab99a6a 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 b3b2b116..b2fc3360 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/man/model_bioclim.Rd b/man/model_bioclim.Rd index ef316188..9147402a 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 5a443d9a..0f5ad1e5 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/tests/testthat/test_model_bioclim.R b/tests/testthat/test_model_bioclim.R index 48c0adaa..e1d546e5 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 16e52c19..e9be364e 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)), From aa59a788aa1799901933f026b38126ab770f0d5a Mon Sep 17 00:00:00 2001 From: Bethany Johnson Date: Thu, 5 Dec 2024 18:47:55 -0500 Subject: [PATCH 06/12] updates for ENMeval 2.0.5: visualize --- DESCRIPTION | 1 + R/vis_bioclimPlot.R | 1 + inst/shiny/modules/vis_bioclimPlot.yml | 2 +- inst/shiny/modules/vis_mapPreds.R | 12 ++++++++---- inst/shiny/modules/vis_mapPreds.Rmd | 18 ++++++++++-------- inst/shiny/modules/vis_mapPreds.yml | 2 +- inst/shiny/modules/vis_maxentEvalPlot.yml | 2 +- inst/shiny/modules/vis_responsePlot.R | 2 +- inst/shiny/modules/vis_responsePlot.Rmd | 2 +- inst/shiny/modules/vis_responsePlot.yml | 2 +- inst/shiny/server.R | 2 +- man/vis_bioclimPlot.Rd | 2 ++ 12 files changed, 29 insertions(+), 19 deletions(-) diff --git a/DESCRIPTION b/DESCRIPTION index fd8ed947..4860e523 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -67,6 +67,7 @@ Suggests: mapview, maxnet, occCite, + predicts, rangeModelMetadata, raster, rgbif (>= 3.3.0), diff --git a/R/vis_bioclimPlot.R b/R/vis_bioclimPlot.R index d979c50f..d20a9479 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/inst/shiny/modules/vis_bioclimPlot.yml b/inst/shiny/modules/vis_bioclimPlot.yml index 1ed41c4e..01ed6974 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 9b73cb69..99e379e7 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 0ae91340..5f67b862 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 92839bc0..b76a04aa 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 918001b7..0cb53999 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 c180303a..39828f49 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 82cecbd9..ba948c91 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 31287809..1da1a5ab 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/server.R b/inst/shiny/server.R index 7439c0cd..b274e2ac 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/vis_bioclimPlot.Rd b/man/vis_bioclimPlot.Rd index 51f557fa..2e055e1a 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 } From edf7ee5160b589a319eb6a170d12419fca4fd29e Mon Sep 17 00:00:00 2001 From: Bethany Johnson Date: Thu, 5 Dec 2024 20:05:38 -0500 Subject: [PATCH 07/12] updates for ENMeval 2.0.5: transfer --- R/xfer_area.R | 19 ++++++++++--------- R/xfer_time.R | 20 +++++++++++--------- R/xfer_userEnvs.R | 24 +++++++++++++++--------- man/xfer_area.Rd | 11 +++++++---- man/xfer_time.Rd | 12 ++++++++---- man/xfer_userEnvs.Rd | 16 ++++++++++++---- tests/testthat/test_xfer_area.R | 17 +++++++++++++---- tests/testthat/test_xfer_time.R | 15 +++++++++++---- tests/testthat/test_xfer_userEnvs.R | 20 ++++++++++++++++---- 9 files changed, 103 insertions(+), 51 deletions(-) diff --git a/R/xfer_area.R b/R/xfer_area.R index f0c2e9cd..5ef00fcc 100644 --- a/R/xfer_area.R +++ b/R/xfer_area.R @@ -69,11 +69,14 @@ #' 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 +120,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 832f4fcd..d6f69121 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 8d87f0c7..3e361998 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/man/xfer_area.Rd b/man/xfer_area.Rd index 2b651359..50702896 100644 --- a/man/xfer_area.Rd +++ b/man/xfer_area.Rd @@ -80,11 +80,14 @@ 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 2f187e21..62434ae8 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 7f43385b..5e493059 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_xfer_area.R b/tests/testthat/test_xfer_area.R index 9cd9571d..71256bca 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 7c707e1f..836ff6b2 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 496255a7..675b739a 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 From af4beeb9ed9169133f08f14f536b18b1eb3fa528 Mon Sep 17 00:00:00 2001 From: Bethany Johnson Date: Fri, 6 Dec 2024 12:11:54 -0500 Subject: [PATCH 08/12] ENMeval 2.0.5 functionality --- NEWS.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/NEWS.md b/NEWS.md index cb954a64..4a3adb34 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,6 +1,6 @@ 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 From 9ba82a5ca337bd7dd9b86d1634903d51d8d36843 Mon Sep 17 00:00:00 2001 From: Bethany Johnson Date: Thu, 19 Dec 2024 12:35:47 -0500 Subject: [PATCH 09/12] no mo' doSNOW --- DESCRIPTION | 2 +- R/model_maxent.R | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/DESCRIPTION b/DESCRIPTION index 4860e523..bbbd9998 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,6 +1,6 @@ Package: wallace Version: 2.2.0 -Date: 2024-12-05 +Date: 2024-12-19 Title: A Modular Platform for Reproducible Modeling of Species Niches and Distributions Description: The 'shiny' application Wallace is a modular platform for diff --git a/R/model_maxent.R b/R/model_maxent.R index 31a8c25d..a1365dba 100644 --- a/R/model_maxent.R +++ b/R/model_maxent.R @@ -204,7 +204,7 @@ model_maxent <- function(occs, bg, user.grp, bgMsk, rms, rmsStep, fcs, categoricals = catEnvs, parallel = parallel, numCores = numCores, - parallelType = "doSNOW", + # parallelType = "doSNOW", # taxon.name = NULL, # user.enm = NULL, # occs.ind = NULL, From ecb58f3024a9e4010d5253159bcd2cca01a51519 Mon Sep 17 00:00:00 2001 From: Daniel Lopez Date: Mon, 3 Mar 2025 15:32:50 -0500 Subject: [PATCH 10/12] Convert xferAreaThr to RasterLayer when working with maxent.jar --- inst/shiny/modules/xfer_area.R | 2 ++ 1 file changed, 2 insertions(+) diff --git a/inst/shiny/modules/xfer_area.R b/inst/shiny/modules/xfer_area.R index 05975332..3f9ecedd 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) From 37b88ff657974419c08c506f596e022eb3cbdb59 Mon Sep 17 00:00:00 2001 From: "Bethany A. Johnson" Date: Wed, 5 Mar 2025 12:07:47 -0500 Subject: [PATCH 11/12] Update DESCRIPTION added dani!!! --- DESCRIPTION | 1 + 1 file changed, 1 insertion(+) diff --git a/DESCRIPTION b/DESCRIPTION index bbbd9998..071fbb7d 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -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"), From 93d70c592d2a3c72f1bff395ee9fccf9578ef917 Mon Sep 17 00:00:00 2001 From: Bethany Johnson Date: Thu, 6 Mar 2025 10:20:11 -0500 Subject: [PATCH 12/12] fixed character length in xfer test --- DESCRIPTION | 2 +- R/xfer_area.R | 14 +++++++++++--- man/xfer_area.Rd | 14 +++++++++++--- 3 files changed, 23 insertions(+), 7 deletions(-) diff --git a/DESCRIPTION b/DESCRIPTION index 071fbb7d..65458712 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,6 +1,6 @@ Package: wallace Version: 2.2.0 -Date: 2024-12-19 +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 diff --git a/R/xfer_area.R b/R/xfer_area.R index 5ef00fcc..4821aa61 100644 --- a/R/xfer_area.R +++ b/R/xfer_area.R @@ -70,10 +70,18 @@ #' sp::SpatialPolygons(list(sp::Polygons(list(sp::Polygon(selCoords)), #' ID = 1))) #' # 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")) +#' 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) +#' 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 = 'maxnet', diff --git a/man/xfer_area.Rd b/man/xfer_area.Rd index 50702896..b58e97fd 100644 --- a/man/xfer_area.Rd +++ b/man/xfer_area.Rd @@ -81,10 +81,18 @@ polyExt <- sp::SpatialPolygons(list(sp::Polygons(list(sp::Polygon(selCoords)), ID = 1))) # 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")) +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) +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 = 'maxnet',