def find_corners(temps, press=1.e3, skew=30.): """ convert a pair of temperatures into skew plotting coordinates at a constant pressure level Parameters ---------- temps : [float] xaxis corner temperatures (degC) press : float pressure level for skew conversion skew : float coefficient to use in the tempToSkew conversion Returns ------- corners : [float] x axis corners in plotting coordinates """ corners = convertTempToSkew(temps, press, skew) return list(corners)
def makePlot(ax,Temp=None,Tdew=None,Tpseudo=None,press=None,Tlcl=None,pLCL=None,botLabel='LCL bot (835 hPa)',topLabel='LCL top (768 hPa)'): """ Draw a tephigram of a convectively unstable layer with Temp, Tdew, Tpseudo soundings, as well as the LCL of the top and the bottom of the layer """ xplot = convertTempToSkew(Tlcl[0] - c.Tc, pLCL[0] * pa2hPa, skew) bot, = ax.plot(xplot, pLCL[0] * pa2hPa, 'ro', markersize=12, markerfacecolor='r',label=botLabel) xplot = convertTempToSkew(Tlcl[-1] - c.Tc, pLCL[-1] * pa2hPa, skew) top, = ax.plot(xplot, pLCL[-1] * pa2hPa,'bd', markersize=12, markerfacecolor='b',label = topLabel) xplot = convertTempToSkew(Tpseudo - c.Tc, press, skew) thetaEhandle, = ax.plot(xplot, press, 'c-', linewidth=2.5,label=r'$\theta_e$') xplot1 = convertTempToSkew(Temp - c.Tc, press, skew) Thandle, = ax.plot(xplot1, press, 'k-', linewidth=2.5,label='Temp (deg C)') xplot2 = convertTempToSkew(Tdew - c.Tc, press, skew) TdHandle, = ax.plot(xplot2, press, 'b--', linewidth=2.5,label='Dewpoint (deg C)') ax.legend(loc='best',numpoints=1) base=press[0] title_string = 'convectively unstable sounding: base at {} hPa'.format(base) ax.set_title(title_string) return ax
title='{} at {}'.format(location,times[0][2:]) print('title: :',title) units=attributes['units'].split(';') units_dict={} for count,var in enumerate(sounding.columns): units_dict[var]=units[count] # In[7]: skew=30. triplets=zip(sounding['temp'],sounding['dwpt'],sounding['pres']) xcoord_T=[] xcoord_Td=[] for a_temp,a_dew,a_pres in triplets: xcoord_T.append(convertTempToSkew(a_temp,a_pres,skew)) xcoord_Td.append(convertTempToSkew(a_dew,a_pres,skew)) # In[8]: get_ipython().magic('matplotlib inline') skew=30 plt.close('all') fig,ax =plt.subplots(1,1,figsize=(8,8)) corners=[-15,35] ax,skew = makeSkewWet(ax,corners=corners,skew=skew) ax.plot(xcoord_T,sounding['pres'],color='k',label='temp') ax.plot(xcoord_Td,sounding['pres'],color='g',label='dew') [line.set(linewidth=3) for line in ax.lines[-2:]] out=ax.set(title=title)
def makeSkewDry(ax, skew=30): """ draw a skew-T lnP diagram on an axis Parameters ---------- ax : matplotlib.axes matplotlib figure axis skew : float adjustable coefficient to make isotherms slope compared to adiabats Returns ------- ax : matplotlib.axes the modified figure axis skew : float skew coefficient (K) """ yplot = range(1000, 190, -10) xplot = range(-300, -139) pvals = np.size(yplot) tvals = np.size(xplot) temp = np.zeros([pvals, tvals]) theTheta = np.zeros([pvals, tvals]) # lay down a reference grid that labels xplot,yplot points # in the new (skewT-lnP) coordinate system . # Each value of the temp matrix holds the actual (data) # temperature label (in deg C) of the xplot, yplot coordinate. # pairs. The transformation is given by W&H 3.56, p. 78. Note # that there is a sign difference, because rather than # taking y= -log(P) like W&H, I take y= +log(P) and # then reverse the y axis for i in yplot: for j in xplot: # Note that we don't have to transform the y # coordinate, as it is still pressure. iInd = yplot.index(i) jInd = xplot.index(j) temp[iInd, jInd] = convertSkewToTemp(j, i, skew) Tk = c.Tc + temp[iInd, jInd] pressPa = i * 100. theTheta[iInd, jInd] = find_theta(Tk, pressPa) # # Contour the temperature matrix. # # First, make sure that all plotted lines are solid. mpl.rcParams['contour.negative_linestyle'] = 'solid' tempLabels = range(-40, 50, 10) tempLevs = ax.contour(xplot, yplot, temp, tempLabels, \ colors='k') # # Customize the plot # ax.set_yscale('log') locs = np.array(range(100, 1100, 100)) labels = locs ax.set_yticks(locs) ax.set_yticklabels(labels) # Conventionally labels semilog graph. ax.set_ybound((200, 1000)) plt.setp(ax.get_xticklabels(), weight='bold') plt.setp(ax.get_yticklabels(), weight='bold') ax.yaxis.grid(True) thetaLabels = list(range(200, 390, 10)) thetaLevs = ax.contour(xplot, yplot, theTheta, thetaLabels, \ colors='b') # Transform the temperature,dewpoint from data coords to # plotting coords. ax.set_title('skew T - lnp chart') ax.set_ylabel('pressure (hPa)') ax.set_xlabel('temperature (deg C)') # # Crop image to a more usable size # TempTickLabels = range(-15, 40, 5) TempTickCoords = TempTickLabels skewTickCoords = convertTempToSkew(TempTickCoords, 1.e3, skew) ax.set_xticks(skewTickCoords) ax.set_xticklabels(TempTickLabels) skewLimits = convertTempToSkew([-15, 35], 1.e3, skew) ax.axis([skewLimits[0], skewLimits[1], 300, 1.e3]) # # Create line labels # fntsz = 9 # Handle for 'fontsize' of the line label. ovrlp = True # Handle for 'inline'. Any integer other than 0 # creates a white space around the label. tempLevs.clabel(inline=ovrlp, inline_spacing=0, fmt='%2d', fontsize=fntsz, use_clabeltext=True) thetaLevs.clabel(inline=ovrlp, inline_spacing=0, fmt='%5d', fontsize=fntsz, use_clabeltext=True) ax.invert_yaxis() ax.figure.canvas.draw() return ax, skew
def makeSkewWet(ax, corners=[-30, 25], skew=30): """ draw a skew-T lnP diagram on an axis Parameters ---------- ax : matplotlib.axes matplotlib figure axis corners : [float] x axis temperature limits (degC) skew : float adjustable coefficient to make isotherms slope compared to adiabats Returns ------- ax : matplotlib.axes the modified figure axis """ yplot = range(1000, 190, -6) # xcorners = find_corners(corners, skew=skew) xplot = list(np.linspace(xcorners[0], xcorners[1], 45)) pvals = np.size(yplot) tvals = np.size(xplot) temp = np.zeros([pvals, tvals]) theTheta = np.zeros_like(temp) the_rsat = np.zeros_like(temp) theThetae = np.zeros([pvals, tvals]) # lay down a reference grid that labels xplot,yplot points # in the new (skewT-lnP) coordinate system . # Each value of the temp matrix holds the actual (data) # temperature label (in deg C) of the xplot, yplot coordinate. # pairs. The transformation is given by W&H 3.56, p. 78. Note # that there is a sign difference, because rather than # taking y= -log(P) like W&H, I take y= +log(P) and # then reverse the y axis for presshPa in yplot: #loop over pressures for skewed in xplot: #loop over skewed xcoords # Note that we don't have to transform the y # coordinate, as it is still pressure. iInd = yplot.index(presshPa) jInd = xplot.index(skewed) temp[iInd, jInd] = convertSkewToTemp(skewed, presshPa, skew) Tk = c.Tc + temp[iInd, jInd] pressPa = presshPa * 100. theTheta[iInd, jInd] = find_theta(Tk, pressPa) rs = find_rsat(Tk, pressPa) the_rsat[iInd, jInd] = rs theThetae[iInd, jInd] = find_thetaet(Tk,rs,Tk, pressPa) # # Contour the temperature matrix. # # First, make sure that all plotted lines are solid. mpl.rcParams['contour.negative_linestyle'] = 'solid' tempLabels = range(-40, 50, 5) ax.contour(xplot, yplot, temp, tempLabels, \ colors='k') # # contour theta # thetaLabels = list(range(200, 390, 10)) thetaLevs = ax.contour(xplot, yplot, theTheta, thetaLabels, \ colors='b') # # contour rsat # rsLabels = [0.1, 0.25, 0.5, 1, 2, 3] + list(range(4, 28, 2)) #+ [26, 28] rsLevs = ax.contour(xplot, yplot, the_rsat * 1.e3, levels=rsLabels, colors='g', linewidths=.5) thetaeLabels = np.arange(250, 410, 10) thetaeLevs = ax.contour(xplot, yplot, theThetae, thetaeLabels, \ colors='r') # # Customize the plot # ax.set_yscale('log') locs = np.array(range(100, 1100, 100)) labels = locs ax.set_yticks(locs) ax.set_yticklabels(labels) # Conventionally labels semilog graph. ax.set_ybound((200, 1000)) plt.setp(ax.get_xticklabels(), weight='bold') plt.setp(ax.get_yticklabels(), weight='bold') ax.yaxis.grid(True) ax.set_title('skew T - lnp chart') ax.set_ylabel('pressure (hPa)') ax.set_xlabel('temperature (deg C)') # # Crop image to a more usable size # TempTickLabels = range(-30, 40, 5) TempTickCoords = TempTickLabels skewTickCoords = convertTempToSkew(TempTickCoords, 1.e3, skew) ax.set_xticks(skewTickCoords) ax.set_xticklabels(TempTickLabels) skewLimits = convertTempToSkew([-15, 35], 1.e3, skew) ax.axis([skewLimits[0], skewLimits[1], 300, 1.e3]) # # Create line labels # fntsz = 9 # Handle for 'fontsize' of the line label. ovrlp = True # Handle for 'inline'. Any integer other than 0 # creates a white space around the label. #tempLevs.clabel(inline=ovrlp, inline_spacing=0,fmt='%2d', fontsize=fntsz,use_clabeltext=True) thetaLevs.clabel(inline=ovrlp, inline_spacing=0, fmt='%3d', fontsize=fntsz, use_clabeltext=True) rsLevs.clabel(inline=ovrlp, inline_spacing=0, fmt='%3.2g', fontsize=fntsz, use_clabeltext=True) thetaeLevs.clabel(thetaeLabels, inline_spacing=0, inline=ovrlp, fmt='%5g', fontsize=fntsz, use_clabeltext=True) ax.invert_yaxis() #ax.figure.canvas.draw() xcorners = find_corners(corners, skew=skew) ax.set(ylim=(1000, 300), xlim=xcorners) return ax, skew
def makeSkewWet(ax, corners=[-30, 25], skew=30): """ draw a skew-T lnP diagram on an axis Parameters ---------- ax : matplotlib.axes matplotlib figure axis corners : [float] x axis temperature limits (degC) skew : float adjustable coefficient to make isotherms slope compared to adiabats Returns ------- ax : matplotlib.axes the modified figure axis """ yplot = range(1000, 190, -6) # xcorners = find_corners(corners, skew=skew) xplot = list(np.linspace(xcorners[0], xcorners[1], 45)) pvals = np.size(yplot) tvals = np.size(xplot) temp = np.zeros([pvals, tvals]) theTheta = np.zeros_like(temp) the_rsat = np.zeros_like(temp) theThetae = np.zeros([pvals, tvals]) # lay down a reference grid that labels xplot,yplot points # in the new (skewT-lnP) coordinate system . # Each value of the temp matrix holds the actual (data) # temperature label (in deg C) of the xplot, yplot coordinate. # pairs. The transformation is given by W&H 3.56, p. 78. Note # that there is a sign difference, because rather than # taking y= -log(P) like W&H, I take y= +log(P) and # then reverse the y axis for presshPa in yplot: #loop over pressures for skewed in xplot: #loop over skewed xcoords # Note that we don't have to transform the y # coordinate, as it is still pressure. iInd = yplot.index(presshPa) jInd = xplot.index(skewed) temp[iInd, jInd] = convertSkewToTemp(skewed, presshPa, skew) Tk = c.Tc + temp[iInd, jInd] pressPa = presshPa * 100. theTheta[iInd, jInd] = find_theta(Tk, pressPa) rs = find_rsat(Tk, pressPa) the_rsat[iInd, jInd] = rs theThetae[iInd, jInd] = find_thetaet(Tk, rs, Tk, pressPa) # # Contour the temperature matrix. # # First, make sure that all plotted lines are solid. mpl.rcParams['contour.negative_linestyle'] = 'solid' tempLabels = range(-40, 50, 10) ax.contour(xplot, yplot, temp, tempLabels, \ colors='k') # # contour theta # thetaLabels = list(range(200, 390, 10)) thetaLevs = ax.contour(xplot, yplot, theTheta, thetaLabels, \ colors='b') # # contour rsat # rsLabels = [0.1, 0.25, 0.5, 1, 2, 3] + list(range(4, 28, 2)) #+ [26, 28] rsLevs = ax.contour(xplot, yplot, the_rsat * 1.e3, levels=rsLabels, colors='g', linewidths=.5) thetaeLabels = np.arange(250, 410, 10) thetaeLevs = ax.contour(xplot, yplot, theThetae, thetaeLabels, \ colors='r') # # Customize the plot # ax.set_yscale('log') locs = np.array(range(100, 1100, 100)) labels = locs ax.set_yticks(locs) ax.set_yticklabels(labels) # Conventionally labels semilog graph. ax.set_ybound((200, 1000)) plt.setp(ax.get_xticklabels(), weight='bold') plt.setp(ax.get_yticklabels(), weight='bold') ax.yaxis.grid(True) ax.set_title('skew T - lnp chart') ax.set_ylabel('pressure (hPa)') ax.set_xlabel('temperature (deg C)') # # Crop image to a more usable size # TempTickLabels = range(-30, 40, 5) TempTickCoords = TempTickLabels skewTickCoords = convertTempToSkew(TempTickCoords, 1.e3, skew) ax.set_xticks(skewTickCoords) ax.set_xticklabels(TempTickLabels) skewLimits = convertTempToSkew([-15, 35], 1.e3, skew) ax.axis([skewLimits[0], skewLimits[1], 300, 1.e3]) # # Create line labels # fntsz = 9 # Handle for 'fontsize' of the line label. ovrlp = True # Handle for 'inline'. Any integer other than 0 # creates a white space around the label. #tempLevs.clabel(inline=ovrlp, inline_spacing=0,fmt='%2d', fontsize=fntsz,use_clabeltext=True) thetaLevs.clabel(inline=ovrlp, inline_spacing=0, fmt='%3d', fontsize=fntsz, use_clabeltext=True) rsLevs.clabel(inline=ovrlp, inline_spacing=0, fmt='%3.2g', fontsize=fntsz, use_clabeltext=True) thetaeLevs.clabel(thetaeLabels, inline_spacing=0, inline=ovrlp, fmt='%5g', fontsize=fntsz, use_clabeltext=True) ax.invert_yaxis() #ax.figure.canvas.draw() xcorners = find_corners(corners, skew=skew) ax.set(ylim=(1000, 300), xlim=xcorners) return ax, skew
press = np.arange(Pbot, Ptop - 10, -10) Temp = (Tbot + slope * (press - Pbot)) slope = (Tdewtop - Tdewbot) / (Ptop - Pbot) Tdew = (Tdewbot + slope * (press - Pbot)) # #figure 1: plot the T,Tdew profile only # plt.close('all') fig, ax = plt.subplots(1, 1, figsize=(10, 10)) ax, skew = makeSkewWet(ax,corners=[5,25]) #zoom the axis to focus on layer skewLimits = convertTempToSkew([5, 25], 1.e3, skew) ax.axis([skewLimits[0], skewLimits[1], 1000, 600]) xplot1 = convertTempToSkew(Temp, press, skew) #plot() returns a list of handles for each line plotted Thandle, = ax.plot(xplot1, press, 'k-', linewidth=2.5,label='Temp (deg C)') xplot2 = convertTempToSkew(Tdew, press, skew) TdHandle, = ax.plot(xplot2, press, 'b--', linewidth=2.5,label='Dewpoint (deg C)') ax.set_title('convectively unstable sounding: base at 900 hPa') ax.legend(numpoints=1,loc='best') fig.savefig('initial_sound.png') fig.savefig('initial_sound.pdf') # # figure 2, add thetae sounding and LCL for layer top and bottom #
tempB=tempA term1=(thetaB/tempB)**(c.cpd/c.Rd) term1=1./term1 pressB=term1*1.e5 tempD=tempC thetaD=thetaA term1=(thetaD/tempD)**(c.cpd/c.Rd) term1=1./term1 pressD=term1*1.e5 plt.close('all') fig,ax = plt.subplots(1,1) corners = [5,30] ax, skew = makeSkewWet(ax,corners=corners) xtempA=convertTempToSkew(tempA - c.Tc,pressA*0.01,skew) xtempB=convertTempToSkew(tempB - c.Tc,pressB*0.01,skew) xtempC=convertTempToSkew(tempC - c.Tc,pressC*0.01,skew) xtempD=convertTempToSkew(tempD - c.Tc,pressD*0.01,skew) ax.text(xtempA,pressA*0.01,'A', fontweight='bold',fontsize= 22, color='b') ax.text(xtempB,pressB*0.01,'B', fontweight='bold',fontsize= 22,color='b') ax.text(xtempC,pressC*0.01,'C', fontweight='bold',fontsize= 22,color='b') ax.text(xtempD,pressD*0.01,'D', fontweight='bold',fontsize= 22, color='b') xmin = convertTempToSkew(corners[0],pressA*0.01,skew) xmax = convertTempToSkew(corners[1],pressA*0.01,skew) ax.axis([xmin, xmax, 1000, 600]) ax.set_title('forward carnot cycle') plt.show()
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) xplot=convertTempToSkew(A_tup.temp - c.Tc,A_tup.press*pa2hPa,skew) bot=ax.plot(xplot, A_tup.press*pa2hPa-10., 'ko', markersize=14, markerfacecolor='k') ax.text(xplot,A_tup.press*pa2hPa-20.,'A',fontsize=30) pressrange=np.arange(1000,395.,-10.) trop_adiabat=[] for press in pressrange: temp,rv,rl = tinvert_thetae(A_thetae,A_tup.rt,press*1.e2) xtemp = convertTempToSkew(temp - c.Tc,press,skew) trop_adiabat.append(xtemp) ax.plot(trop_adiabat,pressrange,'r-',lw=10) B_press=400.e2 #Pa temp,rv,rl = tinvert_thetae(thetae_trop,A_tup.rt,B_press) rl = 0.2*rl #rain out 80% of liquid B_dict = dict(zip(fields,('B',temp,rv,rl,B_press))) ax.text(trop_adiabat[-1],B_press*pa2hPa,'B',fontsize=30) B_tup = calc_enthalpy(B_dict)
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) Tdew_700 = Temp_700 rv_700=find_rsat(Temp_700,press) print("temp,Tdew, rv at LCL press: {} hPa: {} C {} C {} kg/kg" .format(n(press*1.e-2),e(k2c(Temp_700)),e(k2c(Tdew_700)),e(rv_700))) # get the temperature and dewpoint at 800 hPa #