尝试将NetCDF导入R时出错 [英] Error when trying to import NetCDF to R
问题描述
我正在努力在R中打开NetCDF文件. 当我尝试使用
I' struggeling to open a NetCDF file in R. When I try to open it with
library(ncdf)
# read in NetCDF file
maize.nc<-open.ncdf("C:/Users/Jo/Desktop/pft_harvest_maize.nc")
我收到以下错误消息:
Error in R_nc_open: NetCDF: Unknown file format
Error in open.ncdf("C:/Users/Jo/Desktop/pft_harvest_maize.nc") :
Error in open.ncdf trying to open file C:/Users/Jo/Desktop/pft_harvest_maize.nc
奇怪的是,另一个完全相同的模拟和完全相同的数据类型的另一个带有Runoff-Data的NetCDF文件打开了,没有任何问题.
the weird thing is, that another NetCDF file with Runoff-Data from the exact same simulation with the exact same datatype opens without any problems.
文件大小的不同是:径流:56.1 MB(58,870,472字节)和收获:149 MB(156,968,508字节).因此,文件实际上不是太大,打开时不会失败.有谁知道我如何追踪导致此问题的错误?
The difference in filesize is Runoff: 56.1 MB (58,870,472 Bytes) and harvest: 149 MB (156,968,508 Bytes). So the files are actually not too big to fail when opening. Has anybody an idea how I can trackback the error that causes this problem??
使用RNetCDF
程序包,我遇到相同的问题(Error: NetCDF: Unknown file format
)
Using the RNetCDF
Package I get the same problem (Error: NetCDF: Unknown file format
)
从ncdump我得到:
From ncdump I get:
netcdf pft_harvest_maize {
dimensions:
time = 199 ;
npft = 32 ;
latitude = 78 ;
longitude = 79 ;
variables:
string NamePFT(npft) ;
int time(time) ;
time:units = "Years" ;
float latitude(latitude) ;
latitude:units = "degrees_north" ;
latitude:long_name = "latitude" ;
latitude:standard_name = "latitude" ;
latitude:axis = "Y" ;
float longitude(longitude) ;
longitude:units = "degrees_east" ;
longitude:long_name = "longitude" ;
longitude:standard_name = "longitude" ;
longitude:axis = "X" ;
float harvest(time, npft, latitude, longitude) ;
harvest:units = "gC/m2/yr" ;
harvest:long_name = "harvested carbon" ;
harvest:missing_value = -9999.99f ;
harvest:_FillValue = -9999.99f
}
文件可以在这里找到: netCDF文件
the file can be found here: netCDF-file
推荐答案
从ncdump -k进行的转储将netcdf文件格式设置为netCDF-4.我可以使用ncdf4
包打开文件,因为ncdf似乎与版本4文件向后不兼容:
The dump from ncdump -k gives the netcdf file format as netCDF-4. I was able to open the file with the ncdf4
package since ncdf does not seem to be backwards compatible with version 4 files:
但是,ncdf软件包不提供netcdf的接口 版本4文件."
"However, the ncdf package does not provide an interface for netcdf version 4 files."
来自ncdf4
文档.
library(ncdf4)
mycdf <- nc_open(file.choose(), verbose = TRUE, write = FALSE)
timedata <- ncvar_get(mycdf,'time')
lat <- ncvar_get(mycdf,'latitude')
long <- ncvar_get(mycdf,'longitude')
harvestdata <- ncvar_get(mycdf,'harvest')
str(harvestdata)
给予
num [1:79, 1:78, 1:32, 1:199] NA NA NA NA NA NA NA NA NA NA ...
这篇关于尝试将NetCDF导入R时出错的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!