<div dir="ltr">Hi Fadzil,<div><br></div><div>My strong recommendation is that you don't just use numpy/netCDF4 to process your data, but rather use one of a multitude of packages that have been developed specifically to facilitate working with labeled data from netCDF files:</div><div>- Iris: <a href="http://scitools.org.uk/iris/">http://scitools.org.uk/iris/</a><br></div><div>- CDAT: <a href="http://uvcdat.llnl.gov/">http://uvcdat.llnl.gov/</a></div><div>- xray (my project): <a href="http://xray.readthedocs.org">http://xray.readthedocs.org</a></div><div><br></div><div><div>I can't answer your specific question without taking a careful look at your data, but in very general terms, your code will have fewer bugs if you can use meaningful labels to refer to your data rather than numeric ranges like 396:757:12.</div><div><br></div><div>Best,</div><div>Stephan</div><div><br></div></div></div><div class="gmail_extra"><br><div class="gmail_quote">On Tue, Oct 14, 2014 at 3:50 AM, Fadzil Mnor <span dir="ltr"><<a href="mailto:fadzilmnor84@gmail.com" target="_blank">fadzilmnor84@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr">Hi all,<div>I wrote a script and plot monthly mean zonal wind (from a netcdf file names <a href="http://uwnd.mon.mean.nc" target="_blank">uwnd.mon.mean.nc</a>) and I'm not sure if I'm doing it correctly. What I have:</div><div><br></div><div><b>******************************************************************************</b></div><div><i>#this part calculates mean values for january only, from 1980-2010; thus the index looks like this 396:757:12</i></div><div><br></div><div><div>def ujan():</div><div>    f = nc.Dataset('~/data/ncep/<a href="http://uwnd.mon.mean.nc" target="_blank">uwnd.mon.mean.nc</a>')</div><div>    u10_1 = f.variables['uwnd']</div><div>    u10_2 = np.mean(u10_1[396:757:12,:,38,39:43],axis=0)</div><div>    return u10_2</div><div><br></div><div>uJan = ujan()<i> #calling function</i></div><div><br></div><div><i>#this part is only to define lon, lat and level </i></div><div>q = nc.Dataset('~/data/ncep/<a href="http://uwnd.mon.mean.nc" target="_blank">uwnd.mon.mean.nc</a>') </div><div>lon=q.variables['lon']</div><div>lat=q.variables['lat']</div><div>lev=q.variables['level']</div><div><br></div><div><i>#for some reason I need to define this unless it gave error "length of x must be number of column in z"</i></div><div><i><br></i></div><div>lon=lon[39:43]</div><div><br></div><div><i>#begin plotting</i></div><div><br></div><div>clevs=np.arange(-10.,10.,0.5)</div><div>fig = plt.figure(figsize=(11, 8))</div><div>fig.clf()</div><div>ax = fig.add_subplot(111)</div><div>ax.axis([97.5, 105., 1000., 10.])</div><div>ax.tick_params(direction='out', which='both')</div><div>ax.set_xlabel('Lon (degrees)')</div><div>ax.set_ylabel('Pressure (mb)')</div><div>ax.set_xticks(np.arange(97.5, 105., .5))</div><div>ax.set_yticks([1000, 700, 500, 300, 100, 10])</div><div>cs=ax.contourf(lon, lev, uJan, clevs, extend='both',cmap='seismic')</div><div>plt.title('Zonal winds average (Jan, 1981-2010)')</div><div>cax = fig.add_axes([0.99, 0.1, 0.03, 0.8]) </div><div>aa=fig.colorbar(cs,cax=cax,orientation='vertical')</div><div>aa.set_label('m/s')</div><div>plt.savefig('~/uwind-crossection-test.png', bbox_inches='tight')</div></div><div><b>*****************************************************************************</b></div><div><br></div><div>the result is attached.</div><div>I have no idea how to confirm the result (at least until this email is written) , but I believe the lower altitude values should be mostly negative, because over this region, the zonal wind are usually easterly (thus,negative values), but I got positive values.</div><div><br></div><div>Put the information above aside, <u>I just want to know if my slicing in the ujan() function is correct</u>. If it is, then, there must be nothing wrong(except my above mentioned assumption).</div><div>The data file dimension is:</div><div><b>[time,level,latitude,longitude]</b></div><div><br></div><div>This part:</div><div><b>u10_2 = np.mean(u10_1[396:757:12,:,38,39:43],axis=0)</b><br></div><div>The line above will calculate the mean of zonal wind (uwnd) in a range of time index 396 to 757 for each year (january only), for all vertical level, at latitude index 38 (5 N) and in between longitude index 39 to 43 (97.5E-105E).</div><div>I assume it will calculate a 30-year average of zonal wind for january only.</div><div>Is this correct?</div><div><br></div><div>Thank you.</div><span class="HOEnZb"><font color="#888888"><div><br></div><div>Fadzil</div></font></span></div>
<br>_______________________________________________<br>
NumPy-Discussion mailing list<br>
<a href="mailto:NumPy-Discussion@scipy.org">NumPy-Discussion@scipy.org</a><br>
<a href="http://mail.scipy.org/mailman/listinfo/numpy-discussion" target="_blank">http://mail.scipy.org/mailman/listinfo/numpy-discussion</a><br>
<br></blockquote></div><br></div>