2017-10-18 33 views
0
{ 
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) ; 

열고 netCDF의 파일이 나에게 netCDF의 파일에 모든 변수의 목록을 제공특정 크기의 netCDF 변수 목록을 얻으려면 어떻게합니까? <code>R</code></p> <p><code>out <- ncdf4::nc_open('test.nc')</code></p> <p>에서

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

모든 변수를 가져옵니다.

예를 들어 timehru 크기의 변수 목록을 얻으려면 어떻게해야합니까?

의도 출력 : a1, a2

+0

나는 R을 모른다.하지만 도움이된다면 파이썬 솔루션을 보여줄 수있다. –

+0

@EricBridger 제발, – maximusdooku

답변

0

주와

목록이 파이썬이 아닌 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 
+0

음, 질문은'R'에 관한거야? – Bart

+0

파이썬이 도움이된다면 나는 @maximusdooku에게 물었다. –

+0

아, 미안 .. 그거보고 싶었어. – Bart