Skip to content

Commit

Permalink
fixed snow issue by removing raster::clusteR and simplified tests
Browse files Browse the repository at this point in the history
  • Loading branch information
sylvainschmitt committed Oct 24, 2023
1 parent 58f669b commit cf59b06
Show file tree
Hide file tree
Showing 10 changed files with 24 additions and 95 deletions.
3 changes: 0 additions & 3 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -77,12 +77,9 @@ importFrom(raster,"values<-")
importFrom(raster,Which)
importFrom(raster,aggregate)
importFrom(raster,as.factor)
importFrom(raster,beginCluster)
importFrom(raster,calc)
importFrom(raster,clusterR)
importFrom(raster,crop)
importFrom(raster,crs)
importFrom(raster,endCluster)
importFrom(raster,extent)
importFrom(raster,extract)
importFrom(raster,layerStats)
Expand Down
11 changes: 2 additions & 9 deletions R/ensemble.R
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#' @include Algorithm.SDM.R checkargs.R
#' @importFrom raster raster stack reclassify beginCluster clusterR endCluster
#' @importFrom raster raster stack reclassify
NULL

#'Methods to assemble multiple algorithms in an ensemble SDM
Expand Down Expand Up @@ -247,14 +247,7 @@ setMethod("ensemble", "Algorithm.SDM", function(x, ..., name = NULL, ensemble.me
if (verbose) {
cat("uncertainty mapping...")
}
if(cores>0){
beginCluster(cores)
esdm@uncertainty <- clusterR(projections, fun=function(x) calc(x, var))
endCluster()
}
else{
esdm@uncertainty <- calc(projections, var)
}
esdm@uncertainty <- calc(projections, var)
names(esdm@uncertainty) <- "uncertainty map"
if (verbose) {
cat(" done \n")
Expand Down
9 changes: 8 additions & 1 deletion tests/testthat/test_ensemble_modelling.R
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,15 @@ test_that('ensemble modelling function', {
data(Env)
data(Occurrences)
Occurrences <- subset(Occurrences, Occurrences$SPECIES == 'elliptica')
# parrallel
ESDM <- ensemble_modelling(c('CTA', 'MARS'), Occurrences, Env, rep = 1,
Xcol = 'LONGITUDE', Ycol = 'LATITUDE',
ensemble.thresh = c(0), verbose = FALSE)
ensemble.thresh = c(0), verbose = FALSE,
cores = 2, tmp = TRUE)
expect_is(ESDM, 'Ensemble.SDM')
# projection
Env_new <- stack(Env[[1]]-1,Env[[2]],Env[[3]])
ESDM_proj <- project(ESDM,Env_new,output.format='model')
expect_is(ESDM_proj, 'Ensemble.SDM')
expect_false(all(is.na(values(ESDM_proj@projection))))
})
6 changes: 5 additions & 1 deletion tests/testthat/test_modelling.R
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,12 @@ 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"))
show_failure(SDM <- modelling(i, Occurrences, Env, Xcol = 'LONGITUDE', Ycol = 'LATITUDE', verbose = F))
expect_is(SDM, paste0(i,'.SDM'))
}
# projection
Env_new <- stack(Env[[1]]-1,Env[[2]],Env[[3]])
SDM_proj <- project(SDM, Env_new, output.format='model')
expect_is(SDM_proj, 'SVM.SDM')
expect_false(all(is.na(values(SDM_proj@projection))))
})
10 changes: 0 additions & 10 deletions tests/testthat/test_parallel_ESDM.R

This file was deleted.

11 changes: 0 additions & 11 deletions tests/testthat/test_parallel_SSDM.R

This file was deleted.

23 changes: 0 additions & 23 deletions tests/testthat/test_project_ESDM.R

This file was deleted.

11 changes: 0 additions & 11 deletions tests/testthat/test_project_SDM.R

This file was deleted.

25 changes: 0 additions & 25 deletions tests/testthat/test_project_SSDM.R

This file was deleted.

10 changes: 9 additions & 1 deletion tests/testthat/test_stack_modelling.R
Original file line number Diff line number Diff line change
@@ -1,9 +1,17 @@
test_that('stack modelling function', {
data(Env)
data(Occurrences)
# parrallel
i <- "species" # 'algorithms' and 'replicates' missing
SSDM <- stack_modelling(c('CTA', 'SVM'), Occurrences, Env, rep = 1,
Xcol = 'LONGITUDE', Ycol = 'LATITUDE',
Spcol = 'SPECIES', ensemble.thresh = 0,
verbose = FALSE, cores = 0)
verbose = FALSE,
cores = 2, parmode = i , tmp = FALSE)
expect_is(SSDM, 'Stacked.SDM')
# projection
Env_new <- stack(Env[[1]]-0.3,Env[[2]],Env[[3]])
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))))
})

0 comments on commit cf59b06

Please sign in to comment.