# Make the output of plotting commands be displayed inline within the notebook, %matplotlib inline from mpl_toolkits.basemap import Basemap # import Basemap matplotlib toolkit import numpy as np import matplotlib.pyplot as plt import pygrib # import pygrib interface to grib_api grbs = pygrib.open('ecmwf_ensemble.grb') for grb in grbs[:4]: print grb print grb.keys() grbs.rewind() # rewind the iterator from datetime import datetime date_valid = datetime(2014,2,3,0) t2mens = [] for grb in grbs: if grb.validDate == date_valid and grb.parameterName == 'Temperature' and grb.level == 2: t2mens.append(grb.values) t2mens = np.array(t2mens) print t2mens.shape, t2mens.min(), t2mens.max() lats, lons = grb.latlons() # get the lats and lons for the grid. print 'min/max lat and lon',lats.min(), lats.max(), lons.min(), lons.max() fig = plt.figure(figsize=(16,35)) m = Basemap(projection='lcc',lon_0=-74,lat_0=41,width=4.e6,height=4.e6) x,y = m(lons,lats) for nens in range(1,51): ax = plt.subplot(10,5,nens) m.drawcoastlines() cs = m.contourf(x,y,t2mens[nens],np.linspace(230,300,41),cmap=plt.cm.jet,extend='both') t = plt.title('ens member %s' % nens) freezeprob = 100.*((t2mens < 273).sum(axis=0))/t2mens.shape[0] print freezeprob.min(), freezeprob.max(), freezeprob.shape m.drawcoastlines(color='r') from mpl_toolkits.basemap import cm as basemapcm cs = m.contourf(x,y,freezeprob,np.linspace(0,100.,41),cmap=basemapcm.GMT_haxby_r) cb = m.colorbar() xpt, ypt = m(-74,41) nyc = m.plot([xpt],[ypt],'ro') # plot red dot near the Meadowlands. t = plt.title('ens prob t2m < 273 (go Broncos!)')