2

NCEP data is from this website. I want to plot a picture like this: wind field and heights Or this one(this one add trough lines): wind field and heights

My data is different from them, so the content is different. But, the method should be the same.

I dont't know how to smooth the line. This is my result: my_picture

Here is my code:

import numpy as np
import scipy
import matplotlib.pyplot as plt
from netCDF4 import Dataset
from scipy.interpolate import Rbf
from scipy.ndimage import zoom 
from mpl_toolkits.basemap import Basemap

m=Basemap(projection='cyl',llcrnrlat=20,urcrnrlat=50,llcrnrlon=90,urcrnrlon=130)

CHNshp = 'D:\python\shapefile\data\CHN_adm_shp\CHN_adm1'
m.readshapefile(CHNshp,'CHN',drawbounds = False)
TWNshp = 'D:\python\shapefile\data\TWN_adm_shp\TWN_adm0'
m.readshapefile(TWNshp,'TWN',drawbounds = False)

for info, shape in zip(m.CHN_info, m.CHN):
        x, y = zip(*shape) 
        m.plot(x, y, marker=None,color='k',linewidth = 0.5)
for info, shape in zip(m.TWN_info, m.TWN):
        x, y = zip(*shape) 
        m.plot(x, y, marker=None,color='k',linewidth = 0.5)

parallels = np.arange(-90.,91.,10.)
m.drawparallels(parallels,labels=[1,0,0,1],linewidth=0.5,xoffset=1.2)
meridians = np.arange(-180.,181.,10.)
m.drawmeridians(meridians,labels=[1,0,0,1],linewidth=0.5,yoffset=1.2)

u=Dataset(r'D:\python\TRY\ncep\uwnd.2016.nc','r')
v=Dataset(r'D:\python\TRY\ncep\vwnd.2016.nc','r')
hgt_data=Dataset(r'D:\python\TRY\ncep\hgt.2016.nc','r')

uwnd=u.variables['uwnd'][728][2][:]
vwnd=v.variables['vwnd'][728][2][:]
hgt=hgt_data.variables['hgt'][728][2][:]
lat=u.variables['lat'][:]
lon=u.variables['lon'][:]

index1=np.logical_and(lon>=90,lon<=130);index2=np.logical_and(lat>=20,lat<=50)
lons=lon[index1];lats=lat[index2]
u1=uwnd[index2,:];u2=u1[:,index1]
v1=vwnd[index2,:];v2=v1[:,index1]
hgt1=hgt[index2,:];hgt2=hgt1[:,index1]

nx,ny=np.meshgrid(lons,lats)
x,y=m(nx,ny)
Q = m.quiver(x,y,u2,v2,scale=250,width=0.003)
qk = plt.quiverkey(Q, 0.85, -0.12, 20, '20 m/s', labelpos='N')

rbf = scipy.interpolate.Rbf(x, y, hgt2)
zi = rbf(x, y)
plt.contour(x,y,zi,color='k')

plt.show()

Update:

lons = zoom(lons,3,order=3)
lats = zoom(lats,3,order=3)
x,y  = np.meshgrid(lons,lats,copy=False)
hgt2 = zoom(hgt2,3,order=3)
cs = plt.contour(x,y,hgt2,levels=levels,colors='k',linewidths=0.7)

1 Answer 1

2

Have a look at the examples for the contour() function on the matplotlib site https://matplotlib.org/examples/pylab_examples/contour_demo.html

Heres how they generate the x and y coordinates for this plot:

delta = 0.025
x = np.arange(-3.0, 3.0, delta)
y = np.arange(-2.0, 2.0, delta)
X, Y = np.meshgrid(x, y)

What you need to do is increase the resolution for your lons and lats fields which you use in the meshgrid() function in your own program.

higher resolution -> smoother lines

Sign up to request clarification or add additional context in comments.

1 Comment

But, How to get the corresponding 'hgt'?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.