Error when trying to import NetCDF to R

前端 未结 2 1287
醉梦人生
醉梦人生 2021-01-19 18:22

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_         


        
2条回答
  •  南笙
    南笙 (楼主)
    2021-01-19 18:40

    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:

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

    from the 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 ...
    

提交回复
热议问题