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')


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

相关文章
|
缓存 数据可视化
'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
155 0
SAP WM Stock Removal Strategy M (Small/Large Quantity)(1)
SAP WM Stock Removal Strategy M (Small/Large Quantity)(1)
SAP WM Stock Removal Strategy M (Small/Large Quantity)(1)
SAP WM Stock Removal Strategy M (Small/Large Quantity)(2)
SAP WM Stock Removal Strategy M (Small/Large Quantity)(2)
SAP WM Stock Removal Strategy M (Small/Large Quantity)(2)
2015-03-18 header note creation in my Appointment
2015-03-18 header note creation in my Appointment
78 0
2015-03-18 header note creation in my Appointment
header note truncation issue - designed behavior
header note truncation issue - designed behavior
85 0
header note truncation issue - designed behavior
修改某个appointment已经存在的opportunity relation
修改某个appointment已经存在的opportunity relation
87 0
修改某个appointment已经存在的opportunity relation
the code place where the binding is converted to final value displayed in u
the code place where the binding is converted to final value displayed in u
104 0
the code place where the binding is converted to final value displayed in u
how to know which settype an assignment block is built based on
how to know which settype an assignment block is built based on
101 0
how to know which settype an assignment block is built based on
is transfer = C ( only read dynamically) not supported in one order scenario
is transfer = C ( only read dynamically) not supported in one order scenario
102 0
is transfer = C ( only read dynamically) not supported in one order scenario
component set load logic - why coms_pcat_bob is accessed during product search
component set load logic - why coms_pcat_bob is accessed during product search
111 0
component set load logic - why coms_pcat_bob is accessed during product search