plot arrows for wind direction (degrees)

Hi All,
Is there a simple way to plot a directional arrow to represent a degree?
I have a netcdf file containing wind direction as degrees and I would like to make a plot with all little arrows representing the wind direction.
Below is the code I am using currently to plot wind direction but am not sure where/how to add directional arrows.
Thanks

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:/WINDDIR/IDZ00026_VIC_ADFD_Wind_Dir_SFC.nc’, ‘r+’, ‘NETCDF4’)
WDIR=ncfile.variables[‘Wind_Dir_SFC’][-50]
LAT=ncfile.variables[‘latitude’][:]
LON=ncfile.variables[‘longitude’][:]
TIME=ncfile.variables[‘time’][-50]
fillvalue=ncfile.variables[‘Wind_Dir_SFC’]._FillValue
WDIR=MA.masked_values(WDIR, fillvalue)
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))
map.drawstates()
map.drawcoastlines()
plt.title(‘Wind Direction’)
CS = map.contourf(x,y,WDIR,15, cmap=plt.cm.jet)
l,b,w,h =0.1,0.1,0.8,0.8
cax = plt.axes([l+w+0.025, b, 0.025, h])
plt.colorbar(CS,cax=cax,drawedges=True)
plt.savefig((os.path.join(‘E:/WINDDIR/’, ‘WDIRSFC.png’)))
plt.show()

Would the barb() command do what you want?

http://matplotlib.sourceforge.net/api/pyplot_api.html#matplotlib.pyplot.barbs

http://matplotlib.sourceforge.net/examples/pylab_examples/barb_demo.html

They aren’t arrows, but they are commonly used in meteorology to plot windfields.

Cheers,
Ben Root

···

On Mon, Oct 3, 2011 at 6:51 PM, questions anon <questions.anon@…287…> wrote:

Hi All,
Is there a simple way to plot a directional arrow to represent a degree?
I have a netcdf file containing wind direction as degrees and I would like to make a plot with all little arrows representing the wind direction.

Below is the code I am using currently to plot wind direction but am not sure where/how to add directional arrows.
Thanks

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:/WINDDIR/IDZ00026_VIC_ADFD_Wind_Dir_SFC.nc’, ‘r+’, ‘NETCDF4’)
WDIR=ncfile.variables[‘Wind_Dir_SFC’][-50]

LAT=ncfile.variables[‘latitude’][:]
LON=ncfile.variables[‘longitude’][:]
TIME=ncfile.variables[‘time’][-50]
fillvalue=ncfile.variables[‘Wind_Dir_SFC’]._FillValue
WDIR=MA.masked_values(WDIR, fillvalue)

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))
map.drawstates()

map.drawcoastlines()
plt.title(‘Wind Direction’)
CS = map.contourf(x,y,WDIR,15, cmap=plt.cm.jet)
l,b,w,h =0.1,0.1,0.8,0.8
cax = plt.axes([l+w+0.025, b, 0.025, h])
plt.colorbar(CS,cax=cax,drawedges=True)

plt.savefig((os.path.join(‘E:/WINDDIR/’, ‘WDIRSFC.png’)))
plt.show()

    Hi All,
    Is there a simple way to plot a directional arrow to represent a degree?
    I have a netcdf file containing wind direction as degrees and I
    would like to make a plot with all little arrows representing the
    wind direction.
    Below is the code I am using currently to plot wind direction but am
    not sure where/how to add directional arrows.
    Thanks

    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:/WINDDIR/IDZ00026_VIC_ADFD_Wind_Dir_SFC.nc', 'r+',
    'NETCDF4')
    WDIR=ncfile.variables['Wind_Dir_SFC'][-50]
    LAT=ncfile.variables['latitude'][:]
    LON=ncfile.variables['longitude'][:]
    TIME=ncfile.variables['time'][-50]
    fillvalue=ncfile.variables['Wind_Dir_SFC']._FillValue
    WDIR=MA.masked_values(WDIR, fillvalue)
    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))
    map.drawstates()
    map.drawcoastlines()
    plt.title('Wind Direction')
    CS = map.contourf(x,y,WDIR,15, cmap=plt.cm.jet)
    l,b,w,h =0.1,0.1,0.8,0.8
    cax = plt.axes([l+w+0.025, b, 0.025, h])
    plt.colorbar(CS,cax=cax,drawedges=True)
    plt.savefig((os.path.join('E:/WINDDIR/', 'WDIRSFC.png')))
    plt.show()

