Извлечение дополнительных атрибутов из измерения в NetCDF [R] - PullRequest
0 голосов
/ 16 июня 2020

Я хотел бы прочитать некоторые атрибуты измерения в netcdf на R - подход nc$dim$name не имеет доступа к ним.

nc <- nc_open("mydata.nc")

# have a look at the nc info
nc

File mydata.nc (NC_FORMAT_NETCDF4):

 1 variable (excluding dimension variables):
    float stuff [lon,lat,cat]   (Chunking: [360,180,4])  (Compression: level 5)
        units: n
        _FillValue: 1.00000002004088e+20
        long_name: stuff that is data

 3 dimensions:
    lon  Size:720
        units: degrees_east
        long_name: longitude
        axis: X
    lat  Size:360
        units: degrees_north
        long_name: latitude
        axis: Y
    cat Size:4
        long_name: category
        ids: 1: Apples; 2: Pears; 3: Oranges; 4: Bananas
        axis: T
        realtopology: linear

3 global attributes:
    comment: This data is made up.
    creation_date: 2020-06-16
    data_structure: grid

# check names of variables
nc.names <- names(nc$var)
[1] "stuff"

# check the names of dimensions etc.
names(nc$dim)
[1] "lon"    "lat"    "cat" 

обычная команда просто дает обычный материал;

nc$dim$cat

$name
[1] "cat"

$len
[1] 4

$unlim
[1] FALSE

$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] ""

$vals
[1] 1 2 3 4

$create_dimvar
[1] TRUE

attr(,"class")
[1] "ncdim4"

В частности, мне нужен атрибут «ids» под измерением «кошка», с именами различных слоев в переменной в виде строки символов («1: Яблоки; 2: Груши; 3: Апельсины; 4. : Бананы »). Как я могу их извлечь автоматически? (реальные данные - это 20 с лишним переменных, каждая из которых имеет размерность 18 слоев)

...