marlonecobos / kuenm

kuenm: An R package for detailed calibration and construction of Maxent Ecological Niche Models.
63 stars 24 forks source link

Trouble with kuenm_projchanges #58

Open KitSimon opened 1 year ago

KitSimon commented 1 year ago

I'm trying but failing to run kuenm_projchanges as such:

sps <- dir()
out_models <- paste0(sps, "/4_Final_models")
modstats <- paste0(sps, "/6_Final_Model_Stats")

curpatt <- "1981-2010"
emscepatt <- c("ssp126", "ssp370", "ssp585")
timepatt <- c("2011-2040", "2041-2070", "2071-2100")
climpatt <- c("GFDL-ESM4", "IPSL-CM6A-LR", "MPI-ESM1-2-HR", "MRI-ESM2-0", "UKESM1-0-LL")
ext_type <- c("EC","E")
prjchn <- paste0(sps, "/7_Projection_changes")

for (i in 1:length(sps)) {
  kuenm_projchanges(occ = occ_joint[i], 
                    fmod.stats = modstats[i], 
                    threshold = 5, 
                    current = curpatt, 
                    emi.scenarios = emscepatt,
                    time.periods = timepatt,
                    clim.models = climpatt,
                    ext.type = ext_type, 
                    out.dir = prjchn[i])
}

Running the script results in the error below.

Preparing data for starting analyses, please wait...

Starting analyses, please wait...
Error in ext_types[[i]] : subscript out of bounds

The directory prjchn is correctly generated, but containing a single subdirectory "Changes_EC", which is empty. Omitting the for-loop doesn't seem to change anything, as the error message persists. It has me stumped. How can I go about solving this?

KitSimon commented 1 year ago

I did some digging in the kuenm_projchanges function and noticed a quirk in how the model stats are read. It presupposes median statistics if I'm correct? In that case I think the fact that I opted to only generate mean statistics with kuenm_modstats_swd in the previous step might be a contributing factor to the error.

  # Reading model names
  nstas <- list.files(fmod.stats, pattern = "med.tif$",
                  full.names = TRUE, recursive = TRUE)