Would the barb() command do what you want?

http://matplotlib.sourceforge.net/api/pyplot_api.html#matplotlib.pyplot.barbs
http://matplotlib.sourceforge.net/examples/pylab_examples/barb_demo.html

They aren't arrows, but they are commonly used in meteorology to plot
windfields.

Cheers,
Ben Root

There is also quiver, both in matplotlib and in basemap. See the quiver_demo.py and barb_demo.py in the basemap examples directory.

Eric

···

On 10/03/2011 03:00 PM, Benjamin Root wrote:

On Mon, Oct 3, 2011 at 6:51 PM, questions anon <questions.anon@...287... > <mailto:questions.anon@…287…>> wrote:

------------------------------------------------------------------------------
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
Matplotlib-users@lists.sourceforge.net
matplotlib-users List Signup and Options

Thanks for responding. I believe quiver is more appropriate because I am only using wind direction (at this stage) and this results in arrows.
I have had a look at the demos and still do not understand how to plot my degrees in arrows. How do I define which angle is north, south, west, east, etc?
Any suggestions? Thanks

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’][-50]
LAT=ncfile.variables[‘latitude’][:]
LON=ncfile.variables[‘longitude’][:]
TIME=ncfile.variables[‘time’][-50]
ncfile.close()

map = Basemap(projection=‘merc’,llcrnrlat=-40,urcrnrlat=-33,
llcrnrlon=139.0,urcrnrlon=151.0,lat_ts=0,resolution=‘i’)
x,y=LON,LAT
u=10x
v=10
y
map.quiver(x,y,u, v, WDIR)
plt.title(‘Wind Direction’)
plt.show()

Traceback (most recent call last):
File “d:/plot_winddirection.py”, line 22, in
map.quiver(x,y,u, v, WDIR)
File “C:\Python27\lib\site-packages\mpl_toolkits\basemap_init_.py”, line 3102, in quiver
ret = ax.quiver(x,y,u,v,*args,**kwargs)
File “C:\Python27\lib\site-packages\matplotlib\axes.py”, line 6320, in quiver
q = mquiver.Quiver(self, *args, **kw)
File “C:\Python27\lib\site-packages\matplotlib\quiver.py”, line 395, in init
self.XY = np.hstack((X[:,np.newaxis], Y[:,np.newaxis]))
File “C:\Python27\lib\site-packages\numpy\core\shape_base.py”, line 270, in hstack
return _nx.concatenate(map(atleast_1d,tup),1)
ValueError: array dimensions must agree except for d_0

···

On Tue, Oct 4, 2011 at 12:54 PM, Eric Firing <efiring@…202…> wrote:

On 10/03/2011 03:00 PM, Benjamin Root wrote:

On Mon, Oct 3, 2011 at 6:51 PM, questions anon <questions.anon@…287… > > mailto:questions.anon@...287...> wrote:

