biomodhub / biomod2

BIOMOD is a computer platform for ensemble forecasting of species distributions, enabling the treatment of a range of methodological uncertainties in models and the examination of species-environment relationships.
77 stars 21 forks source link

Can't do BIOMOD_EnsembleForecasting after moving models to a new loctaion #445

Closed yuliaUU closed 1 month ago

yuliaUU commented 2 months ago

It is not really a coding question: rather than the organization-related one

I am on windows, and i ran my jobs remotely. after copy all the folders with my models to my computer , and I want to run projections locally

I understand that I need to change paths stored paths in myBiomodModelOut and myBiomodEM objects

file.out <- paste0("models01/",myRespName, "/", myRespName, ".1.models.out")
 myBiomodModelOut <- get(load(file.out))
    myBiomodModelOut@dir.name<- here::here("models01")
file.out <- paste0("models01/",myRespName, "/", myRespName, ".1.ensemble.models.out")
 myBiomodEM <- get(load(file.out))
     myBiomodEM@dir.name<- here::here("models01")

However, when I try to run BIOMOD_EnsembleForecasting i get errors

  myBiomodEMProj <- BIOMOD_EnsembleForecasting(
    bm.em = myBiomodEM,
    bm.proj = myBiomodProj,
    models.chosen = 'all',
    metric.binary = 'all',
    metric.filter = 'all'#,
   # nb.cpu = 12
  )

the BIOMOD_EnsembleForecasting function still trying to take the old path: and I dont undertsand from where I need to change it:

I also changed paths in : myBiomodEM@link myBiomodEM@models.prediction@link myBiomodEM@models.evaluation@link myBiomodEM@models.out@link but I still get error: Error in .BIOMOD_Projection.check.args(bm.mod, proj.name, new.env, new.env.xy, : Projection files missing

yuliaUU commented 2 months ago

I found where it is originated from: in this function: https://github.com/biomodhub/biomod2/blob/master/R/BIOMOD_EnsembleForecasting.R the following part:

 ## 3. Get needed projections --------------------------------------------------------------------
  models.needed <- get_kept_models(bm.em)
  if (!is.null(bm.proj)) {
    formal_pred <- get_predictions(bm.proj, full.name = models.needed)
  } else {
    # make prediction according to given environment
    tmp_dir <- paste0('Tmp', as.numeric(Sys.time())*100000)
    formal_pred <- 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)
    formal_pred <- get_predictions(formal_pred, full.name = models.needed)

issue with load_stored_object(bm.em@models.out), it loads again the bm.em, while I need it to use the one already loaded.

I wonder if it is possible to resave the myBiomodEM object back after modifying it

MayaGueguen commented 2 months ago

Hello Yulia,

Thank you for posting, and for doing such a great search job 🙏 👀

Yes, the managing of file and directory paths is still not optimal... In short, I think using dir.name option in BIOMOD_FormatingData is a good option IF main objective is to be able to run simulation from anywhere and/or to find back where files where stored. But as soon as you move your simulation folder, it is likely to break all of it, as paths are saved, as you figured, in multiple objects, and you have to update all of them...

Did you used, when running first the simulations, this dir.name parameter ?

Maya

yuliaUU commented 2 months ago

I did: the issue is i made a mistake and set it up using here::here() argument: so it saved as absolute path and not a relative path

yuliaUU commented 2 months ago

yeh, i figured it out that i need to rerun them all with fixing teh path issue:) but thank you for your help!