You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

MetPy 1.5气块虚温廓线绘制异常求助

解决MetPy 1.5.0中虚温修正CAPE/CIN廓线不收敛问题

问题说明

MetPy 1.5.0发布后,测试虚温修正的CAPE/CIN热力参数时,绘制的修正廓线(黑色虚线)未向未修正廓线(黑色实线)收敛,可复现代码及效果如下:

气块廓线对比图

错误原因

  • 误用地面虚温作为气块起始温度计算气块廓线(prof1 = parcel_profile(p, vt[0], Td[0])),这违背了虚温修正CAPE的核心逻辑:虚温修正是针对环境大气的温度廓线,而非气块的起始温度
  • MetPy的cape_cin函数原生支持虚温修正,无需手动修改气块廓线

修正方案

  1. 保留原始气块温度廓线的计算(基于地面实际温度和露点)
  2. 计算环境的虚温廓线,将其传入cape_cin函数以获得修正后的CAPE/CIN值
  3. 若需可视化对比,应绘制环境虚温廓线与原始气块廓线的关系,而非修改气块起始温度

修正后的完整代码

from metpy.calc import cape_cin, dewpoint_from_relative_humidity, parcel_profile, mixing_ratio_from_relative_humidity, virtual_temperature
from metpy.units import units
import matplotlib.pyplot as plt
from matplotlib.gridspec import GridSpec
from metpy.plots import SkewT

# 气压数据
p = [1008., 1000., 950., 900., 850., 800., 750., 700., 650., 600.,
     550., 500., 450., 400., 350., 300., 250., 200.,
     175., 150., 125., 100., 80., 70., 60., 50.,
     40., 30., 25., 20.] * units.hPa
# 温度数据
T = [29.3, 28.1, 23.5, 20.9, 18.4, 15.9, 13.1, 10.1, 6.7, 3.1,
     -0.5, -4.5, -9.0, -14.8, -21.5, -29.7, -40.0, -52.4,
     -59.2, -66.5, -74.1, -78.5, -76.0, -71.6, -66.7, -61.3,
     -56.3, -51.7, -50.7, -47.5] * units.degC
# 相对湿度数据
rh = [.85, .65, .36, .39, .82, .72, .75, .86, .65, .22, .52,
      .66, .64, .20, .05, .75, .76, .45, .25, .48, .76, .88,
      .56, .88, .39, .67, .15, .04, .94, .35] * units.dimensionless

# 计算露点温度
Td = dewpoint_from_relative_humidity(T, rh)

# 计算环境虚温廓线(用于CAPE/CIN修正)
mxr = mixing_ratio_from_relative_humidity(p, T, rh).to('g/kg')
vt_env = virtual_temperature(T, mxr)

# 计算原始气块温度廓线(基于地面实际温度和露点)
parcel_prof = parcel_profile(p, T[0], Td[0]).to('degC')

# 计算普通CAPE/CIN和虚温修正后的CAPE/CIN
cape_plain, cin_plain = cape_cin(p, T, Td, parcel_prof)
cape_vt, cin_vt = cape_cin(p, vt_env, Td, parcel_prof)

print(f"普通CAPE: {cape_plain:.2f}, 普通CIN: {cin_plain:.2f}")
print(f"虚温修正CAPE: {cape_vt:.2f}, 虚温修正CIN: {cin_vt:.2f}")

# 绘制Skew-T图
fig = plt.figure(figsize=(13,13))
gs = GridSpec(3, 3)
skew = SkewT(fig, rotation=45, subplot=gs[:, :2])

# 绘制环境温度、虚温、露点
skew.plot(p, T, 'r', label='环境温度')
skew.plot(p, vt_env, 'r', ls='--', label='环境虚温')
skew.plot(p, Td, 'g', label='露点温度')

# 绘制原始气块廓线
skew.plot(p, parcel_prof, color='k', ls='-', lw=2, label='气块温度廓线')

# 设置坐标轴范围
skew.ax.set_ylim(1000, 100)
skew.ax.set_xlim(-30, 40)

# 添加绝热线
skew.plot_dry_adiabats(alpha=0.2)
skew.plot_moist_adiabats(alpha=0.2)

# 添加图例
skew.ax.legend()

plt.show()

关键说明

  • 虚温修正的核心是修正环境大气的温度,而非气块的起始温度,气块仍按实际温度和露点抬升
  • cape_cin函数会自动处理虚温与温度的单位兼容,无需额外转换

内容的提问来源于stack exchange,提问作者CGHA

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.21 17:55:00