python interpolation and data comparison

738 views Asked by At

So I want to read in multiple sets of data and compare them to one set of data to do a grid resolution study. I have a basic script set up to read in my data from the dump file from my CFD code. It interpolates between my data set and works fine but it only plots the spline between my data.

    f = open('x_data.dat','r')
    xd=np.genfromtxt(f)
    f.close() 

    f = open('y_data.dat','r')
    yd=np.genfromtxt(f)
    f.close() 

    plt.plot(xd,yd,'o')

    t = np.arange(xd.shape[0], dtype=float)
    t /= t[-1]
    nt = np.linspace(0, 1, 100)
    x1 = scipy.interpolate.spline(t, xd, nt)
    y1 = scipy.interpolate.spline(t, yd, nt)
    plt.plot(x1, y1, label='range_spline')

    plt.show()

I want to keep that spline data and use it as a f(x,y) to plug other x,y data into and check the surface location to what my "exact solution" should be. The data from my other data sets is not coincident to the exact solution data, hence the need to interpolate. Is there a way to store the spline data between each point so I can get a f(x,y) I can use like a function? Also, are these splines cubic. The don't look cubic and I could not find a simple answer.

1

There are 1 answers

0
ev-br On

spline is a combination of splmake and spleval, all three undocumented. Best not use them directly. interp1d with kind=cubic would use these routines under the hood.

For constructing a spline object for subsequent reuse, use splrep (splprep for parametric splines) / splev, or UnivariateSpline.