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

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

Closed
yuliaUU opened this issue Apr 9, 2024 · 4 comments
Closed
Labels
bug Something isn't working

Comments

@yuliaUU
Copy link

yuliaUU commented Apr 9, 2024

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 yuliaUU added the bug Something isn't working label Apr 9, 2024
@yuliaUU yuliaUU changed the title Cant do BIOMOD_EnsembleForecasting aftre moving models to anew loctaion Can't do BIOMOD_EnsembleForecasting after moving models to a new loctaion Apr 9, 2024
@yuliaUU
Copy link
Author

yuliaUU commented Apr 9, 2024

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
Copy link
Contributor

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 ?

  • If not, you should be able to move your folder and re run projections as soon as you set your working directory to the one where you put your simulation folder.
  • If yes, what was it ?
    - If it was not absolute but relative, one trick could be to recreate a false tree skeleton in your new working directory, matching your previous one...
    - If it was absolute, then I'm afraid you'll have indeed to change also links for each single model object...

Maya

@yuliaUU
Copy link
Author

yuliaUU commented Apr 10, 2024

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
Copy link
Author

yuliaUU commented Apr 10, 2024

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants