Error trying to import NetCDF to R

I am trying 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") 

The following error message appears:

  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 

It is strange that another NetCDF file with Runoff-Data from the same simulation with exactly the same data type opens without problems.

The difference in file size is Runoff: 56.1 MB (58,870,472 bytes) and harvest: 149 MB (156 968 508 bytes). Thus, the files are actually not too large to crash when opened. Does anyone know how I can track the error that causes this problem?

Using the RNetCDF package, I get the same problem ( Error: NetCDF: Unknown file format )

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 } 

file can be found here: netCDF file

+4
source share
2 answers

A dump from ncdump -k gives the netcdf file format as netCDF-4. I managed to open the file with the ncdf4 package, since ncdf does not seem backward compatible with version 4 files:

"However, the ncdf package does not provide an interface for netcdf version 4."

from ncdf4 documentation.

 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) 

gives

 num [1:79, 1:78, 1:32, 1:199] NA NA NA NA NA NA NA NA NA NA ... 
+2
source

I think that the maize netcdf crop file is simply corrupted or not even the netcdf file (the file name says nothing about the real contents). Try it and open it in NCView or dump using ncdump if this tool also does not work, your file is damaged or incomplete. In addition, if you want us to help you need to make your file available.

+1
source

Source: https://habr.com/ru/post/1479756/


All Articles