“无法在xarray中打开Netcdf变量”

huangapple go评论66阅读模式
英文:

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.

huangapple
  • 本文由 发表于 2023年1月6日 11:20:28
  • 转载请务必保留本文链接:https://go.coder-hub.com/75026620.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定