简体   繁体   English

使用 R 从 vobjtovarid4 读取 .netCDF 文件时出错

[英]Error reading netCDF file from vobjtovarid4 using R

I want to get dimensions for my climate model, that is, for longitude, latitude, and time variables from.netCDF file using the R code我想获取气候 model 的维度,即使用 R 代码从 .netCDF 文件获取经度、纬度和时间变量

tas1 <- ncvar_get(climate_output, 'tas')
dim(tas1)

But I am getting error但我收到错误

Error in vobjtovarid4(nc, varid, verbose = verbose, allowdimvar = TRUE): Variable not found vobjtovarid4 中的错误(nc、varid、verbose = verbose、allowdimvar = TRUE):未找到变量

Can anyone help me in this?任何人都可以帮助我吗? Thank you谢谢

I have visited the website you mentioned, and from the site I managed to retrieve a.netCDF dataset that contains only 10 metre U wind component variable.我访问了您提到的网站,并从该网站设法检索了一个仅包含10 metre U wind component变量的 .netCDF 数据集。 You can download the data here .您可以在此处下载数据。 The file size is about 28 MB.文件大小约为 28 MB。

I then open the data in R然后我打开R中的数据

library(ncdf4)
wind_data <- nc_open('wind_speed.nc')
wind_data

## File wind_speed.nc (NC_FORMAT_64BIT):
## 
##      1 variables (excluding dimension variables):
##         short u10[longitude,latitude,time]   
##             scale_factor: 0.000982868773831028
##             add_offset: -0.745013529113478
##             _FillValue: -32767
##             missing_value: -32767
##             units: m s**-1
##             long_name: 10 metre U wind component
## 
##      3 dimensions:
##         longitude  Size:480
##             units: degrees_east
##             long_name: longitude
##         latitude  Size:241
##             units: degrees_north
##             long_name: latitude
##         time  Size:124   *** is unlimited ***
##             units: hours since 1900-01-01 00:00:00.0
##             long_name: time
##             calendar: gregorian

You can get comprehensive dimension data by using $dim :您可以使用$dim获取全面的维度数据:

