Пример #1
0
def make_plot(df_result,df_sounding,interpPress):
    """ return two plots with the vertical velocity and temperature profiles

    Parameters
    ----------
    df_result: dataframe
          dataframe containing wvel (m/s) ,cloud_height (m) , thetae (K), rT (kg/kg) for assending parcel

    df_sounding: pandas dataframe 
               : sounding columns are temperature (deg C), dewpoint (deg C), height (m), press (hPa)

    interpPress: func
            :    interp1d function for presusure  p(z)

    Returns
    -------
    ax1,ax2: matplotlib axes
           : plotting axis for the two figures
    """
    plt.style.use('ggplot')
    fig,ax1 = plt.subplots(1,1)
    ax1.plot(df_result['wvel'], df_result['cloud_height'], label='wvel')
    ax1.set_xlabel('vertical velocity (m/s)')
    ax1.set_ylabel('height above surface (m)')


    Tcloud = np.zeros_like(df_result['cloud_height'])
    rvCloud = np.zeros_like(df_result['cloud_height'])
    rlCloud = np.zeros_like(df_result['cloud_height'])

    for i,row in enumerate(df_result.iterrows()):
        the_press = interpPress(row[1]['cloud_height'])*100.
        Tcloud[i], rvCloud[i], rlCloud[i] = tinvert_thetae(row[1]['thetae_cloud'], 
                                                        row[1]['rT_cloud'], the_press)
        
    Tadia= np.zeros_like(df_result['cloud_height'])
    rvAdia = np.zeros_like(df_result['cloud_height'])
    rlAdia = np.zeros_like(df_result['cloud_height'])
    

    heights=df_result['cloud_height']
    thetae_cloud0 = df_result.loc[0,'thetae_cloud']
    rT_cloud0 = df_result.loc[0,'rT_cloud']
    for i, height in enumerate(heights):
        the_press = interpPress(height)*100.
        Tadia[i], rvAdia[i], rlAdia[i] = tinvert_thetae(thetae_cloud0, 
                                                      rT_cloud0, the_press)
    
    fig,ax2=plt.subplots(1,1)
    ax2.plot(Tcloud - c.Tc, df_result['cloud_height'], 'r-',label='cloud')
    height = df_sounding['hght'].values
    temp = df_sounding['temp'].values
    ax2.plot(temp, height, 'g-',label='environment')
    ax2.plot(Tadia - c.Tc, df_result['cloud_height'], 'b-',label='moist aidabat')
    ax2.set_xlabel('temperature (deg C)')
    ax2.set_ylabel('height above surface (m)')
    ax2.legend(loc='best')
    return ax1,ax2
Пример #2
0
def lift_sounding(rTotal,theThetae,press,):
  #
  # return temp,dewpoint and Tspeudo soundings for an rT,thetae sounding at pressure levels press
  #
  numPoints, = press.shape
  for i in range(0, numPoints):
    #find the actual temperature and dewpoint
    Temp[i], rv, rl = tinvert_thetae(theThetae[i], rTotal[i], press[i] * hPa2pa)
    Tdew[i] = find_Td(rv, press[i] * hPa2pa)
    Tpseudo[i] = find_Tmoist(theThetae[i], press[i] * hPa2pa)
  return Tdew,Temp,Tpseudo
Пример #3
0
def rv_diff(press,thetae_mix,rT_mix):
    """
      the lcl is is the pressure where rv=rT_mix
      we want a difference that changes sign at cloud base
      so below cloud set rv = rsat(temp,press) and 
      rT_mix - rv will be negative below cloud base and 
      positive above cloud base
    """
    Temp, rv, rl = tinvert_thetae(thetae_mix,rT_mix,press)
    #
    # below cloud rl ~ 0, so switch to rv=rsat
    #
    if rl < 1.e-5:
        rv=find_rsat(Temp,press)
    diff = rT_mix - rv
    return diff
Пример #4
0
# In[7]:

