VERTICAL CROSS SECTION , Y AXIS is in PRESSURE(mb)

350 views
Skip to first unread message

miranti indri

unread,
Sep 28, 2020, 10:50:02 AM9/28/20
to wrfpython-talk
hii i want to ask about vertical cross section, i want my y axis is in vertcal cross section is in pressure(mb) not in meter, how can i do that ?
im so i thank you if someone can answer my question

Daniel Russell

unread,
Sep 28, 2020, 11:49:03 AM9/28/20
to wrfpython-talk, mynamei...@gmail.com
You can use wrf-python to get the pressure variable. 

You can also give it units at the end for your mb preference. 

or you can use....

miranti indri

unread,
Sep 28, 2020, 11:59:09 AM9/28/20
to wrfpython-talk, daniels...@gmail.com, miranti indri
thank you for answering daniels
i already try here is my code,

import numpy as np
import matplotlib.pyplot as plt
from matplotlib.cm import get_cmap
#import cartopy.crs as crs
#from cartopy.feature import NaturalEarthFeature
from netCDF4 import Dataset

from wrf import to_np, getvar, CoordPair, vertcross

# Open the NetCDF file
ncfile = Dataset("/home/mirantindri/python/WRFOUT/wrfout_d03_2020-08-09_03:00:00")

# Extract the model height and wind speed
p = getvar(ncfile, "pressure")
z = getvar(ncfile, "z")
wspd =  getvar(ncfile, "uvmet_wspd_wdir", units="kt")[0,:]
dbz=getvar(ncfile, "dbz")
u=getvar(ncfile,"ua")
omega=getvar(ncfile,"omega")

# Create the start point and end point for the cross section
start_point = CoordPair(lat=36.618779, lon=124.0)
end_point = CoordPair(lat=37.0, lon=126.0)

# Compute the vertical cross-section interpolation.  Also, include the
# lat/lon points along the cross-section.
u = vertcross(u, p, wrfin=ncfile, start_point=start_point,
                       end_point=end_point, latlon=True, meta=True)

omega = vertcross(omega, p, wrfin=ncfile, start_point=start_point,
                       end_point=end_point, latlon=True, meta=True)

# Create the figure
fig = plt.figure(figsize=(12,6))
ax = plt.axes()

# Make the contour plot
cont = ax.contour(to_np(u),levels=np.arange(-5,35,5,dtype=int),colors='black')
plt.clabel(cont, inline=1, fontsize=10,fmt='%d')

shade = ax.contourf(to_np(omega), cmap=get_cmap("jet"))

# Add the color bar
plt.colorbar(shade, ax=ax)

# Set the x-ticks to use latitude and longitude labels.
coord_pairs = to_np(u.coords["xy_loc"])
x_ticks = np.arange(coord_pairs.shape[0])
x_labels = [pair.latlon_str(fmt="{:.2f}, {:.2f}")
            for pair in to_np(coord_pairs)]
ax.set_xticks(x_ticks[::20])
ax.set_xticklabels(x_labels[::20], rotation=45, fontsize=8)

# Set the y-ticks to be height.
vert_vals = to_np(u.coords["vertical"])
v_ticks = np.arange(vert_vals.shape[0])
ax.set_yticks(v_ticks[::15])
ax.set_yticklabels(vert_vals[::15],fontsize=8)

# Set the x-axis and  y-axis labels
ax.set_xlabel("Latitude, Longitude", fontsize=12)
ax.set_ylabel("Pressure(mb)", fontsize=12)

plt.title("Vertical Cross Section of Wind Speed (kt)")
plt.savefig('/home/mirantindri/python/case20200822/VERTCROSS_WS_0822.png', dpi=500)

plt.show()

BUT now i want to edit my yticks labels like this, do you know how to make like that ?

thank you in advance..
Capture.PNG

Daniel Russell

unread,
Sep 28, 2020, 1:27:06 PM9/28/20
to wrfpython-talk, mynamei...@gmail.com
I am not sure what you are trying to get to, but it seems like you are almost there.

You're setting your yticks in the below code:
vert_vals = to_np(u.coords["vertical"])
v_ticks = np.arange(vert_vals.shape[0])
ax.set_yticks(v_ticks[::15]) #You are only using every 15th tick mark in your pressure field. 
ax.set_yticklabels(vert_vals[::15],fontsize=8)


You can create a new variable that has more common values (1000,925, 850,700, etc. ) and mark the ticks using the new variable. 

Miranti Indri Hastuti

unread,
Sep 28, 2020, 8:55:19 PM9/28/20
to wrfpython-talk, daniels...@gmail.com, mynamei...@gmail.com
yes, youre right,  i want to make yticks with values (1000,925,850,700,etc) but i couldn't make it..

and i found that array in vert_vals is like this which is there is no values that i want.
array([990. , 980.7, 971.4, 962.1, 952.8, 943.5, 934.2, 924.9, 915.6, 906.3, 897. , 887.7, 878.4, 869.1, 859.8, 850.5, 841.2, 831.9, 822.6, 813.3, 804. , 794.7, 785.4, 776.1, 766.8, 757.5, 748.2, 738.9, 729.6, 720.3, 711. , 701.7, 692.4, 683.1, 673.8, 664.5, 655.2, 645.9, 636.6, 627.3, 618. , 608.7, 599.4, 590.1, 580.8, 571.5, 562.2, 552.9, 543.6, 534.3, 525. , 515.7, 506.4, 497.1, 487.8, 478.5, 469.2, 459.9, 450.6, 441.3, 432. , 422.7, 413.4, 404.1, 394.8, 385.5, 376.2, 366.9, 357.6, 348.3, 339. , 329.7, 320.4, 311.1, 301.8, 292.5, 283.2, 273.9, 264.6, 255.3, 246. , 236.7, 227.4, 218.1, 208.8, 199.5, 190.2, 180.9, 171.6, 162.3, 153. , 143.7, 134.4, 125.1, 115.8, 106.5, 97.2, 87.9, 78.6, 69.3], dtype=float32)  

Daniel Russell

unread,
Sep 29, 2020, 11:30:06 AM9/29/20
to wrfpython-talk, miranti...@gmail.com, Daniel Russell, mynamei...@gmail.com
Create a new variable (making a list below) and set the ticks based on whatever values you want to use. 
new_yticks = [1000,925,850,700,500,300,200,100,50,10]
ax.set_yticks(new_yticks)  
Reply all
Reply to author
Forward
0 new messages