Hi All,
Is there a simple way to plot a directional arrow to represent a degree?
I have a netcdf file containing wind direction as degrees and I
would like to make a plot with all little arrows representing the
wind direction.
Below is the code I am using currently to plot wind direction but am
not sure where/how to add directional arrows.
Thanks
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:/WINDDIR/IDZ00026_VIC_ADFD_Wind_Dir_SFC.nc', 'r+',
'NETCDF4')
WDIR=ncfile.variables['Wind_Dir_SFC'][-50]
LAT=ncfile.variables['latitude'][:]
LON=ncfile.variables['longitude'][:]
TIME=ncfile.variables['time'][-50]
fillvalue=ncfile.variables['Wind_Dir_SFC']._FillValue
WDIR=MA.masked_values(WDIR, fillvalue)
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))
map.drawstates()
map.drawcoastlines()
plt.title('Wind Direction')
CS = map.contourf(x,y,WDIR,15, cmap=plt.cm.jet)
l,b,w,h =0.1,0.1,0.8,0.8
cax = plt.axes([l+w+0.025, b, 0.025, h])
plt.colorbar(CS,cax=cax,drawedges=True)
plt.savefig((os.path.join('E:/WINDDIR/', 'WDIRSFC.png')))
plt.show()

Would the barb() command do what you want?

http://matplotlib.sourceforge.net/api/pyplot_api.html#matplotlib.pyplot.barbs

http://matplotlib.sourceforge.net/examples/pylab_examples/barb_demo.html

They aren’t arrows, but they are commonly used in meteorology to plot

windfields.

Cheers,

Ben Root

There is also quiver, both in matplotlib and in basemap. See the

quiver_demo.py and barb_demo.py in the basemap examples directory.

Eric


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

Matplotlib-users@lists.sourceforge.net

https://lists.sourceforge.net/lists/listinfo/matplotlib-users


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

Matplotlib-users@lists.sourceforge.net

https://lists.sourceforge.net/lists/listinfo/matplotlib-users

Anon,
I don’t know the quiver routine, but u and v are usually vectors for the wind speed in the east-west and north south directions. As such they should not be equal to lat and lon (10), as you are doing, but rather should be windspeed * sin(direction) and windspeedcos(direction). If you don’t have windspeed or want them all to be the same size arrows, just substitute 1 for windspeed (or 10 if you want longer arrows)

You shouldn’t have to “set” north,south,east,west, etc. generally North is 0, South is 180, etc, so that should all be assigned already.

It also looks like you have an array size mis-match, can you print LAT.shape, LON.shape,TIME.shape,WDIR.shape it may be that your lat,lon variables also need to be subset to [-50]?

hope this helps,

Ethan

···

On Oct 4, 2011, at 5:58 PM, questions anon wrote:

Thanks for responding. I believe quiver is more appropriate because I am only using wind direction (at this stage) and this results in arrows.
I have had a look at the demos and still do not understand how to plot my degrees in arrows. How do I define which angle is north, south, west, east, etc?

Any suggestions? Thanks

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’][-50]
LAT=ncfile.variables[‘latitude’][:]
LON=ncfile.variables[‘longitude’][:]
TIME=ncfile.variables[‘time’][-50]
ncfile.close()

map = Basemap(projection=‘merc’,llcrnrlat=-40,urcrnrlat=-33,

          llcrnrlon=139.0,urcrnrlon=151.0,lat_ts=0,resolution='i')

x,y=LON,LAT
u=10x
v=10
y
map.quiver(x,y,u, v, WDIR)
plt.title(‘Wind Direction’)
plt.show()

Traceback (most recent call last):

File “d:/plot_winddirection.py”, line 22, in
map.quiver(x,y,u, v, WDIR)
File “C:\Python27\lib\site-packages\mpl_toolkits\basemap_init_.py”, line 3102, in quiver
ret = ax.quiver(x,y,u,v,*args,**kwargs)

File “C:\Python27\lib\site-packages\matplotlib\axes.py”, line 6320, in quiver
q = mquiver.Quiver(self, *args, **kw)
File “C:\Python27\lib\site-packages\matplotlib\quiver.py”, line 395, in init

self.XY = np.hstack((X[:,np.newaxis], Y[:,np.newaxis]))

