How to fix an Metpy/mpcalc error: "InvalidSoundingError: Pressure does not decrease monotonically in your sounding."

How to fix an Metpy/mpcalc error: "InvalidSoundingError: Pressure does not decrease monotonically in your sounding."

我正在尝试绘制探测数据的 Skew-T 并使用 Python 计算 LFC、LCL,但它给我一个错误:

InvalidSoundingError: 
        Pressure does not decrease monotonically in your sounding.
        Using scipy.signal.medfilt may fix this.

我试过 medfilt,但我遇到了同样的错误。

Press = medfilt(Press)

我正在从 .csv 文件导入数据。 给我错误的行:

LFC_pressure, LFC_temperature = mpcalc.lfc(Press*units('hPa'), Temp*units.degC, Dewpt*units.degC)

有人遇到过同样的问题吗?如果是,你会怎么做?

谢谢

此错误是由于您的探测中似乎存在重复的压力水平(可能是由于将数据写入 CSV 时精度不够所致)引起的。这是 MetPy 开发分支中的 fixed,将包含在即将发布的 1.2.0 版本中。

与此同时,删除重复级别的最简单方法是仅保留从一个级别到下一个级别的压力差 > 0 的点:

import numpy as np

# Need concatenate with True to make sure we keep the bottom point
non_dups = np.concatenate(([True], np.diff(Press) != 0))
Press = Press[non_dups]
Temp = Temp[non_dups]
Dewpt = Dewpt[non_dups]