- 积分
- 25
- 贡献
-
- 精华
- 在线时间
- 小时
- 注册时间
- 2022-9-29
- 最后登录
- 1970-1-1
|
楼主 |
发表于 2022-11-28 14:55:50
|
显示全部楼层
import numpy as np
from matplotlib import pyplot as plt
from mpl_toolkits.basemap import Basemap
import netCDF4 as nc
file = 'F:/Data\\Wind Data\\2018-2020\\CERSAT-GLO-REP_WIND_L4-OBS_FULL_TIME_SERIE_1666701884472.nc'
data = nc.Dataset(file)
wind_u = data.variables['eastward_wind'][:, 0] # 读取纬向速度
wind_v = data.variables['northward_wind'][:, 0] # 读取经向速度
windspeed = data.variables['wind_speed'][:, 0] # 读取总风速数据,数据为四维,第二维读取索引0
lat = data.variables['latitude'][:] # 读取纬度数据
lon = data.variables['longitude'][:] # 读取经度数据
# print(lon)
wind_u_mean = np.ma.mean(wind_u, axis=0)
wind_v_mean = np.ma.mean(wind_v, axis=0)
windspeed_mean = np.ma.mean(windspeed, axis=0) # 通过掩码数组求出风速的平均值
wind_u_mean = np.hstack((wind_u_mean[:, 720:1440], wind_u_mean[:, 0:720]))
wind_v_mean = np.hstack((wind_v_mean[:, 720:1440], wind_u_mean[:, 0:720]))
windspeed_mean = np.hstack((windspeed_mean[:, 720:1440], windspeed_mean[:, 0:720])) # 将风速数组进行平移,因为底图中央经度设置为180
fig = plt.figure(figsize=(10, 8), dpi=100) # 创建画板
ax = plt.subplot(111) # 添加子图
plt.rcParams['font.family'] = 'Times New Roman' # 设置字体
m = Basemap(projection='cyl', lon_0=180, llcrnrlon=lon.min()+180, urcrnrlon=lon.max()+180, llcrnrlat=lat.min(), urcrnrlat=lat.max()) # 创建底图
m.fillcontinents(color='grey', alpha=0.8) # 填充陆地
m.drawcoastlines() # 画海岸线
m.drawmeridians(np.arange(-180, 181, 30), labels=[0, 0, 0, 1], fontsize=10, linewidth=0.8, color='silver') # 经线
m.drawparallels(np.arange(-90, 91, 30), labels=[1, 0, 0, 0], fontsize=10, linewidth=0.8, color='silver') # 纬线
m.imshow(windspeed_mean, cmap='jet',) # 画图
q = m.quiver((lon+180)[::24], lat[::24], wind_u_mean[::24, ::24], wind_v_mean[::24, ::24], scale=500, width=0.002,
headwidth=3, headlength=6) # 画风场的矢量箭头,以24为间隔取点, scale为缩放比例,决定轴长度, width为轴宽度,后边两个参数为箭头宽度和长度
plt.quiverkey(q, 0.95, 1.05, 7, '7 m/s', labelpos='E') # 绘制比例尺,第二个和第三个参数为比例尺位置,第四个参数为比例尺长度,第五个为比例尺标签,最后为标签的位置
cbar = m.colorbar(location='bottom', pad=0.35) # 绘制colorbar,位于底部,距离图0.35
cbar.ax.tick_params(labelsize=10) # 设置colorbar的刻度大小
cbar.set_label('Wind speed m/s') # 为colorbar添加标签
plt.title('Wind field(2018-2020)', fontsize=16) # 标题
plt.savefig('Global Wind Field Climate Patterns.png') # 保存图片
plt.show() |
|