andrefaa / ENMTML

Create Ecological Niche Models with TheMetaLand
47 stars 13 forks source link

Projection error #329

Open bbarker505 opened 3 years ago

bbarker505 commented 3 years ago

Hi, I just have a suggestion for improving ease of use of ENMTML. I kept getting the error below, and finally figured out that it happened because there wasn't a subfolder contained within "proj_dir." My suggestion is that the program should work whether or not you have the projection variables in a subfolder vs. in the main "proj_dir" folder.

Error in ENMTML(pred_dir = pred_dir, proj_dir = proj_dir, result_dir = out_dir, : Select a folder containing folders with environment conditions for different regions or time periods, NOT a folder with this variables!

madeka772 commented 3 years ago

Hello bbarker505,

How did you solve this issue? I am having the same problem even when following the step-by-step guide. Do you have an example?

Thank you

bbarker505 commented 3 years ago

Hi @madeka772,

The only solution I found was to change the path of where my projection variables were located. I'll try to given an example. Let's say my project directory is in "/home/species/ENMTML". So here are the paths to my predictor and projection variables, respectively:

/home/species/ENMTML/Predictors/ /home/species/ENMTML/Projection/World

I was getting that error when I didn't have my projection variables within a subfolder inside of the "Projection" folder, which is very strange and something I recommended that should be changed in future ENMTML versions. In other words, I would get that error if my projection variables were in "/home/species/ENMTML/Projection/".

madeka772 commented 3 years ago

Hi, thanks for responding to me. I appreciate it. I am getting the same error even with the changes to my directory folders though, so I am not sure how to proceed from here.

ENMTML( pred_dir = 'C:/Users/Owner/Desktop/ENMTML/Predictors', proj_dir = 'C:/Users/Owner/Desktop/ENMTML/Projection/World', result_dir = 'C:/Users/Owner/Desktop/ENMTML/Results', occ_file = occ1, sp = 'A_Clade', x = 'x', y = 'y', min_occ = 208, thin_occ = NULL, eval_occ = NULL, colin_var = NULL, imp_var = TRUE, sp_accessible_area = c(method='USER-DEFINED', filepath='C:/Users/Owner/Desktop/AnthraxClades/AClade/Accessible Area Folder'), pseudoabs_method = c(method = 'RND'), pres_abs_ratio = 1, part=c(method='BOOT', replicates='10', proportion='0.7'), save_part = FALSE, save_final = TRUE, algorithm = c('SVM', 'RDF', 'MXD'), thr = c(type='MAX_TSS'), msdm = NULL, ensemble = c(method='W_MEAN', metric='TSS'), extrapolation = TRUE, cores = 1 )

sjevelazco commented 3 years ago

Hi

In the "proj_dir" argument you must write the path to the folder with subfolders projection scenarios. It is mandatory that only environmental data files (e.g. .tif files) are included in each of the projection folders.

madeka772 commented 3 years ago

Hi,

What if I do not have multiple scenarios? Currently, I am working with 13 buffered rasters (.tif) and 13 global projection rasters all in the same .tif format with identical names.

sjevelazco commented 3 years ago

The same rule, even if you have only one scenario you will have to leave the data in a subfolder.

El lun, 30 ago 2021 a las 17:15, madeka772 @.***>) escribió:

Hi,

What if I do not have multiple scenarios? Currently, I am working with 13 buffered rasters (.tif) and 13 global projection rasters all in the same .tif format with identical names.

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/andrefaa/ENMTML/issues/329#issuecomment-908660240, or unsubscribe https://github.com/notifications/unsubscribe-auth/AGW3YWGTSFVREF3SORWEMZDT7PRFVANCNFSM46BXNQVQ . Triage notifications on the go with GitHub Mobile for iOS https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675 or Android https://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub.

--

Santiago J. E. Velazco, PhD

Postdoctoral researcher.

Department of Botany and Plant Sciences. University of California - Riverside

https://twitter.com/Santiag43066556 https://www.researchgate.net/profile/Santiago_Velazco3 https://orcid.org/0000-0002-7527-0967

madeka772 commented 3 years ago

Can you provide an example, please? I understand the concept of putting the data into a subfolder (I have used kuenm in the past).

C:\Users\Owner\Desktop\ENMTML\Projection\World.....do I need to add additional sub-folders?

sjevelazco commented 3 years ago

Yes

Below there is an example.

require(ENMTML) require(raster)

%######################################################%

Directories and data creation

%######################################################%

ENMTML package account with some bioclimantic variables

used to test ENMTML function.

In order to simulate the files and folders needed for an ENMTML function

will be created different folders with some data

First will be created a folder with a working directory

getwd() #' Working directory of R session d_ex <- file.path(getwd(), 'ENMTML_example') d_ex dir.create(d_ex)

Will be saved some ENMTML data sets to ENMTML_example folder

Virtual species occurrences

data("occ") d_occ <- file.path(d_ex, 'occ.txt') utils::write.table(occ, d_occ, sep = '\t', row.names = FALSE)

Five bioclimatic variables for current conditions

data("env") d_env <- file.path(d_ex, 'current_env_var') dir.create(d_env) raster::writeRaster(env, file.path(d_env, names(env)), bylayer=TRUE, format='GTiff')

Five bioclimatic variables for future conditions

(for more details see predictors_future help)

data("env_fut") d_fut <- file.path(d_ex, 'future_env_var') dir.create(d_fut)

