danlwarren / ENMTools

ENMTools R Package
104 stars 30 forks source link

In enmtools.maxent: .local(object, ...):missing layers (or wrong names) #257

Closed JuiTse closed 8 months ago

JuiTse commented 8 months ago

Dear Mr. @danlwarren,

Here I come across the issue in doing ENM by enmtools.maxent (also error in enmtools.bc). ENMTools.zip

Using R 4.1.2, ENMTools 1.1.2, and terra 1.7.18, I follow the process from the github page as below:

Read in the ENV variables:

sel_env.files <- list.files(path = "MyFullPath", pattern = "Mask", full.names = TRUE) sel_env <- terra::rast(sel_env.files) sel_env <- setMinMax(sel_env) sel_env <- project(sel_env, "+proj=longlat +ellps=WGS84 +towgs84=0,0,0,0,0,0,0 +no_defs") sel_env <- check.env(sel_env) sel_env

Creat object

S.revoluta_loc <- read.csv("SB_locOnly.csv", header=TRUE) head(S.revoluta_loc) S.revoluta <- enmtools.species(species.name = "S.revoluta", presence.points = vect(S.revoluta_loc[,c(2,3)], geom = c("Longitude", "Latitude"))) crs(S.revoluta$presence.points) <- crs(sel_env) S.revoluta$range <- background.raster.buffer(S.revoluta$presence.points, 2000, mask = sel_env) S.revoluta$background.points <- background.points.buffer(points = S.revoluta$presence.points, radius = 1000, n = 2000, mask = sel_env[[1]])

S.revoluta <- check.species(S.revoluta)

Building ENM

S.bc <- enmtools.bc(S.revoluta, sel_env, test.prop = 0.2) Error in .local(object, ...):missing variables in x

S.mx <- enmtools.maxent(S.revoluta, sel_env, test.prop = 0.2) Error in .local(object, ...):missing layers (or wrong names)

However, if I just follow the example code below in the same environment, everything work normally. monticola.mx <- enmtools.maxent(monticola, env, test.prop = 0.2)

What happen to my input files? I have checked that the contents/format are same as in the example file.

I am looking forward to know more about this, thank you Jui-Tse

danlwarren commented 8 months ago

I can't run the maxent version since it's not installed on my machine right now, but the bioclim one at least is choking on the variable names, probably due to the presence of special characters. Try adding:

names(sel_env) <- c("bio10", "bio3", "bio7")

After you read in and format the env files and see if that fixes it. Please let me know either way!

JuiTse commented 8 months ago

Dear @danlwarren , You are right, the problem occur due to the presence of special characters. After reassigning the new names, the subsequent analysis work smoothly.

Thank for solving this! Jui-Tse

danlwarren commented 8 months ago

Great!