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 error and empty SRE file created by BIOMOD_Projection() #221

Closed
r-fernandezz opened this issue Mar 23, 2023 · 9 comments
Closed

Maxent error and empty SRE file created by BIOMOD_Projection() #221

r-fernandezz opened this issue Mar 23, 2023 · 9 comments
Labels
bug Something isn't working external problem Issue coming from external source (code, computer, ...)

Comments

@r-fernandezz
Copy link

Hello the biomod team,

I work with biomod2@4.2-2, targets package and linux os. When I follow biomod standard process to build an ensemble model, I don't have any model failed during the construction phase. After run BIOMOD_Projection() and BIOMOD_EnsembleForecasting() functions, I can return maps of all models built (GLM, GAM, MARS, CTA, RF, GBM, ANN) except SRE and MAXENT models. But I can return reponse curves, variables importance and other outputs of SRE and MAXENT models. I don't know if these two errors on SRE and MAXENT models are dependent, but I present both bellow.

My code for models projection:

imageimage

When I run BIOMOD_Projection() SRE and MAXENT models return empty files into biomod output folder without error:

image

SRE file printed on QGIS:
image

MAXENT file printed on QGIS:
image

Print of a working model (GBM):
image

When I run BIOMOD_EnsembleForecasting() with same environmental variable files, I have this error and I don't have any output file created:

MAXENT_error.odt

Why do I have projection errors only on these two models when models seem to be built correctly?

For more information:

I use the default settings of biomod but I would like to tune my settings after solving these bugs

biomod_option <- biomod2::BIOMOD_ModelingOptions()
@r-fernandezz r-fernandezz changed the title Empty SRE file create by BIOMOD_Projection() and BIOMOD_EnsembleForecasting() Empty SRE file created by BIOMOD_Projection() Mar 23, 2023
@rpatin
Copy link
Contributor

rpatin commented Mar 27, 2023

Hi Romain,
Thank you for reporting 🙏

As a summary, you have:

  1. suspicious projection for your SRE models. Although you can look at the response curve. Are you projecting in current or future condition ? If you are projecting in current condition it is indeed quite surprising to have such output. Did you look at the response curve for SRE and do they make sense ? Did the BIOMOD_Modeling step said something about SRE modeling ?
  2. a series of error when you run BIOMOD_Projection for Maxent with two types of error:
Error in file output.biomod_PA1_RUN1_MAXENT_outputs/BATHY.asc: java.lang.NumberFormatException: For input string: "NODATA_value"  

and

Exception in thread "main" java.awt.HeadlessException: 
No X11 DISPLAY variable was set, but this program performed an operation which requires it.
	at java.desktop/java.awt.GraphicsEnvironment.checkHeadless(GraphicsEnvironment.java:208)
	at java.desktop/java.awt.Window.<init>(Window.java:548)
	at java.desktop/java.awt.Frame.<init>(Frame.java:423)
	at java.desktop/java.awt.Frame.<init>(Frame.java:388)
	at java.desktop/javax.swing.SwingUtilities$SharedOwnerFrame.<init>(SwingUtilities.java:1919)
	at java.desktop/javax.swing.SwingUtilities.getSharedOwnerFrame(SwingUtilities.java:1995)
	at java.desktop/javax.swing.JOptionPane.getRootFrame(JOptionPane.java:1689)
	at java.desktop/javax.swing.JOptionPane.showOptionDialog(JOptionPane.java:868)
	at java.desktop/javax.swing.JOptionPane.showMessageDialog(JOptionPane.java:670)
	at java.desktop/javax.swing.JOptionPane.showMessageDialog(JOptionPane.java:641)
	at density.Utils.popupError(Utils.java:226)
	at density.Utils.fatalException(Utils.java:271)
	at density.GridIO.readGrid(GridIO.java:77)
	at density.Extractor.CachedGridFilename(Extractor.java:93)
	at density.Project.newGrid(Project.java:99)
	at density.Project.getGrid(Project.java:65)
	at density.Project.projectGrid(Project.java:210)
	at density.Project.doProject(Project.java:112)
	at density.Project.main(Project.java:523)

