Error of the global climate data set

17 views
Skip to first unread message

Kun Guo

unread,
Mar 30, 2026, 7:52:49 AMMar 30
to NicheMapR

Hi Mike, 

When executing the micro_terra() function (NicheMapR v3.3.2, R v4.3.1) to simulate soil temperature profiles across multiple depths, and I have downloaded  climate input data from TerraClimate (ppt, soil, srad, tmax, tmin, vpd, vap, ws). Howere tthe function terminated with the following error message "you do not appear to have the global climate data set -         run function get.global.climate(folder='folder you want to put it in').........          exiting function micro_global".

 

All the Best

Kun


library(NicheMapR)
library(dplyr)
library(parallel)
micro_path= "D:/data/output"
scenario=4

cal.micro<-function(lon,lat,scenario,micro_path,i){
      ERR=1.5
      micro<-try(micro_terra(
        scenario=scenario,
        terra_source="D:/R_place/TerraClimate",
        loc=c(lon,lat),
        ystart=2006,
        yfinish=2015,
        timeinterval=365,
        DEP=c(0,5,10,20,30,40,50,60,70,200),
        ERR=ERR))
     
  if(class(micro)=="try-error"){
    return(NA)
  }else{
   
    while(min(micro$metout[,1])==0 & ERR <= 2.5){
      cat("model crashed, trying a higher error tolerance \n")
      ERR <- ERR + 0.25
      micro<-try(micro_terra(
        scenario=scenario,
        terra_source="D:/R_place/TerraClimate",
        loc=c(lon,lat),
        ystart=2006,
        yfinish=2015,
        timeinterval=365,
        DEP=c( 0,5,10,20,30,40,50,60,70,200),
        ERR=ERR)) }
    if(min(micro$metout[,1])==0 & ERR > 2.5){
      ERR=">2.5"
    }
   
    write.csv(cbind(micro$soil,ERR),paste0(micro_path,"/",scenario,"/open/",i,"_soil",".csv"),row.names=F)
    write.csv(cbind(micro$shadsoil,ERR),paste0(micro_path,"/",scenario,"/shade/",i,"_shadsoil",".csv"),row.names=F)
  }
}

site_all<-read.csv("D:/data/lizard/Tey.csv")

site_distinct<-distinct(site_all[,1:2])



####loop for the remained points
for (scenario in c(0,2,4)) {
  for (i in 1:10) {
    cal.micro(lon=site_distinct$lon[i],lat=site_distinct$lat[i],scenario=scenario,
              micro_path=micro_path,i=i)
  }
}

for (scenario in c(4)) {
  for (i in 1:10) {
    cal.micro(lon=site_distinct$lon[i],lat=site_distinct$lat[i],scenario=scenario,
              micro_path=micro_path,i=i)
  }
}


NicheMapR

unread,
Mar 30, 2026, 8:05:34 AMMar 30
to NicheMapR

Hi Kun,

Did you try what the error suggested and run the function get.global.climate ?

Also note that the url for the terraclimate data changed very recently so you’ll need the latest version of NicheMapR to get it to work.

All the best,
Mike

Reply all
Reply to author
Forward
0 new messages