gpt4 book ai didi

Python 调用 metpy.calc.lfc() 引发 IndexError : index 0 is out of bounds for axis 0 with size 0

转载 作者:行者123 更新时间:2023-12-01 09:12:41 60 4
gpt4 key购买 nike

我的Python程序引发了IndexError: index 0 is out of bounds for axis 0 with size 0当我调用metpy.calc.lft()时功能。

我的原始代码:

lfc_p, lfc_T = mpcalc.lfc(P,T,Td)

完整信息如下:

Traceback (most recent call last):   
File "cal_sounding_data.py", line 289, in <module>
newset_dic[k] = specStationSounding(k,dataset_dic)
File "cal_sounding_data.py", line 213, in specStationSounding
result_dic = soundingCalculation(num,p,t,td,ws,wd)
File "cal_sounding_data.py", line 142, in soundingCalculation
lfc_p, lfc_T = mpcalc.lfc(P,T,Td)
File "/anaconda2/lib/python2.7/site-packages/metpy/xarray.py", line 138, in wrapper
return func(*args, **kwargs)
File "/anaconda2/lib/python2.7/site-packages/metpy/calc/thermo.py", line 378, in lfc
return x[0], y[0]
File "/anaconda2/lib/python2.7/site-packages/pint/quantity.py", line 1281, in __getitem__
value = self._magnitude[key]
IndexError: index 0 is out of bounds for axis 0 with size 0

我用 pdb 对其进行了调试,并插入了以下代码来捕获错误:

try:
lfc_p, lfc_T = mpcalc.lfc(P,T,Td)
except IndexError:
pdb.set_trace()

我运行了这个程序,然后在遇到该错误时检查了 P、T 和 Td 的变量。

这表明:

(Pdb) P
<Quantity([ 1004. 1000. 943. 928. 925. 850. 839. 749. 700. 699.
603. 500. 404. 400. 363. 306. 300. 250. 213. 200.
176. 150. 120. 105. 100. 70. 66. 58. 50. 40.
33. 30. 23. 20. 16.], 'hectopascal')>
(Pdb) T
<Quantity([ 24.2 24. 20.2 21.6 21.4 20.4 20.2 14.4 13.2 13. 6.8 -3.3
-13.1 -13.7 -17.9 -25.5 -26.9 -37.9 -46.7 -48.7 -52.1 -58.9 -67.3 -66.5
-66.7 -65.1 -66.1 -60.9 -60.5 -57.7 -50.1 -50.3 -50.1 -47.9 -43.1], 'degC')>
(Pdb) Td
<Quantity([ 2.19000000e+01 2.21000000e+01 1.92000000e+01 2.05000000e+01
2.04000000e+01 1.84000000e+01 1.74000000e+01 8.40000000e+00
-2.80000000e+00 -3.00000000e+00 -1.52000000e+01 -2.03000000e+01
-2.91000000e+01 -2.77000000e+01 -2.49000000e+01 -3.95000000e+01
-4.19000000e+01 -5.19000000e+01 -6.07000000e+01 -6.27000000e+01
-6.51000000e+01 -7.19000000e+01 9.99999000e+05 9.99999000e+05
9.99999000e+05 9.99999000e+05 9.99999000e+05 9.99999000e+05
9.99999000e+05 9.99999000e+05 9.99999000e+05 9.99999000e+05
9.99999000e+05 9.99999000e+05 9.99999000e+05], 'degC')>

看来 P、T 和 Td 都是正确的。毕竟,它们实际上不是尺寸为0的轴。大多数时候,这个函数可以运行良好。

我想知道如何解决这个问题。非常感谢!

最佳答案

这是 MetPy 中的一个错误。您可以在MetPy Issue Tracker上打开一个问题吗? ?

关于Python 调用 metpy.calc.lfc() 引发 IndexError : index 0 is out of bounds for axis 0 with size 0,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51515440/

60 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com