1 pièce(s) jointe(s)
Interpolation d'une surface avec des splines
Bonjour
J'essaye d'interpoler une surface par des splines. J'utilise les fonction bisplrep et bisplev mais j'ai une erreur.
Voici mon code :
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44
|
#!/usr/bin/python
# -*- coding=utf-8 -*-
import scipy as sp
nx = 29
ny = 34
def spline(data):
#from scipy.interpolate import BivariateSpline
from scipy.interpolate import bisplrep, bisplev
# data
x, y, z = data.transpose()
m = nx
print("s = [{0}:{1}]".format(m-sp.sqrt(2.*m), m + sp.sqrt(2.*m)))
# create mgrid type object
gx = x.reshape( nx, ny)
gy = y.reshape( nx, ny)
gz = z.reshape( nx, ny)
# create spline object
tck = bisplrep( gx, gy, gz)
# new grid
xn, yn = sp.mgrid[x.min():x.max():50j,y.min():y.max():50j]
zspline = bisplev( xn[:,0], yn[0,:], tck)
from mpl_toolkits.mplot3d import Axes3D
import matplotlib.pyplot as plt
fig = plt.figure()
ax = Axes3D(fig)
ax.plot_wireframe( gx, gy, gz)
ax.plot_wireframe( xn, yn, zspline)
plt.show()
if __name__ == "__main__":
# load data
data = sp.loadtxt("resultats.dat", usecols = (0,1,3))
spline(data) |
Et voici l'erreur que j'obtient :
Code:
1 2 3 4 5 6 7 8 9
|
Traceback (most recent call last):
File "interp2D.py", line 56, in <module>
spline(data)
File "interp2D.py", line 26, in spline
tck = bisplrep( gx, gy, gz)
File "/usr/lib/python2.7/dist-packages/scipy/interpolate/fitpack.py", line 782, in bisplrep
tx,ty,nxest,nyest,wrk,lwrk1,lwrk2)
TypeError: integer argument expected, got float |
J'ai essayé d'exécuter le code proposé sur cette page : doc scipy bisplrep et ça fonctionne très bien ...
Une idée ?
J'ai mis le fichier resultats.dat en pièce jointe sauf que j'ai du l'appeler resultats.txt pour qu'il soit accepter.
Merci