Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

unit tests & documentation #441

Merged
merged 21 commits into from
Oct 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
60e1e06
add unit test & documentation for indic_aoo
bjohnso005 Aug 8, 2024
886d4a3
add unit test & documentation for indic_eoo
bjohnso005 Aug 8, 2024
1268c86
add unit test & documentation for indic_inputPoly: IN PROG
bjohnso005 Aug 21, 2024
c2a4bbd
unit test for indic_inputPoly: IN PROG. gives warnings :(
bjohnso005 Aug 29, 2024
10f3cb8
add unit test & documentation for indic_raster; added prediction map …
bjohnso005 Sep 5, 2024
48cd219
added placeholder for binary error
bjohnso005 Sep 18, 2024
0269c37
unit tests & documentation for indic_inputpoly and indic_overlap; add…
bjohnso005 Sep 18, 2024
0b8df16
updated date & v# (to not confuse dev_biomodelos with biomodelos)
bjohnso005 Sep 18, 2024
30fc5bc
typo in @example
bjohnso005 Sep 19, 2024
2bf96a1
unit testing & documentation for indic_time added; incl MODIS extdata
bjohnso005 Sep 25, 2024
5c841c2
unit tests & documentation for mask_expPoly
bjohnso005 Oct 2, 2024
d686b70
unit tests & documentation for mask_spatialPoly
bjohnso005 Oct 2, 2024
3b9e6c4
added fix=true to fix test with parens
bjohnso005 Oct 2, 2024
8b19c21
unit tests & documentation for mask_tempAnnotate
bjohnso005 Oct 4, 2024
d6a72b5
fixed logger parameter descriptions
bjohnso005 Oct 4, 2024
d82a961
unit tests & documentation for mask_tempExtract
bjohnso005 Oct 8, 2024
652fc92
typo in unit test
bjohnso005 Oct 9, 2024
ef9665d
remove comment
bjohnso005 Oct 9, 2024
1a06288
unit tests & documentation for mask_userSDM
bjohnso005 Oct 10, 2024
2df372e
add unit test & documentation for occs_biomodelos
bjohnso005 Oct 18, 2024
5527f0d
added license & # REFERENCES (knitcitations) to v3 modules
bjohnso005 Oct 18, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Package: wallace
Version: 2024.08.02
Date: 2024-08-02
Version: 2024.09.18
Date: 2024-09-18
Title: A Modular Platform for Reproducible Modeling of Species Niches
and Distributions
Description: The 'shiny' application Wallace is a modular platform for
Expand Down
76 changes: 69 additions & 7 deletions R/indic_aoo.R
Original file line number Diff line number Diff line change
@@ -1,6 +1,33 @@
##' @title indic_aoo
# Wallace EcoMod: a flexible platform for reproducible modeling of
# species niches and distributions.
#
# indic_aoo.R
# File author: Wallace EcoMod Dev Team. 2023.
# --------------------------------------------------------------------------
# This file is part of the Wallace EcoMod application
# (hereafter “Wallace”).
#
# Wallace is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License,
# or (at your option) any later version.
#
# Wallace is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with Wallace. If not, see <http://www.gnu.org/licenses/>.
# --------------------------------------------------------------------------
#
#' @title indic_aoo
#' @description Calculate AOO.
#'
#' @details
#' The function calculates the area of occupancy (AOO) from a thresholded
#' prediction raster or a data.frame of occurrence records.
#'
#' @param r raster. Thresholded prediction raster. It could be NULL if occs provided.
#' @param occs data.frame. Table with occurrences. It could be NULL if raster
#' provided. If occs provided raster is ignored.
Expand All @@ -13,24 +40,57 @@
#' @param logger stores all notification messages to be displayed in the Log
#' Window of Wallace GUI. Insert the logger reactive list here for running in
#' shiny, otherwise leave the default NULL
#'
#' @examples
#' \dontrun{
#' ### Set parameters
#' # binary raster
#' r <- terra::rast(system.file("extdata/Bassaricyon_neblina.tif",
#' package = "wallace"))
#' # occurrences
#'
#' ### Run function
#' # aoo from raster
#' aoo_r <- indic_aoo(r,
#' occs = NULL,
#' lon = NULL,
#' lat = NULL,
#' wktFrom = getWKT("wgs84"),
#' wktTo = getWKT("wcea"),
#' logger = NULL)
#' # aoo from occs
#' aoo_occs <- indic_aoo(r <- NULL,
#' occs,
#' lon = "longitude",
#' lat = "latitude",
#' wktFrom = getWKT("wgs84"),
#' wktTo = getWKT("wcea"),
#' logger = NULL)
#' }
#'
#' @return A list of two elements: area and AOOraster. The first is the numeric
#' value of the area (in km^2). The second is a RasterLayer of the extent
#' (in WCEA & 2x2 km resolution).
#'
#' @author Gonzalo E. Pinilla-Buitrago <gpinillabuitrago@@gradcenter.cuny.edu>
#' @author Bethany A. Johnson <bjohnso005@@citymail.cuny.edu>
#' @export
#'

indic_aoo <- function(r = NULL, occs = NULL, lon = NULL, lat = NULL,
wktFrom, wktTo, logger) {
wktFrom, wktTo, logger = NULL) {
if (!is.null(occs)) {
if (is.null(lon) | is.null(lat)) {
logger %>% writeLog("No longitude and/or latitude name provided (**).")
logger %>% writeLog(type = 'error', "No longitude and/or latitude name provided.")
return()
} else {
p.pts <- occs
if (sum(c(lon, lat) %in% names(p.pts)) != 2) {
logger %>% writeLog("Longitude and/or latitude names not found (**).")
logger %>% writeLog(type = 'error', "Longitude and/or latitude names not found.")
return()
} else {
p.pts <- p.pts %>%
dplyr::select(c(lon, lat)) %>%
dplyr::select(all_of(c(lon, lat))) %>% #BAJ
terra::vect(geom = c(lon, lat))
terra::crs(p.pts) <- wktFrom
rast_temp <- terra::rast(terra::ext(terra::project(p.pts, wktTo)) + 10000,
Expand All @@ -44,7 +104,9 @@ indic_aoo <- function(r = NULL, occs = NULL, lon = NULL, lat = NULL,
}
}
} else if (!is.null(r)) {
if ("RasterLayer" %in% class(r)) {
r <- terra::rast(r)
}
## Unsuitable for NAs
r[r == 0] <- NA
p.poly <- terra::as.polygons(r)
Expand All @@ -56,8 +118,8 @@ indic_aoo <- function(r = NULL, occs = NULL, lon = NULL, lat = NULL,
terra::trim()
AOOarea <- terra::freq(AOOraster, value = 1)$count * 4
} else {
logger %>% writeLog("Provide occurrences or raster (**).")
logger %>% writeLog(type = 'error', "Provide occurrences or raster.")
return()
}
return(list(area = AOOarea, AOOraster = methods::as(AOOraster, "Raster")))
return(list(area = AOOarea, AOOraster = raster::raster(AOOraster)))
}
35 changes: 35 additions & 0 deletions R/indic_area.R
Original file line number Diff line number Diff line change
@@ -1,18 +1,53 @@
# Wallace EcoMod: a flexible platform for reproducible modeling of
# species niches and distributions.
#
# indic_area.R
# File author: Wallace EcoMod Dev Team. 2023.
# --------------------------------------------------------------------------
# This file is part of the Wallace EcoMod application
# (hereafter “Wallace”).
#
# Wallace is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License,
# or (at your option) any later version.
#
# Wallace is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with Wallace. If not, see <http://www.gnu.org/licenses/>.
# --------------------------------------------------------------------------
#
#' @title indic_area
#' @description Calculate Range size in square kilometers.
#' @details Calculate the geographic range size of a thresholded raster. The units are in square kilometers.
#'
#' @param r raster. Thresholded prediction raster. It could be NULL if occs provided.
#' @param wkt character. Well-known text representation of coordinate reference systems
#' to calculate area.
#' @param logger stores all notification messages to be displayed in the Log
#' Window of Wallace GUI. insert the logger reactive list here for running in
#' shiny, otherwise leave the default NULL
#'
#' @examples
#' \dontrun{
#' r <- terra::rast(system.file("extdata/Bassaricyon_neblina.tif",package = "wallace"))
#' wkt <- getWKT("wcea")
#' areaRange <- indic_area(r, wkt, logger = NULL)
#' }
#' @return Numeric value
#' @author Gonzalo E. Pinilla-Buitrago <gpinillabuitrago@@gradcenter.cuny.edu>
#' @author Bethany A. Johnson <bjohnso005@@citymail.cuny.edu>
#' @export
#'

indic_area <- function(r, wkt, logger = NULL) {
if ("RasterLayer" %in% class(r)) {
r <- terra::rast(r)
}
## Unsuitable for NAs
r[r == 0] <- NA
## Raster to polygon
Expand Down
55 changes: 50 additions & 5 deletions R/indic_eoo.R
Original file line number Diff line number Diff line change
@@ -1,5 +1,29 @@
# Wallace EcoMod: a flexible platform for reproducible modeling of
# species niches and distributions.
#
# indic_eoo.R
# File author: Wallace EcoMod Dev Team. 2023.
# --------------------------------------------------------------------------
# This file is part of the Wallace EcoMod application
# (hereafter “Wallace”).
#
# Wallace is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License,
# or (at your option) any later version.
#
# Wallace is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with Wallace. If not, see <http://www.gnu.org/licenses/>.
# --------------------------------------------------------------------------
#
#' @title indic_eoo
#' @description Calculate EOO.
#' @details Calculate extent of occurrence (EOO) based on a binary raster or occurrence points.
#'
#' @param r raster. Thresholded prediction raster. It could be NULL if occs provided.
#' @param occs data.frame. Table with occurrences. It could be NULL if raster
Expand All @@ -11,34 +35,55 @@
#' @param logger stores all notification messages to be displayed in the Log
#' Window of Wallace GUI. Insert the logger reactive list here for running in
#' shiny, otherwise leave the default NULL
#'
#' @examples
#' \dontrun{
#' # binary raster
#' r <- terra::rast(system.file("extdata/Bassaricyon_neblina.tif",package = "wallace"))
#' # occurrences
#' occs <- read.csv(system.file("extdata/Bassaricyon_neblina.csv",package = "wallace"))
#' # wcea
#' wkt <- getWKT("wcea")
#'
#' eoo_r <- indic_eoo(r, occs = NULL, lon = NULL, lat = NULL, wkt, logger = NULL)
#' eoo_o <- indic_eoo(r = NULL, occs, lon = "longitude", lat = "latitude", wkt, logger = NULL)
#' }
#'
#' @return A list of two elements: area and eooPoly. area is a numeric value and eooPoly is a SpatialPolygon.
#' @author Andrea Paz <paz.andreita@@gmail.com>
#' @author Gonzalo E. Pinilla-Buitrago <gpinillabuitrago@@gradcenter.cuny.edu>
#' @author Bethany A. Johnson <bjohnso005@@citymail.cuny.edu>
#' @export
#'

indic_eoo <- function(r = NULL, occs = NULL, lon = NULL, lat = NULL,
wkt, logger) {
wkt, logger=NULL) {
if (!is.null(occs)) {
if (is.null(lon) | is.null(lat)) {
logger %>% writeLog("No longitude and/or latitude name provided (**).")
logger %>% writeLog(type = 'error',
"No longitude and/or latitude name provided.")
return()
} else {
p.pts <- occs
if (sum(c(lon, lat) %in% names(p.pts)) != 2) {
logger %>% writeLog("Longitude and/or latitude names not found (**).")
logger %>% writeLog(type = 'error',
"Longitude and/or latitude names not found.")
return()
} else {
p.pts <- p.pts %>% dplyr::select(c(lon, lat))
p.pts <- p.pts %>% dplyr::select(all_of(c(lon, lat)))
}
}
} else if (!is.null(r)) {
if ("RasterLayer" %in% class(r)) {
r <- terra::rast(r)
}
r[r == 0] <- NA
p.pts <- terra::as.points(r) %>%
terra::geom() %>% data.frame() %>%
dplyr::select(tidyselect::all_of(c("x", "y")))
} else {
logger %>% writeLog("Provide occurrences or raster (**).")
logger %>% writeLog(type = 'error',
"Provide occurrences or raster.")
return()
}
wgs84 <- "+proj=longlat +ellps=WGS84 +datum=WGS84 +no_defs"
Expand Down
Loading
Loading