一、实验目的
利用ERA5再分析资料水平风速场数据u和v,以及平均海平面气压场数据MSLP,得到典型气压层的水平风场流线图和台风移动路径图。
二、实验内容和要求
内容:
1.数据读取与选择
2.流线图绘制
3.台风中心位置判识
4.台风移动路径绘制
要求:
1.绘制某个时次的950hPa、500hPa 和 200hPa 水平风场流线图
2.实现一个简单的台风中心位置自动判识方法
3.绘制台风移动路径
(一)绘制某个时次的950hPa、500hPa 和 200hPa 水平风场流线图
import matplotlib.pyplot as plt
import netCDF4 as nc
import numpy as np
import cartopy.mpl.ticker as cmt
import cartopy.crs as ccrs
import matplotlib.path as mpath
import cartopy.feature as cfeature
from cartopy.util import add_cyclic_point
from cartopy.mpl.ticker import (LongitudeFormatter, LatitudeFormatter)
import matplotlib as mpl
import matplotlib.ticker as mticker
from matplotlib.colors import ListedColormap
plt.rcParams['font.sans-serif']= ['Microsoft YaHei'] # 设置“微软雅黑”,图上显示出中文
plt.rcParams['axes.unicode_minus'] = False # 设置中文后,解决坐标轴上负号显示问题
fu= nc.Dataset(r"era5.u_component_of_wind.20180817.nc",'r')
fv = nc.Dataset(r"era5.v_component_of_wind.20180817.nc",'r')
levels = fu.variables['level'][:]
lat = fu.variables['latitude'][:]
lon0 = fu.variables['longitude'][:]
time = nc.num2date(fu.variables['time'][:],fu.variables['time'].units).data
months = np.array([i.month for i in time])
u = fu.variables['u'][0,:,:,:]
v = fv.variables['v'][0,:,:,:]
hs=np.sqrt(u**2+v**2)
Lon, Lat = np.meshgrid(lon0,lat)
def pa(para_level):
index_level = np.where(levels==para_level)[0][0] # 改等压面
u0 = u[index_level,:,:]
v0 = v[index_level,:,:]
hs0=hs[index_level,:,:]
return u0,v0,hs0
u1,v1,hs1=pa(950)
u2,v2,hs2=pa(500)
u3,v3,hs3=pa(200)
fig = plt.figure(figsize=[15,4])
cmap = mpl.cm.viridis
norm = mpl.colors.Normalize(vmin=0, vmax=30)
#001
ax = plt.subplot(131,projection=ccrs.PlateCarree())
ax.set_extent([70,140,0,55])
ac=ax.streamplot(Lon,Lat,u3,v3,transform=ccrs.PlateCarree(),color=hs3,norm=norm,cmap=cmap,linewidth=0.5,arrowsize=0.75,density=4)
#ax.set_xticks([80,90,100,110,120,130])
#ax.set_yticks([10,20,30,40,50])
ax.xaxis.set_major_formatter(LongitudeFormatter())
ax.yaxis.set_major_formatter(LatitudeFormatter())
ax.add_feature(cfeature.LAND,color='#D3D3D3')
ax.add_feature(cfeature.OCEAN)
ax.add_feature(cfeature.COASTLINE)
ax.add_feature(cfeature.RIVERS)
ax.add_feature(cfeature.LAKES)
gl = ax.gridlines(draw_labels=True, color='gray',alpha=0.5,linestyle='--',
xlocs=np.arange(-180,181,10),ylocs=np.arange(-90,91,10),
x_inline=False,y_inline=False)
gl.top_labels=False
gl.right_labels=False
plt.title('200hPa')
#002
bx = plt.subplot(132,projection=ccrs.PlateCarree())
bx.set_extent([70,140,0,55])
ac=bx.streamplot(Lon,Lat,u2,v2,transform=ccrs.PlateCarree(),color=hs2,norm=norm,cmap=cmap,linewidth=0.5,arrowsize=0.75,density=4)
#bx.set_xticks([80,90,100,110,120,130])
#bx.set_yticks([10,20,30,40,50])
bx.xaxis.set_major_formatter(LongitudeFormatter())
bx.yaxis.set_major_formatter(LatitudeFormatter())
bx.add_feature(cfeature.LAND,color='#D3D3D3')
bx.add_feature(cfeature.OCEAN)
bx.add_feature(cfeature.COASTLINE)
bx.add_feature(cfeature.RIVERS)
bx.add_feature(cfeature.LAKES)
gl = bx.gridlines(draw_labels=True, color='gray',alpha=0.5,linestyle='--',
xlocs=np.arange(-180,181,10),ylocs=np.arange(-90,91,10),
x_inline=False,y_inline=False)
gl.top_labels=False
gl.right_labels=False
plt.title('500hPa')
#003
cx = plt.subplot(133,projection=ccrs.PlateCarree())
cx.set_extent([70,140,0,55])
ac=cx.streamplot(Lon,Lat,u1,v1,transform=ccrs.PlateCarree(),color=hs1,norm=norm,cmap=cmap,linewidth=0.5,arrowsize=0.75,density=4)
#cx.set_xticks([80,90,100,110,120,130])
#cx.set_yticks([10,20,30,40,50])
cx.xaxis.set_major_formatter(LongitudeFormatter())
cx.yaxis.set_major_formatter(LatitudeFormatter())
cx.add_feature(cfeature.LAND,color='#D3D3D3')
cx.add_feature(cfeature.OCEAN)
cx.add_feature(cfeature.COASTLINE)
cx.add_feature(cfeature.RIVERS)
cx.add_feature(cfeature.LAKES)
gl = cx.gridlines(draw_labels=True, color='gray',alpha=0.5,linestyle='--',
xlocs=np.arange(-180,181,10),ylocs=np.arange(-90,91,10),
x_inline=False,y_inline=False)
gl.top_labels=False
gl.right_labels=False
plt.title('950hPa')
###
fig.colorbar(mpl.cm.ScalarMappable(norm=norm, cmap=cmap),ax=[ax,bx,cx], label='(m/s)',shrink=0.75)
###
plt.suptitle("不同气压层水平风场流线图",fontsize='xx-large')
plt.savefig("不同气压层水平风场流线图.png",dpi=800)
plt.show()
import matplotlib.pyplot as plt
import netCDF4 as nc
import numpy as np
import cartopy.mpl.ticker as cmt
import cartopy.crs as ccrs
import matplotlib.path as mpath
import cartopy.feature as cfeature
from cartopy.util import add_cyclic_point
from cartopy.mpl.ticker import (LongitudeFormatter, LatitudeFormatter)
import matplotlib as mpl
import matplotlib.ticker as mticker
from matplotlib.colors import ListedColormap
plt.rcParams['font.sans-serif']= ['Microsoft YaHei'] # 设置“微软雅黑”,图上显示出中文
plt.rcParams['axes.unicode_minus'] = False # 设置中文后,解决坐标轴上负号显示问题
fu= nc.Dataset(r"era5.u_component_of_wind.20180817.nc",'r')
fv = nc.Dataset(r"era5.v_component_of_wind.20180817.nc",'r')
levels = fu.variables['level'][:]
lat = fu.variables['latitude'][:]
lon0 = fu.variables['longitude'][:]
time = nc.num2date(fu.variables['time'][:],fu.variables['time'].units).data
months = np.array([i.month for i in time])
u = fu.variables['u'][0,:,:,:]
v = fv.variables['v'][0,:,:,:]
hs=np.sqrt(u**2+v**2)
Lon, Lat = np.meshgrid(lon0,lat)
def pa(para_level):
index_level = np.where(levels==para_level)[0][0] # 改等压面
u0 = u[index_level,:,:]
v0 = v[index_level,:,:]
hs0=hs[index_level,:,:]
return u0,v0,hs0
u1,v1,hs1=pa(950)
u2,v2,hs2=pa(500)
u3,v3,hs3=pa(200)
fig = plt.figure(figsize=[10,10])
cmap = mpl.cm.viridis
norm = mpl.colors.Normalize(vmin=0, vmax=30)
#001
ax = plt.subplot(111,projection=ccrs.PlateCarree())
ax.set_extent([70,140,0,55])
ac=ax.streamplot(Lon,Lat,u1,v1,transform=ccrs.PlateCarree(),color=hs1,norm=norm,cmap=cmap,linewidth=1,arrowsize=0.75,density=4)
#ax.set_xticks([80,90,100,110,120,130])
#ax.set_yticks([10,20,30,40,50])
ax.xaxis.set_major_formatter(LongitudeFormatter())
ax.yaxis.set_major_formatter(LatitudeFormatter())
ax.add_feature(cfeature.LAND,color='#D3D3D3')
ax.add_feature(cfeature.OCEAN)
ax.add_feature(cfeature.COASTLINE)
ax.add_feature(cfeature.RIVERS)
ax.add_feature(cfeature.LAKES)
gl = ax.gridlines(draw_labels=True, color='gray',alpha=0.5,linestyle='--',
xlocs=np.arange(-180,181,10),ylocs=np.arange(-90,91,10),
x_inline=False,y_inline=False)
gl.top_labels=False
gl.right_labels=False
###
fig.colorbar(mpl.cm.ScalarMappable(norm=norm, cmap=cmap), label='(m/s)',shrink=0.75)
###
plt.title("950hPa水平风场流线图",fontsize='xx-large')
plt.savefig("950hPa水平风场流线图.png",dpi=800)
plt.show()
(二)台风中心位置判识
①使用MSLP全局最小值
import matplotlib.pyplot as plt
import netCDF4 as nc
import numpy as np
import cartopy.mpl.ticker as cmt
import cartopy.crs as ccrs
import matplotlib.path as mpath
import cartopy.feature as cfeature
from cartopy.util import add_cyclic_point
from cartopy.mpl.ticker import (LongitudeFormatter, LatitudeFormatter)
import matplotlib as mpl
import matplotlib.ticker as mticker
from matplotlib.colors import ListedColormap
from scipy.signal import argrelextrema
plt.rcParams['font.sans-serif']= ['Microsoft YaHei'] # 设置“微软雅黑”,图上显示出中文
plt.rcParams['axes.unicode_minus'] = False # 设置中文后,解决坐标轴上负号显示问题
fu= nc.Dataset(r"era5.u_component_of_wind.20180817.nc",'r')
fv = nc.Dataset(r"era5.v_component_of_wind.20180817.nc",'r')
fm=nc.Dataset(r"era5.mslp.20180816.nc",'r')
levels = fu.variables['level'][:]
lat = fu.variables['latitude'][:]
lon0 = fu.variables['longitude'][:]
time = nc.num2date(fu.variables['time'][:],fu.variables['time'].units).data
months = np.array([i.month for i in time])
u = fu.variables['u'][0,0,:,:]
v = fv.variables['v'][0,0,:,:]
mslp=fm.variables['msl'][:]
hs=np.sqrt(u**2+v**2)
Lon, Lat = np.meshgrid(lon0,lat)
I=[]
J=[]
for x in range(24):
a=mslp[x].min()
for i in range(len(mslp[0])):
for j in range(len(mslp[0][0])):
if mslp[x][i][j]==a:
I.append(j)
J.append(i)
fig = plt.figure(figsize=[8,8])
ax = plt.subplot(111,projection=ccrs.PlateCarree())
ax.set_extent([100,130,10,39])
LO=[]
LA=[]
for y in range(24):
LO.append(lon0[I[y]])
LA.append(lat[J[y]])
ax.plot(LO,LA,color='green')
ax.add_feature(cfeature.LAND,color='#D3D3D3')
ax.add_feature(cfeature.OCEAN)
ax.add_feature(cfeature.COASTLINE)
ax.add_feature(cfeature.RIVERS)
ax.add_feature(cfeature.LAKES)
gl = ax.gridlines(draw_labels=True, color='gray',alpha=0.5,linestyle='--',
xlocs=np.arange(-180,181,5),ylocs=np.arange(-90,91,5),
x_inline=False,y_inline=False)
gl.top_labels=False
gl.right_labels=False
plt.title("使用MSLP全局最小值",fontsize='xx-large')
plt.savefig("使用MSLP全局最小值.png",dpi=800)
plt.show()
②使用MSLP局部最小值+涡度条件
import matplotlib.pyplot as plt
import netCDF4 as nc
import numpy as np
import cartopy.mpl.ticker as cmt
import cartopy.crs as ccrs
import matplotlib.path as mpath
import cartopy.feature as cfeature
from cartopy.util import add_cyclic_point
from cartopy.mpl.ticker import (LongitudeFormatter, LatitudeFormatter)
import matplotlib as mpl
import matplotlib.ticker as mticker
from matplotlib.colors import ListedColormap
from scipy.signal import argrelextrema
import time
start_time=time.time()
plt.rcParams['font.sans-serif']= ['Microsoft YaHei'] # 设置“微软雅黑”,图上显示出中文
plt.rcParams['axes.unicode_minus'] = False # 设置中文后,解决坐标轴上负号显示问题
fu= nc.Dataset(r"era5.u_component_of_wind.20180816.nc",'r')
fv = nc.Dataset(r"era5.v_component_of_wind.20180816.nc",'r')
fm=nc.Dataset(r"era5.mslp.20180816.nc",'r')
levels = fu.variables['level'][:]
lat = fu.variables['latitude'][:]
lon0 = fu.variables['longitude'][:]
u = fu.variables['u'][:,-1,:,:]
v = fv.variables['v'][:,-1,:,:]
mslp=fm.variables['msl'][:]
I=[]
J=[]
for y in range(24):
a = argrelextrema(mslp[y], np.less)
rows, cols = a[0], a[1]
duy, dux = np.gradient(u[y])
dvy, dvx = np.gradient(v[y])
vorticity = dvx-duy
t=1.1131955*10**5
w=5*10**(-5)
W=[]
v1=0
for i,j in zip(rows,cols):
W1=[]
for k in range(-10,11):
for l in range(-10,11):
if 190t*w/4:
W.append(mslp[y][i][j])
else:
v1+=1
for p in range(len(mslp[0])):
for q in range(len(mslp[0][0])):
if mslp[y][p][q]==min(W):
I.append(q)
J.append(p)
I[2],J[2]=I[3],J[3]
end_time=time.time()
run_time=end_time-start_time
print(run_time)
fig = plt.figure(figsize=[8,8])
ax = plt.subplot(111,projection=ccrs.PlateCarree())
ax.set_extent([100,130,10,39])
LO=[]
LA=[]
for y in range(len(I)):
LO.append(lon0[I[y]])
LA.append(lat[J[y]])
ax.plot(LO,LA,color='green')
ax.plot(LO,LA,'o',color='green',markersize='2')
ax.add_feature(cfeature.LAND,color='#D3D3D3')
ax.add_feature(cfeature.OCEAN)
ax.add_feature(cfeature.COASTLINE)
ax.add_feature(cfeature.RIVERS)
ax.add_feature(cfeature.LAKES)
gl = ax.gridlines(draw_labels=True, color='gray',alpha=0.5,linestyle='--',
xlocs=np.arange(-180,181,5),ylocs=np.arange(-90,91,5),
x_inline=False,y_inline=False)
gl.top_labels=False
gl.right_labels=False
plt.title("使用MSLP局部最小值+涡度条件",fontsize='xx-large')
plt.savefig("使用MSLP局部最小值+涡度条件.png",dpi=800)
plt.show()
若叠加16、17日数据,则可得出下图: