简体   繁体   English

读取多个 netcdf 文件

[英]Reading multiple netcdf files

I am trying to read multple nc4 files in r.我正在尝试在 r 中读取多个 nc4 文件。 below is the code I am using to execute this task;下面是我用来执行此任务的代码;

library(ncdf4)
OSND_gpmr.df<-NULL

GPM_R.files= list.files(path,pattern='*.nc4',full.names=TRUE) 

for(i in seq_along(GPM_R.files)) {
  nc_data = nc_open(GPM_R.files[i])

  GPM_Prec<-ncvar_get(nc_data, 'IRprecipitation')

  x=dim(GPM_Prec)

  ### note start=c(42,28) are the index in image regards to real coordinates of interset
  ## R reads images from lat,long. 
  OSND_gpmr.spec =ncvar_get(nc_data, 'IRprecipitation', start = c(42,28), count = c(1,1))
  rbind(OSND_gpmr.df,data.frame(OSND_gpmr.spec))->OSND_gpmr.df 

  nc_close(nc_data)
}

but I consistently get this error:但我始终收到此错误:

Error in R_nc4_open: No such file or directory. R_nc4_open 中的错误:没有这样的文件或目录。

But the list of files is correctly recognised as chr [1:1440] as shown in the global environments-Values.但是文件列表被正确识别为 chr [1:1440],如全局环境值所示。

Can someone please help me with what I am doing wrong?有人可以帮我解决我做错了什么吗?

Your working directory might have been different from the files location.您的工作目录可能与文件位置不同。 Your GPM_R.files list stores only the file names from the given location without file paths.您的 GPM_R.files 列表仅存储来自给定位置的文件名,而没有文件路径。 While nc_open() expects filenames with complete path.而 nc_open() 需要具有完整路径的文件名。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM