Hello again,
I finally found the command I was looking for. It is the to_polygons().
Here is what worked :

# make a LineCollection of contours
col=contour(X,Y,Z,LevelsNumber).collections


for i in np.arange(0,LevelsNumber,1):
    polygoni=col[i].get_paths()[0].to_polygons()[0]
    print polygoni

All the vertices in each collections are extracted to the "polygoni".

Thanks again to Jeff and Patrick !

By the way, I found out that I do not actually need this procedure to achieve may goal
which was to make a contour plot in ternary coordinates.

Eli



On Tue, Jan 27, 2009 at 11:08 PM, Patrick Marsh <patrickmarshwx@gmail.com> wrote:
On Tue, Jan 27, 2009 at 7:16 PM, Eli Brosh <ebrosh1@gmail.com> wrote:
> Many thanks to Jeff and to Patric !
> I will try to work along the line suggested by Jeff.
> Patric, please send me your code.
> I hope to learn from it.
>
> Thanks again,
> Eli


Here is a template that can be used.  I use this for meteorological
models, but should work with any gridded file.


import numpy as np
from mpl_toolkits.basemap import Basemap

f = (some gridded file)
X = np.array(grab longitudes from f)
Y = np.array(grab latitudes from f)
field = np.array(grab field to be contoured from f)
map = Basemap(make a Basemap call here)
level = np.arange(minval, maxval, interval)
col   = map.contour(X, Y, field, level).collections

for vertex in col[i].get_paths():    # GET THE PATHS FOR THE EACH
CONTOUR BY LOOPING THROUGH CONTOURS
   for vertex in xy.vertices:          # ITERATE OVER THE PATH OBJECTS
       x, y = map(vertex[0],vertex[1],inverse=True)       # vertex[0]
and now 'x' is the longitude of the vertex and vertex[1] and now 'y'
is the latitude of the vertex


Let me know how this works.

-Patrick









>
> On Tue, Jan 27, 2009 at 7:09 PM, Patrick Marsh <patrickmarshwx@gmail.com>
> wrote:
>>
>> On Tue, Jan 27, 2009 at 5:33 PM, Jeff Whitaker <jswhit@fastmail.fm> wrote:
>> > Eli Brosh wrote:
>> >> Hello,
>> >> I am trying to extract the coordinates of contour lines.
>> >> I tried the following:
>> >>
>> >> cs = *contour*(Z)
>> >> for lev, col in zip(cs.levels, cs.collections):
>> >>      s = col._segments
>> >>
>> >> that I found in a previous post (title "contouring", by Jose
>> >> Gómez-Dans-2 <http://www.nabble.com/user/UserProfile.jtp?user=30071>
>> >> Nov 30, 2007; 07:47am ) .
>> >>
>> >> I hoped that s will be a list of numpy arrays, each containing the
>> >> (x,y) vertices
>> >> defining a contour line at level lev.
>> >> However, I got an error message:
>> >> AttributeError: 'LineCollection' object has no attribute '_segments'
>> >>
>> >>
>> >> How is it possible to get coordinates of the contours, similar to the
>> >> MATLAB command
>> >>  [C,H] = *CONTOUR*(...)
>> >> where the result in C is the coordinates of the contours.
>> >>
>> >> A similar question appeared in a post "contour data" (by Albert Swart
>> >> <http://www.nabble.com/user/UserProfile.jtp?user=382945> May 17, 2006;
>> >> 09:42am) but I could not understand the answer.
>> >> Is it possible to get more specific directions with a simple example ?
>> >>
>> >>
>> >> Thanks
>> >> Eli
>> > Eli:  Calling get_paths() on each line collection in CS.collections will
>> > return a list of Path objects.  From the Path objects, you can get a Nx2
>> > array of vertices from the "vertices" attribute.  There are no examples
>> > that I know of, but if you get it to do what you want to do, it would be
>> > great if you could contribute an example.  As you noted, this question
>> > has come up several times before.
>> >
>> > -Jeff
>> >
>> > --
>> > Jeffrey S. Whitaker         Phone  : (303)497-6313
>> > Meteorologist               FAX    : (303)497-6449
>> > NOAA/OAR/PSD  R/PSD1        Email  : Jeffrey.S.Whitaker@noaa.gov
>> > 325 Broadway                Office : Skaggs Research Cntr 1D-113
>> > Boulder, CO, USA 80303-3328 Web    : http://tinyurl.com/5telg
>> >
>> >
>> >
>> >
>> > ------------------------------------------------------------------------------
>> > This SF.net email is sponsored by:
>> > SourcForge Community
>> > SourceForge wants to tell your story.
>> > http://p.sf.net/sfu/sf-spreadtheword
>> > _______________________________________________
>> > Matplotlib-users mailing list
>> > Matplotlib-users@lists.sourceforge.net
>> > https://lists.sourceforge.net/lists/listinfo/matplotlib-users
>> >
>>
>> I'm not sure if this is entirely what you (Eli) are looking for, but I
>> have code that will contour model data on a map and then extract the
>> lat,lon pairs of all the vertices.  If this is what you are looking
>> for, I'm happy to share what I've done.
>>
>> -Patrick
>>
>> --
>> Patrick Marsh
>> Graduate Research Assistant
>> School of Meteorology
>> University of Oklahoma
>> http://www.patricktmarsh.com
>
>



--
Patrick Marsh
Graduate Research Assistant
School of Meteorology
University of Oklahoma
http://www.patricktmarsh.com