1

新手用户在这里。

我在尝试使用 parcel_profile 时遇到了一个问题,它不断弹出一个错误,指出该变量没有与之关联的单位:

回溯(最近一次通话最后):文件“Advanced_Sounding_3Dnetcdf2.py”,第 165 行,在 prof = mpcalc.parcel_profile(p, T[0], Td[0]).to('degC')

有问题的代码片段:

p = phPa * units.hPa
T = TdegC* units.degC
Td = TddegC* units.degC

lcl_pressure, lcl_temperature = mpcalc.lcl(p[0], T[0], Td[0])
skew.plot(lcl_pressure, lcl_temperature, 'ko', markerfacecolor='black')

print(p)

prof = mpcalc.parcel_profile(p, T[0], Td[0]).to('degC')

当我打印“p”时,它如下所示:

[<Quantity(965.2435302734375, 'hectopascal')>
 <Quantity(959.7489624023438, 'hectopascal')>
 <Quantity(954.278564453125, 'hectopascal')>
...

数据读入如下:

file = 'cm1out_000001.nc'
figname = 'control'
figtime = '1'

f = Dataset(file, 'r')

[deleted for brevity]

th = f.variables['th'][0,0:zfl,yfl,xfl] #Read in potential temperature
p0=f.variables['prs0'][0,0:zfl,yfl,xfl] #Read in base state pressure
p = f.variables['prs'][0,0:zfl,yfl,xfl] #Read in pressure

[deleted for brevity]

phPA = p/100

[deleted for brevity]

p = phPa * units.hPa

我这里有另一个编码错误还是有其他问题?

谢谢。

4

1 回答 1

0

netCDF4-python 默认为您提供掩码数组,这些数组在 Pint 的单元支持方面存在一些奇怪的问题。在左侧乘以单位应该可以解决它:

p = units.hPa * phPa
T = units.degC * TdegC
Td = units.degC * TddegC
于 2020-05-25T22:58:29.087 回答