[SciPy-User] [SciPy-user] mgrid format from unstructured data

nicky van foreest vanforeest@gmail....
Thu Mar 3 14:13:08 CST 2011


Hi Sloan,

Thanks for the hint.

bye

Nicky

On 2 March 2011 11:56, Sloan Lindsey <sloan.lindsey@gmail.com> wrote:
> Hi,
> on mvsplines:
> Take a look at http://docs.scipy.org/doc/scipy/reference/generated/scipy.interpolate.griddata.html#scipy.interpolate.griddata
> There is a linear version too.
>
> For the initial question: here is a snippit that works :
> import scipy.interpolate as inter
> import numpy as np
> import matplotlib.pyplot as plt
> datax,datay,dataz = np.genfromtxt('mydata.blah', skip_header=1, unpack=True)
> points = np.array([datax,datay]).T
> nearest = inter.NearestNDInterpolator(points,dataz)
> linear = inter.LinearNDInterpolator(points,dataz,fill_value=0.0)
> curvey = inter.CloughTocher2DInterpolator(points,dataz, fill_value =
> 0.0) #careful about the boundary conditions
>
> #now you have 3 interpolants. To determine dataz @ datax,datay
> value = curvey(datax,datay)
>
> #if you want a grid so that you can plot your interpolation:
> xrange = np.arange(-10.0, 100.0, 0.05)
> yrange = np.arange(-100.0, 100.0, 0.05)
> mesh = np.meshgrid(xrange,yrange)
> a_int_mesh = curvey(mesh)
> plt.imshow(Zn-Zno)
> plt.show
>
> This works for un ordered data.
> Sloan
>
> On Tue, Mar 1, 2011 at 8:53 PM, nicky van foreest <vanforeest@gmail.com> wrote:
>> Hi,
>>
>> In relation to this topic: does anybody know of  a scipy
>> implementation for multivariate splines?
>>
>> bye
>>
>> Nicky
>>
>> On 1 March 2011 12:51, Peter Combs <peter.combs@berkeley.edu> wrote:
>>> On Feb 23, 2011, at 1:49 AM, Spiffalizer wrote:
>>>> I have found some examples that looks like this
>>>> x,y = np.mgrid[-1:1:10j,-1:1:10j]
>>>> z = (x+y)*np.exp(-6.0*(x*x+y*y))
>>>> xnew,ynew = np.mgrid[-1:1:3j,-1:1:3j]
>>>> tck = interpolate.bisplrep(x,y,z,s=0)
>>>> znew = interpolate.bisplev(xnew[:,0],ynew[0,:],tck)
>>>>
>>>>
>>>> So my question really is how to sort/convert my input to a format that can
>>>> be used by the interpolate function?
>>>
>>> I use the LSQBivariateSpline functions:
>>>
>>> import numpy as np
>>> import scipy.interpolate as interp
>>>
>>> num_knots = int(floor(sqrt(len(z))))
>>> xknots = np.linspace(xmin, xmax, n)
>>> yknots = np.linspace(ymin, ymax, n)
>>> interpolator = interp.LSQBivariateSpline(x, y, z, xknots, yknots)
>>> znew = interpolator.ev(xnew, ynew)
>>>
>>> The object orientation is useful for my applications, for reasons that I no longer quite remember.  Looking through the documentation for bisplrep, though, it doesn't seem like you need to worry about the order that the points are in. You might try something like:
>>>
>>> xknots = list(set(x))
>>> yknots = list(set(y))
>>> tck = interpolate.bisplrep(x,y,z, task=-1, tx = xknots, ty=yknots)
>>>
>>> but my understanding of the bisplrep function is hazy at best, so probably best to check it with data you already know the answer.
>>>
>>> Peter Combs
>>> peter.combs@berkeley.edu
>>>
>>>
>>> _______________________________________________
>>> SciPy-User mailing list
>>> SciPy-User@scipy.org
>>> http://mail.scipy.org/mailman/listinfo/scipy-user
>>>
>> _______________________________________________
>> SciPy-User mailing list
>> SciPy-User@scipy.org
>> http://mail.scipy.org/mailman/listinfo/scipy-user
>>
> _______________________________________________
> SciPy-User mailing list
> SciPy-User@scipy.org
> http://mail.scipy.org/mailman/listinfo/scipy-user
>


More information about the SciPy-User mailing list