Project

General

Profile

error message python/cdo: AttributeError: 'netcdf_file' object has no attribute 'var'

Added by Arne Kriegsmann over 11 years ago

dear all,

i am using a simple python script, that worked a few months ago, to read a variable from a file:

from cdo import *
cdo = Cdo()
cdf = cdo.readCdf("/scratch/clisap/Hamburg-2K/data/HH2K/A1B_r1/temp2m_HH_DJF.nc")
v_dummy=cdf.var('var167').get()

and get an error:

Traceback (most recent call last):
File "test.py", line 11, in <module>
v_dummy=cdf.variable('var167').get()
AttributeError: 'netcdf_file' object has no attribute 'variable'

Any ideas?
Thanks
Arne


Replies (1)

RE: error message python/cdo: AttributeError: 'netcdf_file' object has no attribute 'var' - Added by Ralf Mueller over 11 years ago

I started the task of returning numpy arrays with the pycdf library, which provides the methods you use (see here. In April this year (release 1.0.9) I added support for the built-in netcdf-class of numpy: scipy.io.netcdf and the external python-netcdf4. the scipy interface became the default, because pycdf has not been updated for years and scipy is under constant development.

My recommondation is to change the calls in your python script to the ones of scipy, i.e.:

v_dummy=cdf.variable('var167').get()

has to become
v_dummy=cdf.variables["var167"][:]

hth
ralf

    (1-1/1)