Re: [Matplotlib-users] griddata fails
Yes, you are absolutely correct. I did not realize that I did not actually evaluate the function over a grid, makes sense that interpolation fails. I thought that since I created the two axis vectors the function evaluation occurs over the entire domain, meshgrid is what I was missing. thanks, Shahar On Jan 9, 2013, at 8:45 PM, Ian Thomas wrote: On 9 January 2013 09:32, Shahar Shani-Kadmiel kadm...@post.bgu.ac.il wrote: Hi, I'm trying to contour some data that I have and the griddata line fails. I tried running it on some synthetically generated data and I get the same IndexError. Any Ideas? Here is the example with the synthetic data: x = y = arange(-10,10,0.01) z = x**2+y**3 xi = yi = linspace(-10.1, 10.1, 100) zi = griddata(x, y, z, xi, yi) --- IndexErrorTraceback (most recent call last) ipython-input-52-0458ab6ea672 in module() 1 zi = griddata(x, y, z, xi, yi) /Library/Frameworks/Python.framework/Versions/7.3/lib/python2.7/site-packages/matplotlib/mlab.py in griddata(x, y, z, xi, yi, interp) 2766 xi,yi = np.meshgrid(xi,yi) 2767 # triangulate data - 2768 tri = delaunay.Triangulation(x,y) Hello Shahar, I think that your simple example is probably not what you intended. Your (x,y) points are all defined on the straight line from (-10,-10) to (10,10). The Delaunay triangulation of these points (which is what griddata does) is not very interesting! Perhaps you wanted (x,y) defined on the 2D grid from (-10,-10) to (10,10), in which case you should follow the x = y ... line with, for example: x, y = meshgrid(x, y) (see numpy.meshgrid for further details). You may still obtain the same IndexError, and the traceback shows this is happening in the delaunay.Triangulation function call. The matplotlib delaunay package is not particularly robust, and can have problems handling regularly-spaced data points. The griddata documentation explains some of this, see http://matplotlib.org/api/mlab_api.html#matplotlib.mlab.griddata. To avoid the problem, the griddata documentation explains one possible way that uses the natgrid algorithm. A simpler solution that I often use is to add a very small amount of noise to my regularly-spaced (x,y) points using the numpy.random module. I can give more details if you wish. Ian -- Master Visual Studio, SharePoint, SQL, ASP.NET, C# 2012, HTML5, CSS, MVC, Windows 8 Apps, JavaScript and much more. Keep your skills current with LearnDevNow - 3,200 step-by-step video tutorials by Microsoft MVPs and experts. ON SALE this month only -- learn more at: http://p.sf.net/sfu/learnmore_122712___ Matplotlib-users mailing list Matplotlib-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/matplotlib-users
[Matplotlib-users] griddata fails
Hi, I'm trying to contour some data that I have and the griddata line fails. I tried running it on some synthetically generated data and I get the same IndexError. Any Ideas? Here is the example with the synthetic data: x = y = arange(-10,10,0.01) z = x**2+y**3 xi = yi = linspace(-10.1, 10.1, 100) zi = griddata(x, y, z, xi, yi) --- IndexErrorTraceback (most recent call last) ipython-input-52-0458ab6ea672 in module() 1 zi = griddata(x, y, z, xi, yi) /Library/Frameworks/Python.framework/Versions/7.3/lib/python2.7/site-packages/matplotlib/mlab.py in griddata(x, y, z, xi, yi, interp) 2766 xi,yi = np.meshgrid(xi,yi) 2767 # triangulate data - 2768 tri = delaunay.Triangulation(x,y) 2769 # interpolate data 2770 if interp == 'nn': /Library/Frameworks/Python.framework/Versions/7.3/lib/python2.7/site-packages/matplotlib/delaunay/triangulate.py in __init__(self, x, y) 88 self.triangle_neighbors = delaunay(self.x, self.y) 89 --- 90 self.hull = self._compute_convex_hull() 91 92 def _collapse_duplicate_points(self): /Library/Frameworks/Python.framework/Versions/7.3/lib/python2.7/site-packages/matplotlib/delaunay/triangulate.py in _compute_convex_hull(self) 113 114 edges = {} -- 115 edges.update(dict(zip(self.triangle_nodes[border[:,0]][:,1], 116 self.triangle_nodes[border[:,0]][:,2]))) 117 edges.update(dict(zip(self.triangle_nodes[border[:,1]][:,2], IndexError: invalid index -- Master Java SE, Java EE, Eclipse, Spring, Hibernate, JavaScript, jQuery and much more. Keep your Java skills current with LearnJavaNow - 200+ hours of step-by-step video tutorials by Java experts. SALE $49.99 this month only -- learn more at: http://p.sf.net/sfu/learnmore_122612 ___ Matplotlib-users mailing list Matplotlib-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/matplotlib-users
Re: [Matplotlib-users] griddata fails
On 9 January 2013 09:32, Shahar Shani-Kadmiel kadm...@post.bgu.ac.ilwrote: Hi, I'm trying to contour some data that I have and the griddata line fails. I tried running it on some synthetically generated data and I get the same IndexError. Any Ideas? Here is the example with the synthetic data: x = y = arange(-10,10,0.01) z = x**2+y**3 xi = yi = linspace(-10.1, 10.1, 100) zi = griddata(x, y, z, xi, yi) --- IndexErrorTraceback (most recent call last) ipython-input-52-0458ab6ea672 in module() 1 zi = griddata(x, y, z, xi, yi) /Library/Frameworks/Python.framework/Versions/7.3/lib/python2.7/site-packages/matplotlib/mlab.py in griddata(x, y, z, xi, yi, interp) 2766 xi,yi = np.meshgrid(xi,yi) 2767 # triangulate data - 2768 tri = delaunay.Triangulation(x,y) Hello Shahar, I think that your simple example is probably not what you intended. Your (x,y) points are all defined on the straight line from (-10,-10) to (10,10). The Delaunay triangulation of these points (which is what griddata does) is not very interesting! Perhaps you wanted (x,y) defined on the 2D grid from (-10,-10) to (10,10), in which case you should follow the x = y ... line with, for example: x, y = meshgrid(x, y) (see numpy.meshgrid for further details). You may still obtain the same IndexError, and the traceback shows this is happening in the delaunay.Triangulation function call. The matplotlib delaunay package is not particularly robust, and can have problems handling regularly-spaced data points. The griddata documentation explains some of this, see http://matplotlib.org/api/mlab_api.html#matplotlib.mlab.griddata. To avoid the problem, the griddata documentation explains one possible way that uses the natgrid algorithm. A simpler solution that I often use is to add a very small amount of noise to my regularly-spaced (x,y) points using the numpy.random module. I can give more details if you wish. Ian -- Master Java SE, Java EE, Eclipse, Spring, Hibernate, JavaScript, jQuery and much more. Keep your Java skills current with LearnJavaNow - 200+ hours of step-by-step video tutorials by Java experts. SALE $49.99 this month only -- learn more at: http://p.sf.net/sfu/learnmore_122612 ___ Matplotlib-users mailing list Matplotlib-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/matplotlib-users
Re: [Matplotlib-users] griddata is not working after update to Python 2.7
Dear Benjamin, Thanks for the reply. Apparently my Python 2.6 version was completely removed and I only have Python 2.7. My matplotlib and numpy are the latest versions. In matplotlib homepage, I found that meshgrid should do the same job, but I cannot make script to run it from a file. Is there a simple way to do contour plotting on a simple 3 column file (x, y, z) where I gave a link to the table file in my previous email? Thanks a lot Umut First, if you were importing griddata before like that, that it is quite likely that it was some other module that was installed in your python-2.6/site-packages directory that overrode numpy's griddata. When you upgraded, that griddata module could not be found in python-2.7/site-packages. Commenting it out allowed python to find pylab's griddata. Second, you really need to clean up your imports. There is no need for the two math imports, or the numpy import (because the pylab import handles that). Oddly, though, your griddata import comes before the pylab import. I would expect that the pylab griddata would have overridden the first griddata import. And so there shouldn't have been a difference. Did you happen to upgrade matplotlib and/or numpy as well? Ben Root -- Live Security Virtual Conference Exclusive live event will cover all the ways today's security and threat landscape has changed and how IT managers can respond. Discussions will include endpoint security, mobile security and the latest in malware threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/___ Matplotlib-users mailing list Matplotlib-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/matplotlib-users
[Matplotlib-users] griddata is not working after update to Python 2.7
Dear All, I used to use griddata in order to make my contourmaps. However, after I updated my Python from 2.6 to 2.7 griddata is not working anymore. I tried some workarounds but no success. The countourmap that I produced before is here. http://dl.dropbox.com/u/17983476/matplotlib/contour_dT_workingbefore.png After the Python 2.7 update, it turns to the following. http://dl.dropbox.com/u/17983476/matplotlib/contour_dT_broken.png Here is the datafile. http://dl.dropbox.com/u/17983476/matplotlib/contour_dT.dat And the associated python script (which is also below). http://dl.dropbox.com/u/17983476/matplotlib/contour_dT.py The code that I was using before is here. I had to comment out #import griddata line because this is the only way that it continues. Is this a bug in griddata, or if there are new workarounds, I would be glad to know a new method to produce my contourplots again. Thanks a lot #! /usr/bin python import os import sys import math from math import * from numpy import * #import griddata from pylab import * from matplotlib.ticker import FormatStrFormatter params = {'axes.labelsize': 20, 'text.fontsize': 15, 'legend.fontsize': 14, 'xtick.labelsize': 20, 'ytick.labelsize': 20, 'text.usetex': True } rcParams.update(params) par1 = [] par2 = [] chis = [] rfile = file('contour_dT.dat','r') line = rfile.readline() data = line.split() while len(data) 1: par1.append(float(data[0])) par2.append(float(data[1])) chis.append(float(data[2])) line = rfile.readline() data = line.split() par1 = array(par1) par2 = array(par2) chis = array(chis) xi = linspace(3.2,7.8,50) yi = linspace(15,300,50) zi = griddata(par2,par1,chis,xi,yi) levels = [0.4,0.5,0.6,0.7,0.8,0.9,1.0,1.2,1.5,2,3,4,6,10,12,15,20,25,30,40,50] CS = contourf(xi,yi,zi,levels,cmap=cm.jet) CS2 = contour(CS, levels=CS.levels[::2], colors = 'r', hold='on') cbar = colorbar(CS) cbar.add_lines(CS2) savefig(contour_dT.png) show() -- Live Security Virtual Conference Exclusive live event will cover all the ways today's security and threat landscape has changed and how IT managers can respond. Discussions will include endpoint security, mobile security and the latest in malware threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/ ___ Matplotlib-users mailing list Matplotlib-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/matplotlib-users
Re: [Matplotlib-users] Griddata failling; how to try natgrid version?
On 12/21/11 12:31 AM, Brad Malone wrote: Hi, I'm still working on my interpolating from an irregularly space grid and then running pcolormesh on the resulting output. With some of the newer data I've been plotting I've noticed that my plots are complete garbage. I realized that this was actually because of the output from griddata rather than some problem with pcolormesh/pcolor/etc (basically I get huge negative values like -8 from the interpolation when all of my data points lie within [0,20]) . Googling I found out that the default griddata has some problems, and that there is a better, more robust version available through natgrid. I downloaded the natgrid-0.2.1 package from here http://sourceforge.net/projects/matplotlib/files%2Fmatplotlib-toolkits%2Fnatgrid-0.2/. My question now is, how do I install this and give it a shot? I'm running on Ubuntu (or Xubuntu rather). The README doesn't seem to have any directions. Brad: python setup.py install should do it. matplotlib will automatically use it if it's installed. -Jeff Also, let's say that this new griddata doesn't work for me, is there something else I could try? The interpolation problems are strange, because I can break my data into 3 segments (I read 3 files to obtain the data so this is the natural way to do it) and I can plot and interpolate correctly any segment individually. It's only when I do all 3 segments together that the interpolation begins to fail. Any ideas? Thanks for the continued help! Brad -- Write once. Port to many. Get the SDK and tools to simplify cross-platform app development. Create new or port existing apps to sell to consumers worldwide. Explore the Intel AppUpSM program developer opportunity. appdeveloper.intel.com/join http://p.sf.net/sfu/intel-appdev ___ Matplotlib-users mailing list Matplotlib-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/matplotlib-users -- Write once. Port to many. Get the SDK and tools to simplify cross-platform app development. Create new or port existing apps to sell to consumers worldwide. Explore the Intel AppUpSM program developer opportunity. appdeveloper.intel.com/join http://p.sf.net/sfu/intel-appdev___ Matplotlib-users mailing list Matplotlib-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/matplotlib-users
Re: [Matplotlib-users] Griddata failling; how to try natgrid version?
Jeff, Thanks. That indeed did work (after downloading python-dev package). I just didn't know that 'install' was the argument that I was supposed to pass to it =) After installing I tried griddata again. My input data was originally a list. The new griddata didn't like this and so I simply used a=array(thelist) to convert to an array and tried again. It took quite a bit longer than the old griddata, but the resulting output now looks correct! Better a slow and correct answer than a fast and garbage one. Thanks again Jeff (and thanks for the new griddata if you are the one that made it)! Brad On Wed, Dec 21, 2011 at 5:55 AM, Jeff Whitaker jsw...@fastmail.fm wrote: On 12/21/11 12:31 AM, Brad Malone wrote: Hi, I'm still working on my interpolating from an irregularly space grid and then running pcolormesh on the resulting output. With some of the newer data I've been plotting I've noticed that my plots are complete garbage. I realized that this was actually because of the output from griddata rather than some problem with pcolormesh/pcolor/etc (basically I get huge negative values like -8 from the interpolation when all of my data points lie within [0,20]) . Googling I found out that the default griddata has some problems, and that there is a better, more robust version available through natgrid. I downloaded the natgrid-0.2.1 package from here http://sourceforge.net/projects/matplotlib/files%2Fmatplotlib-toolkits%2Fnatgrid-0.2/ . My question now is, how do I install this and give it a shot? I'm running on Ubuntu (or Xubuntu rather). The README doesn't seem to have any directions. Brad: python setup.py install should do it. matplotlib will automatically use it if it's installed. -Jeff Also, let's say that this new griddata doesn't work for me, is there something else I could try? The interpolation problems are strange, because I can break my data into 3 segments (I read 3 files to obtain the data so this is the natural way to do it) and I can plot and interpolate correctly any segment individually. It's only when I do all 3 segments together that the interpolation begins to fail. Any ideas? Thanks for the continued help! Brad -- Write once. Port to many. Get the SDK and tools to simplify cross-platform app development. Create new or port existing apps to sell to consumers worldwide. Explore the Intel AppUpSM program developer opportunity. appdeveloper.intel.com/joinhttp://p.sf.net/sfu/intel-appdev ___ Matplotlib-users mailing listMatplotlib-users@lists.sourceforge.nethttps://lists.sourceforge.net/lists/listinfo/matplotlib-users -- Write once. Port to many. Get the SDK and tools to simplify cross-platform app development. Create new or port existing apps to sell to consumers worldwide. Explore the Intel AppUpSM program developer opportunity. appdeveloper.intel.com/join http://p.sf.net/sfu/intel-appdev___ Matplotlib-users mailing list Matplotlib-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/matplotlib-users
[Matplotlib-users] Griddata failling; how to try natgrid version?
Hi, I'm still working on my interpolating from an irregularly space grid and then running pcolormesh on the resulting output. With some of the newer data I've been plotting I've noticed that my plots are complete garbage. I realized that this was actually because of the output from griddata rather than some problem with pcolormesh/pcolor/etc (basically I get huge negative values like -8 from the interpolation when all of my data points lie within [0,20]) . Googling I found out that the default griddata has some problems, and that there is a better, more robust version available through natgrid. I downloaded the natgrid-0.2.1 package from here http://sourceforge.net/projects/matplotlib/files%2Fmatplotlib-toolkits%2Fnatgrid-0.2/ . My question now is, how do I install this and give it a shot? I'm running on Ubuntu (or Xubuntu rather). The README doesn't seem to have any directions. Also, let's say that this new griddata doesn't work for me, is there something else I could try? The interpolation problems are strange, because I can break my data into 3 segments (I read 3 files to obtain the data so this is the natural way to do it) and I can plot and interpolate correctly any segment individually. It's only when I do all 3 segments together that the interpolation begins to fail. Any ideas? Thanks for the continued help! Brad -- Write once. Port to many. Get the SDK and tools to simplify cross-platform app development. Create new or port existing apps to sell to consumers worldwide. Explore the Intel AppUpSM program developer opportunity. appdeveloper.intel.com/join http://p.sf.net/sfu/intel-appdev___ Matplotlib-users mailing list Matplotlib-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/matplotlib-users
[Matplotlib-users] griddata
Hi all, what are the differences between the griddata implementations in matplotlib and scipy, i.e. from scipy.interpolate import griddata and from matplotlib.mlab import griddata Is the Shepard algorithm available in matplotlib/scipy ? Nils Reference: Robert J. Renka Algorithm 790: CSHEP2D: Cubic Shepard Method for Bivariate Interpolation of Scattered Data. ACM Transactions on Mathematical Software, Vol. 25 No. 1 (1999) pp. 70-73 -- Doing More with Less: The Next Generation Virtual Desktop What are the key obstacles that have prevented many mid-market businesses from deploying virtual desktops? How do next-generation virtual desktops provide companies an easier-to-deploy, easier-to-manage and more affordable virtual desktop model.http://www.accelacomm.com/jaw/sfnl/114/51426474/ ___ Matplotlib-users mailing list Matplotlib-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/matplotlib-users
[Matplotlib-users] griddata usage
Hello all Can any one explain me how can I use griddata in matplotlib for 2-d interpolation of polar to cartesian co-ordinates. I have two 1D arrays r and theta of 128 and 64 cells respectively I have a 2D array temperature T(r,theta) with (128, 64) cells. I would like to have Tnew(200,200) cells in cartesian coordinates x = r*cos(th) and y = r*sin(th) for the same I use Tnew = griddata(x,y,T,xi,yi) and x = outer(r,cos(th)) and y=outer(r,sin(th)) where xi,yi = mgrid[x.min():x.max():200j,y.min():y.max():200j] I get a ValueError suggesting that griddata does not like to have 2D arrays of x and y How can I get this to work? Regards Bhargav Vaidya -- Get a FREE DOWNLOAD! and learn more about uberSVN rich system, user administration capabilities and model configuration. Take the hassle out of deploying and managing Subversion and the tools developers use with it. http://p.sf.net/sfu/wandisco-d2d-2 ___ Matplotlib-users mailing list Matplotlib-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/matplotlib-users
Re: [Matplotlib-users] griddata question
Fri, 18 Feb 2011 20:24:31 +0100, Nils Wagner wrote: what is the reason for the white areas in the corners of the interpolation domain? Any idea ? Griddata does not do any extrapolation, and the corners are outside the convex hull of the point set. import numpy as np from scipy.interpolate import griddata BTW, if you're using Scipy's griddata, the Scipy lists might be a better place to ask :) -- The ultimate all-in-one performance toolkit: Intel(R) Parallel Studio XE: Pinpoint memory and threading errors before they happen. Find and fix more than 250 security defects in the development cycle. Locate bottlenecks in serial and parallel code that limit performance. http://p.sf.net/sfu/intel-dev2devfeb ___ Matplotlib-users mailing list Matplotlib-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/matplotlib-users
Re: [Matplotlib-users] griddata question
On Fri, Feb 18, 2011 at 1:24 PM, Nils Wagner nwag...@iam.uni-stuttgart.de wrote: Hi all, what is the reason for the white areas in the corners of the interpolation domain ? Any idea ? The white areas are not bounded by your data points (they are located outside the convex hull of the data points), so the interpolation algorithm would effectively be extrapolating. Ryan -- Ryan May Graduate Research Assistant School of Meteorology University of Oklahoma -- The ultimate all-in-one performance toolkit: Intel(R) Parallel Studio XE: Pinpoint memory and threading errors before they happen. Find and fix more than 250 security defects in the development cycle. Locate bottlenecks in serial and parallel code that limit performance. http://p.sf.net/sfu/intel-dev2devfeb ___ Matplotlib-users mailing list Matplotlib-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/matplotlib-users
[Matplotlib-users] griddata
Hi all, Is it possible to apply griddata to polar coordinates or do I need cartesian coordinates ? http://matplotlib.sourceforge.net/api/mlab_api.html#matplotlib.mlab.griddata Nils -- The ultimate all-in-one performance toolkit: Intel(R) Parallel Studio XE: Pinpoint memory and threading errors before they happen. Find and fix more than 250 security defects in the development cycle. Locate bottlenecks in serial and parallel code that limit performance. http://p.sf.net/sfu/intel-dev2devfeb ___ Matplotlib-users mailing list Matplotlib-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/matplotlib-users
Re: [Matplotlib-users] griddata
On Mon, Feb 14, 2011 at 8:40 AM, Nils Wagner nwag...@iam.uni-stuttgart.de wrote: Hi all, Is it possible to apply griddata to polar coordinates or do I need cartesian coordinates ? http://matplotlib.sourceforge.net/api/mlab_api.html#matplotlib.mlab.griddata You can keep the data in polar coordinates, you just need to pass in the locations of the points in cartesian coordinates: x = r * cos(theta) y = r * sin(theta) Ryan -- Ryan May Graduate Research Assistant School of Meteorology University of Oklahoma -- The ultimate all-in-one performance toolkit: Intel(R) Parallel Studio XE: Pinpoint memory and threading errors before they happen. Find and fix more than 250 security defects in the development cycle. Locate bottlenecks in serial and parallel code that limit performance. http://p.sf.net/sfu/intel-dev2devfeb ___ Matplotlib-users mailing list Matplotlib-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/matplotlib-users
[Matplotlib-users] griddata and masked arrays
Hi, I am trying to use griddata to plot some (irregularly) spaced data as a contour plot, but sometimes ALL the grid it outputs is masked: so no plot. In the docs I read: A masked array is returned if any grid points are outside convex hull defined by input data (no extrapolation is done). but I have no real idea of what does it mean. Any suggestion to troubleshoot / understand what's going on? Thanks! m. -- Download Intel#174; Parallel Studio Eval Try the new software tools for yourself. Speed compiling, find bugs proactively, and fine-tune applications for parallel performance. See why Intel Parallel Studio got high marks during beta. http://p.sf.net/sfu/intel-sw-dev ___ Matplotlib-users mailing list Matplotlib-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/matplotlib-users
Re: [Matplotlib-users] griddata array size limit?
tfoutz99, I occasionally run into this issue as well. At quick glance I suspect it may be related to the limitation listed at: http://www.scipy.org/scipy/scikits/ticket/61 ...but I could be way off base as I'm not sure if the code is derived from the same place. -Erik tfoutz99 wrote: Hi! I am basing my code off the example posted at: http://www.scipy.org/Cookbook/Matplotlib/Gridding_irregularly_spaced_data Gridding irregularly spaced data When I use my own data, I am getting a KeyError (Posted below) However, if I only use a subset of my data (for which the total length=26328), I can get rid of the error: # This subset works # I incremented the final index until I got the error # Length: 19877 x=np.array(R[0:19876]) y=np.array(Z[0:19876]) z=np.array(volt[0:19876]) # And this subset works # I incremented the starting index until I got the error # Length: 19040 x=np.array(R[7288:-1]) y=np.array(Z[7288:-1]) z=np.array(volt[7288:-1]) The weird thing is that these two lengths are different. There doesn't seem to be anything particularly strange about the values near 19876 or 7288. Any ideas? -Tom ##Error Message ### --- 81 zi = griddata(x,y,z,xi,yi) 82 # contour the gridded data, plotting dots at the randomly spaced data points. 83 CS = plt.contour(xi,yi,zi,15,linewidths=0.5,colors='k') /Library/Frameworks/Python.framework/Versions/4.3.0/lib/python2.5/site-packages/matplotlib-0.98.5.2n2-py2.5-macosx-10.3-fat.egg/matplotlib/mlab.pyc in griddata(x, y, z, xi, yi) 2940 xi,yi = np.meshgrid(xi,yi) 2941 # triangulate data - 2942 tri = delaunay.Triangulation(x,y) 2943 # interpolate data 2944 interp = tri.nn_interpolator(z) /Library/Frameworks/Python.framework/Versions/4.3.0/lib/python2.5/site-packages/matplotlib-0.98.5.2n2-py2.5-macosx-10.3-fat.egg/matplotlib/delaunay/triangulate.pyc in __init__(self, x, y) 86 self.triangle_neighbors = delaunay(self.x, self.y) 87 --- 88 self.hull = self._compute_convex_hull() 89 90 def _collapse_duplicate_points(self): /Library/Frameworks/Python.framework/Versions/4.3.0/lib/python2.5/site-packages/matplotlib-0.98.5.2n2-py2.5-macosx-10.3-fat.egg/matplotlib/delaunay/triangulate.pyc in _compute_convex_hull(self) 121 hull = list(edges.popitem()) 122 while edges: -- 123 hull.append(edges.pop(hull[-1])) 124 125 # hull[-1] == hull[0], so remove hull[-1] KeyError: 2559 -- View this message in context: http://www.nabble.com/griddata-array-size-limit--tp24827814p25026351.html Sent from the matplotlib - users mailing list archive at Nabble.com. -- Let Crystal Reports handle the reporting - Free Crystal Reports 2008 30-Day trial. Simplify your report design, integration and deployment - and focus on what you do best, core application coding. Discover what's new with Crystal Reports now. http://p.sf.net/sfu/bobj-july ___ Matplotlib-users mailing list Matplotlib-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/matplotlib-users
[Matplotlib-users] griddata array size limit?
Hi! I am basing my code off the example posted at: http://www.scipy.org/Cookbook/Matplotlib/Gridding_irregularly_spaced_data Gridding irregularly spaced data When I use my own data, I am getting a KeyError (Posted below) However, if I only use a subset of my data (for which the total length=26328), I can get rid of the error: # This subset works # I incremented the final index until I got the error # Length: 19877 x=np.array(R[0:19876]) y=np.array(Z[0:19876]) z=np.array(volt[0:19876]) # And this subset works # I incremented the starting index until I got the error # Length: 19040 x=np.array(R[7288:-1]) y=np.array(Z[7288:-1]) z=np.array(volt[7288:-1]) The weird thing is that these two lengths are different. There doesn't seem to be anything particularly strange about the values near 19876 or 7288. Any ideas? -Tom ##Error Message ### --- 81 zi = griddata(x,y,z,xi,yi) 82 # contour the gridded data, plotting dots at the randomly spaced data points. 83 CS = plt.contour(xi,yi,zi,15,linewidths=0.5,colors='k') /Library/Frameworks/Python.framework/Versions/4.3.0/lib/python2.5/site-packages/matplotlib-0.98.5.2n2-py2.5-macosx-10.3-fat.egg/matplotlib/mlab.pyc in griddata(x, y, z, xi, yi) 2940 xi,yi = np.meshgrid(xi,yi) 2941 # triangulate data - 2942 tri = delaunay.Triangulation(x,y) 2943 # interpolate data 2944 interp = tri.nn_interpolator(z) /Library/Frameworks/Python.framework/Versions/4.3.0/lib/python2.5/site-packages/matplotlib-0.98.5.2n2-py2.5-macosx-10.3-fat.egg/matplotlib/delaunay/triangulate.pyc in __init__(self, x, y) 86 self.triangle_neighbors = delaunay(self.x, self.y) 87 --- 88 self.hull = self._compute_convex_hull() 89 90 def _collapse_duplicate_points(self): /Library/Frameworks/Python.framework/Versions/4.3.0/lib/python2.5/site-packages/matplotlib-0.98.5.2n2-py2.5-macosx-10.3-fat.egg/matplotlib/delaunay/triangulate.pyc in _compute_convex_hull(self) 121 hull = list(edges.popitem()) 122 while edges: -- 123 hull.append(edges.pop(hull[-1])) 124 125 # hull[-1] == hull[0], so remove hull[-1] KeyError: 2559 -- View this message in context: http://www.nabble.com/griddata-array-size-limit--tp24827814p24827814.html Sent from the matplotlib - users mailing list archive at Nabble.com. -- Let Crystal Reports handle the reporting - Free Crystal Reports 2008 30-Day trial. Simplify your report design, integration and deployment - and focus on what you do best, core application coding. Discover what's new with Crystal Reports now. http://p.sf.net/sfu/bobj-july ___ Matplotlib-users mailing list Matplotlib-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/matplotlib-users
Re: [Matplotlib-users] griddata returns nan
plankton wrote: Greetings all, I rotate a vector field and than I tried to interpolate it to a new grid using griddata. CODE: x_grid_unique = unique(x_grid) y_grid_unique = unique(y_grid) x_meshgrid, y_meshgrid = meshgrid(x_grid_unique, y_grid_unique) x_rot_meshgrid = reshape(x_rot, [ len(x_meshgrid[:, 0]), len(x_meshgrid[0, :])] ) y_rot_meshgrid = reshape(y_rot, [ len(x_meshgrid[:, 0]), len(x_meshgrid[0, :])] ) u_rot_meshgrid = reshape(u_rot, [ len(x_meshgrid[:, 0]), len(x_meshgrid[0, :])] ) v_rot_meshgrid = reshape(v_rot, [ len(x_meshgrid[:, 0]), len(x_meshgrid[0, :])] ) u_interpolate = griddata(x_rot, y_rot, u_rot, x_rot_meshgrid, y_rot_meshgrid) v_interpolate = griddata(x_rot, y_rot, v_rot, x_rot_meshgrid, y_rot_meshgrid) I unfortunately griddata returns some nan (It seems that there are multiple occurrences of the same [X,Y] pair in the data). In matlab you can use griddata with additional options e.g. ru = griddata(nx,ny,nu,rx,ry,'linear', {'QJ'}) to fix this, but this seems to be not possible using the griddata function in matplotlib. Is there any other way to avoid a return of nan? For any help many thanks in advance Andreas Problem solved more or less. Griddata produces only at the boundary of the vector field nan, which seems to be the result of my data matrixes u and v. They contain serveral colums and rows with zeros at the boundary, which leads to nan at the boundary. Finaly this is not a great problem and can be fixed easily by adding zeros at the boundary after using griddata. But maybe this can be fixed otherwise e.g. using griddata with parameters, so that it is not necessary to fix the matrix by rewriting the boundary. Therefore, following a sample script, which demonstrates the problem. SAMPLE SCRIPT --CODE-- from pylab import * def rotate(x, y, angle): x_rot = x * cos(angle) - y * sin(angle) y_rot = x * sin(angle) + y * cos(angle) return x_rot, y_rot def generate_new_grid(x_rot, y_rot, x_elements, y_elements): xmin = min(x_rot) xmax = max(x_rot) ymin = min(y_rot) ymax = max(y_rot) x = linspace(xmin, xmax, x_elements) y = linspace(ymin, ymax, y_elements) x_tecplot_vector = zeros(25, float) y_tecplot_vector = zeros(25, float) for i in range(5): first = i *5 last = (i+1) * 5 x_tecplot_vector[first:last] = x y_tecplot_vector[first:last] = y[i] return x_tecplot_vector, y_tecplot_vector # ### u = zeros(25, float) u[12] = 1 v = zeros(25, float) v[11] = 2 x = zeros(5, float) y = zeros(5, float) x = linspace(1, 5, 5) y = linspace(1, 5, 5) x_grid, y_grid= generate_new_grid(x, y, 5, 5) print y_grid # ### angle = 0.1 x_rot, y_rot = rotate(x_grid, y_grid, angle) x_elements = 5 y_elements = 5 x_grid, y_grid= generate_new_grid(x_rot, y_rot, x_elements, y_elements) u_rot, v_rot = rotate(u, v, angle) x_meshgrid, y_meshgrid = meshgrid(x_grid, y_grid) x_rot_meshgrid = reshape(x_grid, [ 5, 5] ) y_rot_meshgrid = reshape(y_grid, [ 5, 5] ) u_rot_meshgrid = reshape(u_rot, [ 5, 5] ) u_interpolate = griddata(x_rot, y_rot, u_rot, x_rot_meshgrid, y_rot_meshgrid) #save('test.dat', u_interpolate) print u_interpolate --CODE-- -- View this message in context: http://www.nabble.com/griddata-returns-nan-tp24537481p24623042.html Sent from the matplotlib - users mailing list archive at Nabble.com. -- ___ Matplotlib-users mailing list Matplotlib-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/matplotlib-users
[Matplotlib-users] griddata returns nan
Greetings all, I rotate a vector field and than I tried to interpolate it to a new grid using griddata. CODE: x_grid_unique = unique(x_grid) y_grid_unique = unique(y_grid) x_meshgrid, y_meshgrid = meshgrid(x_grid_unique, y_grid_unique) x_rot_meshgrid = reshape(x_rot, [ len(x_meshgrid[:, 0]), len(x_meshgrid[0, :])] ) y_rot_meshgrid = reshape(y_rot, [ len(x_meshgrid[:, 0]), len(x_meshgrid[0, :])] ) u_rot_meshgrid = reshape(u_rot, [ len(x_meshgrid[:, 0]), len(x_meshgrid[0, :])] ) v_rot_meshgrid = reshape(v_rot, [ len(x_meshgrid[:, 0]), len(x_meshgrid[0, :])] ) u_interpolate = griddata(x_rot, y_rot, u_rot, x_rot_meshgrid, y_rot_meshgrid) v_interpolate = griddata(x_rot, y_rot, v_rot, x_rot_meshgrid, y_rot_meshgrid) I unfortunately griddata returns some nan (It seems that there are multiple occurrences of the same [X,Y] pair in the data). In matlab you can use griddata with additional options e.g. ru = griddata(nx,ny,nu,rx,ry,'linear', {'QJ'}) to fix this, but this seems to be not possible using the griddata function in matplotlib. Is there any other way to avoid a return of nan? For any help many thanks in advance Andreas -- View this message in context: http://www.nabble.com/griddata-returns-nan-tp24537481p24537481.html Sent from the matplotlib - users mailing list archive at Nabble.com. -- Enter the BlackBerry Developer Challenge This is your chance to win up to $100,000 in prizes! For a limited time, vendors submitting new applications to BlackBerry App World(TM) will have the opportunity to enter the BlackBerry Developer Challenge. See full prize details at: http://p.sf.net/sfu/Challenge ___ Matplotlib-users mailing list Matplotlib-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/matplotlib-users
Re: [Matplotlib-users] Griddata
I ve a problem with the use of griddata. I have a grid of x,y with value z. the grid have 4500 points I would like to have a rigular grid of 1500 points. I try the function zi = griddata(x,y,z,xi,yi) but I have an error too many indices. I don't understant why!!! x,y,z,xi and yi are numpy array with 1 column. Sorry for my bad english!! Thanks Josh Lawrence-2 wrote: Greetings all, In using the function griddata in mlab.py, I think I have found a bug. The following line in mlab.py errors for me. I supply it an xi and yi that have shape (N,1). I have surface data, but I only care about the variation in one direction. In mlab, when it gets to this line (2956 in svn revision 7040): if min(xo[1:]-xo[0:-1]) 0 or min(yo[1:]-yo[0:-1]) 0: raise ValueError, 'output grid defined by xi,yi must be monotone increasing' the result is an error. That is, I get the following: ValueError: min() arg is an empty sequence A couple of things. First, if I make my variation in x to be 2 points (x = 0 for the case I'm interested in--so I just have both values of x be zero), I do not get this error and I believe the result works. So, it seems that there should be some handling of the case that there are only 1 point in either x or y direction. Second, is it better to use the builtin python function min, or should numpy.min be used instead? Cheers, Josh Lawrence Ph.D. Student Clemson University -- Stay on top of everything new and different, both inside and around Java (TM) technology - register by April 22, and save $200 on the JavaOne (SM) conference, June 2-5, 2009, San Francisco. 300 plus technical and hands-on sessions. Register today. Use priority code J9JMT32. http://p.sf.net/sfu/p ___ Matplotlib-users mailing list Matplotlib-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/matplotlib-users -- View this message in context: http://www.nabble.com/Griddata-tp23083610p23929245.html Sent from the matplotlib - users mailing list archive at Nabble.com. -- Crystal Reports - New Free Runtime and 30 Day Trial Check out the new simplified licensing option that enables unlimited royalty-free distribution of the report engine for externally facing server and web deployment. http://p.sf.net/sfu/businessobjects ___ Matplotlib-users mailing list Matplotlib-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/matplotlib-users
[Matplotlib-users] Griddata
Greetings all, In using the function griddata in mlab.py, I think I have found a bug. The following line in mlab.py errors for me. I supply it an xi and yi that have shape (N,1). I have surface data, but I only care about the variation in one direction. In mlab, when it gets to this line (2956 in svn revision 7040): if min(xo[1:]-xo[0:-1]) 0 or min(yo[1:]-yo[0:-1]) 0: raise ValueError, 'output grid defined by xi,yi must be monotone increasing' the result is an error. That is, I get the following: ValueError: min() arg is an empty sequence A couple of things. First, if I make my variation in x to be 2 points (x = 0 for the case I'm interested in--so I just have both values of x be zero), I do not get this error and I believe the result works. So, it seems that there should be some handling of the case that there are only 1 point in either x or y direction. Second, is it better to use the builtin python function min, or should numpy.min be used instead? Cheers, Josh Lawrence Ph.D. Student Clemson University -- Stay on top of everything new and different, both inside and around Java (TM) technology - register by April 22, and save $200 on the JavaOne (SM) conference, June 2-5, 2009, San Francisco. 300 plus technical and hands-on sessions. Register today. Use priority code J9JMT32. http://p.sf.net/sfu/p ___ Matplotlib-users mailing list Matplotlib-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/matplotlib-users
Re: [Matplotlib-users] Griddata
Josh Lawrence wrote: Greetings all, In using the function griddata in mlab.py, I think I have found a bug. The following line in mlab.py errors for me. I supply it an xi and yi that have shape (N,1). I have surface data, but I only care about the variation in one direction. In mlab, when it gets to this line (2956 in svn revision 7040): if min(xo[1:]-xo[0:-1]) 0 or min(yo[1:]-yo[0:-1]) 0: raise ValueError, 'output grid defined by xi,yi must be monotone increasing' the result is an error. That is, I get the following: ValueError: min() arg is an empty sequence A couple of things. First, if I make my variation in x to be 2 points (x = 0 for the case I'm interested in--so I just have both values of x be zero), I do not get this error and I believe the result works. So, it seems that there should be some handling of the case that there are only 1 point in either x or y direction. Second, is it better to use the builtin python function min, or should numpy.min be used instead? Cheers, Josh Lawrence Ph.D. Student Clemson University Josh: griddata currently only works for 2-D output grids. It may be possible to modify it to work with 1-D data, but that was not the original intent of the function. -Jeff -- Jeffrey S. Whitaker Phone : (303)497-6313 Meteorologist FAX: (303)497-6449 NOAA/OAR/PSD R/PSD1Email : jeffrey.s.whita...@noaa.gov 325 BroadwayOffice : Skaggs Research Cntr 1D-113 Boulder, CO, USA 80303-3328 Web: http://tinyurl.com/5telg -- Stay on top of everything new and different, both inside and around Java (TM) technology - register by April 22, and save $200 on the JavaOne (SM) conference, June 2-5, 2009, San Francisco. 300 plus technical and hands-on sessions. Register today. Use priority code J9JMT32. http://p.sf.net/sfu/p ___ Matplotlib-users mailing list Matplotlib-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/matplotlib-users
[Matplotlib-users] griddata performance
Hi, I would like to interpolate an array of shape (801,676) to regularily spaced datapoints using griddata. This interpolation is quick if the (x,y) supporting points are computed as X,Y = meshgrid(x,y). If this condition is not fullfilled the delaunay triangulation is extremely slow, i.e. not useable. Is this a known property of the used triangulation? The triangulation can be performed with matlab without any problems. Armin -- 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 Matplotlib-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/matplotlib-users
Re: [Matplotlib-users] griddata performance
Armin Moser wrote: Hi, I would like to interpolate an array of shape (801,676) to regularily spaced datapoints using griddata. This interpolation is quick if the (x,y) supporting points are computed as X,Y = meshgrid(x,y). If this condition is not fullfilled the delaunay triangulation is extremely slow, i.e. not useable. Is this a known property of the used triangulation? The triangulation can be performed with matlab without any problems. Armin Armin: You could try installing the natgrid toolkit and see if that speeds up griddata at all. If not, please post a test script with data and maybe we can figure out what is going on. -Jeff -- Jeffrey S. Whitaker Phone : (303)497-6313 Meteorologist FAX: (303)497-6449 NOAA/OAR/PSD R/PSD1Email : jeffrey.s.whita...@noaa.gov 325 BroadwayOffice : 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 Matplotlib-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/matplotlib-users
Re: [Matplotlib-users] griddata performance
On Fri, Feb 20, 2009 at 8:11 AM, Armin Moser armin.mo...@student.tugraz.atwrote: Hi, I would like to interpolate an array of shape (801,676) to regularily spaced datapoints using griddata. This interpolation is quick if the (x,y) supporting points are computed as X,Y = meshgrid(x,y). If this condition is not fullfilled the delaunay triangulation is extremely slow, i.e. not useable. Is this a known property of the used triangulation? The triangulation can be performed with matlab without any problems. If you're not using meshgrid, how do you compute x,y? A small complete example would be helpful. Ryan -- Ryan May Graduate Research Assistant School of Meteorology University of Oklahoma Sent from: Norman Oklahoma United States. -- 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 Matplotlib-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/matplotlib-users
Re: [Matplotlib-users] griddata performance
Jeff Whitaker wrote: Armin Moser wrote: Hi, I would like to interpolate an array of shape (801,676) to regularily spaced datapoints using griddata. This interpolation is quick if the (x,y) supporting points are computed as X,Y = meshgrid(x,y). If this condition is not fullfilled the delaunay triangulation is extremely slow, i.e. not useable. Is this a known property of the used triangulation? The triangulation can be performed with matlab without any problems. Armin Armin: You could try installing the natgrid toolkit and see if that speeds up griddata at all. If not, please post a test script with data and maybe we can figure out what is going on. I have already tried natgrid and it didn't improve the situation. As suggested I append a script demonstrating the problem. Thanks Armin --8- from numpy import * from pylab import * import time deg2rad = pi/180.0 ai = 0.12*deg2rad x = linspace(13,40,676) y = linspace(10,22,801) x = x*deg2rad y = y*deg2rad [x,y] = meshgrid(x,y) z = (x**2+y**2) xi = linspace(x.min(),x.max(),x.shape[1]) yi = linspace(y.min(),y.max(),y.shape[0]) tic= time.time() zi = griddata(x.flatten(),y.flatten(),z.flatten(),xi,yi) toc = time.time() print toc-tic fac = 2*pi/1.2681 nx = fac * (cos(y)*cos(x) - cos(ai)) ny = fac * (cos(y)*sin(x)) nz = fac * (sin(y) + sin(ai)) np = sqrt(nx**2 + ny**2) z = (np**2+nz**2)*exp(-0.001*nz) xi = linspace(np.min(),np.max(),x.shape[1]) yi = linspace(nz.min(),nz.max(),y.shape[0]) tic = time.time() zi = griddata(np.flatten(),nz.flatten(),z.flatten(),xi,yi) toc = time.time() print toc-tic -- 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 Matplotlib-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/matplotlib-users
Re: [Matplotlib-users] griddata performance
Armin Moser wrote: Jeff Whitaker wrote: Armin Moser wrote: Hi, I would like to interpolate an array of shape (801,676) to regularily spaced datapoints using griddata. This interpolation is quick if the (x,y) supporting points are computed as X,Y = meshgrid(x,y). If this condition is not fullfilled the delaunay triangulation is extremely slow, i.e. not useable. Is this a known property of the used triangulation? The triangulation can be performed with matlab without any problems. Armin Armin: You could try installing the natgrid toolkit and see if that speeds up griddata at all. If not, please post a test script with data and maybe we can figure out what is going on. I have already tried natgrid and it didn't improve the situation. As suggested I append a script demonstrating the problem. Thanks Armin Armin: On my mac, your two benchmarks take 15 and 14 seconds. Do you consider that too slow? Perhaps this is just a toy example to test griddata, but I assume you realize that you wouldn't normally use griddata to interpolate data on one regular grid to another regular grid. griddata is strictly for interpolating scatter data (not on a regular mesh) to a regular mesh. -Jeff --8- from numpy import * from pylab import * import time deg2rad = pi/180.0 ai = 0.12*deg2rad x = linspace(13,40,676) y = linspace(10,22,801) x = x*deg2rad y = y*deg2rad [x,y] = meshgrid(x,y) z = (x**2+y**2) xi = linspace(x.min(),x.max(),x.shape[1]) yi = linspace(y.min(),y.max(),y.shape[0]) tic= time.time() zi = griddata(x.flatten(),y.flatten(),z.flatten(),xi,yi) toc = time.time() print toc-tic fac = 2*pi/1.2681 nx = fac * (cos(y)*cos(x) - cos(ai)) ny = fac * (cos(y)*sin(x)) nz = fac * (sin(y) + sin(ai)) np = sqrt(nx**2 + ny**2) z = (np**2+nz**2)*exp(-0.001*nz) xi = linspace(np.min(),np.max(),x.shape[1]) yi = linspace(nz.min(),nz.max(),y.shape[0]) tic = time.time() zi = griddata(np.flatten(),nz.flatten(),z.flatten(),xi,yi) toc = time.time() print toc-tic -- Jeffrey S. Whitaker Phone : (303)497-6313 Meteorologist FAX: (303)497-6449 NOAA/OAR/PSD R/PSD1Email : jeffrey.s.whita...@noaa.gov 325 BroadwayOffice : 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 Matplotlib-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/matplotlib-users
Re: [Matplotlib-users] griddata performance
Jeff Whitaker wrote: Armin Moser wrote: Jeff Whitaker wrote: Armin Moser wrote: Hi, I would like to interpolate an array of shape (801,676) to regularily spaced datapoints using griddata. This interpolation is quick if the (x,y) supporting points are computed as X,Y = meshgrid(x,y). If this condition is not fullfilled the delaunay triangulation is extremely slow, i.e. not useable. Is this a known property of the used triangulation? The triangulation can be performed with matlab without any problems. Armin Armin: You could try installing the natgrid toolkit and see if that speeds up griddata at all. If not, please post a test script with data and maybe we can figure out what is going on. I have already tried natgrid and it didn't improve the situation. As suggested I append a script demonstrating the problem. Thanks Armin Armin: On my mac, your two benchmarks take 15 and 14 seconds. Do you consider that too slow? Jeff, I got 10 s and 8 s on my Thinkpad--but that was without natgrid. When I installed natgrid, the benchmark was taking so long I killed the window. I'm running 32-bit Ubuntu. Eric Perhaps this is just a toy example to test griddata, but I assume you realize that you wouldn't normally use griddata to interpolate data on one regular grid to another regular grid. griddata is strictly for interpolating scatter data (not on a regular mesh) to a regular mesh. -Jeff --8- from numpy import * from pylab import * import time deg2rad = pi/180.0 ai = 0.12*deg2rad x = linspace(13,40,676) y = linspace(10,22,801) x = x*deg2rad y = y*deg2rad [x,y] = meshgrid(x,y) z = (x**2+y**2) xi = linspace(x.min(),x.max(),x.shape[1]) yi = linspace(y.min(),y.max(),y.shape[0]) tic= time.time() zi = griddata(x.flatten(),y.flatten(),z.flatten(),xi,yi) toc = time.time() print toc-tic fac = 2*pi/1.2681 nx = fac * (cos(y)*cos(x) - cos(ai)) ny = fac * (cos(y)*sin(x)) nz = fac * (sin(y) + sin(ai)) np = sqrt(nx**2 + ny**2) z = (np**2+nz**2)*exp(-0.001*nz) xi = linspace(np.min(),np.max(),x.shape[1]) yi = linspace(nz.min(),nz.max(),y.shape[0]) tic = time.time() zi = griddata(np.flatten(),nz.flatten(),z.flatten(),xi,yi) toc = time.time() print toc-tic -- 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 Matplotlib-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/matplotlib-users
Re: [Matplotlib-users] griddata performance
Jeff Whitaker wrote: Armin Moser wrote: Jeff Whitaker wrote: Armin Moser wrote: Hi, I would like to interpolate an array of shape (801,676) to regularily spaced datapoints using griddata. This interpolation is quick if the (x,y) supporting points are computed as X,Y = meshgrid(x,y). If this condition is not fullfilled the delaunay triangulation is extremely slow, i.e. not useable. Is this a known property of the used triangulation? The triangulation can be performed with matlab without any problems. Armin Armin: You could try installing the natgrid toolkit and see if that speeds up griddata at all. If not, please post a test script with data and maybe we can figure out what is going on. I have already tried natgrid and it didn't improve the situation. As suggested I append a script demonstrating the problem. Thanks Armin Armin: On my mac, your two benchmarks take 15 and 14 seconds. Do you consider that too slow? No definitely not but up to now I always killed the process (after more than 10 minutes). I tried the script again and it worked... I have to check the original on monday at work. Perhaps this is just a toy example to test griddata, but I assume you realize that you wouldn't normally use griddata to interpolate data on one regular grid to another regular grid. griddata is strictly for interpolating scatter data (not on a regular mesh) to a regular mesh. Yes I do, but the supporting points of the second example are not on a regular grid. Thanks a lot Armin -- 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 Matplotlib-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/matplotlib-users
Re: [Matplotlib-users] griddata performance
Eric Firing wrote: Jeff Whitaker wrote: Armin Moser wrote: Jeff Whitaker wrote: Armin Moser wrote: Hi, I would like to interpolate an array of shape (801,676) to regularily spaced datapoints using griddata. This interpolation is quick if the (x,y) supporting points are computed as X,Y = meshgrid(x,y). If this condition is not fullfilled the delaunay triangulation is extremely slow, i.e. not useable. Is this a known property of the used triangulation? The triangulation can be performed with matlab without any problems. Armin Armin: You could try installing the natgrid toolkit and see if that speeds up griddata at all. If not, please post a test script with data and maybe we can figure out what is going on. I have already tried natgrid and it didn't improve the situation. As suggested I append a script demonstrating the problem. Thanks Armin Armin: On my mac, your two benchmarks take 15 and 14 seconds. Do you consider that too slow? I got 10 s and 8 s on my Thinkpad--but that was without natgrid. When I installed natgrid, the benchmark was taking so long I killed the window. Thats the behaviour I observed (on Windows and Linux) with and without natgrid. I'm very puzzled at the moment. Thanks a lot Armin -- 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 Matplotlib-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/matplotlib-users
Re: [Matplotlib-users] griddata performance
Jeff Whitaker wrote: Armin Moser wrote: Jeff Whitaker wrote: Armin Moser wrote: Hi, I would like to interpolate an array of shape (801,676) to regularily spaced datapoints using griddata. This interpolation is quick if the (x,y) supporting points are computed as X,Y = meshgrid(x,y). If this condition is not fullfilled the delaunay triangulation is extremely slow, i.e. not useable. Is this a known property of the used triangulation? The triangulation can be performed with matlab without any problems. Armin Armin: You could try installing the natgrid toolkit and see if that speeds up griddata at all. If not, please post a test script with data and maybe we can figure out what is going on. I have already tried natgrid and it didn't improve the situation. As suggested I append a script demonstrating the problem. Reducing the original grid from 676x801 to 100x120, I get benchmarks of about 6 seconds with natgrid and 0.15 s with Robert's delaunay. This seems quite repeatable. I also tried randomizing x and y in the first benchmark with natgrid, and it made only a slight difference. Eric Thanks Armin Armin: On my mac, your two benchmarks take 15 and 14 seconds. Do you consider that too slow? Perhaps this is just a toy example to test griddata, but I assume you realize that you wouldn't normally use griddata to interpolate data on one regular grid to another regular grid. griddata is strictly for interpolating scatter data (not on a regular mesh) to a regular mesh. -Jeff --8- from numpy import * from pylab import * import time deg2rad = pi/180.0 ai = 0.12*deg2rad x = linspace(13,40,676) y = linspace(10,22,801) x = x*deg2rad y = y*deg2rad [x,y] = meshgrid(x,y) z = (x**2+y**2) xi = linspace(x.min(),x.max(),x.shape[1]) yi = linspace(y.min(),y.max(),y.shape[0]) tic= time.time() zi = griddata(x.flatten(),y.flatten(),z.flatten(),xi,yi) toc = time.time() print toc-tic fac = 2*pi/1.2681 nx = fac * (cos(y)*cos(x) - cos(ai)) ny = fac * (cos(y)*sin(x)) nz = fac * (sin(y) + sin(ai)) np = sqrt(nx**2 + ny**2) z = (np**2+nz**2)*exp(-0.001*nz) xi = linspace(np.min(),np.max(),x.shape[1]) yi = linspace(nz.min(),nz.max(),y.shape[0]) tic = time.time() zi = griddata(np.flatten(),nz.flatten(),z.flatten(),xi,yi) toc = time.time() print toc-tic -- 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 Matplotlib-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/matplotlib-users