I suspect there is an issue with the bathymetry raster which cause problem when exported as .asc (which is required by Maxent). And I suspect the second error is caused because the first one has caused maxent and the projection to crash. In any case the maxent prediction were not run properly so the following results were bugged.
Several solution are possible:

  • use MAXNET instead of MAXENT. MAXNET is highly similar to MAXENT but natively written in R so much more stable and easy to use
  • alternatively we need to have a reproducible example, with at least the bathymetry layer which is causing issue so that we can try to evaluate what is wrong and eventually fix the issue internally or advise you with how to reformat the bathymetry. You can send me data/script to remi.patin@univ-grenoble-alpes.fr. Note that we are quite busy right now so there may be some delay...

I also noticed at the end of you .odt that you had There were 50 or more warnings (use warnings() to see the first 50). Could you print the given warning ? maybe there have some useful information.

Best,
Rémi

@rpatin rpatin changed the title Empty SRE file created by BIOMOD_Projection() Maxent error and empty SRE file created by BIOMOD_Projection() Mar 27, 2023
@rpatin rpatin added the bug Something isn't working label Mar 27, 2023
@r-fernandezz
Copy link
Author

Hi Rémi,

Thank you for your quick response! 👍

  1. I projecting in current projection with same environmental variables files (vars_mean_MIG) for BIOMOD_Projection() and BIOMOD_EnsembleForecasting(). I didn't time to download environmental variables for futur conditions yet.

  2. I can see the reponse curve for SRE and it makes sense. BIOMOD_Modeling() doesn't report anything about SRE model, you can see my outputs from this function here : output_BIOMOD_Modeling.txt

  3. I will try with MAXNET and I send you bathymetry file by mail.

  4. Warnings come from other functions of my pipeline because biomod package functions are integrated in a larger process.

Best,
Romain

@rpatin rpatin added the external problem Issue coming from external source (code, computer, ...) label Mar 29, 2023
@rpatin
Copy link
Contributor

rpatin commented Mar 29, 2023

Hi Romain,
Thank you for the file and additional explanation 🙏

The maxent error was quite nasty. The topography data that you used had rectangular cells:

class       : SpatRaster 
dimensions  : 34, 61, 1  (nrow, ncol, nlyr)
resolution  : 1.996558, 1.994203  (x, y)
extent      : 19.98279, 141.7728, -40.7913, 27.01159  (xmin, xmax, ymin, ymax)
coord. ref. : +proj=longlat +datum=WGS84 +no_defs 
source      : ETOPO1_Bed_g_geotiff_crs-resolution-extent__BATHY.grd 
name        :      layer 
min value   : -5878.7331 
max value   :   191.1008  

You can see there that resolution is different between x and y, although very close to 2.
This is perfectly fine for most function working on raster data. But Maxent only reads ASCII raster and do not manage them properly, so it can use only raster with square cells. Also note that the problem is not specifically with the topography layer, but with all layer - bathymetry is just the first one read by Maxent)

If you want to keep using MAXENT (although you still have the option to use MAXNET) you will need to use a grid with a square resolution. You can do it fairly easily, considering that you raster have nearly a resolution of 2:

library(terra)
etopo_rect <- rast("ETOPO1_Bed_g_geotiff_crs-resolution-extent__BATHY.grd")
# create empty raster with square cells
etopo_square <- etopo_rect
res(etopo_square) <- 2

# reproject rectangle raster into the square one
# here the method used is nearest neighbor as both grid should match fairly easily (given the grid is not to large). 
# But you could also consider other projection method
etopo_square_projected <- project(etopo_rect, etopo_square, method = "near")

then if you do that to all environmental layer, the MAXENT projection should hopefully work.

I am still studying the issue with SRE projection.

Best,
Rémi

@r-fernandezz
Copy link
Author

r-fernandezz commented Mar 29, 2023

Hi Rémi,

Thank you for your first response part!

This is strange because I used same raster last year with another version of biomod to build the maxent model and it worked. I'm going to change my raster resolution. I tried too with maxnet and it's working.

