Skewt复合参数问题

我正在绘制一些包含某些合成参数的观测到的测深图,但是我对STP输出有一个小问题:它总是带有方括号。

我试图检查是否有统一的因素造成这种情况,但我没有发现任何错误。

想法?

Skewt复合参数问题

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

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,Td)
    ml_cape,ml_cin = mpcalc.mixed_layer_cape_cin(p,Td)
    mu_cape,mu_cin = mpcalc.most_unstable_cape_cin(p,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,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,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,depth = 3000 * units.meter,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,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,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,'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,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,markerfacecolor='blue')

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

    # Shade CAPE
    skew.shade_cape(p,prof)

    # Shade CIN
    skew.shade_cin(p,prof)

    # Plot the freezing layer isotherms
    skew.ax.axvline(0,color='c',linestyle='--',linewidth=1)
    skew.ax.axvline(-20,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,f'{lcl_hgt:~P}')
    plt.figtext( 0.65,0.56,'LFC Height:')
    plt.figtext( 0.8,f'{lfc_hgt:~P}')
    #plt.figtext( 0.65,0.54,'MLLR:')
    #plt.figtext( 0.8,f'{lr_700_500:~P}')
    plt.figtext( 0.65,'SBCAPE:')
    plt.figtext( 0.8,f'{sbcape:~P}')
    plt.figtext( 0.65,0.52,'SBCIN:')
    plt.figtext( 0.8,f'{sbcin:~P}')
    plt.figtext( 0.65,0.50,'MLCAPE:')
    plt.figtext( 0.8,f'{mlcape:~P}')
    plt.figtext( 0.65,0.48,'MLCIN:')
    plt.figtext( 0.8,f'{mlcin:~P}')
    plt.figtext( 0.65,0.46,'MUCAPE:')
    plt.figtext( 0.8,f'{mucape:~P}')
    plt.figtext( 0.65,0.44,'Shear 0-1 km:')
    plt.figtext( 0.8,f'{shear01:~P}')
    plt.figtext( 0.65,0.42,'Shear 0-6 km:')
    plt.figtext( 0.8,f'{shear06:~P}')
    plt.figtext( 0.65,0.40,'SRH 0-1 km:')
    plt.figtext( 0.8,f'{srh_01:~P}')
    plt.figtext( 0.65,0.38,'SRH 0-3 km:')
    plt.figtext( 0.8,f'{srh_03:~P}')
    plt.figtext( 0.65,0.36,'EHI 0-1 km:')
    plt.figtext( 0.8,f'{ehi_01:~P}')
    plt.figtext( 0.65,0.34,'EHI 0-3 km:')
    plt.figtext( 0.8,f'{ehi_03:~P}')
    plt.figtext( 0.65,0.32,'SCP:')
    plt.figtext( 0.8,f'{scp:~P}')
    plt.figtext( 0.65,0.30,'SIGTOR (FL):')
    plt.figtext( 0.8,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
iCMS 回答:Skewt复合参数问题

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

本文链接:https://www.f2er.com/1934840.html

大家都在问