plt.close('all')
from a405thermo.thermlib import tinvert_thetae
mix_level=np.searchsorted(clipped_press[::-1],700.e2)
index=len(clipped_press) - mix_level
mix_press = clipped_press[index]
print('pressure, {:5.3g} hPa  dewpoint {:5.3g} K , temp {:5.3g} K'      .format(clipped_press[index]*1.e-2,env_Td[index],env_temps[index]))
env_thetae = find_thetaep(env_Td[index],env_temps[index],clipped_press[index])
env_rvap = env_rvaps[index]
print('cloud thetae {:5.3f} K, env_thetae {:5.3f} K'.format(sfc_thetae,env_thetae))
fenv=np.linspace(0,1,100.)
logthetae_mix = fenv*np.log(env_thetae) + (1 - fenv)*np.log(sfc_thetae)
rTot_mix = fenv*env_rvap  + (1 - fenv)*sfc_rvap
thetae_mix = np.exp(logthetae_mix)
pairs = zip(thetae_mix,rTot_mix)
Tvlist = []
for thetae,rtot in pairs:
    temp,rv,rl = tinvert_thetae(thetae,rtot,mix_press)
    Tvlist.append(find_Tv(temp,rv,rl))
fig,ax = plt.subplots(1,1,figsize=(10,8))
ax.plot(fenv,Tvlist)
title='cloud environment mixing at {:5.2f} hPa'.format(clipped_press[index]*1.e-2)
out=ax.set(xlabel='fraction of environmental air',ylabel='Mixture Tv (K)',title=title)


# In[ ]:



Пример #5
0
    
   
get_ipython().magic('matplotlib inline')
pa2hPa = 1.e-2

A_press = 1.e5  #Pa
B_press = 4.e4  #Pa
A_temp = 300  #K
RH = 0.8
e = find_esat(A_temp)*RH
A_rv = c.eps*e/(A_press - e)
A_Td = find_Td(A_rv,A_press)
print('tropical surface dewpoint: {} K'.format(A_Td))
A_thetae=find_thetaet(A_Td,A_rv,A_temp,A_press)
print('tropical surface thetae: {} K'.format(A_thetae))
A_temp,A_rv,A_rl = tinvert_thetae(A_thetae,A_rv,A_press)
fields=['id','temp','rv','rl','press']
A_dict = dict(zip(fields,('A',A_temp,A_rv,A_rl,A_press)))
A_tup = calc_enthalpy(A_dict)
print(format_tup(A_tup))


# ### B. Lift to 400 hPa and remove 80% of the liquied water

# In[201]:

plt.close('all')
fig,ax = plt.subplots(1,1,figsize=[10,8])
ax,skew = makeSkewWet(ax,corners=[-15,35])

lcl_temp, lcl_press = find_lcl(A_Td,A_tup.temp,A_tup.press)
Пример #6
0
import a405thermo.thermlib as tl
#
# set the lcl for 900 hPa to 860 hPa and thetae to 338 K
#
press=860.e2
thetae_900=338.  #K
Temp_860=find_Tmoist(thetae_900,press)
rv_860=find_rsat(Temp_860,press)
rv_900 = rv_860  #vapor is conserved
Tdew_860=Temp_860
print("temp,Tdew,rv at LCL press:  {} hPa {} C {} C {} kg/kg"      .format(n(press*1.e-2),e(k2c(Temp_860)),e(k2c(Tdew_860)),e(rv_900)))
#
# now descend adiabatically to 900 hPa
#
press=900.e2
Temp_900,rv_900,rl_900=tinvert_thetae(thetae_900,rv_900,press)
Tdew_900=find_Td(rv_900,press)
print("temperature and dewpoint at {} hPa hPa = {} C {} C".format(n(press*1.e-2),e(k2c(Temp_900)), e(k2c(Tdew_900))))
#
#  draw these on the sounding at 900 hPa as a red circle and blue diamond
#
xplot=convertTempToSkew(Temp_900 - c.Tc,press*pa2hPa,skew)
bot=ax.plot(xplot, press*pa2hPa, 'ro', markersize=14, markerfacecolor='r')
xplot=convertTempToSkew(Tdew_900 - c.Tc,press*pa2hPa,skew)
bot=ax.plot(xplot, press*pa2hPa, 'bd', markersize=14, markerfacecolor='b')
#
#now look at an LCL of 700 hPa  -- with thetae = 332 K
#
press=700.e2
thetae_800=332.  #K
Temp_700=find_Tmoist(thetae_800,press)