wind_data$dim
## $longitude
## $name
## [1] "longitude"
## 
## $len
## [1] 480
## 
## $unlim
## [1] FALSE
## 
## $group_index
## [1] 1
## 
## $group_id
## [1] 65536
## 
## $id
## [1] 0
## 
## $dimvarid
## $id
## [1] 0
## 
## $group_index
## [1] 1
## 
## $group_id
## [1] 65536
## 
## $list_index
## [1] -1
## 
## $isdimvar
## [1] TRUE
## 
## attr(,"class")
## [1] "ncid4"
## 
## $units
## [1] "degrees_east"
## 
## $vals
##   [1]   0.00   0.75   1.50   2.25   3.00   3.75   4.50   5.25   6.00   6.75
##  [11]   7.50   8.25   9.00   9.75  10.50  11.25  12.00  12.75  13.50  14.25
##  [21]  15.00  15.75  16.50  17.25  18.00  18.75  19.50  20.25  21.00  21.75
##  [31]  22.50  23.25  24.00  24.75  25.50  26.25  27.00  27.75  28.50  29.25
##  [41]  30.00  30.75  31.50  32.25  33.00  33.75  34.50  35.25  36.00  36.75
##  [51]  37.50  38.25  39.00  39.75  40.50  41.25  42.00  42.75  43.50  44.25
##  [61]  45.00  45.75  46.50  47.25  48.00  48.75  49.50  50.25  51.00  51.75
##  [71]  52.50  53.25  54.00  54.75  55.50  56.25  57.00  57.75  58.50  59.25
##  [81]  60.00  60.75  61.50  62.25  63.00  63.75  64.50  65.25  66.00  66.75
##  [91]  67.50  68.25  69.00  69.75  70.50  71.25  72.00  72.75  73.50  74.25
## [101]  75.00  75.75  76.50  77.25  78.00  78.75  79.50  80.25  81.00  81.75
## [111]  82.50  83.25  84.00  84.75  85.50  86.25  87.00  87.75  88.50  89.25
## [121]  90.00  90.75  91.50  92.25  93.00  93.75  94.50  95.25  96.00  96.75
## [131]  97.50  98.25  99.00  99.75 100.50 101.25 102.00 102.75 103.50 104.25
## [141] 105.00 105.75 106.50 107.25 108.00 108.75 109.50 110.25 111.00 111.75
## [151] 112.50 113.25 114.00 114.75 115.50 116.25 117.00 117.75 118.50 119.25
## [161] 120.00 120.75 121.50 122.25 123.00 123.75 124.50 125.25 126.00 126.75
## [171] 127.50 128.25 129.00 129.75 130.50 131.25 132.00 132.75 133.50 134.25
## [181] 135.00 135.75 136.50 137.25 138.00 138.75 139.50 140.25 141.00 141.75
## [191] 142.50 143.25 144.00 144.75 145.50 146.25 147.00 147.75 148.50 149.25
## [201] 150.00 150.75 151.50 152.25 153.00 153.75 154.50 155.25 156.00 156.75
## [211] 157.50 158.25 159.00 159.75 160.50 161.25 162.00 162.75 163.50 164.25
## [221] 165.00 165.75 166.50 167.25 168.00 168.75 169.50 170.25 171.00 171.75
## [231] 172.50 173.25 174.00 174.75 175.50 176.25 177.00 177.75 178.50 179.25
## [241] 180.00 180.75 181.50 182.25 183.00 183.75 184.50 185.25 186.00 186.75
## [251] 187.50 188.25 189.00 189.75 190.50 191.25 192.00 192.75 193.50 194.25
## [261] 195.00 195.75 196.50 197.25 198.00 198.75 199.50 200.25 201.00 201.75
## [271] 202.50 203.25 204.00 204.75 205.50 206.25 207.00 207.75 208.50 209.25
## [281] 210.00 210.75 211.50 212.25 213.00 213.75 214.50 215.25 216.00 216.75
## [291] 217.50 218.25 219.00 219.75 220.50 221.25 222.00 222.75 223.50 224.25
## [301] 225.00 225.75 226.50 227.25 228.00 228.75 229.50 230.25 231.00 231.75
## [311] 232.50 233.25 234.00 234.75 235.50 236.25 237.00 237.75 238.50 239.25
## [321] 240.00 240.75 241.50 242.25 243.00 243.75 244.50 245.25 246.00 246.75
## [331] 247.50 248.25 249.00 249.75 250.50 251.25 252.00 252.75 253.50 254.25
## [341] 255.00 255.75 256.50 257.25 258.00 258.75 259.50 260.25 261.00 261.75
## [351] 262.50 263.25 264.00 264.75 265.50 266.25 267.00 267.75 268.50 269.25
## [361] 270.00 270.75 271.50 272.25 273.00 273.75 274.50 275.25 276.00 276.75
## [371] 277.50 278.25 279.00 279.75 280.50 281.25 282.00 282.75 283.50 284.25
## [381] 285.00 285.75 286.50 287.25 288.00 288.75 289.50 290.25 291.00 291.75
## [391] 292.50 293.25 294.00 294.75 295.50 296.25 297.00 297.75 298.50 299.25
## [401] 300.00 300.75 301.50 302.25 303.00 303.75 304.50 305.25 306.00 306.75
## [411] 307.50 308.25 309.00 309.75 310.50 311.25 312.00 312.75 313.50 314.25
## [421] 315.00 315.75 316.50 317.25 318.00 318.75 319.50 320.25 321.00 321.75
## [431] 322.50 323.25 324.00 324.75 325.50 326.25 327.00 327.75 328.50 329.25
## [441] 330.00 330.75 331.50 332.25 333.00 333.75 334.50 335.25 336.00 336.75
## [451] 337.50 338.25 339.00 339.75 340.50 341.25 342.00 342.75 343.50 344.25
## [461] 345.00 345.75 346.50 347.25 348.00 348.75 349.50 350.25 351.00 351.75
## [471] 352.50 353.25 354.00 354.75 355.50 356.25 357.00 357.75 358.50 359.25
## 
## $create_dimvar
## [1] TRUE
## 
## attr(,"class")
## [1] "ncdim4"
## 
## $latitude
## $name
## [1] "latitude"
## 
## $len
## [1] 241
## 
## $unlim
## [1] FALSE
## 
## $group_index
## [1] 1
## 
## $group_id
## [1] 65536
## 
## $id
## [1] 1
## 
## $dimvarid
## $id
## [1] 1
## 
## $group_index
## [1] 1
## 
## $group_id
## [1] 65536
## 
## $list_index
## [1] -1
## 
## $isdimvar
## [1] TRUE
## 
## attr(,"class")
## [1] "ncid4"
## 
## $units
## [1] "degrees_north"
## 
## $vals
##   [1]  90.00  89.25  88.50  87.75  87.00  86.25  85.50  84.75  84.00  83.25
##  [11]  82.50  81.75  81.00  80.25  79.50  78.75  78.00  77.25  76.50  75.75
##  [21]  75.00  74.25  73.50  72.75  72.00  71.25  70.50  69.75  69.00  68.25
##  [31]  67.50  66.75  66.00  65.25  64.50  63.75  63.00  62.25  61.50  60.75
##  [41]  60.00  59.25  58.50  57.75  57.00  56.25  55.50  54.75  54.00  53.25
##  [51]  52.50  51.75  51.00  50.25  49.50  48.75  48.00  47.25  46.50  45.75
##  [61]  45.00  44.25  43.50  42.75  42.00  41.25  40.50  39.75  39.00  38.25
##  [71]  37.50  36.75  36.00  35.25  34.50  33.75  33.00  32.25  31.50  30.75
##  [81]  30.00  29.25  28.50  27.75  27.00  26.25  25.50  24.75  24.00  23.25
##  [91]  22.50  21.75  21.00  20.25  19.50  18.75  18.00  17.25  16.50  15.75
## [101]  15.00  14.25  13.50  12.75  12.00  11.25  10.50   9.75   9.00   8.25
## [111]   7.50   6.75   6.00   5.25   4.50   3.75   3.00   2.25   1.50   0.75
## [121]   0.00  -0.75  -1.50  -2.25  -3.00  -3.75  -4.50  -5.25  -6.00  -6.75
## [131]  -7.50  -8.25  -9.00  -9.75 -10.50 -11.25 -12.00 -12.75 -13.50 -14.25
## [141] -15.00 -15.75 -16.50 -17.25 -18.00 -18.75 -19.50 -20.25 -21.00 -21.75
## [151] -22.50 -23.25 -24.00 -24.75 -25.50 -26.25 -27.00 -27.75 -28.50 -29.25
## [161] -30.00 -30.75 -31.50 -32.25 -33.00 -33.75 -34.50 -35.25 -36.00 -36.75
## [171] -37.50 -38.25 -39.00 -39.75 -40.50 -41.25 -42.00 -42.75 -43.50 -44.25
## [181] -45.00 -45.75 -46.50 -47.25 -48.00 -48.75 -49.50 -50.25 -51.00 -51.75
## [191] -52.50 -53.25 -54.00 -54.75 -55.50 -56.25 -57.00 -57.75 -58.50 -59.25
## [201] -60.00 -60.75 -61.50 -62.25 -63.00 -63.75 -64.50 -65.25 -66.00 -66.75
## [211] -67.50 -68.25 -69.00 -69.75 -70.50 -71.25 -72.00 -72.75 -73.50 -74.25
## [221] -75.00 -75.75 -76.50 -77.25 -78.00 -78.75 -79.50 -80.25 -81.00 -81.75
## [231] -82.50 -83.25 -84.00 -84.75 -85.50 -86.25 -87.00 -87.75 -88.50 -89.25
## [241] -90.00
## 
## $create_dimvar
## [1] TRUE
## 
## attr(,"class")
## [1] "ncdim4"
## 
## $time
## $name
## [1] "time"
## 
## $len
## [1] 124
## 
## $unlim
## [1] TRUE
## 
## $group_index
## [1] 1
## 
## $group_id
## [1] 65536
## 
## $id
## [1] 2
## 
## $dimvarid
## $id
## [1] 2
## 
## $group_index
## [1] 1
## 
## $group_id
## [1] 65536
## 
## $list_index
## [1] -1
## 
## $isdimvar
## [1] TRUE
## 
## attr(,"class")
## [1] "ncid4"
## 
## $units
## [1] "hours since 1900-01-01 00:00:00.0"
## 
## $calendar
## [1] "gregorian"
## 
## $vals
##   [1] 1008078 1008084 1008090 1008102 1008108 1008114 1008126 1008132 1008138
##  [10] 1008150 1008156 1008162 1008174 1008180 1008186 1008198 1008204 1008210
##  [19] 1008222 1008228 1008234 1008246 1008252 1008258 1008270 1008276 1008282
##  [28] 1008294 1008300 1008306 1008318 1008324 1008330 1008342 1008348 1008354
##  [37] 1008366 1008372 1008378 1008390 1008396 1008402 1008414 1008420 1008426
##  [46] 1008438 1008444 1008450 1008462 1008468 1008474 1008486 1008492 1008498
##  [55] 1008510 1008516 1008522 1008534 1008540 1008546 1008558 1008564 1008570
##  [64] 1008582 1008588 1008594 1008606 1008612 1008618 1008630 1008636 1008642
##  [73] 1008654 1008660 1008666 1008678 1008684 1008690 1008702 1008708 1008714
##  [82] 1008726 1008732 1008738 1008750 1008756 1008762 1008774 1008780 1008786
##  [91] 1008798 1008804 1008810 1008087 1008111 1008135 1008159 1008183 1008207
## [100] 1008231 1008255 1008279 1008303 1008327 1008351 1008375 1008399 1008423
## [109] 1008447 1008471 1008495 1008519 1008543 1008567 1008591 1008615 1008639
## [118] 1008663 1008687 1008711 1008735 1008759 1008783 1008807
## 
## $create_dimvar
## [1] TRUE
## 
## attr(,"class")
## [1] "ncdim4"

You can use ncvar_get(nc, varid) function this way:您可以这样使用ncvar_get(nc, varid) function:

wind_get <- ncvar_get(wind_data, wind_data$var[[1]])
wind_get
## , , 1
## 
##             [,1]         [,2]         [,3]          [,4]        [,5]
##   [1,] 0.2152493 -10.17858802 -10.50981480 -10.050815080 -9.19277064
##   [2,] 0.2152493 -10.17957089 -10.50981480 -10.042952130 -9.19571925
##   [3,] 0.2152493 -10.17957089 -10.50981480 -10.036072048 -9.19965072
##   [4,] 0.2152493 -10.17957089 -10.50981480 -10.029191967 -9.20358220
##   [5,] 0.2152493 -10.17858802 -10.50981480 -10.023294754 -9.20849654
##   [6,] 0.2152493 -10.17858802 -10.50981480 -10.017397541 -9.21341088
##   [7,] 0.2152493 -10.17858802 -10.50981480 -10.012483198 -9.21930810

Then, you can get the sizes of longitude, latitude, and time by using dim()然后,您可以使用dim()获取经度、纬度和时间的大小

dim(wind_get)
## [1] 480 241 124

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM