简体   繁体   English

无法在 xarray 中打开 Netcdf 变量

[英]Unable to open Netcdf variable in xarray

I am opening a dataset using xarray with this line: DS = xr.open_dataset(dataDIR) .我正在使用 xarray 打开一个数据集,这条线是: 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:当我使用DS.variables时,我看到有一个名为“u-vel”的变量,但是,当我尝试使用DS.u-vel打开这个变量时,它会返回以下内容:

'Dataset' object has no attribute 'u' “数据集”object 没有属性“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.我认为 python 将其解释为我试图在 DS 中打开 u 变量并从我的局部变量 vel 中减去它。 I have tried using DS."u-vel" , but it did not work either.我试过使用DS."u-vel" ,但它也没有用。

Does anybody know how should I open this variable using xarray?有人知道我应该如何使用 xarray 打开这个变量吗?

u-vel is not a valid name for a Python attribute. u-vel不是 Python 属性的有效名称。 You'll want to use the getitem interface to the dataset to access this variable:您需要使用数据集的 getitem 接口来访问此变量:

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.一般来说,虽然属性样式访问很方便,但我认为最好默认使用 getitem 访问模式来避免此类问题以及与 xarray 命名空间的其他部分发生冲突。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM