How can I find all the variables 2D or higher in a netcdf file using python? -


i find variables in netcdf file have 2 or more dimensions. in other words, list of variables not 0 or 1 dimensional.

it seems should able like:

import netcdf4 nc = netcdf4.dataset(file) varlist = [<something> k,v in nc.variables.iteritems()]

where uses v.ndim > 1 can't figure out.

you're there list comprehension provided. boolean condition goes @ end though, not @ beginning.

[(nm, var) nm, var in nc.variables.iteritems() if var.ndim > 1] 

that outputs list of length-2 tuples, each 1 containing name , netcdf4 variable object. if want variables, can do

[var var in nc.variables.itervalues() if var.ndim > 1] 

list comprehensions powerful tool; see official documentation here: https://docs.python.org/2/tutorial/datastructures.html#list-comprehensions


Comments

Popular posts from this blog

shopping cart - Page redirect not working PHP -

php - How to modify a menu to show sub-menus -

python - Installing PyDev in eclipse is failed -