File “C:\Python27\lib\site-packages\numpy\core\shape_base.py”, line 270, in hstack
return _nx.concatenate(map(atleast_1d,tup),1)
ValueError: array dimensions must agree except for d_0

On Tue, Oct 4, 2011 at 12:54 PM, Eric Firing <efiring@…202…> wrote:

On 10/03/2011 03:00 PM, Benjamin Root wrote:

On Mon, Oct 3, 2011 at 6:51 PM, questions anon <questions.anon@…287… > > > mailto:questions.anon@...287...> wrote:

Hi All,
Is there a simple way to plot a directional arrow to represent a degree?
I have a netcdf file containing wind direction as degrees and I
would like to make a plot with all little arrows representing the
wind direction.
Below is the code I am using currently to plot wind direction but am
not sure where/how to add directional arrows.
Thanks
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:/WINDDIR/IDZ00026_VIC_ADFD_Wind_Dir_SFC.nc', 'r+',
'NETCDF4')
WDIR=ncfile.variables['Wind_Dir_SFC'][-50]
LAT=ncfile.variables['latitude'][:]
LON=ncfile.variables['longitude'][:]
TIME=ncfile.variables['time'][-50]
fillvalue=ncfile.variables['Wind_Dir_SFC']._FillValue
WDIR=MA.masked_values(WDIR, fillvalue)
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))
map.drawstates()
map.drawcoastlines()
plt.title('Wind Direction')
CS = map.contourf(x,y,WDIR,15, cmap=plt.cm.jet)
l,b,w,h =0.1,0.1,0.8,0.8
cax = plt.axes([l+w+0.025, b, 0.025, h])
plt.colorbar(CS,cax=cax,drawedges=True)
plt.savefig((os.path.join('E:/WINDDIR/', 'WDIRSFC.png')))
plt.show()

Would the barb() command do what you want?

http://matplotlib.sourceforge.net/api/pyplot_api.html#matplotlib.pyplot.barbs

http://matplotlib.sourceforge.net/examples/pylab_examples/barb_demo.html

They aren’t arrows, but they are commonly used in meteorology to plot

windfields.

Cheers,

Ben Root

There is also quiver, both in matplotlib and in basemap. See the

quiver_demo.py and barb_demo.py in the basemap examples directory.

Eric


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

Matplotlib-users@lists.sourceforge.net

https://lists.sourceforge.net/lists/listinfo/matplotlib-users


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

Matplotlib-users@lists.sourceforge.net

https://lists.sourceforge.net/lists/listinfo/matplotlib-users


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
Matplotlib-users@…813…ourceforge.net
matplotlib-users List Signup and Options

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.
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]
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)

otherwise use the barb tool - map.barbs(x,y,u, v)

plt.title(‘Wind Direction’)
plt.show()

···

On Wed, Oct 5, 2011 at 2:00 PM, Ethan Gutmann <ethan.gutmann@…287…> wrote:

Anon,
I don’t know the quiver routine, but u and v are usually vectors for the wind speed in the east-west and north south directions. As such they should not be equal to lat and lon (10), as you are doing, but rather should be windspeed * sin(direction) and windspeedcos(direction). If you don’t have windspeed or want them all to be the same size arrows, just substitute 1 for windspeed (or 10 if you want longer arrows)

You shouldn’t have to “set” north,south,east,west, etc. generally North is 0, South is 180, etc, so that should all be assigned already.

It also looks like you have an array size mis-match, can you print LAT.shape, LON.shape,TIME.shape,WDIR.shape it may be that your lat,lon variables also need to be subset to [-50]?

hope this helps,

Ethan

On Oct 4, 2011, at 5:58 PM, questions anon wrote:

Thanks for responding. I believe quiver is more appropriate because I am only using wind direction (at this stage) and this results in arrows.

I have had a look at the demos and still do not understand how to plot my degrees in arrows. How do I define which angle is north, south, west, east, etc?

