Marjolaine Rouault wrote: > Hi, > > I am trying to extract a a line (or transect) of data across a 2 dimensional > array. I want to know what the best way of finding data points within my 2D > dataset closest to each point on my line. Is there a matplotlib pre-defined > function to find the closest point within a radius or must I create my own? > > Thanks a lot, Marjolaine. >
Marjolaine: Sounds like what you want is nearest neighbor interpolation. The Basemap toolkit has an interp function that can do bilinear or nearest neighbor interpolation. It's typically used for regridding, but I think it will work for your use case too. Here's some pseudo-code: from mpl_toolkits.basemap import interp # here datarr is 2d data array on a regular grid with x,y coordinates # defined by 1-d arrays x,y. The arrays xout, yout describe the points # on the transect. order=0 means nearest neighbor interp, order=1 means bilinear. # dataout is the data interpolated to the transect. dataout = interp(datarr,x,y,xout,yout,order=0) -Jeff -- Jeffrey S. Whitaker Phone : (303)497-6313 Meteorologist FAX : (303)497-6449 NOAA/OAR/PSD R/PSD1 Email : [email protected] 325 Broadway Office : Skaggs Research Cntr 1D-113 Boulder, CO, USA 80303-3328 Web : http://tinyurl.com/5telg ------------------------------------------------------------------------------ Open Source Business Conference (OSBC), March 24-25, 2009, San Francisco, CA -OSBC tackles the biggest issue in open source: Open Sourcing the Enterprise -Strategies to boost innovation and cut costs with open source participation -Receive a $600 discount off the registration fee with the source code: SFAD http://p.sf.net/sfu/XcvMzF8H _______________________________________________ Matplotlib-users mailing list [email protected] https://lists.sourceforge.net/lists/listinfo/matplotlib-users