HERE I WILL CREATE A SINGLE CLIMATE SCENARIO TO SIMULATE YOU CASE

d0 <- file.path(d_fut, names(env_fut))[1] sapply(d0, dir.create)

raster::writeRaster(env_fut$2080_4.5, file.path(d0[1],

names(env_fut$2080_4.5)), bylayer=TRUE, format='GTiff', )

raster::writeRaster(env_fut$2080_8.5, file.path(d0[2],

# names(env_fut$2080_8.5)), bylayer=TRUE, format='GTiff')

Polygon of terrestrial ecoregions

data("ecoregions") d_eco <- file.path(d_ex, 'ecoregions') dir.create(d_eco) d_eco <- file.path(d_eco, paste0('eco','.shp')) shapefile(ecoregions, d_eco)

shell.exec(d_ex) # open the directory and folders created

rm(list = c('d0', 'd_ex', 'ecoregions', 'env', 'env_fut', 'occ'))

Now we have the minimum data needed to create models with ENMTML package

a directory with environmental rasters and a .txt file with occurrence

%######################################################%

Construction ENM with ENMTML

%######################################################%

args(ENMTML)

ENMTML provides a variety of tools to build different models

depending on the modeling objectives.

Here will be provided a single modeling procedure.

For more example and exploration of models

see https://github.com/andrefaa/ENMTML

Will be fitted models for five virtual species with

current and future conditions. Please read ENMTML arguments.

The next object contains the directory and file path data and folders

that will be used d_occ # file path with species occurrences d_env # directory path with current environmental conditions (raster in tiff format)

d_fut <---- THIS IS THE PATH TO A FOLDER WITH A SINGLE SUBFOLDER

d_fut # directory path with folders with future environmental conditions (raster in tiff format) d_eco # file path with shapefile used to constrain models

ENMTML( pred_dir = d_env, proj_dir = d_fut, result_dir = NULL, occ_file = d_occ, sp = 'species', x = 'x', y = 'y', min_occ = 10, thin_occ = NULL, eval_occ = NULL, colin_var = c(method='PCA'), imp_var = FALSE, sp_accessible_area = c(method='BUFFER', type='2', width='500'), pseudoabs_method = c(method = 'RND'), pres_abs_ratio = 1, part=c(method= 'KFOLD', folds='2'), save_part = FALSE, save_final = TRUE, algorithm = c('SVM', 'RDF', 'MXD'), thr = c(type='MAX_TSS'), msdm = NULL, ensemble = c(method='PCA'), extrapolation = FALSE, cores = 1 )

El lun, 30 ago 2021 a las 17:24, madeka772 @.***>) escribió:

Can you provide an example, please? I understand the concept of putting the data into a subfolder (I have used kuenm in the past).

C:\Users\Owner\Desktop\ENMTML\Projection\World.....do I need to add additional sub-folders?

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/andrefaa/ENMTML/issues/329#issuecomment-908667576, or unsubscribe https://github.com/notifications/unsubscribe-auth/AGW3YWBTV5ZYYSVOWE5IADLT7PSJNANCNFSM46BXNQVQ . Triage notifications on the go with GitHub Mobile for iOS https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675 or Android https://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub.

--

Santiago J. E. Velazco, PhD

Postdoctoral researcher.

Department of Botany and Plant Sciences. University of California - Riverside

https://twitter.com/Santiag43066556 https://www.researchgate.net/profile/Santiago_Velazco3 https://orcid.org/0000-0002-7527-0967

madeka772 commented 3 years ago

Thank you! My next question is in regards to an error I am receiving that has prevented me from completing the analysis. This is been a constant error when using the KFOLDS option with 3 partitions:

Error: Problem with summarise() input Partition. x Calling var(x) on a factor x is defunct. Use something like 'all(duplicated(x)[-1L])' to test for a constant vector. i Input Partition is stats::sd(Partition, na.rm = T). i The error occurred in group 1: Sp = "anthrax", Algorithm = "RDF", Threshold = "MAX_TSS".

sjevelazco commented 3 years ago

It seems to be an error caused by the R version. Which R version you are using?

El mié, 1 sept 2021 a las 12:07, madeka772 @.***>) escribió:

Thank you! My next question is in regards to an error I am receiving that has prevented me from completing the analysis. This is been a constant error when using the KFOLDS option with 3 partitions:

Error: Problem with summarise() input Partition. x Calling var(x) on a factor x is defunct. Use something like 'all(duplicated(x)[-1L])' to test for a constant vector. i Input Partition is stats::sd(Partition, na.rm = T). i The error occurred in group 1: Sp = "anthrax", Algorithm = "RDF", Threshold = "MAX_TSS".

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/andrefaa/ENMTML/issues/329#issuecomment-910376996, or unsubscribe https://github.com/notifications/unsubscribe-auth/AGW3YWBALIMBDAOK4HWCAATT7Y6STANCNFSM46BXNQVQ . Triage notifications on the go with GitHub Mobile for iOS https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675 or Android https://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub.

--

Santiago J. E. Velazco, PhD

Postdoctoral researcher.

Department of Botany and Plant Sciences. University of California - Riverside

https://twitter.com/Santiag43066556 https://www.researchgate.net/profile/Santiago_Velazco3 https://orcid.org/0000-0002-7527-0967

madeka772 commented 3 years ago

I am using R 1.4.1717, the newest version of the software.