[SciPy-User] 1-d Interpolation of unevenly spaced data
Dybbroe Adam
Adam.Dybbroe at smhi.se
Wed Feb 2 05:36:16 EST 2011
Thanks for the kind and useful help.
I am using the InterpolatedUnivariateSpline now, after having sorted the data and removed for duplicates.
-Adam
On 2011-02-02 01:09, Charles R Harris wrote:
On Tue, Feb 1, 2011 at 4:23 PM, Dybbroe Adam <Adam.Dybbroe at smhi.se> wrote:
Thanks.
Ok, I have stored my data in an npz-file (attached).
You should be able to run the following code (with the npz file in the
same directory from where you run):
import numpy as np
outfile = './ipol_test_arrays.npz'
from scipy.interpolate import splrep, splev
# Load data and try do the spline interpolation:
npzfile = np.load(outfile)
wvl = npzfile['wvl']
resp = npzfile['resp']
xspl = np.linspace(wvl[0], wvl[-1], 300)
tck = splrep(wvl, resp)
resp_ipol = splev(xspl, tck)
Here is what I get:
In [1]: run scipy_ipol_test_ext.py
---------------------------------------------------------------------------
ValueError Traceback (most recent call last)
/local_disk/laptop/NowcastingSaf/radiationStuff/test/scipy_ipol_test_ext.py
in <module>()
14 xspl = np.linspace(wvl[0], wvl[-1], 300)
15
---> 16 tck = splrep(wvl, resp)
17 resp_ipol = splev(xspl, tck)
18
/home/a000680/usr/lib64/python2.5/site-packages/scipy/interpolate/fitpack.pyc
in splrep(x, y, w, xb, xe, k, task, s, t, full_output, per, quiet)
416 else:
417 try:
--> 418 raise _iermess[ier][1],_iermess[ier][0]
419 except KeyError:
420 raise _iermess['unknown'][1],_iermess['unknown'][0]
ValueError: Error on input data
WARNING: Failure executing file: <scipy_ipol_test_ext.py>
The contents of wvl need to be in sorted order, wvl[16] is out of order. Further, I wouldn't recommend letting splrep choose the knot points. A plain old spline with not-a-knot end conditions might be preferable to splrep.
Chuck
_______________________________________________
SciPy-User mailing list
SciPy-User at scipy.org
http://mail.scipy.org/mailman/listinfo/scipy-user
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.scipy.org/pipermail/scipy-user/attachments/20110202/3da7f113/attachment.html>
More information about the SciPy-User
mailing list