Neither Quantity object nor its magnitude supports indexing

简介: Neither Quantity object nor its magnitude supports indexing

Issue



python 处理气象数据过程中,使用metpy的units 给变量附上单位并进行相关求偏导,循环计算时,出现报错:Neither Quantity object nor its magnitude supports indexing


发现问题来源:对变量赋上单位,求完梯度之后还是array格式,而不是pint.quantity.build_quantity_class.<locals>.Quantity


问题解决:

上述问题在于,提取变量赋上单位时,需要提供的是变量的实际values,而不是dataarray等其他格式。


所以,只需要在提取变量时在其后面加上.data再进行赋单位即可,举个例子如下所示:


import xarray as xr
f_w = r'D:/PV/omega_smooth3.nc'
da  = xr.open_dataset(f_w)
omega = da.omega.data.units('Pa/s')


这样,就可以成功解决循环时的报错问题啦

相关文章
|
6月前
|
消息中间件 Oracle 关系型数据库
Note_Logistics_Day03
Note_Logistics_Day03
47 0
|
6月前
|
canal 消息中间件 关系型数据库
Note_Logistics_Day04
Note_Logistics_Day04
55 0
解决Mapped Statements collection already contains value for experiment4.UserMapper.listUser错误~
解决Mapped Statements collection already contains value for experiment4.UserMapper.listUser错误~
解决办法:Type safety: The expression of type List needs unchecked conversion to conform
解决办法:Type safety: The expression of type List needs unchecked conversion to conform
325 0
|
缓存 数据可视化
'dict' object has no attribute '_txn_read_preference' && Sort exceeded memory limit of 10485760
'dict' object has no attribute '_txn_read_preference' && Sort exceeded memory limit of 10485760
212 0
Stock Removal Strategy A(Partial Pallet Quantity)in SAP WM
Stock Removal Strategy A(Partial Pallet Quantity)in SAP WM
Stock Removal Strategy A(Partial Pallet Quantity)in SAP WM
成功解决KeyError: “Passing list-likes to .loc or [] with any missing labels is no longer supported. The
成功解决KeyError: “Passing list-likes to .loc or [] with any missing labels is no longer supported. The