Hi all,
I’ve been looking for solution on this for days, and seems like nothing works.
I wrote this code to read TRMM data and it works, but somehow not working when I use the same script to read NCEP reanalysis data…which later I found out it worked for netCDF files with only 1 ‘level’ (Zsize=1), not multiple ‘levels’ (Zsize more than 1).
I’m stuck at where went wrong, and I tried everything and lost of track what the error massages were.
This is what I wrote to read and plot NCEP reanalysis data. (this omega data has Xsize=144, Ysize=73, Zsize=12, Tsize=792, Esize=1)
···
import netCDF4 as nc
import matplotlib.pyplot as plt
from mpl_toolkits.basemap import Basemap
import numpy as np
f = nc.Dataset(‘D:/data/omega.mon.mean.nc’,‘r’)
omg = f.variables[‘omega’][0]
lon = f.variables[‘lon’][:]
lat = f.variables[‘lat’][:]
times = f.variables[‘time’][:]
**# Set up a map **
map = Basemap(projection=‘cyl’,llcrnrlat=0.,urcrnrlat=10.,llcrnrlon=97.,urcrnrlon=110.,resolution=‘i’)
x,y=map(*np.meshgrid(lon,lat))
map.drawcoastlines()
map.drawcountries()
map.drawparallels(np.arange(-90.,90.,3),labels=[1,0,0,0],fontsize=10)
map.drawmeridians(np.arange(-180.,180.,3),labels=[0,0,0,1],fontsize=10)
#contour data
clevs=np.arange(0.,1.,0.1) # contour interval
cs = map.contourf(x,y,pcpr,clevs,extent=‘both’)
**cb = map.colorbar(cs,‘bottom’,size=‘2%’,pad=“5%”) #plot the colorbar **
cb.set_label(‘m/s’)
plt.title(‘Omega-test’)
plt.show()
f.close()
Above code gave error: Input z must be a 2D array…
(that’s at cs = map.contourf(x,y,pcpr,clevs,extent=‘both’)…)
Hopefully anyone can help.
Thanks for your time reading this.
Fadzil