Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to draw the global wind field by Python

2025-04-02 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)06/01 Report--

This article mainly explains "how to draw the global wind field by Python". The content of the explanation is simple and clear, and it is easy to learn and understand. Please follow the editor's train of thought to study and learn "how to draw the global wind field by 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 ('FRRRA2, 300.tavg1, 2d slope slope, 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.FillValueU2Mans [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 (tween 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 = 180rather 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)) 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 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 Labelpad=15) cb.ax.tick_params (labelsize=10) plt.savefig ('FGV Rpython cb.ax.tick_params lp28) plot29.pngtogether) 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= (9meme 5)) ax = plt.axes (projection=ccrs.PlateCarree ()) ax.set_extent ([- 62qiang 38je 35je 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 = Truegl.xlocator = mticker.FixedLocator ([- 6550m] ) gl.ylocator = mticker.FixedLocator gl.xformatter = LONGITUDE_FORMATTERgl.yformatter = LATITUDE_FORMATTERgl.xlabel_style = {'size':10,' color':'black'} gl.ylabel_style = {'size':10,' color':'black'} # Plot windspeedclevs = np.arange) plt.contourf (lon, lat, ws, clevs, transform=ccrs.PlateCarree () Cmap=plt.cm.jet) plt.title ('MERRA-2 2m Wind Speed and Direction, 00Z 1 June 2010mm, size=16) cb = plt.colorbar (ax=ax, orientation= "vertical", pad=0.02, aspect=16, shrink=0.8) cb.set_label (' m paddles) cb.ax.tick_params (labelsize=10) # Overlay wind vectorsqv = plt.quiver (lon, lat, U2M_nans:], V2M_nans. Color='k') plt.savefig ('FGV hand Rpython plt.savefig lp28 RPY plot29.1. Pngtogether paper dpique 1200) plt.show ()

Thank you for your reading, the above is the content of "how to draw the global wind field with Python". After the study of this article, I believe you have a deeper understanding of how to draw the global wind field with Python, and the specific use needs to be verified in practice. Here is, the editor will push for you more related knowledge points of the article, welcome to follow!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 282

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report