0

我正在用绘图中包含的一些复合参数绘制一些观察到的声音,但我对 STP 输出有一个小问题:它总是带有方括号。

我试图检查是否有统一的东西导致了这种情况,但我没有发现任何问题。

想法?在此处输入图像描述

编辑:我很笨,忘记添加代码行

import posixpath
import matplotlib.pyplot as plt
import metpy.calc as mpcalc
import matplotlib.gridspec as gridspec
import numpy as np
from metpy.plots import add_metpy_logo, add_timestamp, SkewT, Hodograph
from metpy.units import units
from mpl_toolkits.axes_grid1.inset_locator import inset_axes
from siphon.simplewebservice.wyoming import WyomingUpperAir

def plot_skewt(df):
    # Pull the data out of the dataset and set them as individual variables and assign units.
    height_AGL = (df['height']-df['elevation']).values * units.m
    z = df['height'].values * units.m
    p = df['pressure'].values * units.hPa
    T = df['temperature'].values * units.degC
    Td = df['dewpoint'].values * units.degC
    wind_speed = df['speed'].values * units.knots
    wind_dir = df['direction'].values * units.degrees
    u, v = mpcalc.wind_components(wind_speed, wind_dir)

    # Calculate LCL height and plot as black dot
    lcl_pressure, lcl_temperature = mpcalc.lcl(p[0], T[0], Td[0])
    lfc_pressure, lfc_temperature = mpcalc.lfc(p, T, Td)
    lcl_hgt = np.round(mpcalc.pressure_to_height_std(lcl_pressure), decimals=3).to(units.meter)
    lfc_hgt = np.round(mpcalc.pressure_to_height_std(lfc_pressure), decimals=3).to(units.meter)

    # Calculate thermodynamic parameters
    sb_cape, sb_cin = mpcalc.surface_based_cape_cin(p, T, Td)
    ml_cape, ml_cin = mpcalc.mixed_layer_cape_cin(p, T, Td)
    mu_cape, mu_cin = mpcalc.most_unstable_cape_cin(p, T, Td)
    #lr_700_500 = np.round(-1 * np.divide(T[]-T[], (z[]-z[]).to(units.kilometer)),2)
    sbcape = np.round(sb_cape, 1)
    sbcin = np.round(sb_cin, 1)
    mlcape = np.round(ml_cape, 1)
    mlcin = np.round(ml_cin, 1)
    mucape = np.round(mu_cape, 1)

    # Calculate kinematic parameters

    u_shear01, v_shear01 = mpcalc.bulk_shear(p, u.to(units('m/s')), v.to(units('m/s')), depth = 1000 * units.meter)
    shear01 = np.round((np.sqrt(u_shear01**2 + v_shear01**2)), 1)
    u_shear06, v_shear06 = mpcalc.bulk_shear(p, u.to(units('m/s')), v.to(units('m/s')), depth = 6000 * units.meter)
    shear06 = np.round((np.sqrt(u_shear06**2 + v_shear06**2)), 1)
    rmover, lmover, mean = mpcalc.bunkers_storm_motion(p, u, v, z)
    srh_01_pos, srh_01_neg, srh_01_tot = mpcalc.storm_relative_helicity(u, v, z, depth = 1000 * units.meter, bottom = height_AGL[0], storm_u = lmover[0], storm_v = lmover[1])
    srh_01 = np.round(srh_01_neg, 1)
    srh_03_pos, srh_03_neg, srh_03_tot = mpcalc.storm_relative_helicity(u, v, z, depth = 3000 * units.meter, bottom = height_AGL[0], storm_u = lmover[0], storm_v = lmover[1])
    srh_03 = np.round(srh_03_neg, 1)

    # Calculate composite parameters
    ehi_01 = np.round(np.divide(srh_01_neg * sb_cape, 160000 * ((units.m**2 * units.joule)/(units.s**2 * units.kilogram))), 1)
    ehi_03 = np.round(np.divide(srh_03_neg * sb_cape, 160000 * ((units.m**2 * units.joule)/(units.s**2 * units.kilogram))), 1)
    scp = np.round(np.divide(sb_cape, 1000 * units('J/kg')) * np.divide(shear06, 20 * units('m/s')) * np.divide(srh_03_neg, 100 * (units.m**2/units.s**2)), 1)
    sig_tor =  np.round((mpcalc.significant_tornado(sb_cape, lcl_hgt, srh_01_neg, shear06)), 1)

    # Create a new axis
    ax = plt.figure(figsize=(9,9))

    # Grid for plots
    gs = gridspec.GridSpec(3, 3)
    skew = SkewT(ax, rotation=45, subplot=gs[:,:2])

    # Plot the enviromental temperature and dewpoint profiles
    skew.plot(p, T, 'r')
    skew.plot(p, Td, 'g')

    # Mask barbs to below 100 hPa only
    mask = p >= 100 * units.hPa

    # Plot wind barbs
    skew.plot_barbs(p[mask], u[mask], v[mask], y_clip_radius=0.01)

    # Set axis limits
    skew.ax.set_ylim(1050, 100)
    skew.ax.set_xlim(-25, 40)

    # Calculate full parcel profile and add to plot as black line
    prof = mpcalc.parcel_profile(p, T[0], Td[0]).to('degC')
    skew.plot(p, prof, 'k', linewidth=2)

    # Mark with a dot the LCL and LFC heights
    skew.plot(lcl_pressure, lcl_temperature, 'ko', markerfacecolor='black')
    skew.plot(lfc_pressure, lfc_temperature, 'ko', markerfacecolor='blue')

    # Mask barbs to below 100 hPa only
    mask = p >= 100 * units.hPa

    # Shade CAPE
    skew.shade_cape(p, T, prof)

    # Shade CIN
    skew.shade_cin(p, T, prof)

    # Plot the freezing layer isotherms
    skew.ax.axvline(0, color='c', linestyle='--', linewidth=1)
    skew.ax.axvline(-20, color='c', linestyle='--', linewidth=1)

    # Add the relevant special lines
    skew.plot_dry_adiabats()
    skew.plot_moist_adiabats()
    skew.plot_mixing_lines()

    # Write parameters outputs in the SkewT
    plt.figtext( 0.65, 0.58, 'LCL Height:')
    plt.figtext( 0.8, 0.58, f'{lcl_hgt:~P}')
    plt.figtext( 0.65, 0.56, 'LFC Height:')
    plt.figtext( 0.8, 0.56, f'{lfc_hgt:~P}')
    #plt.figtext( 0.65, 0.54, 'MLLR:')
    #plt.figtext( 0.8, 0.54, f'{lr_700_500:~P}')
    plt.figtext( 0.65, 0.54, 'SBCAPE:')
    plt.figtext( 0.8, 0.54, f'{sbcape:~P}')
    plt.figtext( 0.65, 0.52, 'SBCIN:')
    plt.figtext( 0.8, 0.52, f'{sbcin:~P}')
    plt.figtext( 0.65, 0.50, 'MLCAPE:')
    plt.figtext( 0.8, 0.50, f'{mlcape:~P}')
    plt.figtext( 0.65, 0.48, 'MLCIN:')
    plt.figtext( 0.8, 0.48, f'{mlcin:~P}')
    plt.figtext( 0.65, 0.46, 'MUCAPE:')
    plt.figtext( 0.8, 0.46, f'{mucape:~P}')
    plt.figtext( 0.65, 0.44, 'Shear 0-1 km:')
    plt.figtext( 0.8, 0.44, f'{shear01:~P}')
    plt.figtext( 0.65, 0.42, 'Shear 0-6 km:')
    plt.figtext( 0.8, 0.42, f'{shear06:~P}')
    plt.figtext( 0.65, 0.40, 'SRH 0-1 km:')
    plt.figtext( 0.8, 0.40, f'{srh_01:~P}')
    plt.figtext( 0.65, 0.38, 'SRH 0-3 km:')
    plt.figtext( 0.8, 0.38, f'{srh_03:~P}')
    plt.figtext( 0.65, 0.36, 'EHI 0-1 km:')
    plt.figtext( 0.8, 0.36, f'{ehi_01:~P}')
    plt.figtext( 0.65, 0.34, 'EHI 0-3 km:')
    plt.figtext( 0.8, 0.34, f'{ehi_03:~P}')
    plt.figtext( 0.65, 0.32, 'SCP:')
    plt.figtext( 0.8, 0.32, f'{scp:~P}')
    plt.figtext( 0.65, 0.30, 'SIGTOR (FL):')
    plt.figtext( 0.8, 0.30, f'{sig_tor:~P}')

    # Mask velocities to below 10 km only
    mask = z <= 10*units.km

    # Custom colorscale for the wind profile
    intervals = np.array([0, 1, 3, 5, 10]) * units.km
    colors = ['tab:red', 'tab:green', 'tab:blue', 'tab:olive']

    # Create a hodograph
    ax1 = ax.add_subplot(gs[0,-1])
    h = Hodograph(ax1, component_range=40.)
    h.add_grid(increment=5)
    u1 = u.to(units('m/s'))
    v1 = v.to(units('m/s'))
    h.plot_colormapped(u1[mask], v1[mask], z[mask], intervals=intervals, colors=colors)

    return skew
4

1 回答 1

0

metpy.calc.significant_tornado正在将标量值转换为单值 ndarray 并返回它们,以便您打印带有括号的 ndarray 字符串。当前,您应该能够更新您的文本字符串行以plt.figtext( 0.8, 0.30, f'{sig_tor[0]:~P}')在此处单独打印该值。

于 2020-07-20T17:27:43.663 回答