卫星轨道资料洋面风的绘图

1、一般格点数据的绘图

import cartopy.crs as ccrs
import cartopy.feature as cfeature
import cartopy.mpl.ticker as cticker
import matplotlib.pyplot as plt
import meteva.base as meb
def paint_contour_quiver(u,v,lon,lat,cmap,title,output_dir,shici):  #这里的u和v是dataArray格式的
    spd = (u**2+v**2)**0.5
    ######画图尝试2
    fig = plt.figure(figsize=(12,8))
    proj = ccrs.PlateCarree(central_longitude=113)
    leftlon, rightlon, lowerlat, upperlat = (106,121,15,24)
    img_extent = [leftlon, rightlon, lowerlat, upperlat]
    ax = fig.add_axes([0.1, 0.1, 0.8, 0.6],projection = proj)
    # ax.set_extent(img_extent, crs=ccrs.PlateCarree())
    ax.add_feature(cfeature.COASTLINE) 
    ax.set_xticks(np.arange(leftlon,rightlon,1), crs=ccrs.PlateCarree())
    ax.set_yticks(np.arange(lowerlat,upperlat,1), crs=ccrs.PlateCarree())
    lon_formatter = cticker.LongitudeFormatter()
    lat_formatter = cticker.LatitudeFormatter()
    ax.xaxis.set_major_formatter(lon_formatter)
    ax.yaxis.set_major_formatter(lat_formatter)
    c = ax.contourf(lon,lat,spd,extend='both' ,cmap=cmap,transform=ccrs.PlateCarree())
    cbar = fig.colorbar(c, orientation='vertical', pad=0.02, aspect=20, shrink=0.6)
    cbar.set_label('Speed (m/s)')
    q = ax.quiver(lon,lat,u,v,transform=ccrs.PlateCarree(),scale=150,color='k',regrid_shape = 10,width=0.003,headwidth=4,headlength=7)
    ax.quiverkey(q, 0.95, 1.05, 10, '10m/s', labelpos='E',coordinates='axes')
    ax.set_title(title)
    plt.savefig(output_dir+shici+'-'+title+'.png',dpi=400)

其中u和v是二维的numpy.ndarray格式的。
卫星轨道资料洋面风的绘图_第1张图片

2、卫星轨道资料

但是卫星轨道资料并不是二维格点的。
它在解码后是dataframe格式的。

3、插值到格点并绘图

所以,要画图,需要把卫星轨道资料插值到格点上,然后再画图。这里用meteva库的cressman插值函数进行站点到格点的插值。

def paint_obs(obs_data,type_of_obs,output_dir,shici,cmap):
    #####################站点数据#################################################
    ###o
    #u
    sta_u = meb.sta_data(obs_data[['类型','经度','纬度','U风']],columns = ["id","lon","lat","data0"])
    meb.set_stadata_coords(sta_u,level = 0,time = datetime.datetime(2019,1,1,8,0),dtime = 0)
    #v
    sta_v = meb.sta_data(obs_data[['类型','经度','纬度','V风']],columns = ["id","lon","lat","data0"])
    meb.set_stadata_coords(sta_v,level = 0,time = datetime.datetime(2019,1,1,8,0),dtime = 0)
    ################################################################################
    ##################################网格106,121,15,24#################################
    grid0 = meb.grid([106,121,0.01],[15,24,0.01])
    #
    start = time.time()
    ##o
    grd_u = meb.interp_sg_cressman(sta_u,grid = grid0,r_list = [16,12,8,4],nearNum = 100)
    grd_v = meb.interp_sg_cressman(sta_v,grid = grid0,r_list = [16,12,8,4],nearNum = 100)
    
    used_time = time.time() - start
    ############################################################
    ################################画图#########################################################
    cmap,clev = meb.def_cmap_clevs(meb.cmaps.wind_speed) #设置色标
    #按照种类把obs分开,画一个总的,再分别画每个种类的obs
    #画总的obs、o-b、o-a
    paint_contour_quiver(grd_u.values[0,0,0,0,:,:],grd_v.values[0,0,0,0,:,:],grd_u.lon.values,grd_u.lat.values,cmap,type_of_obs+'Obs',output_dir,shici)
    

卫星轨道资料洋面风的绘图_第2张图片

4、困惑

我有几个困惑:1是洋面风的色标好丑;2是轨道之外虽然没有数据,但还是有点,可不可以让轨道之外没有点?

你可能感兴趣的:(python,python,numpy)