大家好,地球江南体育网页版科学界,gydF4y2Ba
我是一个初学者Python程序员,试图在我的mac (mac OS Mojave 10.14.6)上绘制从ECMWF ERA5再分析单级数据集中抓取的10米地面风数据的单个时间步。我在底图上的风矢量密度上遇到了一些麻烦,因为我的代码产生的结果图几乎是黑屏。下面是我正在工作的代码。作为说明,该图还显示了一个时间步长的平均海平面压力,我已经能够成功地绘制出这个图。gydF4y2Ba
导入pygrib导入numpy如np导入matplotlib。Pyplot作为PLT从mpl_toolkits。从mpl_toolkits中导入basemap。技术进口shiftgrid #--------------------------------------------------------------------------------------------- # 有用的链接,我发现这些代码# https://confluence.ecmwf.int/display/CKB/How + +情节+格丽+ + + Python +和+ matplotlib #文件//www.hoelymoley.com/questions/7012/plotting-wind-barbs-in-python #----------------------------------------------------------------------------------------- 无花果= plt plt.clf()。图(figsize =(10,10)) #--------------------------------------------------------------------------------------------- #设置底图投影的经纬度坐标(默认投影=柱面等距)lllon = -170 lllon = 10 urlon = -110 urlat = 61 #设置经纬度坐标以及绘制经纬度的绘图间隔作为绘图轴latmin=0 latmax=70 lonmin=-180 lonmax=-100 latinterval=20 loninterval=20#--------------------------------------------------------------------------------------------- # 创建基础图和添加一些地理内容为绘图数据创建一个好的起点bmap =基础图(llcrnrlon = lllon llcrnrlat = lllat urcrnrlon = urlon urcrnrlat = urlat分辨率= f, epsg = 3311) bmap.drawcoastlines(线宽= 2,zorder = 1) bmap。Drawstates (linewidth=2,zorder=1) bmap.drawcountries(linewidth=2,zorder=1) bmap.drawlsmask(land_color='white',ocean_color='white',lakes='false',resolution='f')排列(latmin, latmax, latinterval), label = [1,0,0,0],color='k',textcolor='k',linewidth = 2, fonts =14)不等(lonmax铂金生产商lonmin loninterval),标签=[0,0,0,1],颜色=“k”,输入textcolor =“k”,线宽= 2,字形大小= 14 ) #--------------------------------------------------------------------------------------------- # 读ERA5格丽= '下载文件并抓住MSLP值文件。grb ' grbs = pygrib.open(file) grb_mslp = grb_mslp. select()[2] #MSLP for 2012-03-26 @00UTC data = grb_mslp。在Pa值# MSLP值 #--------------------------------------------------------------------------------------------- # 设置绘图参数经度和背阔肌。移动长度,使投影从-180到180(而不是0-360)#使用第一个到最后一个网格点创建均匀间隔的长度。int(grb[Ni]) = 1440 (360/0.25) lons = np.linspace(float(grb_mslp['longitude deoflastgridpointindegrees ']), \ float(grb_mslp['longitude udeoflastgridpointindegrees ']), int(grb_mslp['Ni'])) #使用第一个到最后一个网格点创建均匀间隔的lats。int(grb[Nj]) = 721(180/。25+ 1) lats = np.linspace(float(grb['latitudeOfFirstGridPointInDegrees']), \ float(grb['latitudeOfLastGridPointInDegrees']), int(grb_mslp['Nj']) ) #Grid shifting of lons. Not exactly sure how function works. data, lons = shiftgrid(180., data, lons, start=False) grid_lon, grid_lat = np.meshgrid(lons, lats) #regularly spaced 2D grid. Still not sure how this works. #--------------------------------------------------------------------------------------------- #Plotting MSLP on basemap x,y = bmap(grid_lon,grid_lat) #Pass ERA5 lat/lon to basemap cs = bmap.contour(x,y,data/100,10,colors='r') #Plot MSLP contours. Divide by 100 = mb plt.clabel(cs,inline=1,inline_spacing=5,fontsize=10,fmt='%1.1f') #Add labels to contours #--------------------------------------------------------------------------------------------- #Repeat process for other parameters until I figure out a better method grb_uwind = grbs.select()[0] #U 10m wind component for 2012-03-26 @00UTC grb_vwind = grbs.select()[1] #V 10m wind component for 2012-03-26 @00UTC data_uwind = grb_uwind.values #U 10m wind values in m/s data_vwind = grb_vwind.values #V 10m wind values in m/s #--------------------------------------------------------------------------------------------- #Plotting wind on basemap x,y = bmap(grid_lon,grid_lat) #Pass ERA5 lat/lon to basemap barbs = plt.quiver(x,y,data_uwind,data_vwind) #Plot 10m wind in m/s
我尝试过的唯一解决方案是尝试使用以下符号来绘制每50个数据点:gydF4y2Ba
barbs = plt.quiver(x[::50],y[::50],data_uwind[::50],data_vwind[::50]) #以m/s为单位绘制每50个10m风点gydF4y2Ba
然而,这产生了一张几乎没有结果的地图。有人知道我是如何错误地处理这个问题的吗?最好是尝试猜测和检查不同的值来绘制而不是每50个点?gydF4y2Ba
我真诚地感谢任何关于如何继续进行的建议。感谢您花时间阅读这篇文章。gydF4y2Ba
谷歌Grib文件的驱动器链接:gydF4y2Bahttps://drive.google.com/file/d/1XEuatdp5piyTIiADgZhxFHQ1_WghMwPJ/view?usp=sharinggydF4y2Ba