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

Error in BIOMOD_Modeling - [MaxEnt error in file] #341

Open
jiayuanxie opened this issue Oct 8, 2023 · 6 comments
Open

Error in BIOMOD_Modeling - [MaxEnt error in file] #341

jiayuanxie opened this issue Oct 8, 2023 · 6 comments
Labels
bug Something isn't working

Comments

@jiayuanxie
Copy link

Hello, the maintenance team of Biomod2:

I'm a ecological doctor. recently, I was working with biomod2 to finish my project, but meet some troubles which beyond my ability to solve. So can you help me?

Error and context
When I run Maxent in biomod2, I meet the error, although I have tried many solutions which other people have solved their similar problems, but they didn't work with my code. I have tried to change the file path of maxent.jar to without any spaces or change the system environmental variables(followed: http://modata.ceoe.udel.edu/dev/dhaulsee/class_rcode/r_pkgmanuals/MAXENT4R_directions.pdf), but they don't help me for my trouble.

Code used to get the error
#######################Format sdm data for biomod2
Sp.biomod.data = BIOMOD_FormatingData(resp.name = Resp.name,
resp.var = Resp.vector,
expl.var = Sdm.env,
resp.xy = Resp.coor,
na.rm = T,
dir.name = paste("D:/Rtry/SDM",Resp.name,sep = "/"))

#######################Defining Models Options using default options
sdm.opt.default = BIOMOD_ModelingOptions( MAXENT = list( path_to_maxent.jar = "C://Users//Public//maxent.jar"))

####################Constrcut sdm models by setting parameters
Bio.mod.all = BIOMOD_Modeling( bm.format = Sp.biomod.data,
models = "MAXENT",
models.pa = Sp.biomod.data@data.species,
bm.options = sdm.opt.default,
CV.strategy = 'random',
#Number of Evaluation run
CV.nb.rep = 1,
#80% of data train the model
CV.perc = 0.8,
#models be calibrated and validated over the whole dataset
CV.do.full.models = F,
#Below arg is whether control the weight?
weights=NULL,
#absences will be weighted equally to the presences
prevalence = 0.5,
#Set model evaluations methods
metric.eval = mode.eva,
#Number of permutation to estimate variable importance
var.import = 1,
nb.cpu =1,
do.progress =T)

#show errors
-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= Build Single Models -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=

