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.
82 stars 21 forks source link

BIOMOD_EnsembleModeling Error when running code #412

Closed Joost134 closed 7 months ago

Joost134 commented 7 months ago

Context and question When running the BIOMOD_Ensembling code I get this error:

task 1 failed - "task 1 failed - "task 1 failed - "cannot open the connection""" In addition: Warning messages: 1: In gzfile(file, "wb") : cannot open compressed file './MangocurrentPA100/.BIOMOD_DATA/1707135501/ensemble.models/ensemble.models.predictions/MangocurrentPA100_EMmeanByTSS_mergedData_mergedRun_mergedAlgo.predictions', probable reason 'No such file or directory' 2: In gzfile(file, "wb") : cannot open compressed file './MangocurrentPA100/.BIOMOD_DATA/1707135501/ensemble.models/ensemble.models.predictions/MangocurrentPA100_EMwmeanByTSS_mergedData_mergedRun_mergedAlgo.predictions', probable reason 'No such file or directory'

image

The rest of the process and codes are running correctly and give good output. But only when I try to ensemble the models something goes wrong as there is 'No such file or directory'

The location where I refers to seems correct, when I look in my documents: C:\Users\Joost\OneDrive - Retail Management Center B.V\Documenten\universiteit Joost\GIMA\Masterthesis\Rtools\LayersforinR\MangocurrentPA10000.BIOMOD_DATA\1706626957\ensemble.models

But no files are saved here? Other codes from the internet do exactly the same and do get output. Do you change the path and how?

As I am a beginner in R maybe this is easily solved but I am running into this problem for quite some time now.

Code:

Set environment

setwd("C:\Users\Joost\OneDrive - Retail Management Center B.V\Documenten\universiteit Joost\GIMA\Masterthesis\Rtools\layersforinR")

load in only presence layer

occurrencepresence_data<-read.csv("presencelayerNewR.csv", sep=";", dec = ",", header=TRUE) tail(occurrencepresence_data) occurrencepresence_data$CID<-as.numeric(occurrencepresence_data$CID) summary(occurrencepresence_data)

Load in env variables

Totaldegreedays <- raster('totaldegreedayseumaskclip.asc') Airhumidity <- raster('airhumidityeumaskclip2.asc') Avtempfruitset <- raster('avtempfruitset2maskclip.asc') Cloudcover <- raster('cloudcovereumaskclip2.asc') Elevation <- raster('elevationeumaskclip.asc') Soilerosion <- raster('soileroeumaskclip.asc') Soildimp <- raster('soildimpeumaskclip.asc') Soiltexture <- raster('soiltextureeumaskclip.asc')

a rasterstack is made of the different variables

predictorvariables <- stack(Soiltexture,Soildimp,Soilerosion,Totaldegreedays,Cloudcover, Airhumidity) names(predictorvariables)<- c("SoilTexture", "SoilDepth", "SoilErosion", "DegreeDays", "Cloudcover", "AirHumidity") names(predictorvariables) plot(predictorvariables)

