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

MAXENT preventing the EnsembleForecasting function of running #245

Closed
beardant opened this issue Apr 18, 2023 · 1 comment
Closed

MAXENT preventing the EnsembleForecasting function of running #245

beardant opened this issue Apr 18, 2023 · 1 comment
Labels
bug Something isn't working external problem Issue coming from external source (code, computer, ...)

Comments

@beardant
Copy link

beardant commented Apr 18, 2023

I'm trying to run an ensemble model whereby I'm not making any real projections in time or space,
I just have presences and pseudo-absences and want to model habitat suitability using an ensemble model.

The problem is related to MAXENT, as running the code without it works.

I first format the data;

myBiomodData1 <- BIOMOD_FormatingData(resp.name= myRespName1,
resp.var = myResp1,
expl.var = stack1,
resp.xy = myRespXY1,
filter.raster=TRUE,
PA.nb.rep = 1

I then use BIOMOD_modeling to create the 'submodels', three runs for each.

myBiomodModelOut1 <- BIOMOD_Modeling(
myBiomodData1,
models = c('GLM','GBM','FDA', 'RF', 'MARS','MAXENT','CTA','ANN','GAM','SRE'),
bm.options = myBiomodOption,
nb.rep=3,
data.split.perc=70,
var.import=3,
metric.eval = c('ROC', "TSS"),
save.output = TRUE,
scale.models = FALSE,
do.full.models=FALSE,
do.progress=TRUE)

Besides a warning (see below), all models are computed.
Warning message:
In newton(lsp = lsp, X = G$X, y = G$y, Eb = G$Eb, UrS = G$UrS, L = G$L, :
Iteration limit reached without full convergence - check carefully

The evaluations for the MAXENT submodels are adequate.

I then create an ensemble model using the following criteria;
myBiomodEM1 <- BIOMOD_EnsembleModeling(
bm.mod = myBiomodModelOut1,
em.by = 'all',
metric.eval = 'TSS',
metric.select='TSS',
metric.select.thresh = 0.5,
em.algo=c('EMca', 'EMwmean'))

To then attain a raster predicting habitat, I use the BIOMOD_EnsembleForecasting function.
Even though my desired output is not really a 'forecast', in so much that I have no new environment to project to, so the 'new.env' is the same RasterStack the 'expl.var' in the BIOMOD_formatingdata function. I suspect this may be causing an issue? I'm not sure if I would call the type of model output I want 'projections', or 'forecasts'.

myBiomodEF <- BIOMOD_EnsembleForecasting(
proj.name="ensemble",
bm.em = myBiomodEM1,
output.format='.img',
metric.binary='TSS',
new.env=stack1
)

The forecasting function runs, but at each projection of one of the three MAXENT runs, I get a pop-up error from outside of R saying :

Error in file C\Layers.\Species\models\1681839621\Species_PA1_RUN1_MAXENT_outputs\agriprop.asc:java.lang.NumberFormatException: For input string:"NODATA_value"

The final error in R , after all single models are projected, reads as follows:

Error: [rast] extents do not match
In addition: Warning messages: 1: In system(command = maxent.command, wait = TRUE, intern = TRUE) : running command 'java -mx512m -cp "C:/layers/maxent.jar" density.Project "./Species/models/1681839621/Species_PA1_RUN1_MAXENT_outputs/Species_PA1_RUN1.lambdas" "./Species/models/1681839621/Species_PA1_RUN1_MAXENT_outputs" "./Species/models/1681839621/Species_PA1_RUN1_MAXENT_outputs/projMaxent.asc" doclamp=false visible=false autorun nowarnings notooltips' had status 1 2: In system(command = maxent.command, wait = TRUE, intern = TRUE) : running command 'java -mx512m -cp "C:/layers/maxent.jar" density.Project "./Species/models/1681839621/Species_PA1_RUN2_MAXENT_outputs/Species_PA1_RUN2.lambdas" "./Species/models/1681839621/Species_PA1_RUN2_MAXENT_outputs" "./Species/models/1681839621/Species_PA1_RUN2_MAXENT_outputs/projMaxent.asc" doclamp=false visible=false autorun nowarnings notooltips' had status 1 3: In system(command = maxent.command, wait = TRUE, intern = TRUE) : running command 'java -mx512m -cp "C:/layers/maxent.jar" density.Project "./Species/models/1681839621/Species_PA1_RUN3_MAXENT_outputs/Species_PA1_RUN3.lambdas" "./Species/models/1681839621/Species_PA1_RUN3_MAXENT_outputs" "./Species/models/1681839621/Species_PA1_RUN3_MAXENT_outputs/projMaxent.asc" doclamp=false visible=false autorun nowarnings notooltips' had status 1

@rpatin rpatin added bug Something isn't working external problem Issue coming from external source (code, computer, ...) labels Apr 19, 2023
@rpatin
Copy link
Contributor

rpatin commented Apr 19, 2023

Hello @beardant,
This is likely an issue with the environmental raster used for prediction, which probably have rectangular cells (more explanations here: #221 (comment)).

  1. You can check that with show(stack1) which will show something like that:
class       : SpatRaster 
dimensions  : 47, 120, 5  (nrow, ncol, nlyr)
resolution  : 3, 3  (x, y)
[...]

If your resolution have different values for x and y then this is the problem. Only MAXENT is concerned as internally it uses .asc files and do not read them properly.

  1. To solve that, you can:
    1. do not project MAXENT models by using models.chosen argument in BIOMOD_Projection
    2. use MAXNET instead of MAXENT, both algorithm are highly similar
    3. use only rasters with square resolution if you want to keep using MAXENT

In any case we are aware of the issue but this depends on MAXENT development and we will try to submit the issue there.
Best regards,
Rémi

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working external problem Issue coming from external source (code, computer, ...)
Projects
None yet
Development

No branches or pull requests

2 participants