From: questions a. <que...@gm...> - 2011-10-05 04:21:08
|
thank you! of course! On Wed, Oct 5, 2011 at 3:08 PM, Eric Firing <ef...@ha...> wrote: > On 10/04/2011 05:40 PM, questions anon wrote: > > Excellent, thank you. That works for both quiver and barb. > > In regards to the shape that has to do with the netcdf file, wind > > direction variable also has lat and lon. I ended up needing to slice so > > I could skip a few points otherwise there was too many arrows on the map. > > Below is the code that worked in case someone else needs help. > > Are you sure it worked correctly? I don't think so. See below. > > > Thanks again > > > > from netCDF4 import Dataset > > import numpy as N > > import pylab as plt > > from numpy import ma as MA > > from mpl_toolkits.basemap import Basemap > > import os > > > > ncfile=Dataset('E:/temp_winddir/IDZ00026_VIC_ADFD_Wind_Dir_SFC.nc', > > 'r+', 'NETCDF4') > > WDIR=ncfile.variables['Wind_Dir_SFC'][20,0::5,0::5] > > Don't you need to convert from degrees to radians? sin and cos (used > below) expect radians, not degrees. You can use N.deg2rad(WDIR) to > convert. > > > LAT=ncfile.variables['latitude'][0::5] > > LON=ncfile.variables['longitude'][0::5] > > TIME=ncfile.variables['time'][20] > > ncfile.close() > > > > map = Basemap(projection='merc',llcrnrlat=-40,urcrnrlat=-33, > > llcrnrlon=139.0,urcrnrlon=151.0,lat_ts=0,resolution='i') > > x,y=map(*N.meshgrid(LON,LAT)) > > u=1*N.sin(WDIR) > > v=1*N.cos(WDIR) > > map.quiver(x,y,u, v) > > Assuming you do convert to radians the above will work for your mercator > projection but it will not align the vectors correctly with respect to > the parallels and meridians for other projections, so you should use > map.rotate_vector as in the basemap quiver demo. > > Eric > > > > > > # otherwise use the barb tool - map.barbs(x,y,u, v) > > > > plt.title('Wind Direction') > > plt.show() > > > ------------------------------------------------------------------------------ > All the data continuously generated in your IT infrastructure contains a > definitive record of customers, application performance, security > threats, fraudulent activity and more. Splunk takes this data and makes > sense of it. Business sense. IT sense. Common sense. > http://p.sf.net/sfu/splunk-d2dcopy1 > _______________________________________________ > Matplotlib-users mailing list > Mat...@li... > https://lists.sourceforge.net/lists/listinfo/matplotlib-users > |