CurrentmangomodelPA100 <- BIOMOD_FormatingData( resp.var = occurrencepresence_data$CID, #presencedata expl.var = predictorvariables, #expl variables resp.xy = occurrencepresence_data[, c("Longitude", "Latitude")], resp.name = 'MangocurrentPA100', PA.nb.rep = 2, PA.nb.absences = 100, PA.strategy = 'random', PA.dist.min = 100)

Output: -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= MangocurrentPA100 Data Formating -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=

  ! No data has been set aside for modeling evaluation
  ! No data has been set aside for modeling evaluation

Checking Pseudo-absence selection arguments...

  ! No data has been set aside for modeling evaluation

random pseudo absences selection natory variables

                                      eling evaluation
  ! No data has been set aside for modeling evaluation

-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= Done

Biomodoptions

myBiomodOptions <- BIOMOD_ModelingOptions( GLM = list(type = 'quadratic', test = 'AIC', interaction.level = 1), GBM = list(n.trees = 2000, shrinkage = 0.001, bag.fraction = 0.5, interaction.depth = 1, n.minobsinnode = 3))

BIOMOD modeling

myBiomodModelOutGBM10005 <- BIOMOD_Modeling(

  • bm.format = CurrentmangomodelPA100,
  • models = c('GBM'),
  • bm.options = myBiomodOptions,
  • CV.strategy = 'random',
  • CV.nb.rep = 4,
  • CV.perc = 0.5,
  • metric.eval = c('ROC','TSS', 'ACCURACY'),
  • var.import = 4)

-=-=-=--=-=-=- MangocurrentPA100_PA2_RUN4_GBM

Model=Generalised Boosting Regression 2000 maximum different trees and 3 Fold Cross-Validation

GBM modeling... Evaluating Model stuff... Evaluating Predictor Contributions... |===========================================================================================| 100%

-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= Done -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= Warning message: executing %dopar% sequentially: no parallel backend registered

BIOMOD ensemble

EnsemblemodelcurrentGBM <- BIOMOD_EnsembleModeling(bm.mod = myBiomodModelOutGBM10005, models.chosen = 'all', em.by = 'all', em.algo = c('EMmean', 'EMwmean'), metric.select = 'TSS', metric.select.thresh = c(0.4), metric.eval = c('TSS', 'ROC', 'ACCURACY'), var.import = 4)

-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= Build Ensemble Models -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=

! all models available will be included in ensemble.modeling ! Ensemble Models will be filtered and/or weighted using validation dataset (if possible). Please use metric.select.dataset for alternative options.

Evaluation & Weighting methods summary : TSS over 0.4

mergedData_mergedRun_mergedAlgo ensemble modeling ! Additional projection required for ensemble models merging several pseudo-absence dataset... -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= Do Single Models Projection -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=

Projecting MangocurrentPA100_PA1_RUN1_GBM ... Projecting MangocurrentPA100_PA1_RUN2_GBM ... Projecting MangocurrentPA100_PA1_RUN3_GBM ... Projecting MangocurrentPA100_PA1_RUN4_GBM ... -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= Done -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=

-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= Do Single Models Projection -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=

> Projecting MangocurrentPA100_PA2_RUN1_GBM ...
> Projecting MangocurrentPA100_PA2_RUN2_GBM ...
> Projecting MangocurrentPA100_PA2_RUN3_GBM ...
> Projecting MangocurrentPA100_PA2_RUN4_GBM ...

-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= Done -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=

Mean of probabilities by TSS ... original models scores = 0.789 0.809 0.7 0.829 0.94 0.749 0.678 0.738 final models weights = 0.127 0.13 0.112 0.133 0.151 0.12 0.109 0.118 Probabilities weighting mean by TSS ...Error in { : task 1 failed - "task 1 failed - "task 1 failed - "cannot open the connection""" In addition: Warning messages: 1: In gzfile(file, "wb") : cannot open compressed file './MangocurrentPA100/.BIOMOD_DATA/1707135501/ensemble.models/ensemble.models.predictions/MangocurrentPA100_EMmeanByTSS_mergedData_mergedRun_mergedAlgo.predictions', probable reason 'No such file or directory' 2: In gzfile(file, "wb") : cannot open compressed file './MangocurrentPA100/.BIOMOD_DATA/1707135501/ensemble.models/ensemble.models.predictions/MangocurrentPA100_EMwmeanByTSS_mergedData_mergedRun_mergedAlgo.predictions', probable reason 'No such file or directory'

MayaGueguen commented 7 months ago

Hello Joost,

Thank you for your code and data. Which operating system are you using ? :eyes: If you are using Windows, you may have an issue with path length, in which case I suggest moving your folder higher in the folder hierarchy to have shorter path. Tell me if this does the trick !

Maya

Joost134 commented 7 months ago

Hi Maya,

Thank you very much for the quick help. To be honest, I tried to solve the issue with your solution but it didn't work. I found a other solution via the BIOMOD_projection function by adding new environmental variables and combining the different layers in Arcgis Pro.

Have a good day!

Joost