brenovisk7
brenovisk7

Reputation: 35

Unable to open Netcdf variable in xarray

I am opening a dataset using xarray with this line: DS = xr.open_dataset(dataDIR). When I use DS.variables, I see that there's a variable named 'u-vel', however, when I try to open this variable using DS.u-vel, it returns me the following:

'Dataset' object has no attribute 'u'

I think that the python is interpreting it as me trying to open the u variable in DS and subtract it from my local variable vel. I have tried using DS."u-vel", but it did not work either.

Does anybody know how should I open this variable using xarray?

Upvotes: 0

Views: 118

Answers (1)

jhamman
jhamman

Reputation: 6434

u-vel is not a valid name for a Python attribute. You'll want to use the getitem interface to the dataset to access this variable:

da = ds['u-vel']

In general, while the attribute style access is convenient, I think its better to default to using the getitem access pattern to avoid issues like this one as well as conflicts with other parts of the xarray namespace.

Upvotes: 3

Related Questions