Any suggestions? Thanks

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’][-50]
LAT=ncfile.variables[‘latitude’][:]
LON=ncfile.variables[‘longitude’][:]
TIME=ncfile.variables[‘time’][-50]
ncfile.close()

map = Basemap(projection=‘merc’,llcrnrlat=-40,urcrnrlat=-33,

          llcrnrlon=139.0,urcrnrlon=151.0,lat_ts=0,resolution='i')

x,y=LON,LAT
u=10x
v=10
y
map.quiver(x,y,u, v, WDIR)
plt.title(‘Wind Direction’)
plt.show()

Traceback (most recent call last):

File “d:/plot_winddirection.py”, line 22, in
map.quiver(x,y,u, v, WDIR)
File “C:\Python27\lib\site-packages\mpl_toolkits\basemap_init_.py”, line 3102, in quiver
ret = ax.quiver(x,y,u,v,*args,**kwargs)

File “C:\Python27\lib\site-packages\matplotlib\axes.py”, line 6320, in quiver
q = mquiver.Quiver(self, *args, **kw)
File “C:\Python27\lib\site-packages\matplotlib\quiver.py”, line 395, in init

self.XY = np.hstack((X[:,np.newaxis], Y[:,np.newaxis]))

File “C:\Python27\lib\site-packages\numpy\core\shape_base.py”, line 270, in hstack
return _nx.concatenate(map(atleast_1d,tup),1)
ValueError: array dimensions must agree except for d_0

On Tue, Oct 4, 2011 at 12:54 PM, Eric Firing <efiring@…202…> wrote:

On 10/03/2011 03:00 PM, Benjamin Root wrote:

On Mon, Oct 3, 2011 at 6:51 PM, questions anon <questions.anon@…287… > > > > mailto:questions.anon@...287...> wrote:

Hi All,
Is there a simple way to plot a directional arrow to represent a degree?
I have a netcdf file containing wind direction as degrees and I
would like to make a plot with all little arrows representing the
wind direction.
Below is the code I am using currently to plot wind direction but am
not sure where/how to add directional arrows.
Thanks
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:/WINDDIR/IDZ00026_VIC_ADFD_Wind_Dir_SFC.nc', 'r+',
'NETCDF4')
WDIR=ncfile.variables['Wind_Dir_SFC'][-50]
LAT=ncfile.variables['latitude'][:]
LON=ncfile.variables['longitude'][:]
TIME=ncfile.variables['time'][-50]
fillvalue=ncfile.variables['Wind_Dir_SFC']._FillValue
WDIR=MA.masked_values(WDIR, fillvalue)
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))
map.drawstates()
map.drawcoastlines()
plt.title('Wind Direction')
CS = map.contourf(x,y,WDIR,15, cmap=plt.cm.jet)
l,b,w,h =0.1,0.1,0.8,0.8
cax = plt.axes([l+w+0.025, b, 0.025, h])
plt.colorbar(CS,cax=cax,drawedges=True)
plt.savefig((os.path.join('E:/WINDDIR/', 'WDIRSFC.png')))
plt.show()

Would the barb() command do what you want?

http://matplotlib.sourceforge.net/api/pyplot_api.html#matplotlib.pyplot.barbs

http://matplotlib.sourceforge.net/examples/pylab_examples/barb_demo.html

They aren’t arrows, but they are commonly used in meteorology to plot

windfields.

Cheers,

Ben Root

There is also quiver, both in matplotlib and in basemap. See the

quiver_demo.py and barb_demo.py in the basemap examples directory.

Eric


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

Matplotlib-users@lists.sourceforge.net

https://lists.sourceforge.net/lists/listinfo/matplotlib-users


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

Matplotlib-users@lists.sourceforge.net

https://lists.sourceforge.net/lists/listinfo/matplotlib-users


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
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users

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

···

On 10/04/2011 05:40 PM, questions anon wrote:

