Skip to content

Commit

Permalink
clean tests
Browse files Browse the repository at this point in the history
  • Loading branch information
sylvainschmitt committed Oct 19, 2023
1 parent 205ced2 commit 369b0b1
Show file tree
Hide file tree
Showing 20 changed files with 104 additions and 37 deletions.
2 changes: 2 additions & 0 deletions .Rbuildignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,5 @@ cran-comments.md
^appveyor\.yml$
ToDo.md
^\.github$
^codecov\.yml$
^\.covrignore$
3 changes: 3 additions & 0 deletions .covrignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
R/zzz.R
inst/shiny/*
R/plot.model.R
11 changes: 6 additions & 5 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Package: SSDM
Type: Package
Title: Stacked Species Distribution Modelling
Version: 0.2.8.9002
Version: 0.2.9
Author: Sylvain Schmitt, Robin Pouteau, Dimitri Justeau, Florian de Boissieu, Lukas Baumbach, Philippe Birnbaum
Maintainer: Sylvain Schmitt <sylvain.m.schmitt@gmail.com>
URL: https://github.com/sylvainschmitt/SSDM
Expand Down Expand Up @@ -34,16 +34,16 @@ Imports:
scales (>= 1.0.0),
shiny (>= 0.12.2),
shinydashboard (>= 0.5.1),
shinyFiles (>= 0.7.0),
spThin (>= 0.1.0),
poibin (>= 1.3.0),
foreach (>= 1.4.4),
doParallel (>= 1.0.14),
iterators (>= 1.0.10),
itertools (>= 0.1-3),
parallel (>= 3.5.2),
snow (>= 0.4-3),
leaflet (>= 2.2.0)
leaflet (>= 2.2.0),
magrittr (>= 2.0.3),
sdm (>= 1.1.8)
Depends:
R (>= 3.2.2)
Collate:
Expand Down Expand Up @@ -77,12 +77,13 @@ Collate:
'stack_modelling.R'
'stacking.R'
'update.stack.R'
'utils-pipe.R'
'zzz.R'
Suggests:
testthat,
knitr,
rmarkdown,
sdm
shinyFiles
RoxygenNote: 7.2.3
VignetteBuilder:
knitr,
Expand Down
5 changes: 5 additions & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# Generated by roxygen2: do not edit by hand

export("%>%")
export(ensemble)
export(ensemble_modelling)
export(evaluate)
Expand Down Expand Up @@ -63,6 +64,7 @@ importFrom(leaflet,colorNumeric)
importFrom(leaflet,leaflet)
importFrom(leaflet,leafletOutput)
importFrom(leaflet,renderLeaflet)
importFrom(magrittr,"%>%")
importFrom(mgcv,gam)
importFrom(mgcv,gam.control)
importFrom(nnet,nnet)
Expand Down Expand Up @@ -103,6 +105,7 @@ importFrom(reshape2,melt)
importFrom(rpart,rpart)
importFrom(rpart,rpart.control)
importFrom(scales,muted)
importFrom(sdm,calibration)
importFrom(sf,st_as_sf)
importFrom(sf,st_buffer)
importFrom(shiny,actionButton)
Expand All @@ -115,6 +118,7 @@ importFrom(shiny,fluidRow)
importFrom(shiny,h1)
importFrom(shiny,h2)
importFrom(shiny,h3)
importFrom(shiny,htmlOutput)
importFrom(shiny,icon)
importFrom(shiny,incProgress)
importFrom(shiny,observeEvent)
Expand Down Expand Up @@ -158,6 +162,7 @@ importFrom(stats,rbinom)
importFrom(stats,runif)
importFrom(stats,sd)
importFrom(stats,var)
importFrom(utils,capture.output)
importFrom(utils,lsf.str)
importFrom(utils,read.csv)
importFrom(utils,read.csv2)
Expand Down
4 changes: 2 additions & 2 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
NEWS
================

SSDM 0.2.8.9001
SSDM 0.2.9
===============

bug fixes:
- totally removing rgdal following r-spatial evolution
- moving from sp to sf following r-spatial evolution
- moving from sp to sf and leaflet following r-spatial evolution

SSDM 0.2.8.9000
===============
Expand Down
1 change: 1 addition & 0 deletions R/evaluate.R
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#' @importFrom stats aggregate.data.frame cor glm glm.control rbinom runif sd var
#' @importFrom utils lsf.str read.csv read.csv2 tail write.csv
#' @importFrom raster reclassify rasterize extract stack
#' @importFrom sdm calibration
NULL

#' Evaluate
Expand Down
3 changes: 2 additions & 1 deletion R/get_model.R
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
#' @importFrom e1071 svm
#' @importFrom stats aggregate.data.frame cor glm glm.control rbinom runif sd var
#' @importFrom utils lsf.str read.csv read.csv2 tail write.csv
#' @importFrom utils capture.output
NULL

setGeneric("get_model", function(obj, ...) {
Expand Down Expand Up @@ -188,7 +189,7 @@ setMethod("get_model", "GBM.SDM", function(obj, gbm.args=list(), ...) {
}

# call GBM
model <- do.call(gbm, gbm.args)
capture.output(model <- do.call(gbm, gbm.args), file = nullfile())
return(model)
})

Expand Down
3 changes: 2 additions & 1 deletion R/mapDiversity.R
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
#' @importFrom raster raster stack reclassify mask calc overlay values rasterize rasterToPoints values<- Which setValues
#' @importFrom stats lm optim
#' @importFrom poibin dpoibin
#' @importFrom sf st_as_sf
NULL

#' Map Diversity
Expand Down Expand Up @@ -191,7 +192,7 @@ setMethod("mapDiversity", "Stacked.SDM", function(obj, method, rep.B = 1000,
Richness <- reclassify(obj@esdms[[1]]@projection, c(-Inf, Inf, 0))
for (i in seq_len(length(obj@esdms)))
Richness <- Richness + rasterize(
SpatialPoints(obj@esdms[[i]]@data[1:2]),
sf::st_as_sf(obj@esdms[[i]]@data[1:2], coords = c("X", "Y")),
Richness, field = obj@esdms[[i]]@data$Presence,
background = 0)
if (all(values(Richness) %in% c(0, 1, NA)))
Expand Down
2 changes: 1 addition & 1 deletion R/plot.model.R
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#' @include Algorithm.SDM.R Ensemble.SDM.R Stacked.SDM.R
#' @importFrom raster stack crop extent aggregate reclassify
#' @importFrom shiny h1 h2 h3 p reactiveValues observeEvent icon brushOpts shinyApp
#' @importFrom shiny h1 h2 h3 p reactiveValues observeEvent icon brushOpts shinyApp htmlOutput
#' @importFrom shiny fluidPage fluidRow tabPanel actionButton
#' @importFrom shiny selectInput sliderInput radioButtons checkboxInput checkboxGroupInput
#' @importFrom shiny textOutput uiOutput plotOutput dataTableOutput tableOutput
Expand Down
14 changes: 14 additions & 0 deletions R/utils-pipe.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#' Pipe operator
#'
#' See \code{magrittr::\link[magrittr:pipe]{\%>\%}} for details.
#'
#' @name %>%
#' @rdname pipe
#' @keywords internal
#' @export
#' @importFrom magrittr %>%
#' @usage lhs \%>\% rhs
#' @param lhs A value or the magrittr placeholder.
#' @param rhs A function call using the magrittr semantics.
#' @return The result of calling `rhs(lhs)`.
NULL
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ SSDM: Stacked species distribution modelling

[![R-CMD-check](https://github.com/sylvainschmitt/SSDM/actions/workflows/R-CMD-check.yaml/badge.svg)](https://github.com/sylvainschmitt/SSDM/actions/workflows/R-CMD-check.yaml)
[![Downloads](http://cranlogs.r-pkg.org/badges/SSDM?color=brightgreen)](http://www.r-pkg.org/pkg/SSDM)
[![Coverage Status](https://img.shields.io/codecov/c/github/sylvainschmitt/SSDM/master.svg)](https://codecov.io/github/sylvainschmitt/SSDM?branch=master) [![Research software impact](http://depsy.org/api/package/cran/SSDM/badge.svg)](http://depsy.org/package/r/SSDM) [![Gitter](https://badges.gitter.im/S-SDM/community.svg)](https://gitter.im/S-SDM/community?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge)
[![Codecov test coverage](https://codecov.io/gh/sylvainschmitt/SSDM/branch/master/graph/badge.svg)](https://app.codecov.io/gh/sylvainschmitt/SSDM?branch=master) [![Research software impact](http://depsy.org/api/package/cran/SSDM/badge.svg)](http://depsy.org/package/r/SSDM) [![Gitter](https://badges.gitter.im/S-SDM/community.svg)](https://gitter.im/S-SDM/community?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge)

SSDM is a package to map species richness and endemism based on stacked species distribution models (SSDM). Individual SDMs can be created using a single or multiple algorithms (ensemble SDMs). For each species, an SDM can yield a habitat suitability map, a binary map, a between-algorithm variance map, and can assess variable importance, algorithm accuracy, and between-algorithm correlation. Methods to stack individual SDMs include summing individual probabilities and thresholding then summing. Thresholding can be based on a specific evaluation metric or by drawing repeatedly from a Bernouilli distribution. The SSDM package also provides a user-friendly interface `gui`.

Expand Down
14 changes: 14 additions & 0 deletions codecov.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
comment: false

coverage:
status:
project:
default:
target: auto
threshold: 1%
informational: true
patch:
default:
target: auto
threshold: 1%
informational: true
25 changes: 15 additions & 10 deletions cran-comments.md
Original file line number Diff line number Diff line change
@@ -1,18 +1,23 @@
## Test environments

* local Ubuntu 16.04 LTS, R 3.6.0
* Travis CI Ubuntu 14.04.5 LTS, R-release
* R-hub Fedora Linux, R-devel, clang
* R-hub Ubuntu Linux 16.04 LTS, R-release
* R-hub Windows Server 2008 R2 SP1, R-devel
* Win-builder Windows, R-4.0.0
* local Ubuntu 22.04 LTS, R 4.3.1
* GitHub Actions Ubuntu 20.04 LTS, R-release

## R CMD check results

There were no NOTEs, ERRORs or WARNINGs.
There were no ERRORs or WARNINGs.

## Resubmission
There was one NOTE:

Imports includes 24 non-default packages.
Importing from so many packages makes the package vulnerable to any of
them becoming unavailable. Move as many as possible to Suggests and
use conditionally.

The fact that we quickly updated the package following several dependency
changes shows that we are able to assume all the needed dependencies.

This is a resubmission. In this version I have:
## Resubmission

# * Added stringsAsFactors = TRUE in read.csv2 from load_occ.R folowwing the new defaulot in R 4.0.0
This is a resubmission. In this version I have removed rgdal and sp
from the package dependencies following r-spatial package archiving.
20 changes: 20 additions & 0 deletions man/pipe.Rd

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

2 changes: 1 addition & 1 deletion tests/testthat/test_modelling.R
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ test_that('modelling function', {
Occurrences <- subset(Occurrences, Occurrences$SPECIES == 'elliptica')
available.algo <- available.algo <- c("GLM", "GAM", "MARS", "GBM", "CTA", "RF", "ANN", "SVM")
for(i in available.algo){
cat(paste("testing", i, "...\n"))
# cat(paste("testing", i, "...\n"))
show_failure(SDM <- modelling(i, Occurrences, Env, Xcol = 'LONGITUDE', Ycol = 'LATITUDE', verbose = F))
expect_is(SDM, paste0(i,'.SDM'))
}
Expand Down
2 changes: 1 addition & 1 deletion tests/testthat/test_parallel_ESDM.R
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ test_that('Ensemble parallelization', {
data(Env)
data(Occurrences)
Occurrences <- subset(Occurrences, Occurrences$SPECIES == 'elliptica')
ESDM <- ensemble_modelling(c('CTA', 'MARS'), Occurrences, Env, rep = 10,
ESDM <- ensemble_modelling(c('CTA', 'MARS'), Occurrences, Env, rep = 1,
Xcol = 'LONGITUDE', Ycol = 'LATITUDE',
ensemble.thresh = c(0), verbose = FALSE, cores = 2,
minimal.memory = TRUE, tmp = TRUE)
Expand Down
2 changes: 1 addition & 1 deletion tests/testthat/test_parallel_SSDM.R
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ test_that('Stack parallelization', {
data(Env)
data(Occurrences)
for(i in c('species', 'algorithms', 'replicates')){
SSDM <- stack_modelling(c('CTA', 'MARS'), Occurrences, Env, rep = 10,
SSDM <- stack_modelling(c('CTA', 'MARS'), Occurrences, Env, rep = 1,
Xcol = 'LONGITUDE', Ycol = 'LATITUDE', Spcol = 'SPECIES',
ensemble.thresh = c(0), method="pSSDM", uncertainty = TRUE,
verbose = FALSE, cores = 2, parmode = i , minimal.memory = TRUE, tmp = FALSE)
Expand Down
12 changes: 6 additions & 6 deletions tests/testthat/test_project_ESDM.R
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,18 @@ test_that('project Ensemble.SDM', {
Occurrences <- subset(Occurrences, Occurrences$SPECIES == 'elliptica')
ESDM <- ensemble_modelling(c('CTA', 'MARS'), Occurrences, Env, rep = 2, Xcol = 'LONGITUDE', Ycol = 'LATITUDE', ensemble.thresh = 0, verbose = FALSE)
Env_new <- stack(Env[[1]]-1,Env[[2]],Env[[3]])
cat(paste("test sequential ESDM projection \n"))

# cat(paste("test sequential ESDM projection \n"))
ESDM_proj <- project(ESDM,Env_new,output.format='model')
expect_is(ESDM_proj, 'Ensemble.SDM')
expect_false(all(is.na(values(ESDM_proj@projection))))
cat(paste("test parallel ESDM projection \n"))

# cat(paste("test parallel ESDM projection \n"))
ESDM_proj <- project(ESDM,Env_new,output.format='model',cores=2,minimal.memory=TRUE)
expect_is(ESDM_proj, 'Ensemble.SDM')
expect_false(all(is.na(values(ESDM_proj@projection))))
cat(paste("test ESDM projection with raster output \n"))

# cat(paste("test ESDM projection with raster output \n"))
ESDM_proj <- project(ESDM,Env_new,output.format='rasters')
expect_is(ESDM_proj, 'list')
expect_is(ESDM_proj$projection, 'RasterLayer')
Expand Down
12 changes: 6 additions & 6 deletions tests/testthat/test_project_SSDM.R
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,19 @@ test_that('project Stacked.SDM', {
Xcol = 'LONGITUDE', Ycol = 'LATITUDE',
Spcol = 'SPECIES', ensemble.thresh = 0,
verbose = FALSE, cores = 0)

Env_new <- stack(Env[[1]]-0.3,Env[[2]],Env[[3]])
cat(paste("test sequential SSDM projection \n"))
# cat(paste("test sequential SSDM projection \n"))
SSDM_proj <- project(SSDM,Env_new,output.format='model')
expect_is(SSDM_proj, 'Stacked.SDM')
expect_false(all(is.na(values(SSDM_proj@diversity.map))))
cat(paste("test parallel SSDM projection \n"))

# cat(paste("test parallel SSDM projection \n"))
SSDM_proj <- project(SSDM,Env_new,output.format='model',cores=2, minimal.memory=TRUE)
expect_is(SSDM_proj, 'Stacked.SDM')
expect_false(all(is.na(values(SSDM_proj@diversity.map))))
cat(paste("test SSDM projection with raster output \n"))

# cat(paste("test SSDM projection with raster output \n"))
SSDM_proj <- project(SSDM,Env_new,output.format='rasters')
expect_is(SSDM_proj, 'list')
expect_is(SSDM_proj$diversity.map, 'RasterLayer')
Expand Down
2 changes: 1 addition & 1 deletion vignettes/SSDM.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ The workflow of the package ‘SSDM’ is based on three modelling levels:

### Environmental variables

In order to build species distribution models you will need environmental variables. Currently ‘SSDM’ uses all raster formats supported by the R package ‘rgdal’. The package ‘SSDM’ supports both continuous (e.g., climate maps, digital elevation models, bathymetric maps) and categorical environmental variables (e.g., land cover maps, soil type maps) as inputs. The package also allows normalizing environmental variables, which may be useful to improve the fit of certain algorithms (like artificial neural networks or support vector machines).
In order to build species distribution models you will need environmental variables. Currently ‘SSDM’ uses all raster formats supported by the R package ‘raster’. The package ‘SSDM’ supports both continuous (e.g., climate maps, digital elevation models, bathymetric maps) and categorical environmental variables (e.g., land cover maps, soil type maps) as inputs. The package also allows normalizing environmental variables, which may be useful to improve the fit of certain algorithms (like artificial neural networks or support vector machines).

Rasters of environmental data need to have the same coordinate reference system while spatial extent and resolution of the environmental layers can differ. During processing, the package will deal with between-variables discrepancies in spatial extent and resolution by rescaling all environmental rasters to the smallest common spatial extent then upscaling them to the coarsest resolution.

Expand Down

0 comments on commit 369b0b1

Please sign in to comment.