Best,
Romain

@rpatin
Copy link
Contributor

rpatin commented Mar 29, 2023

Hi Romain,
I guess there have been some changes within biomod2, we now use maxent directly on raster to do the projection. Previously we used to convert raster into data.frame, then project with maxent and format back the data.frame into a raster. When we changed to using directly the raster projection, it felt cleaner, although it might raise other problems as you discovered.
Best,
Rémi

@rpatin
Copy link
Contributor

rpatin commented Mar 29, 2023

Concerning the SRE problem, I would be curious to see the response curves, although you did not find anything suspicious with them. Additionally what are the results for:

  • get_predictions(myBiomodModelOut, algo = "SRE") and especially the column pred to see whether you have correct predictions for the training data already.
  • get_evaluations(myBiomodModelOut, algo = "SRE") to ensure that SRE models were correctly run.

Best,
Rémi

@r-fernandezz
Copy link
Author

Reponse curves:

image

Predictions:

> myBiomodModelOut <- targets::tar_read("individual_model2_c9bb1cd3")
> pred_tab <- get_predictions(myBiomodModelOut, algo = "SRE")
> pred_tab$pred

output.txt

Evaluations:


> myBiomodModelOut <- targets::tar_read("individual_model2_c9bb1cd3")
> get_evaluations(myBiomodModelOut, algo = "SRE")
                     full.name  PA  run algo metric.eval cutoff sensitivity
19  output.biomod_PA1_RUN1_SRE PA1 RUN1  SRE         TSS    495      54.148
20  output.biomod_PA1_RUN1_SRE PA1 RUN1  SRE         ROC    500      54.148
21  output.biomod_PA1_RUN1_SRE PA1 RUN1  SRE       KAPPA    495      54.148
46  output.biomod_PA1_RUN2_SRE PA1 RUN2  SRE         TSS    495      55.095
47  output.biomod_PA1_RUN2_SRE PA1 RUN2  SRE         ROC    500      55.095
48  output.biomod_PA1_RUN2_SRE PA1 RUN2  SRE       KAPPA    495      55.095
73  output.biomod_PA2_RUN1_SRE PA2 RUN1  SRE         TSS    495      53.712
74  output.biomod_PA2_RUN1_SRE PA2 RUN1  SRE         ROC    500      53.712
75  output.biomod_PA2_RUN1_SRE PA2 RUN1  SRE       KAPPA    495      53.712
100 output.biomod_PA2_RUN2_SRE PA2 RUN2  SRE         TSS    495      54.440
101 output.biomod_PA2_RUN2_SRE PA2 RUN2  SRE         ROC    500      54.440
102 output.biomod_PA2_RUN2_SRE PA2 RUN2  SRE       KAPPA    495      54.440
    specificity calibration validation evaluation
19       82.030       0.362      0.304      0.365
20       82.030       0.681      0.652      0.683
21       82.030       0.360      0.302      0.363
46       81.429       0.365      0.351      0.367
47       81.429       0.683      0.676      0.684
48       81.429       0.364      0.349      0.366
73       80.075       0.338      0.341      0.369
74       80.075       0.669      0.671      0.684
75       80.075       0.336      0.339      0.367
100      78.868       0.333      0.327      0.364
101      78.868       0.667      0.663      0.682
102      78.868       0.332      0.325      0.362

Best,
Romain

@rpatin
Copy link
Contributor

rpatin commented Mar 29, 2023

Hi Romain,
Thank you for the update 🙏
Indeed everything looks fine here 🤔
From there I would need to have a reproducible example (data+script) to understand what may be going wrong.

Best,
Rémi

@rpatin
Copy link
Contributor

rpatin commented Apr 4, 2023

Hi Romain,

Thank you for the reproducible example, this helped a lot 🙏

The problem was that environmental variables ordering was different between the data used for the fit and the data used for predicting. For most algorithm this is not a problem. But for the old code we used for SRE predictions, ordering of column was assumed to be identical. Therefore prediction mixed variables and predicted only absences. It is now corrected and the correction will be available with the soon to be released version.

Best,
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