Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/r/83.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/objective-c/24.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何在windows 7上使用NCO或R将每月的TRMM netCDF文件连接到单个netCDF文件?_R_Concatenation_Netcdf_Nco - Fatal编程技术网

如何在windows 7上使用NCO或R将每月的TRMM netCDF文件连接到单个netCDF文件?

如何在windows 7上使用NCO或R将每月的TRMM netCDF文件连接到单个netCDF文件?,r,concatenation,netcdf,nco,R,Concatenation,Netcdf,Nco,我从1998年到2016年以netCDF格式下载了TRMM月降水率,因此大约有200多个文件。这些文件的名称是3B43.19980101.7.HDF.nc 3B43.19980201.7.HDF.nc 3B43.19980301.7.HDF.nc,等等。 我想将所有这些文件连接到一个netCDF中。我尝试过使用NCO操作符“ncrcat”,它应该能够沿着记录维度连接一系列非常长的文件,在本例中是时间,但到目前为止没有成功。我一开始只尝试了两个简单的文件 ncrcat-O-h3b43.199801

我从1998年到2016年以netCDF格式下载了TRMM月降水率,因此大约有200多个文件。这些文件的名称是
3B43.19980101.7.HDF.nc 3B43.19980201.7.HDF.nc 3B43.19980301.7.HDF.nc
,等等。 我想将所有这些文件连接到一个netCDF中。我尝试过使用NCO操作符“ncrcat”,它应该能够沿着记录维度连接一系列非常长的文件,在本例中是时间,但到目前为止没有成功。我一开始只尝试了两个简单的文件

ncrcat-O-h3b43.19980101.7.HDF.nc3b43.19980201.7.HDF.nc out.nc

得到

错误:没有用于处理的变量拟合条件

于是我试着

ncks --mk_rec_dmn time 3B43.19980101.7.HDF.nc TD.3B43.19980101.7.HDF.nc
ncks --mk_rec_dmn time 3B43.19980201.7.HDF.nc TD.3B43.19980201.7.HDF.nc
我又试了一次

ncrcat -O -h TD.3B43.19980101.7.HDF.nc TD.3B43.19980201.7.HDF.nc out.nc
还是有同样的错误

错误:没有用于处理的变量拟合条件

有没有更简单的方法来处理200多个文件?我可以遵循的脚本?我对这一切都不熟悉,所以请温柔一点


任何帮助都将不胜感激。我使用的是Windows7x86

在R中,您可以通过读取所有数据,合并成一个大型3d数组(latxlonxtime)来实现这一点。例如,数组[,,1]将是1998年1月的latxlon网格。然后,可以将其保存为.rds格式,以便在R中进一步使用,或者保存为netCDF文件,我将不介绍这一点,但在线上有将R阵列保存为.nc文件的教程

首先,创建一个.csv文件,其中包含一列您下载的所有文件名。一种简单的方法是将终端中键入“ls”的输出按ctrl-C键输入excel工作表。下面的代码逐个读取这些文件,并将每个文件添加到数组中

library(ncdf4)
library(abind)
filenames=read.csv('TRMM.filenames.csv',head=F) #read in filenames
filenames=as.character(filenames[,1]) #convert to 'character' format

n.lon=192 #input the correct #'s here, must be the same for all files
n.lat=94

NA.matrix=matrix(rep(NA,n.lon*n.lat),nrow=n.lon) #used to initialize
prcp=array(NA.matrix,c(n.lon,n.lat,1)) #n.lonxn.latx1 array of NA's to initialize
for (i in 1:length(filenames)){
  ncdata=nc_open(filenames[i]) #read in file i, assuming files are in same location as filenames.csv/your current working directory
  #ncdata=nc_open(paste(data.dir,filenames[i],sep="")) #if your data is in another directory than the filenames.csv file, you could read it in with this line instead
  nc=ncvar_get(ncdata,"precip") #check the .nc files to see what the variable name actually is; this reads in the variable "precip"
  prcp=abind(prcp,nc)
}
prcp=prcp[,,-1] #remove the NA.matrix used to initialize

dim(prcp) #check that the lonxlatxtime dimensions make sense
saveRDS(prcp,'TRMM.all.rds') #save as .rds file, or proceed to save it as .nc file, which takes a bit more work

使用NCO完全可以做到这一点。我查看了您的输入文件,它们只是缺少时间维度,所以ncrcat失败。添加一个时间维度

ncecat -u time in.nc out.nc
然后像上面所说的那样使用ncrcat。p、 我已将ncrcat和ncra错误消息更改为更明确的方式。以前,这些提示仅适用于文件已具有维度但已修复的情况。您的文件没有时间维度,因此您发出的ncks命令无效

编辑以显示循环:

要在循环中执行此操作或类似操作,请使用

for fl in `ls trmm*.nc`; do
    ncecat -u time ${fl} ${fl/trmm/trmm_new} # Base output name in input name
    ... # more processing
done

NCO手册中有许多使用文件循环的示例。

我可以访问PPS TRMM FTP服务器。您能否将链接发送到正在访问的3B43.19980101.7.HDF.nc文件?我可以看一下。有没有办法和我们共享这两个文件?这将有助于诊断问题。你能为其中一个文件做一个
ncdump-h[filename]
吗?@EricBridger我使用坐标(15.04,-90.05),(15.31,-89.24)下载了文件@N1B4这里有一个链接:@N1B4因为某种原因,ncdump对我不起作用。安装后,如果我转到NCO文件夹,我可以找到:ncap2、NCATT、ncbo、ncea、NCCAT、ncflint、ncks、ncpdq、ncra、ncrcat、ncrename和ncwa。但是没有ncdump…你说n.lon=192和n.lat=94是什么意思?如何检查数据集的经度和纬度维度是否正确。在终端中,如果您安装并加载了netCDF,您可以执行
ncdump-h filename
,它将打印摘要信息。否则,在R中打开一个文件:
filename=“3B43.19980101.7.HDF.nc”;ncdata=nc_open(文件名);打印(ncdata)
这将为您提供文件摘要,包括经度和纬度维度的“大小”。非常感谢Jack!使用您的脚本,我能够创建一个rds文件。但是,我对将其保存为nc文件非常感兴趣。你知道我在哪里可以找到更多关于这件事的信息吗?谢谢!我想这可能奏效了。现在我的最后一个问题是,是否有一种方法可以在循环中实现这一点。我有200多个文件,我想添加一个时间维度,然后连接在一起。