1

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

我的原始代码:

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 的轴。大多数时候,这个函数可以运行良好。

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

4

1 回答 1

1

这是 MetPy 中的一个错误。你能在MetPy 问题跟踪器上打开一个问题吗?

于 2018-07-26T22:28:49.810 回答