# otherwise use the barb tool - map.barbs(x,y,u, v)

plt.title('Wind Direction')
plt.show()

thank you! of course!

···

On Wed, Oct 5, 2011 at 3:08 PM, Eric Firing <efiring@…202…> 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

Matplotlib-users@lists.sourceforge.net

https://lists.sourceforge.net/lists/listinfo/matplotlib-users

Another quick question,
I noticed that the wind direction appeared back-to-front so I have added a negative to my equation as I am in the southern hemisphere. It now looks correct but I wanted to check if this is the right way to do this? I saw something called ‘flip’ for barb but nothing for quiver.
Thanks, see code below

           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*N.pi/180)# added negative to account for southern hemisphere
            v=-1*N.cos(WDIR*N.pi/180)
            map.quiver(x,y,u, v)
···

On Wed, Oct 5, 2011 at 3:20 PM, questions anon <questions.anon@…83…287…> wrote:

thank you! of course!

On Wed, Oct 5, 2011 at 3:08 PM, Eric Firing <efiring@…202…> 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

Matplotlib-users@lists.sourceforge.net

https://lists.sourceforge.net/lists/listinfo/matplotlib-users

It probably nothing to do with southern hemisphere but rather that it is typical for wind data to be recorded and displayed as direction “from”, instead of direction “to”. If you think “flip” should be available for quiver(), file a feature request.

Ben Root

···

On Thursday, October 13, 2011, questions anon <questions.anon@…287…> wrote:

Another quick question,
I noticed that the wind direction appeared back-to-front so I have added a negative to my equation as I am in the southern hemisphere. It now looks correct but I wanted to check if this is the right way to do this? I saw something called ‘flip’ for barb but nothing for quiver.

> Another quick question,
> I noticed that the wind direction appeared back-to-front so I have
added a negative to my equation as I am in the southern hemisphere. It
now looks correct but I wanted to check if this is the right way to do
this? I saw something called 'flip' for barb but nothing for quiver.

It probably nothing to do with southern hemisphere but rather that it is
typical for wind data to be recorded and displayed as direction "from",
instead of direction "to". If you think "flip" should be available for
quiver(), file a feature request.

It looks to me like the barb "flip" is for something else entirely--it is a right-hand versus left-hand sort of flip. This would be inappropriate for quiver, which makes symmetric arrows. I would strongly oppose any proposal for a kwarg to reverse the direction of the arrows.

Eric

···

On 10/13/2011 12:22 PM, Benjamin Root wrote:

On Thursday, October 13, 2011, questions anon <questions.anon@...287... > <mailto:questions.anon@…287…>> wrote:

Ben Root

Thanks,
Ben, that makes sense although I think the angles I have can be considered the direction ‘to’ and I want direction ‘from’ so adding a negative makes them come from the direction I need.

I should add I don’t really know what flip does so will ignore that.
thanks for the responses.

···

On Fri, Oct 14, 2011 at 9:32 AM, Eric Firing <efiring@…202…> wrote:

On 10/13/2011 12:22 PM, Benjamin Root wrote:

On Thursday, October 13, 2011, questions anon <questions.anon@…287… > > mailto:questions.anon@...3818...com> wrote:

Another quick question,

I noticed that the wind direction appeared back-to-front so I have

added a negative to my equation as I am in the southern hemisphere. It

now looks correct but I wanted to check if this is the right way to do

this? I saw something called ‘flip’ for barb but nothing for quiver.

It probably nothing to do with southern hemisphere but rather that it is

typical for wind data to be recorded and displayed as direction “from”,

instead of direction “to”. If you think “flip” should be available for

quiver(), file a feature request.

It looks to me like the barb “flip” is for something else entirely–it is a right-hand versus left-hand sort of flip. This would be inappropriate for quiver, which makes symmetric arrows. I would strongly oppose any proposal for a kwarg to reverse the direction of the arrows.

Eric

Ben Root