如何获得特定维度的netCDF变量列表?
问题描述:
{
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')
的netCDF文件获取所有的变量
ncvars <- names(out[['var']])
这给我的所有变量在netCDF文件列表。
我怎样才能得到它们的尺寸time
和hru
,例如变量列表?
拟输出:
列表与a1, a2
答
注意:这是蟒,不属于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
我不知道R,但我可以显示一个Python解决方案,如果这可能有所帮助。 –
@EricBridger请问, – maximusdooku