英文:
Unable to open Netcdf variable in xarray
问题
It looks like you're trying to open a variable named 'u-vel' using xarray in Python. To access this variable, you can use square brackets like this: DS['u-vel']
. This should allow you to access the 'u-vel' variable in your dataset.
英文:
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
得分: 3
u-vel
不是Python属性的有效名称。您应该使用getitem接口来访问数据集以访问此变量:
da = ds['u-vel']
总的来说,虽然属性样式访问很方便,但我认为最好默认使用getitem访问模式,以避免类似这种问题以及与xarray命名空间的其他部分冲突。
英文:
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.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论