【问题标题】:why R does not provide information as much as gdalinfo?为什么 R 提供的信息不如 gdalinfo 多?
【发布时间】:2012-10-03 08:28:06
【问题描述】:

我在R中打开了一个netCDF文件,查看了头信息。后来我用gdalinfo查看了同一个文件的头信息。

我发现gdalinfo 显示了更多信息(时间原点、单位等)。有没有用R获取netCDF文件中变量的更多信息的命令?

             f=open.ncdf("C:\\BR_Ban.nc")

              > f
            [1] "file C:\\GF_Guy_6Y.nc has 4 dimensions:"
              [1] "x   Size: 1"
              [1] "y   Size: 1"
              [1] "land   Size: 1"
           [1] "tstep   Size: 105120"
       [1] "double nav_lon[x,y]  Longname:Longitude Missval:1e+30"
       [1] "double nav_lat[x,y]  Longname:Latitude Missval:1e+30"
       [1] "float time[tstep]  Longname:Time axis Missval:1e+30"
     [1] "float timestp[tstep]  Longname:Time step axis Missval:1e+30"

Then read one variable

           A = get.var.ncdf(nc=f,varid="time",verbose=TRUE)
     [1] "vobjtodimname: is a character type varid.  This file has 6 dims"
    [1] "vobjtodimname: no cases found, returning FALSE"
     [1] "get.var.ncdf: isdimvar: FALSE"
      [1] "vobjtovarid: entering with varid=date"
     [1] "Variable named date found in file with varid= 7"
     [1] "vobjtovarid: returning with varid deduced from name; varid= 7"
    [1] "get.var.ncdf: ending up using varid= 7"
     [1] "ndims: 2"
  [1] "get.var.ncdf: varsize:"
    [1]     3 52560
     [1] "get.var.ncdf: start:"
     [1] 1 1
      [1] "get.var.ncdf: count:"
    [1]     3 52560
     [1] "get.var.ncdf: totvarsize: 157680"
     [1] "Getting var of type 3  (1=short, 2=int, 3=float, 4=double, 5=char, 6=byte)"
    [1] "get.var.ncdf: C call returned 0"
    [1] "count.nodegen: 3    Length of data: 157680"     "count.nodegen: 52560    Length of data: 157680"
     [1] "get.var.ncdf: final dims of returned array:"
        [1]     3 52560

【问题讨论】:

  • 您的帖子缺少一些相当重要的信息(例如,您是如何读入 NetCDF 数据的)。 rgdal 包支持这种格式并且也有可用的 GDALinfo 命令。我不知道为什么有人会希望在阅读或摘要期间回显所有这些信息。我同意 R 向我发送垃圾邮件会让我发疯。我还要补充一点,如果您通过 raster 包读取数据(这是一种内存安全选项),则此信息将显示在栅格摘要中。
  • 要从 R 中运行 gdalinfo,请查看 system
  • system 是 R 命令,看?system
  • 你不需要使用系统。该函数内置于 rgdal 包中。使用 require(rgdal) 添加库,然后使用 ?GDALinfo 显示帮助。您甚至可以在不读取文件的情况下显示信息。

标签: r netcdf


【解决方案1】:

简而言之,因为gdalinfo 是用于显示有关特定类型数据集的信息的程序,而 R 是旨在分析各种数据集的语言。如果每次导入数据集时 R 都会向我发送此类信息,我很快就会发疯。

当然,这些信息可以在 R 中访问,你只需要请求它。

class( f )
dim( f )
summary( f )
plot( f )

【讨论】:

  • 如果单元存在于 netcdf 文件中,则可以访问它们。请让你的问题更具体,你需要什么 ncdf 不提供。
猜你喜欢
  • 2017-07-19
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2020-11-19
  • 2019-10-16
相关资源
最近更新 更多