Closed Joost134 closed 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
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
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'
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 -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
Checking Pseudo-absence selection arguments...
-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= 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
-=-=-=--=-=-=- MangocurrentPA100_PA2_RUN4_GBM
Model=Generalised Boosting Regression 2000 maximum different trees and 3 Fold Cross-Validation
-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= 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.-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= Do Single Models Projection -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= Done -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=