Hi all,
Signel, yeah, I should have post it on stackoverflow. Will do that next
time.
Benjamin, I've been using GrADS for the last 3 years, and just recently
using python for more functionality (which came with a price,of
course-learning curve).

Seems like I 've found the solution. I should have declared the 'level'
early , as suggested by Alex, for eg:
---
*...*
*....*

*f = nc.Dataset('D:/data/omega.mon.mean.nc
<http://omega.mon.mean.nc/>','r')*
*omg = f.variables['omega'][2,5,:,:] # the dimension is -
levels,time,lon,lat*
*...*
*....*
*---------*
Thanks



Postgraduate Student Room 1U09 - Dept of Meteorology University of Reading,
Earley Gate Reading RG6 6BB, UK


On Wed, Mar 5, 2014 at 3:36 PM, Benjamin Root <ben.r...@ou.edu> wrote:

> The issue I see is one of ensuring that your inputs into contourf() are of
> the expected shapes. If you want a generalized script, then you will need
> to do various steps that can prepare 3d data into a 2d by assuming a
> particular level. The fun part of all of this is that different data
> sources organize their data differently. You might have data defined as
> (time, lat, lon, z), or you might have (lon, lat, time), or maybe (z, lat,
> lon). If your data sources are CF-compliant, then you might be able to take
> advantage of tools such as ncview that tries to be very intelligent about
> all of these fun issues.
>
> Cheers!
> Ben Root
>
>
>
> On Tue, Mar 4, 2014 at 10:22 PM, Fadzil Mnor <fadzilmno...@gmail.com>wrote:
>
>> 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
>> <http://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
>>
>>
>>
>>
>> ------------------------------------------------------------------------------
>> Subversion Kills Productivity. Get off Subversion & Make the Move to
>> Perforce.
>> With Perforce, you get hassle-free workflows. Merge that actually works.
>> Faster operations. Version large binaries.  Built-in WAN optimization and
>> the
>> freedom to use Git, Perforce or both. Make the move to Perforce.
>>
>> http://pubads.g.doubleclick.net/gampad/clk?id=122218951&iu=/4140/ostg.clktrk
>> _______________________________________________
>> Matplotlib-users mailing list
>> Matplotlib-users@lists.sourceforge.net
>> https://lists.sourceforge.net/lists/listinfo/matplotlib-users
>>
>>
>
------------------------------------------------------------------------------
Subversion Kills Productivity. Get off Subversion & Make the Move to Perforce.
With Perforce, you get hassle-free workflows. Merge that actually works. 
Faster operations. Version large binaries.  Built-in WAN optimization and the
freedom to use Git, Perforce or both. Make the move to Perforce.
http://pubads.g.doubleclick.net/gampad/clk?id=122218951&iu=/4140/ostg.clktrk
_______________________________________________
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users

Reply via email to