Checking Models arguments...
Warning in .BIOMOD_Modeling.check.args(bm.format = bm.format, modeling.id = modeling.id, :
models.pa has been disabled because no PA datasets have been given

 MAXENT default prevalence option was updated to fit with modeling prevalence (i.e 0.5 )
> Automatic weights creation to rise a 0.5 prevalence

Creating suitable Workdir...

Checking Cross-Validation arguments...

Random cross-validation selection

-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= Bandicota.bengalensis.reg.1 Modeling Summary -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=

8 environmental variables ( PCA_1 PCA_2 PCA_3 PCA_4 PCA_5 PCA_6 PCA_7 PCA_8 )
Number of evaluation repetitions : 1
Models selected : MAXENT

Total number of model runs: 1

-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=

-=-=-=--=-=-=- Bandicota.bengalensis.reg.1_allData_RUN1_MAXENT

Model=MAXENT
> MAXENT modeling...
Creating Maxent Temp Proj Data...
Getting predictions...Error in file(file, "rt") : cannot open the connection
In addition: Warning message:
In file(file, "rt") :
cannot open file 'D:/Rtry/SDM/Bandicota.bengalensis.reg.1/Bandicota.bengalensis.reg.1/models/1696750966/Bandicota.bengalensis.reg.1_allData_RUN1_MAXENT_outputs/Bandicota.bengalensis.reg.1_allData_RUN1_Pred_swd.csv': No such file or directory

Getting predictor contributions...Error in file(fname, "r") : cannot open the connection
In addition: Warning messages:
1: In system(command = maxent.command, wait = TRUE, intern = TRUE) :
running command 'java -mx512m -cp "C:\Users\Public/maxent.jar" density.Project "" "D:/Rtry/SDM/Bandicota.bengalensis.reg.1/Bandicota.bengalensis.reg.1/models/1696750966/Bandicota.bengalensis.reg.1_allData_RUN1_MAXENT_outputs/Predictions/Pred_swdBis_5125.csv" "D:/Rtry/SDM/Bandicota.bengalensis.reg.1/Bandicota.bengalensis.reg.1/models/1696750966/Bandicota.bengalensis.reg.1_allData_RUN1_MAXENT_outputs/projMaxent.asc" doclamp=false visible=false autorun nowarnings notooltips' had status 1
2: In file(fname, "r") :
cannot open file 'D:/Rtry/SDM/Bandicota.bengalensis.reg.1/Bandicota.bengalensis.reg.1/models/1696750966/Bandicota.bengalensis.reg.1_allData_RUN1_MAXENT_outputs/projMaxent.asc': No such file or directory
Error in { : task 1 failed - "Unable to make model prediction"

#show(Bio.mod.all)

show(Bio.mod.all)
Error in h(simpleError(msg, call)) : There was an error evaluating the 'object' parameter when selecting a method for the 'show' function: object 'Bio.mod.all' not found

Inaddition, my computer system is windows 10; R version is R-4.3.1; Java version is "21" 2023-09-19 LTS; Biomod2 package version is 4.2-4

To now, I really have tried many methods to solve my problem, but them didn't work, If you can help me , I will be great grateful!!!

Thanks , from JY Xie

@jiayuanxie jiayuanxie added the bug Something isn't working label Oct 8, 2023
@MayaGueguen
Copy link
Contributor

Hello JY Xie,

Thank you for reporting 🙏

Could you try changing your BIOMOD_FormatingData command by this please ?

Sp.biomod.data = BIOMOD_FormatingData(resp.name = Resp.name,
                                      resp.var = Resp.vector,
                                      expl.var = Sdm.env,
                                      resp.xy = Resp.coor,
                                      na.rm = TRUE,
                                      dir.name = "D:/Rtry/SDM/")

It seems biomod2 get a bit lost through file names.

Maya

@jiayuanxie
Copy link
Author

Hello JY Xie,

Thank you for reporting 🙏

Could you try changing your BIOMOD_FormatingData command by this please ?

Sp.biomod.data = BIOMOD_FormatingData(resp.name = Resp.name,
                                      resp.var = Resp.vector,
                                      expl.var = Sdm.env,
                                      resp.xy = Resp.coor,
                                      na.rm = TRUE,
                                      dir.name = "D:/Rtry/SDM/")

It seems biomod2 get a bit lost through file names.

Maya

Maya,

Thank you for your prompt reply!

According to your advising, I just have tried the method, but it seem to not work with the same error above, do you have any other suggestion? Indeed, I have tried on two computer, so it should not be responsible for computer or file name.

JY XIE

#######################Format sdm data for biomod2
Sp.biomod.data = BIOMOD_FormatingData(resp.name = Resp.name,
resp.var = Resp.vector,
expl.var = Sdm.env,
resp.xy = Resp.coor,
na.rm = T,
dir.name = "D:/Rtry/SDM/")

#######################Defining Models Options using default options
sdm.opt.default = BIOMOD_ModelingOptions( MAXENT = list( path_to_maxent.jar = "D:/Rtry/SDM/maxent.jar"))

####################Constrcut sdm models by setting parameters
Bio.mod.all = BIOMOD_Modeling( bm.format = Sp.biomod.data,
models = "MAXENT",
models.pa = Sp.biomod.data@data.species,
bm.options = sdm.opt.default,
CV.strategy = 'random',
#Number of Evaluation run
CV.nb.rep = 1,
#80% of data train the model
CV.perc = 0.8,
#models be calibrated and validated over the whole dataset
CV.do.full.models = F,
#Below arg is whether control the weight?
weights=NULL,
#absences will be weighted equally to the presences
prevalence = 0.5,
#Set model evaluations methods
metric.eval = mode.eva,
#Number of permutation to estimate variable importance
var.import = 1,
nb.cpu =1,
do.progress =T)

@MayaGueguen
Copy link
Contributor

Thank you for trying 🙏

Could you try and check into your files browser if the files mentioned really exist or not ?

@jiayuanxie
Copy link
Author

the files "D:/Rtry/SDM/maxent.jar" & "D:/Rtry/SDM/" both exist,

In addition, It's interesting, my error was:
Getting predictions...Error in file(file, "rt") : cannot open the connection
In addition: Warning messages:
1: executing %dopar% sequentially: no parallel backend registered
2: In file(file, "rt") :
cannot open file 'D:/Rtry/SDM//Bandicota.bengalensis.mach.1/models/1696861384/Bandicota.bengalensis.mach.1_allData_RUN1_MAXENT_outputs/Bandicota.bengalensis.mach.1_allData_RUN1_Pred_swd.csv': No such file or directory

but there exist a file named "Pred_swd.csv" in the path(my species name is "Bandicota.bengalensis.mach.1"): D:\Rtry\SDM\Bandicota.bengalensis.mach.1\models\1696860853\Bandicota.bengalensis.mach.1_allData_RUN1_MAXENT_outputs\Predictions\Pred_swd.csv. I guess the file bring the bug to me. it make me fell confused, the file is generated by my codes, why they can't found it?

@MayaGueguen
Copy link
Contributor

Huuum it is not the same path in the error message :

D:/Rtry/SDM//Bandicota.bengalensis.mach.1/models/1696861384/Bandicota.bengalensis.mach.1_allData_RUN1_MAXENT_outputs/Bandicota.bengalensis.mach.1_allData_RUN1_Pred_swd.csv

and in your folder :

D:\Rtry\SDM\Bandicota.bengalensis.mach.1\models\1696860853\Bandicota.bengalensis.mach.1_allData_RUN1_MAXENT_outputs\Predictions\Pred_swd.csv

The numbers do not match. You can give a modeling.id parameter value to the BIOMOD_Modeling function to have more explicit path.
Try starting again from a blank repository.

@jiayuanxie
Copy link
Author

Thanks for your reminding!
Yeah, it's not the same path in the error message due to I have tried many times, So created many similar folders, but their hierarchical structures and error are same!

Try starting again from a blank repository seem have no impact on my error, so , it's really a headache problem!

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