如何获得具有特定维度的netCDF变量列表?

2024-09-28 01:23:09 发布

您现在位置:Python中文网/ 问答频道 /正文

{
dimensions:
    grp = 50 ;
    time = UNLIMITED ; // (0 currently)
    depth = 3 ;
    scalar = 1 ;
    spectral_bands = 2 ;
    x1AndTime = 13041 ;
    x2AndTime = 13041 ;
    midTotoAndTime = 13041 ;
variables:
    double time(time) ;
    double a1(time, hru) ;
    double a2(time, hru) ;
    double a3(x1AndTime, hru) ;
    double a4(x2AndTime, hru) ;
    double a5(hru) ;

R中打开netCDF文件

out <- ncdf4::nc_open('test.nc')

获取所有变量

ncvars <- names(out[['var']])

这给了我一个netCDF文件中所有变量的列表。在

例如,我如何获得维度为time和{}的变量列表?在

预期输出:

使用a1, a2列出


Tags: 文件a2列表timea1netcdfoutdimensions
1条回答
网友
1楼 · 发布于 2024-09-28 01:23:09

注意:这是python,不是R,但说明了逻辑。在

import netCDF4

out = netCDF4.Dataset("test.nc")
# list of vars w dimenions 'time' and 'hru'
wanted_vars = []

# loop thru all the variables
for v in out.variables:
  # this is the name of the variable.
  print v
  # variable.dimensions is a tuple of the dimension names for the variable
  # In R you might need just ('time', 'hru')
  if out.variables[v].dimensions == (u'time', u'hru'):
    wanted_vars.append(v)

print wanted_vars

相关问题 更多 >

    热门问题