Open Irene131998 opened 1 month ago
Hi Irene !
Thanks for reporting and this well-explained issue🙏
Could you try to see if it is a memory issue, by running MAXENT alone for example ?
You could also try to run these commands before calling BIOMOD_EnsembleForecasting
:
cl <- makeCluster(2)
on.exit(stopCluster(cl))
Thanks a lot ! Hélène
Hi Hélène! Many thanks for your quick reply! I tried to run the projections only with the maxent models and with those commands, and it still doesn't work.... But if I run the projections without maxent, it works fine.
cl <- makeCluster(2) registerDoParallel(cl) on.exit(stopCluster(cl)) Q_ilex_0ka <- BIOMOD_EnsembleForecasting(
- bm.em = Quercus_ilex_ensemble_models,
- proj.name = '0',
- new.env = Env_present,
- models.chosen = "all",
- metric.binary = 'all',
- metric.filter = 'all',
- output.format= ".tif",
- on_0_1000 = FALSE,
- build.clamping.mask = FALSE,
- do.stack = FALSE,
- keep.in.memory = FALSE)
-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= Do Ensemble Models Projection -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
Creating suitable Workdir...
-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= Do Single Models Projection -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= Error in { : task 1 failed - "task 1 failed - "[writeRaster] path does not exist""
Thanks for your reactivity !
It's not the problem, but I will avoid to setproj.name = '0'
as it can maybe lead to another issue.
Could you share the path to the file that biomod2
can't find ?
Could you also send me the output of traceback()
after the error ?
Thanks !
Thanks for the advise! I changed it to proj.name='present'. The path is C:\Users\irene13\Documents\Quercus.ilex and it seems it can't create the folder 'proj_present' within that path. This is the output of traceback(): traceback() 5: stop(simpleError(msg, call = expr)) 4: e$fun(obj, substitute(ex), parent.frame(), e$data) 3: foreach(mod.name = models.chosen) %dopar% { cat("\n\t> Projecting", mod.name, "...") if (proj_is_raster) { new.env <- unwrap(new.env.wrap) names(new.env) <- bm.mod@expl.var.names } if (do.stack) { filename <- NULL } else { filename <- file.path(namePath, "individualprojections", paste0(nameProj, "", mod.name, ifelse(output.format == ".RData", ".tif", output.format))) } mod <- get(BIOMOD_LoadModels(bm.out = bm.mod, full.name = mod.name)) temp_workdir = NULL if (length(grep("MAXENT$", mod.name)) == 1) { temp_workdir = mod@model_output_dir } pred.tmp <- predict(mod, new.env, on_0_1000 = on_0_1000, ... 2: BIOMOD_Projection(bm.mod = load_stored_object(bm.em@models.out), new.env = new.env, proj.name = tmp_dir, new.env.xy = NULL, models.chosen = models.needed, compress = TRUE, build.clamping.mask = FALSE, do.stack = TRUE, on_0_1000 = on_0_1000, nb.cpu = nb.cpu) 1: BIOMOD_EnsembleForecasting(bm.em = Quercus_ilex_ensemble_models, proj.name = "present", new.env = Env_present, models.chosen = "all", metric.binary = "all", metric.filter = "all", output.format = ".tif", on_0_1000 = FALSE, build.clamping.mask = FALSE, do.stack = FALSE, keep.in.memory = FALSE)
Hello again Irene,
I tried to reproduce your error but I failed 😬
Could you try and share the output of :
hop <- get(BIOMOD_LoadModels(bm.out = Quercus_ilex_models_biomod2_folds, full.name = "Quercus.ilex_PA1_RUN1_MAXENT"))
print(hop)
print(hop@model_output_dir)
Maybe also :
Ibex_proj <- BIOMOD_Projection(bm.mod = Quercus_ilex_models_biomod2_folds,
proj.name = 'Current',
new.env = Env_present,
models.chosen = 'all')
You should have the same error, but maybe it can help to localise it.
Could you also share the output of:
print(tuned.maxent$`_PA1_allRun`)
print(tuned.maxent$`_PA2_allRun`)
And finally, do you have full administrator rights on your computer?
Thanks ! Hélène !
Hi Hélène. Thank you very much for all your help!
This is the output for the first commands:
hop <- get(BIOMOD_LoadModels(bm.out = Quercus_ilex_models_biomod2_folds, full.name = "Quercus.ilex_PA1_RUN1_MAXENT")) print(hop)
-=-=-=-=-=-=-=-=-=-=-=-= biomod2_model -=-=-=-=-=-=-=-=-=-=-=-=
model name : Quercus.ilex_PA1_RUN1_MAXENT
model class : MAXENT
This model doesn't have its own scale
modeling folder: .
response modelled: Quercus.ilex
explanatory variables used:
name type range
bio1 numeric -8.200245 28.38519
bio12 numeric 16.31025 1680.499
bio4 numeric 62.68266 695.2313
roughness numeric 1.908143 568.7271
soil_type numeric 17.25019 109.0062
NOTE :
You can access 'formal' model with get_formal_model function
print(hop@model_output_dir) [1] "./Quercus.ilex/models/Quercus_ilex_model_Hopcroft/Quercus.ilex_PA1_RUN1_MAXENT_outputs"
I have run the projection for Ibex_proj and indeed the same error occurs: Ibex_proj <- BIOMOD_Projection(bm.mod = Quercus_ilex_models_biomod2_folds,
-=-=-=-=-=-=-=-=-=-=-=-=-=-= Do Single Models Projection -=-=-=-=-=-=-=-=-=-=-=-=-=-=
> Building clamping mask
Error in { : task 3 failed - "task 1 failed - "[writeRaster] path does not exist""
The outputs for tuned maxent are these:
print(tuned.maxent$
_PA1_allRun
) $path_to_maxent.jar [1] "C:/Users/irene13/Documents"
$memory_allocated [1] 512
$initial_heap_size NULL
$max_heap_size NULL
$background_data_dir [1] "default"
$visible [1] FALSE
$linear [1] TRUE
$quadratic [1] FALSE
$product [1] FALSE
$threshold [1] FALSE
$hinge [1] FALSE
$lq2lqptthreshold [1] 80
$l2lqthreshold [1] 10
$hingethreshold [1] 15
$beta_threshold [1] -1
$beta_categorical [1] -1
$beta_lqp [1] -1
$beta_hinge [1] -1
$betamultiplier [1] 0.5 Levels: 0.5 1
$defaultprevalence [1] 0.5
print(tuned.maxent$
_PA2_allRun
) $path_to_maxent.jar [1] "C:/Users/irene13/Documents"
$memory_allocated [1] 512
$initial_heap_size NULL
$max_heap_size NULL
$background_data_dir [1] "default"
$visible [1] FALSE
$linear [1] TRUE
$quadratic [1] FALSE
$product [1] FALSE
$threshold [1] FALSE
$hinge [1] FALSE
$lq2lqptthreshold [1] 80
$l2lqthreshold [1] 10
$hingethreshold [1] 15
$beta_threshold [1] -1
$beta_categorical [1] -1
$beta_lqp [1] -1
$beta_hinge [1] -1
$betamultiplier [1] 0.5 Levels: 0.5 1
$defaultprevalence [1] 0.5
As for your last question, no, I do not have full administrator rights, as I am using a university computer.
That's it ! I should have ask the question sooner but the problem should come from the administrator rights ! If you have some codes to open Rstudio as admin, it should work.
Thanks a lot for all the information ! Hélène
Oh okay it makes sense! Thanks a lot for your help!
Hi Hélène! I'm sorry to bother you again with this. But I tried to run the projection with full admin rights, and the same error is still there... I honestly don't know how to solve this.
No problem at all: it's a strange error ! Is it possible for you to send your data? If you prefer, you can send it to helene.blancheteau@univ-grenoble-alpes.fr
Hélène
Context and question Hi, I am using Biomod2 (version 4.2-5-2) to run some species distribution models and I have a problem with BIOMOD_EnsembleForecasting. The previous steps work fine, but apparently not the projection. I've tried shortening the folder path (I'm working on Windows) and I've updated the terra and biomod2 packages, but it doesn't seem to work either. I'm using 5 different algorithms (‘GLM’, ‘GBM’, ‘GAM’, ‘RF’, ‘MAXENT’), and when I remove maxent from my BIOMOD.models.out, the projections work fine, so I guess it must be a bug with maxent.
Code used
Here is my session info: sessionInfo()
R version 4.4.1 (2024-06-14 ucrt) Platform: x86_64-w64-mingw32/x64 Running under: Windows 10 x64 (build 19045)
Matrix products: default
locale: [1] LC_COLLATE=English_United Kingdom.utf8 LC_CTYPE=English_United Kingdom.utf8
[3] LC_MONETARY=English_United Kingdom.utf8 LC_NUMERIC=C
[5] LC_TIME=English_United Kingdom.utf8
time zone: Europe/London tzcode source: internal
attached base packages: [1] splines stats graphics grDevices utils datasets methods base
other attached packages: [1] qrencoder_0.1.0 gifski_1.12.0-2 xgboost_1.7.8.1 randomForest_4.7-1.1 maxnet_0.1.4
[6] earth_5.3.3 plotmo_3.6.4 plotrix_3.8-4 Formula_1.2-5 gbm_2.2.2
[11] mgcv_1.9-1 nlme_3.1-164 gam_1.22-4 foreach_1.5.2 mda_0.5-4
[16] class_7.3-22 rpart_4.1.23 nnet_7.3-19 biomod2_4.2-5-2 dismo_1.3-14
[21] raster_3.6-26 factoextra_1.0.7 ggplot2_3.5.1 fuzzySim_4.10.7 tibble_3.2.1
[26] MASS_7.3-60.2 blockCV_3.1-4 ggtext_0.1.2 tidyterra_0.6.1 dplyr_1.1.4
[31] geodata_0.6-2 usdm_2.1-7 terra_1.7-78 sf_1.0-16 sp_2.1-4
[36] ade4_1.7-22
loaded via a namespace (and not attached): [1] DBI_1.2.3 pROC_1.18.5 remotes_2.5.0 readxl_1.4.3
[5] rlang_1.1.4 magrittr_2.0.3 e1071_1.7-14 compiler_4.4.1
[9] png_0.1-8 vctrs_0.6.5 reshape2_1.4.4 stringr_1.5.1
[13] profvis_0.3.8 pkgconfig_2.0.3 fastmap_1.2.0 magick_2.8.4
[17] ellipsis_0.3.2 utf8_1.2.4 promises_1.3.0 markdown_1.13
[21] sessioninfo_1.2.2 purrr_1.0.2 xfun_0.47 cachem_1.1.0
[25] jsonlite_1.8.8 PresenceAbsence_1.1.11 later_1.3.2 reshape_0.8.9
[29] parallel_4.4.1 R6_2.5.1 stringi_1.8.4 pkgload_1.4.0
[33] cellranger_1.1.0 Rcpp_1.0.13 iterators_1.0.14 knitr_1.48
[37] usethis_3.0.0 base64enc_0.1-3 httpuv_1.6.15 Matrix_1.7-0
[41] tidyselect_1.2.1 rstudioapi_0.16.0 abind_1.4-5 codetools_0.2-20
[45] miniUI_0.1.1.1 pkgbuild_1.4.4 lattice_0.22-6 plyr_1.8.9
[49] withr_3.0.1 shiny_1.9.1 survival_3.6-4 units_0.8-5
[53] proxy_0.4-27 urlchecker_1.0.1 xml2_1.3.6 pillar_1.9.0
[57] KernSmooth_2.23-24 modEvA_3.18.2 generics_0.1.3 rprojroot_2.0.4
[61] commonmark_1.9.1 munsell_0.5.1 scales_1.3.0 xtable_1.8-4
[65] glue_1.7.0 tools_4.4.1 data.table_1.16.0 fs_1.6.4
[69] grid_4.4.1 tidyr_1.3.1 devtools_2.4.5 colorspace_2.1-1
[73] cli_3.6.3 fansi_1.0.6 gtable_0.3.5 digest_0.6.37
[77] classInt_0.4-10 ggrepel_0.9.5 farver_2.1.2 htmlwidgets_1.6.4
[81] memoise_2.0.1 htmltools_0.5.8.1 lifecycle_1.0.4 here_1.0.1
[85] mime_0.12 gridtext_0.1.5