Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

Page info
infoTypeModified date
prefixLast modified on
typeFlat

Example Python code

Code Block
languagepy
import pygrib
import matplotlib.pyplot as plt
import matplotlib.colors as colors
from mpl_toolkits.basemap import Basemap
from mpl_toolkits.basemap import shiftgrid
import numpy as np

plt.figure(figsize=(12,8))

grib = 'frpcams_05aod.grbgrib' # 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=

# need to shift data grid longitudes from (0..360) to (-180..180)
lons = np.linspace(float(grb['longitudeOfFirstGridPointInDegrees']), \
float(grb['longitudeOfLastGridPointInDegrees']), int(grb['Ni']) )
lats = np.linspace(float(grb['latitudeOfFirstGridPointInDegrees']), \
float(grb['latitudeOfLastGridPointInDegrees']), int(grb['Nj']) )
data, lons = shiftgrid(180., data, lons, start=False)
grid_lon, grid_lat = np.meshgrid(lons, lats) #regularly spaced 2D grid

m = Basemap(projection='cyl', llcrnrlon=-180, \
    urcrnrlon=180.,llcrnrlat=latlats.min(),urcrnrlat=latlats.max(), \
    resolution='c')

x, y = m(grid_lon, grid_lat)

cs = m.pcolormesh(x,y,data,shading='flat',cmap=plt.cm.hot, norm=colors.LogNorm()gist_stern_r)

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)AOD forecast') # Set the name of the variable to plot
plt.savefig(grib+'gfas_05.png') # Set the output file name
plt.show()

Notes

Changing the grid resolution

...

Code Block
languagetext
#
# 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


Info
iconfalse

This document has been produced in the context of the Copernicus Atmosphere Monitoring Service (CAMS) and Copernicus Climate Change Service (C3S).

The activities leading to these results have been contracted by the European Centre for Medium-Range Weather Forecasts, operator of CAMS and C3S on behalf of the European Union (Delegation Agreement signed on 11/11/2014 and Contribution Agreement signed on 22/07/2021). All information in this document is provided "as is" and no guarantee or warranty is given that the information is fit for any particular purpose.

The users thereof use the information at their sole risk and liability. For the avoidance of all doubt , the European Commission and the European Centre for Medium - Range Weather Forecasts have no liability in respect of this document, which is merely representing the author's view.

Content by Label
showLabelsfalse
max5
spacesCKB
showSpacefalse
sortmodified
reversetrue
typepage
cqllabel in ("grib","python","plot") and type = "page" and space = "CKB"
labelsplot python grib visualize

Page properties
hiddentrue


 
Related issues