0

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?

1 Answer 1

4

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.

Sign up to request clarification or add additional context in comments.

1 Comment

I completely forgot about the getitem, thought it wouldn't work in xarray, but it did, thanks!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.