Example Python code
import pygrib import matplotlib.pyplot as plt import matplotlib.colors as colors from mpl_toolkits.basemap import Basemap import numpy as np plt.figure(figsize=(12,8)) grib='frp_05.grb' # Set the file name of your input GRIB file grbs=pygrib.open(grib) grb = grbs.select()[0] data=grb.values print max(data[0]) lat,lon = grb.latlons() # Set the names of the latitude and longitude variables in your input GRIB file m=Basemap(projection='cyl', llcrnrlon=-180, \ urcrnrlon=180.,llcrnrlat=lat.min(),urcrnrlat=lat.max(), \ resolution='c') x, y = m(lon,lat) cs = m.pcolormesh(x,y,data,shading='flat',cmap=plt.cm.hot, norm=colors.LogNorm()) m.drawcoastlines() m.drawmapboundary() m.drawparallels(np.arange(-90.,120.,30.),labels=[1,0,0,0]) m.drawmeridians(np.arange(-180.,180.,60.),labels=[0,0,0,1]) plt.colorbar(cs,orientation='vertical', shrink=0.5) plt.title('CAMS GFAS fire radiative power (W / m2)') # Set the name of the variable to plot plt.savefig('gfas_05.png') # Set the output file name
Notes
Changing the grid resolution
Before plotting the field you can use the cdo software to conservatively regrid the data, for example from 0.1˘x0.1˘ to 0.5˘x0.5˘ regular latitude-longitude grid:
cdo -s gencon,grid.R720x360.txt frp_01.grb remapweights.rencon.R3600x1800.to.R720x360.grb cdo -s remap,grid.R720x360.txt,remapweights.rencon.R3600x1800.to.R720x360.grb frp_01.grb frp_05.grb
The content of grid definition file (grid.R720x360.txt) is:
# # gridID 2 # gridtype = lonlat gridsize = 259200 xname = lon xlongname = longitude xunits = degrees_east yname = lat ylongname = latitude yunits = degrees_north xsize = 720 ysize = 360 xfirst = 0.25 xinc = 0.5 yfirst = 89.75 yinc = -0.5