使用气候数据运算符(CDO)的RStudio中的ETCCDI暖期持续时间指数(wsdi)

时间:2018-07-24 00:14:36

标签: r raster cdo ncdf4

我正在尝试使用气候数据运算符(cdo)在RStudio中计算ETCCDI暖期持续时间指数(wsdi)。我使用以下脚本,并使用KNMI网页中的可用值检查了结果。结果与KNMI中提供的结果不匹配。 clippedtasmax_2100.nc文件中的所有clippedtasmax_1981.nc文件(单位在dC中)都在input_folder中。您能告诉我此脚本有什么问题吗?

library(raster)  
library(ncdf4)  
startyear <- 1981  
endyear <- 2100  
for (i in startyear:endyear)  
{  
file_tmax <- paste(input_folder,"\\clippedtasmax_ ",i,".nc",sep="")  
command <- paste("cdo timmin ",file_tmax," ",workdir,"tmax_min.nc",sep="")  
system(command)  
command <- paste("cdo timmax ",file_tmax," ",workdir,"tmax_max.nc",sep="")  
system(command)   
command <- paste("cdo timpctl,90 ",file_tmax," ",workdir,"tmax_min.nc ",workdir,"tmax_max.nc ",workdir,"temp_tmax_90.nc",sep="")  
system(command)  
command <- paste("cdo -add ",workdir,"temp_tmax_90.nc -sub ",file_tmax," ",file_tmax," ",workdir,"temp_tmax_90_timesteps.nc",sep = "")  
system(command)  
command <- paste("cdo eca_hwfi ",file_tmax," ",workdir,"temp_tmax_90_timesteps.nc ",outdir,"\\Warmspell_",i,".nc",sep = "")  
system(command)  
} 

然后,我对输出的“ Warmspell_i.nc”文件进行了重新采样。

rm(list=ls())   
library(raster)  
#create new reference raster
referenceraster<-raster(xmn=80, xmx=90, ymn=25, ymx=30,      
      crs=CRS('+proj=longlat +datum=WGS84'))  
res(referenceraster)<-2.5  
referenceraster
#files to be resampled  
wsdi<-"X:\\outdir\\warmspell_1981.nc"  
wsdi<-raster(wsdi)  
wsdi  
resample_raster<-resample(wsdi, referenceraster, method="bilinear", nas.rm=TRUE)  
values(resample_raster)  
extent<-extent(80, 90, 25, 30)  
e <- extract(resample_raster, extent, weights=TRUE, fun=mean)   
e  

谢谢。

0 个答案:

没有答案