Python怎么绘制全球风场
发表于:2025-02-07 作者:千家信息网编辑
千家信息网最后更新 2025年02月07日,这篇文章主要讲解了"Python怎么绘制全球风场",文中的讲解内容简单清晰,易于学习与理解,下面请大家跟着小编的思路慢慢深入,一起来研究和学习"Python怎么绘制全球风场"吧!1.MERRA-2 w
千家信息网最后更新 2025年02月07日Python怎么绘制全球风场
这篇文章主要讲解了"Python怎么绘制全球风场",文中的讲解内容简单清晰,易于学习与理解,下面请大家跟着小编的思路慢慢深入,一起来研究和学习"Python怎么绘制全球风场"吧!
1.MERRA-2 windspeed calculated from 2-meter northward and eastward wind component variables:
from netCDF4 import Datasetimport numpy as npimport matplotlib.pyplot as pltimport cartopy.crs as ccrsfrom cartopy.mpl.gridliner import LONGITUDE_FORMATTER, LATITUDE_FORMATTERimport matplotlib.ticker as mticker# Open the NetCDF4 file (add a directory path if necessary) for reading:data = Dataset('F:/Rpython/lp28/data/MERRA2_300.tavg1_2d_slv_Nx.20100601.nc4', mode='r')# Run the following cell to see the MERRA2 metadata. This line will print attribute and variable information. From the 'variables(dimensions)' list, choose which variable(s) to read in below:print(data)# Read in variables:# longitude and latitudelons = data.variables['lon']lats = data.variables['lat']lon, lat = np.meshgrid(lons, lats)# 2-meter eastward wind m/sU2M = data.variables['U2M']# 2-meter northward wind m/sV2M = data.variables['V2M']# Replace _FillValues with NaNs:U2M_nans = U2M[:]V2M_nans = V2M[:]_FillValueU2M = U2M._FillValue_FillValueV2M = V2M._FillValueU2M_nans[U2M_nans == _FillValueU2M] = np.nanV2M_nans[V2M_nans == _FillValueV2M] = np.nan# Calculate wind speed:ws = np.sqrt(U2M_nans**2+V2M_nans**2)# Calculate wind direction in radians:ws_direction = np.arctan2(V2M_nans,U2M_nans)# NOTE: the MERRA-2 file contains hourly data for 24 hours (t=24). To get the daily mean wind speed, take the average of the hourly wind speeds:ws_daily_avg = np.nanmean(ws, axis=0)# NOTE: To calculate the average wind direction correctly it is important to use the 'vector average' as atan2(,) where and are the daily average component vectors, rather than as mean of the individual wind vector direction angle. This avoids a situation where averaging 1 and 359 = 180 rather than the desired 0.U2M_daily_avg = np.nanmean(U2M_nans, axis=0)V2M_daily_avg = np.nanmean(V2M_nans, axis=0)ws_daily_avg_direction = np.arctan2(V2M_daily_avg, U2M_daily_avg)#Plot Global MERRA-2 Wind Speed# Set the figure size, projection, and extentfig = plt.figure(figsize=(8,4))ax = plt.axes(projection=ccrs.Robinson())ax.set_global()ax.coastlines(resolution="110m",linewidth=1)ax.gridlines(linestyle='--',color='black')# Plot windspeed: set contour levels, then draw the filled contours and a colorbarclevs = np.arange(0,19,1)plt.contourf(lon, lat, ws_daily_avg, clevs, transform=ccrs.PlateCarree(),cmap=plt.cm.jet)plt.title('MERRA-2 Daily Average 2-meter Wind Speed, 1 June 2010', size=14)cb = plt.colorbar(ax=ax, orientation="vertical", pad=0.02, aspect=16, shrink=0.8)cb.set_label('m/s',size=12,rotation=0,labelpad=15)cb.ax.tick_params(labelsize=10)plt.savefig('F:/Rpython/lp28/plot29.png',dpi=1200)plt.show()
2.MERRA-2 windspeed and direction calculated from 2-meter northward and eastward wind component variables:
# The filled contours show the wind speed. The "quiver" function is used to overlay arrows to show the wind direction. The length of the arrows is determined by the wind speed.# Set the figure size, projection, and extentfig = plt.figure(figsize=(9,5))ax = plt.axes(projection=ccrs.PlateCarree())ax.set_extent([-62,-38,35,54])ax.coastlines(resolution="50m",linewidth=1)# Add gridlinesgl = ax.gridlines(crs=ccrs.PlateCarree(), draw_labels=True,linewidth=1, color='black', linestyle='--')gl.xlabels_top = Falsegl.ylabels_right = Falsegl.xlines = Truegl.xlocator = mticker.FixedLocator([-65,-60,-50,-40,-30])gl.ylocator = mticker.FixedLocator([30,40,50,60])gl.xformatter = LONGITUDE_FORMATTERgl.yformatter = LATITUDE_FORMATTERgl.xlabel_style = {'size':10, 'color':'black'}gl.ylabel_style = {'size':10, 'color':'black'}# Plot windspeedclevs = np.arange(0,14.5,1)plt.contourf(lon, lat, ws[0,:,:], clevs, transform=ccrs.PlateCarree(),cmap=plt.cm.jet)plt.title('MERRA-2 2m Wind Speed and Direction, 00Z 1 June 2010', size=16)cb = plt.colorbar(ax=ax, orientation="vertical", pad=0.02, aspect=16, shrink=0.8)cb.set_label('m/s',size=14,rotation=0,labelpad=15)cb.ax.tick_params(labelsize=10)# Overlay wind vectorsqv = plt.quiver(lon, lat, U2M_nans[0,:,:], V2M_nans[0,:,:], scale=420, color='k')plt.savefig('F:/Rpython/lp28/plot29.1.png',dpi=1200)plt.show()
感谢各位的阅读,以上就是"Python怎么绘制全球风场"的内容了,经过本文的学习后,相信大家对Python怎么绘制全球风场这一问题有了更深刻的体会,具体使用情况还需要大家实践验证。这里是,小编将为大家推送更多相关知识点的文章,欢迎关注!
全球
学习
内容
就是
思路
情况
文章
更多
知识
知识点
篇文章
跟着
问题
实践
推送
研究
验证
数据库的安全要保护哪些东西
数据库安全各自的含义是什么
生产安全数据库录入
数据库的安全性及管理
数据库安全策略包含哪些
海淀数据库安全审计系统
建立农村房屋安全信息数据库
易用的数据库客户端支持安全管理
连接数据库失败ssl安全错误
数据库的锁怎样保障安全
以萨服务器的服务热线
中国解决网络安全问题
北京网络技术服务标准
浙江互联网软件开发产品介绍
上海健康云 服务器
深圳今玖互联网科技有限公司
浩博网络技术有限公司
数据库开发必备技能
网络安全周记300
网络安全找漏洞
成年人网络安全教育知识
网络安全法 隐私政策
高速公路联想服务器的厂家代码
软件开发怎么审
英特尔软件开发工程师
网络技术吧
浙江电脑软件开发公司
罗湖区无源网络技术开发咨询报价
苏州微软社招软件开发待遇
vr软件开发需要掌握
暑假学软件开发在哪儿学
c#链接数据库cs架构
网络安全 博客
河南net软件开发如何收费
sdk软件开发套件
谷歌服务器管理员
林业科技互联网
定远工业软件开发技术怎么样
多因子校验 数据库防火墙
澳门威海软件开发